diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..16bd810a18 --- /dev/null +++ b/.clang-format @@ -0,0 +1,7 @@ +--- +Language: Cpp +BasedOnStyle: LLVM +SortIncludes: false +Standard: Cpp11 +TabWidth: 2 +UseTab: Never diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..0d1fd1c33b --- /dev/null +++ b/.flake8 @@ -0,0 +1,19 @@ +[flake8] +max_line_length = 88 +ignore = + C408 # Unnecessary dict/list/tuple call - rewrite as a literal + E203 # whitespace before ':' - doesn't work well with black + E225 # missing whitespace around operator - let black worry about that + E262 # inline comment should start with '# ' + E265 # block comment should start with '# ' + E266 # too many leading '#' for block comment + E302 # expected 2 blank lines, found 1 + E402 # module level import not at top of file + E501 # line too long - let black handle that + E711 # comparison to None should be + E712 # comparison to False/True should be + E741 # ambiguous variable name + F405 # may be undefined, or defined from star imports + W291 # trailing + W503 # line break occurred before a binary operator - let black worry about that + W504 # line break occurred adter a binary operator - let black worry about that diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000000..160503aefc --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1 @@ +8c475073defe4add51fd6bba2b7e41a23f9dc55b diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 04284d7d08..8c8575bd3a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout repository contents - uses: actions/checkout@v2 + uses: actions/checkout@v5 - name: Build run: docker run -e WORK_DIR="$PWD" -v $PWD:$PWD ubuntu:20.04 $PWD/.github/workflows/start.sh diff --git a/.github/workflows/check-crlf.yml b/.github/workflows/check-crlf.yml index e6ec0e623c..abeaad3dc7 100644 --- a/.github/workflows/check-crlf.yml +++ b/.github/workflows/check-crlf.yml @@ -8,13 +8,13 @@ on: [push, pull_request] jobs: Check-CRLF: name: verify that only LF linefeeds are used - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - name: Checkout repository contents - uses: actions/checkout@v1 + uses: actions/checkout@v5 - name: Use action to check for CRLF endings - uses: erclu/check-crlf@v1.2.0 + uses: erclu/check-crlf@master with: # ignore directories containing *.pdf and *.tab exclude: msautotest/misc/data/ /msautotest/renderers/expected/ \ No newline at end of file diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml new file mode 100644 index 0000000000..64ceb3d2f9 --- /dev/null +++ b/.github/workflows/code_checks.yml @@ -0,0 +1,19 @@ +name: Code Checks + +on: [push, pull_request] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + + linting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-python@v4 + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/coverity-scan.yml b/.github/workflows/coverity-scan.yml index aecc58954c..ffb0e97432 100644 --- a/.github/workflows/coverity-scan.yml +++ b/.github/workflows/coverity-scan.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-20.04 if: github.repository == 'MapServer/MapServer' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Install Libraries run: | diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml index 1066452292..cc19fa7982 100644 --- a/.github/workflows/cppcheck.yml +++ b/.github/workflows/cppcheck.yml @@ -9,7 +9,7 @@ jobs: if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')" steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v5 - name: Install Requirements run: | diff --git a/.github/workflows/irc_notify.yml b/.github/workflows/irc_notify.yml index d93f673efd..de7bc58a42 100644 --- a/.github/workflows/irc_notify.yml +++ b/.github/workflows/irc_notify.yml @@ -16,7 +16,7 @@ jobs: #if: github.repository == 'MapServer/MapServer' steps: - name: irc push - uses: rectalogic/notify-irc@v1 + uses: rectalogic/notify-irc@v2 if: github.event_name == 'push' with: channel: "#mapserver" @@ -26,7 +26,7 @@ jobs: ${{ github.actor }} pushed ${{ github.event.ref }} ${{ github.event.compare }} ${{ join(github.event.commits.*.message) }} - name: irc pull request - uses: rectalogic/notify-irc@v1 + uses: rectalogic/notify-irc@v2 if: github.event_name == 'pull_request' with: channel: "#mapserver" @@ -35,7 +35,7 @@ jobs: message: | ${{ github.actor }} opened PR ${{ github.event.pull_request.html_url }} - name: irc tag created - uses: rectalogic/notify-irc@v1 + uses: rectalogic/notify-irc@v2 if: github.event_name == 'create' && github.event.ref_type == 'tag' with: channel: "#mapserver" diff --git a/.github/workflows/start.sh b/.github/workflows/start.sh index c26bb98210..cf7aaca310 100755 --- a/.github/workflows/start.sh +++ b/.github/workflows/start.sh @@ -4,7 +4,7 @@ set -e apt-get update -y -export BUILD_NAME=PHP_7.4_WITH_PROJ8 +export BUILD_NAME=PHP_8.1_WITH_PROJ8 #export PYTHON_VERSION=3.6 export PYTHON_VERSION=system @@ -12,11 +12,14 @@ LANG=en_US.UTF-8 export LANG DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ sudo locales tzdata software-properties-common python3-dev python3-pip python3-setuptools git curl \ - apt-transport-https ca-certificates gnupg software-properties-common wget \ - php-dev php-xml php-mbstring && \ + apt-transport-https ca-certificates gnupg software-properties-common wget +#install PHP 8.1 +DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:ondrej/php -y +DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + sudo php8.1-dev php8.1-xml php8.1-mbstring && \ echo "$LANG UTF-8" > /etc/locale.gen && \ dpkg-reconfigure --frontend=noninteractive locales && \ - update-locale LANG=$LANG + update-locale LANG=$LANG USER=root export USER @@ -106,6 +109,14 @@ echo "Running FastCGI query again" curl -s "http://localhost/cgi-bin/mapserv.fcgi?MAP=/tmp/wfs_simple.map&SERVICE=WFS&REQUEST=GetCapabilities" > /tmp/res.xml cat /tmp/res.xml | grep wfs:WFS_Capabilities >/dev/null || (cat /tmp/res.xml && /bin/false) +echo "Check that we return an error if given no arguments" +curl -s "http://localhost/cgi-bin/mapserv.fcgi" > /tmp/res.xml +cat /tmp/res.xml | grep -q 'QUERY_STRING is set, but empty' || (cat /tmp/res.xml && /bin/false) + +echo "Check again to make sure further errors are reported (#6543)" +curl -s "http://localhost/cgi-bin/mapserv.fcgi" > /tmp/res.xml +cat /tmp/res.xml | grep -q 'QUERY_STRING is set, but empty' || (cat /tmp/res.xml && /bin/false) + cd msautotest/wxs export PATH=/tmp/install-mapserver/bin:$PATH @@ -113,6 +124,7 @@ export PATH=/tmp/install-mapserver/bin:$PATH # Demonstrate that mapserv will error out if cannot find config file mapserv 2>&1 | grep "msLoadConfig(): Unable to access file" >/dev/null && echo yes mapserv QUERY_STRING="MAP=wfs_simple.map&REQUEST=GetCapabilities" 2>&1 | grep "msLoadConfig(): Unable to access file" >/dev/null && echo yes +mapserv QUERY_STRING="map=ows_context.map&CONTEXT=ows_context.xml&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities" 2>&1 | grep "msLoadConfig(): Unable to access file" >/dev/null && echo "Check that we can't load a OWS context file if MS_CONTEXT_PATTERN is not defined: yes" echo "Check that MS_MAP_NO_PATH works" cat </tmp/mapserver.conf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..ded56ecca0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,32 @@ +repos: + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + - repo: https://github.com/timothycrosley/isort + rev: 5.12.0 + hooks: + - id: isort + args: ["--profile", "black"] + - repo: https://github.com/pycqa/flake8 + rev: 3.9.2 + hooks: + - id: flake8 + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: 'v15.0.7' + hooks: + - id: clang-format + exclude_types: [c#, java, javascript, json, proto] + exclude: > + (?x)^( + build | + renderers/agg/ | + flatgeobuf/ | + opengl/ | + third-party/ | + maplexer.c | + mapparser.c | + mapparser.h | + dejavu-sans-condensed.h | + uthash.h + ) diff --git a/.travis.yml b/.travis.yml index 31ba2a43da..29a0d4cc60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,20 +8,14 @@ language: php matrix: include: - - php: 7.4 + - php: 8.1 env: - - BUILD_NAME=PHP_7.4_WITH_ASAN - - PYTHON_VERSION=3.7.7 - - CRYPTOGRAPHY_DONT_BUILD_RUST=1 # to avoid issue when building Cryptography python module (https://travis-ci.com/github/MapServer/MapServer/jobs/482212623) - - - php: 8.0 - env: - - BUILD_NAME=PHP_8.0 + - BUILD_NAME=PHP_8.1_WITH_ASAN - PYTHON_VERSION=3.8 - - php: 8.1.7 + - php: 8.2.0 env: - - BUILD_NAME=PHP_8.1 + - BUILD_NAME=PHP_8.2 - PYTHON_VERSION=3.9 cache: diff --git a/CMakeLists.txt b/CMakeLists.txt index 32c8a2692b..57048fd102 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,12 +11,13 @@ endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") include(CheckLibraryExists) include(CheckFunctionExists) +include(CheckSymbolExists) include(CheckIncludeFile) include(CheckCSourceCompiles) -set (MapServer_VERSION_MAJOR 7) -set (MapServer_VERSION_MINOR 7) -set (MapServer_VERSION_REVISION 0) +set (MapServer_VERSION_MAJOR 8) +set (MapServer_VERSION_MINOR 0) +set (MapServer_VERSION_REVISION 2) set (MapServer_VERSION_SUFFIX "") # Set C++ version @@ -119,7 +120,12 @@ check_function_exists("strlcat" HAVE_STRLCAT) check_function_exists("strlcpy" HAVE_STRLCPY) check_function_exists("strlen" HAVE_STRLEN) check_function_exists("strncasecmp" HAVE_STRNCASECMP) -check_function_exists("vsnprintf" HAVE_VSNPRINTF) + +check_symbol_exists(vsnprintf stdio.h HAVE_VSNPRINTF) +IF(NOT HAVE_VSNPRINTF) + check_function_exists("vsnprintf" HAVE_VSNPRINTF) +ENDIF() + check_function_exists("lrintf" HAVE_LRINTF) check_function_exists("lrint" HAVE_LRINT) @@ -228,8 +234,10 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR "${_LIBDIR_DEFAULT}" CACHE PATH "object code libraries (${_LIBDIR_DEFAULT})") endif() -SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") -SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +if(NOT DEFINED CMAKE_INSTALL_RPATH) + SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +endif() SET(CMAKE_MACOSX_RPATH ON) if(LINK_STATIC_LIBMAPSERVER) @@ -282,8 +290,14 @@ if(WIN32) set(REGEX_MALLOC 1) set(USE_GENERIC_MS_NINT 1) set(HAVE_STRING_H 0) - # Suppress warnings for regex.c - set_source_files_properties(${REGEX_SOURCES} PROPERTIES COMPILE_FLAGS /w) + if(MSVC) + # Suppress warnings for regex.c + set_source_files_properties(${REGEX_SOURCES} PROPERTIES COMPILE_FLAGS /w) + endif(MSVC) + if(MINGW) + # mingw provides stdlib.h + add_definitions(-DSTDC_HEADERS=1) + endif(MINGW) else(WIN32) set(REGEX_SOURCES "") endif(WIN32) @@ -933,7 +947,6 @@ status_optional_component("GIF" "${USE_GIF}" "${GIF_LIBRARY}") status_optional_component("MYSQL" "${USE_MYSQL}" "${MYSQL_LIBRARY}") status_optional_component("FRIBIDI" "${USE_FRIBIDI}" "${FRIBIDI_LIBRARY}") status_optional_component("HARFBUZZ" "${USE_HARFBUZZ}" "${HARFBUZZ_LIBRARY}") -status_optional_component("GIF" "${USE_GIF}" "${GIF_LIBRARY}") status_optional_component("CAIRO" "${USE_CAIRO}" "${CAIRO_LIBRARY}") status_optional_component("SVGCAIRO" "${USE_SVG_CAIRO}" "${SVGCAIRO_LIBRARY}") status_optional_component("RSVG" "${USE_RSVG}" "${RSVG_LIBRARY}") @@ -1005,7 +1018,7 @@ if(USE_MSSQL2008) endif(USE_MSSQL2008) -INSTALL(TARGETS sortshp shptree shptreevis msencrypt legend scalebar tile4ms shptreetst map2img mapserv +INSTALL(TARGETS coshp sortshp shptree shptreevis msencrypt legend scalebar tile4ms shptreetst map2img mapserv RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin ) @@ -1101,5 +1114,5 @@ install( install( FILES ${PROJECT_SOURCE_DIR}/etc/mapserver-sample.conf - DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/ + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/ ) diff --git a/HISTORY.TXT b/HISTORY.md similarity index 98% rename from HISTORY.TXT rename to HISTORY.md index 8e37bdfb32..7d8c51a11a 100644 --- a/HISTORY.TXT +++ b/HISTORY.md @@ -1,4 +1,3 @@ - MapServer Revision History ========================== @@ -12,6 +11,92 @@ For a complete change history, please see the Git log comments. For more details about recent point releases, please see the online changelog at: https://mapserver.org/development/changelog/ +The online Migration Guide can be found at https://mapserver.org/MIGRATION_GUIDE.html + +8.0.2 release (2024-06-11) +-------------------------- + +- security fix to prevent SQL injections through regex validation (#7075) + +8.0.1 release (2023-04-17) +-------------------------- + +- fix WFS paging on Oracle (#6774) + +- allow runtime substitutions on the Web template parameter (#6804) + +- handle multiple PROJ_DATA paths through config (#6863) + +see detailed changelog for other fixes + +8.0.0 release (2022-09-12) +-------------------------- + +RC2 was released as the final 8.0.0 (see major changes below) + +8.0.0-rc2 release (2022-09-05) +------------------------------ + +- fix !BOX! token not working for a PostGIS connection (#6601) + +- check if a LAYER has a NAME, before including it in a GROUP (#6603) + +8.0.0-rc1 release (2022-08-19) +------------------------------ + +- add missing include to fix build issue on some compilers (#6595) + +- update the distributed mapserver-sample.conf (#6598) + +8.0.0-beta2 release (2022-08-09) +-------------------------------- + +- install coshp utility (#6540) + +- improve error messages about missing mandatory metadata (#6542) + +- fix reprojection of lines crossing the antimeridian (#6557) + +- config file parsing: use msSetPROJ_LIB() when ENV PROJ_LIB is set (#6565) + +- handle PROJ_DATA as well as PROJ_LIB (#6573) + +- reset layer filteritem to its old value in case of no overlap (#6550) + +8.0.0-beta1 release (2022-06-27) +-------------------------------- + +- add new MapServer config file requirement (RFC 135) + +- initial OGC API support (RFC 134) + +- rename shp2img utility to map2img (RFC 136) + +- make STYLES parameter mandatory for WMS GetMap requests (#6012) + +- improve SLD label conformance (#6017) + +- enable PHP 8 MapScript support, through SWIG, re-enable unit tests, and remove old native PHP MapScript (#6430) + +- remove deprecated mapfile parameters (RFC 133) + +- improve numerical validation of mapfile parameter values (#6458) + +- fix various security vulnerabilities found by libFuzzer (#6419) + +- add new GEOMTRANSFORM 'centerline' labeling method for polygons (#6417) + +- upgrade Travis and GitHub CI to run on Ubuntu Focal (#6430) + +7.6.5 release (2023-04-17) +-------------------------- + +- remove password content from logs (#6621) + +- increase security and stability (#6818) + +see detailed changelog for other fixes + 7.6.4 release (2021-07-12) -------------------------- @@ -172,7 +257,7 @@ see detailed changelog for other fixes - No other major changes, see detailed changelog for bug fixes 7.2.0-beta1 release (2018-5-9) --------------------- +------------------------------ - Support for Enhanced Layer Metadata Management (RFC82) @@ -272,7 +357,7 @@ see detailed changelog for other fixes - Implementation of offsets on follow labels (#4399) 6.2.0 release (git branch-6-2) 2012/11/14: --------------------------------------------------- +------------------------------------------ - Fix WFS GetFeature result bounds are not written in requested projection (#4494) @@ -302,7 +387,7 @@ see detailed changelog for other fixes - implement OFFSET x -99 on ANGLE FOLLOW labels (#4399) Version 6.2 (beta1: 20120629): -------------------------------------------------- +------------------------------ - Fix WFS filter is produced as non-standard XML (#4171) diff --git a/INSTALL b/INSTALL index 77d45994d5..fc27754e6d 100644 --- a/INSTALL +++ b/INSTALL @@ -1,14 +1,14 @@ -Visit http://www.mapserver.org/ for full documentation and installation +Visit https://mapserver.org/ for full documentation and installation instructions. Unix compilation instructions ----------------------------- See INSTALL.CMAKE or the document on the MapServer website at - + Win32 compilation instructions ------------------------------ See README.WIN32 or the document on the MapServer website at - + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000000..78a65ccd0a --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,36 @@ +MapServer Licensing +=================== + +MapServer General +----------------- + +Copyright (c) 2008-2024 Open Source Geospatial Foundation. +Copyright (c) 1996-2008 Regents of the University of Minnesota. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies of this Software or works derived from this Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +FlatGeobuf +---------- + +Refer to the FlatGeobuf license found at [/flatgeobuf/LICENSE](flatgeobuf/LICENSE) + +FlatBuffers +----------- + +Refer to the FlatBuffers license found at [/flatgeobuf/include/flatbuffers/LICENSE](flatgeobuf/include/flatbuffers/LICENSE) \ No newline at end of file diff --git a/MIGRATION_GUIDE.txt b/MIGRATION_GUIDE.md similarity index 100% rename from MIGRATION_GUIDE.txt rename to MIGRATION_GUIDE.md diff --git a/README.md b/README.md new file mode 100644 index 0000000000..06c8348a3a --- /dev/null +++ b/README.md @@ -0,0 +1,87 @@ +MapServer +========= + +[![Build Status](https://travis-ci.com/MapServer/MapServer.svg?branch=main)](https://travis-ci.com/MapServer/MapServer) +[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/vw1n07095a8bg23u?svg=true)](https://ci.appveyor.com/project/mapserver/mapserver) +[![Coveralls Status](https://coveralls.io/repos/github/MapServer/MapServer/badge.svg?branch=main)](https://coveralls.io/github/MapServer/MapServer?branch=main) +[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5842012.svg)](https://doi.org/10.5281/zenodo.5842012) + +------- +Summary +------- + +MapServer is a system for developing web-based GIS applications. +The basic system consists of a CGI program that can be configured to +respond to a variety of spatial requests like making maps, scalebars, +and point, area and feature queries. Virtually all aspects of an +application, from web interface to map appearance can be developed +without any programming. For the more ambitious user, MapServer +applications can be enhanced using Python, PHP, Java, JavaScript or +many other web technologies. For more information and complete +documentation please visit: + + https://mapserver.org/ + +Bug reports and enhancement submissions can be reported in the MapServer +issue tracker at the following url. If you do make changes and/or enhancements, +please let us know so that they might be incorporated into future releases. + + https://github.com/MapServer/MapServer/issues + + +Join the MapServer user mailing list online at: + + https://mapserver.org/community/lists.html + +Credits +------- + +MapServer was originally written by Stephen Lime. Major funding for development of +MapServer has been provided by NASA through cooperative argreements with +the University of Minnesota, Department of Forest Resources. + +PHP/MapScript developed by DM Solutions Group. + +GDAL/OGR support and significant WMS support provided by DM Solutions Group +which received funding support from Canadian Government's GeoConnections +Program and the Canadian Forest Service. + +Raster support developed by Pete Olson of the State of Minnesota, Land +Management Information Center, and maintained by Frank Warmerdam (DM +Solutions). + +PostGIS spatial database support provided by Dave Blasby of Refractions +Research. + +PDF support developed by Jeff Spielberg and Jamie Wall of Market Insite Group, +Inc. + +OracleSpatial support developed by Rodrigo Cabral of CTTMAR/UNIVALI, Brazil. + +Portions Copyright (c) 1998 State of Minnesota, Land Management Information +Center. + +Portions derived from Shapelib, Copyright 1995-1999 Frank Warmerdam. + +Supporting packages are covered by their own copyrights. + +License +------- + +See [LICENSE.md](LICENSE.md) + +Security policy +--------------- + +See [SECURITY.md](SECURITY.md) + +How to Contribute +----------------- + +See [CONTRIBUTING.md](CONTRIBUTING.md) + +Documentation Repository +------------------------ + +Use the separate [MapServer-documentation](https://github.com/MapServer/MapServer-documentation) +repository for filing documentation tickets and changes. \ No newline at end of file diff --git a/README.rst b/README.rst deleted file mode 100644 index fd49758a01..0000000000 --- a/README.rst +++ /dev/null @@ -1,116 +0,0 @@ -MapServer -========= - -| |Build Status| |Appveyor Build Status| |Coveralls Status| |DOI| - -------- -Summary -------- - -MapServer is a system for developing web-based GIS applications. -The basic system consists of a CGI program that can be configured to -respond to a variety of spatial requests like making maps, scalebars, -and point, area and feature queries. Virtually all aspects of an -application, from web interface to map appearance can be developed -without any programming. For the more ambitious user, MapServer -applications can be enhanced using Python, PHP, Java, JavaScript or -many other web technologies. For more information and complete -documentation please visit: - - https://mapserver.org/ - -Bug reports and enhancement submissions can be reported in the MapServer -issue tracker at the following url. If you do make changes and/or enhancements, -please let us know so that they might be incorporated into future releases. - - https://github.com/MapServer/MapServer/issues - - -Join the MapServer user mailing list online at: - - https://mapserver.org/community/lists.html - - - -Credits -------- - -MapServer was originally written by Stephen Lime. Major funding for development of -MapServer has been provided by NASA through cooperative argreements with -the University of Minnesota, Department of Forest Resources. - -PHP/MapScript developed by DM Solutions Group. - -GDAL/OGR support and significant WMS support provided by DM Solutions Group -which received funding support from Canadian Government's GeoConnections -Program and the Canadian Forest Service. - -Raster support developed by Pete Olson of the State of Minnesota, Land -Management Information Center, and maintained by Frank Warmerdam (DM -Solutions). - -PostGIS spatial database support provided by Dave Blasby of Refractions -Research. - -PDF support developed by Jeff Spielberg and Jamie Wall of Market Insite Group, -Inc. - -OracleSpatial support developed by Rodrigo Cabral of CTTMAR/UNIVALI, Brazil. - -Portions Copyright (c) 1998 State of Minnesota, Land Management Information -Center. - -Portions derived from Shapelib, Copyright 1995-1999 Frank Warmerdam. - -Supporting packages are covered by their own copyrights. - -License -------- - -:: - - Copyright (c) 2008-2022 Open Source Geospatial Foundation. - Copyright (c) 1996-2008 Regents of the University of Minnesota. - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is furnished - to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies of this Software or works derived from this Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - - FlatGeobuf - ---------- - - Refer to the FlatGeobuf license found at /flatgeobuf/LICENSE - - FlatBuffers - ----------- - - Refer to the FlatBuffers license found at /flatgeobuf/include/flatbuffers/LICENSE - - - -.. |Build Status| image:: https://travis-ci.com/MapServer/MapServer.svg?branch=main - :target: https://travis-ci.com/MapServer/MapServer - -.. |Appveyor Build Status| image:: https://ci.appveyor.com/api/projects/status/vw1n07095a8bg23u?svg=true - :target: https://ci.appveyor.com/project/mapserver/mapserver - -.. |Coveralls Status| image:: https://coveralls.io/repos/github/MapServer/MapServer/badge.svg?branch=main - :target: https://coveralls.io/github/MapServer/MapServer?branch=main - -.. |DOI| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.5842012.svg - :target: https://doi.org/10.5281/zenodo.5842012 - :alt: Digital Object Identifier (DOI) for MapServer \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md index 20cc093f94..43e72602a5 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -11,23 +11,30 @@ submissions, when describing the vulnerability (see https://mapserver.org/develo ## Supported Versions The MapServer PSC (Project Steering Committee) will release patches for security vulnerabilities -for the last release branch of the **two most recent release series** (such as 8.x, 7.x. 6.x, etc...). +for the last release branch of the **two most recent release series** (such as 8.x, 7.x, 6.x, etc..., +where "x" is the most recent release in the series, such as: 7.6.6 being supported, but +not 7.6.5). For example, once 8.4 is released, support for 8.2 will be dropped. + Patches will only be provided **for a period of three years** from the release date of the current series. -For example, once 8.0 is released, then only 8.0.x and 7.6.x will be supported/patched and 7.6.x will -only be supported for three years from the date of the 8.0 series release. +For example, as 8.2 has been released, now 8.2.x, and 7.6.x will be supported/patched, and 7.6.x will +only be supported for three years from the date of the 8.0 series release (until 2025-09-12). Currently, the following versions are supported: -| Version | Supported | -| ------- | ------------------ | -| 7.6.x | :white_check_mark: | -| 7.4.x | :x: | -| 7.2.x | :x: | -| 7.0.x | :x: | -| 6.4.x | :x: | -| < 6.4 | :x: | - -Note: _MapServer 7.0.0 was released on 2015-07-24._ +| Version | Supported | Support Until | +| ------- | ------------------ |-------------- | +| 8.2.x | :white_check_mark: | | +| 8.0.x | :x: | | +| 7.6.x | :white_check_mark: | 2025-09-12 | +| 7.4.x | :x: | | +| 7.2.x | :x: | | +| 7.0.x | :x: | | +| 6.4.x | :x: | | +| < 6.4 | :x: | | + +- _MapServer 8.2.0 was released on 2024-07-08_ +- _MapServer 8.0.0 was released on 2022-09-12_ +- _MapServer 7.0.0 was released on 2015-07-24_ ## Version Numbering: Explained @@ -37,7 +44,7 @@ version x.y.z means: - Major release series number. - Major releases indicate substantial changes to the software and backwards compatibility is not guaranteed across series. Current - release series is 7. + release series is 8. **y** - Minor release series number. diff --git a/apache/mod_mapserver.c b/apache/mod_mapserver.c index 9de35418aa..5d1512e7ee 100644 --- a/apache/mod_mapserver.c +++ b/apache/mod_mapserver.c @@ -12,7 +12,7 @@ #include "apr_tables.h" #include "apr_file_info.h" -#include "../mapserver.h" /* for mapObj */ +#include "../mapserver.h" /* for mapObj */ #include "../cgiutil.h" #include "../mapserv.h" @@ -21,45 +21,39 @@ module AP_MODULE_DECLARE_DATA mapserver_module; typedef struct { apr_pool_t *config_pool; apr_time_t mtime; - char *mapfile_name; - char *uri; + char *mapfile_name; + char *uri; mapObj *map; } mapserver_dir_config; /* These are the IO redirection hooks. They are mostly copied over from * mapio.c. Note that cbData contains Apache's request_rec! */ -static int -msIO_apacheWrite (void *cbData, void *data, int byteCount) -{ +static int msIO_apacheWrite(void *cbData, void *data, int byteCount) { /* simply use the block writing function which is very similiar to fwrite */ - return ap_rwrite (data, byteCount, (request_rec*) cbData); + return ap_rwrite(data, byteCount, (request_rec *)cbData); } -static int -msIO_apacheError (void *cbData, void *data, int byteCount) -{ +static int msIO_apacheError(void *cbData, void *data, int byteCount) { /* error reporting is done through the log file... */ - ap_log_error (APLOG_MARK, APLOG_ERR, 0, NULL, "%s", (char*) data); - return strlen ((char*) data); + ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "%s", (char *)data); + return strlen((char *)data); } -int -msIO_installApacheRedirect (request_rec *r) -{ +int msIO_installApacheRedirect(request_rec *r) { msIOContext stdout_ctx, stderr_ctx; - stdout_ctx.label = "apache"; + stdout_ctx.label = "apache"; stdout_ctx.write_channel = MS_TRUE; stdout_ctx.readWriteFunc = msIO_apacheWrite; - stdout_ctx.cbData = (void*) r; + stdout_ctx.cbData = (void *)r; - stderr_ctx.label = "apache"; + stderr_ctx.label = "apache"; stderr_ctx.write_channel = MS_TRUE; stderr_ctx.readWriteFunc = msIO_apacheError; - stderr_ctx.cbData = (void*) r; + stderr_ctx.cbData = (void *)r; - msIO_installHandlers (NULL, &stdout_ctx, &stderr_ctx); + msIO_installHandlers(NULL, &stdout_ctx, &stderr_ctx); return MS_TRUE; } @@ -72,91 +66,89 @@ msIO_installApacheRedirect (request_rec *r) /* This is our simple query decoding function. Should be improved but for now * it works... */ -static int -mapserver_decode_args (apr_pool_t *p, char *args, - char ***ParamNames, char ***ParamValues) -{ +static int mapserver_decode_args(apr_pool_t *p, char *args, char ***ParamNames, + char ***ParamValues) { char **argv = NULL; - int i; - int n; - int argc = 0; - char *sep; + int i; + int n; + int argc = 0; + char *sep; /* alloc the name/value pointer list */ - argv = (char**) apr_pcalloc (p, (WMS_MAX_ARGS + 1) * 2 * sizeof (char*)); - *ParamNames = argv; + argv = (char **)apr_pcalloc(p, (WMS_MAX_ARGS + 1) * 2 * sizeof(char *)); + *ParamNames = argv; *ParamValues = argv + WMS_MAX_ARGS + 1; /* No arguments? Then we're done */ - if (!args) return 0; + if (!args) + return 0; - argv [0] = args; + argv[0] = args; /* separate the arguments */ - for (i = 1, n = 0; args [n] && (i < WMS_MAX_ARGS); n++) - if (args [n] == '&') { - argv [i++] = args + n + 1; - args [n ] = '\0'; + for (i = 1, n = 0; args[n] && (i < WMS_MAX_ARGS); n++) + if (args[n] == '&') { + argv[i++] = args + n + 1; + args[n] = '\0'; } /* eleminate empty args */ - for (n = 0, i = 0; argv [i]; i++) - if (*(argv [i]) != '\0') - argv [n++] = argv [i]; + for (n = 0, i = 0; argv[i]; i++) + if (*(argv[i]) != '\0') + argv[n++] = argv[i]; else - argv [i ] = NULL; + argv[i] = NULL; /* argument count is the number of non-zero arguments! */ argc = n; /* split the name/value pairs */ - for (i = 0; argv [i]; i++) { - sep = strchr (argv [i], '='); - if (!sep) continue; + for (i = 0; argv[i]; i++) { + sep = strchr(argv[i], '='); + if (!sep) + continue; *sep = '\0'; - argv [i + WMS_MAX_ARGS + 1] = (char*) apr_pstrdup (p, sep + 1); + argv[i + WMS_MAX_ARGS + 1] = (char *)apr_pstrdup(p, sep + 1); - if (ap_unescape_url (argv [i + WMS_MAX_ARGS + 1]) == HTTP_BAD_REQUEST) { - ap_log_error (APLOG_MARK, APLOG_ERR, 0, NULL, - "%s: malformed URI, couldn't unescape parm %s", - __func__, argv [i]); + if (ap_unescape_url(argv[i + WMS_MAX_ARGS + 1]) == HTTP_BAD_REQUEST) { + ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, + "%s: malformed URI, couldn't unescape parm %s", __func__, + argv[i]); - argv [i + WMS_MAX_ARGS + 1] = NULL; + argv[i + WMS_MAX_ARGS + 1] = NULL; } else { - plustospace (argv [i + WMS_MAX_ARGS + 1]); + plustospace(argv[i + WMS_MAX_ARGS + 1]); } } return argc; } -static char* -mapserver_read_post_data (request_rec *r) -{ - int size; - long blen, rsize, rpos = 0; +static char *mapserver_read_post_data(request_rec *r) { + int size; + long blen, rsize, rpos = 0; char *buffer = NULL; - char buf [512]; + char buf[512]; - if (ap_setup_client_block (r, REQUEST_CHUNKED_ERROR) != OK) + if (ap_setup_client_block(r, REQUEST_CHUNKED_ERROR) != OK) return NULL; - if (!ap_should_client_block (r)) + if (!ap_should_client_block(r)) return NULL; - buffer = (char*) apr_palloc (r->pool, r->remaining + 1); + buffer = (char *)apr_palloc(r->pool, r->remaining + 1); if (!buffer) return NULL; size = r->remaining; - buffer [size] = '\0'; + buffer[size] = '\0'; - while ((blen = ap_get_client_block (r, buf, sizeof (buf))) > 0) { + while ((blen = ap_get_client_block(r, buf, sizeof(buf))) > 0) { if (rpos + blen > size) { rsize = blen - rpos; } else { rsize = blen; } - memcpy ((char*) buffer + rpos, buf, rsize); + memcpy((char *)buffer + rpos, buf, rsize); rpos += rsize; } @@ -167,32 +159,37 @@ mapserver_read_post_data (request_rec *r) ** Extract Map File name from params and load it. ** Returns map object or NULL on error. */ -static mapObj* -msModuleLoadMap(mapservObj *mapserv, mapserver_dir_config *conf) -{ +static mapObj *msModuleLoadMap(mapservObj *mapserv, + mapserver_dir_config *conf) { int i; /* OK, here's the magic: we take the mapObj from our stored config. * We will use a copy of it created by msCopyMap since MapServer * modifies the object at several places during request processing */ - mapObj *map = msNewMapObj (); - if(!map) return NULL; - msCopyMap (map, conf->map); - + mapObj *map = msNewMapObj(); + if (!map) + return NULL; + msCopyMap(map, conf->map); - /* check for any %variable% substitutions here, also do any map_ changes, we do this here so WMS/WFS */ + /* check for any %variable% substitutions here, also do any map_ changes, we + * do this here so WMS/WFS */ /* services can take advantage of these "vendor specific" extensions */ - for(i=0; irequest->NumParams; i++) { + for (i = 0; i < mapserv->request->NumParams; i++) { /* ** a few CGI variables should be skipped altogether ** - ** qstring: there is separate per layer validation for attribute queries and the substitution checks + ** qstring: there is separate per layer validation for attribute queries and + *the substitution checks ** below conflict with that so we avoid it here */ - if(strncasecmp(mapserv->request->ParamNames[i],"qstring",7) == 0) continue; + if (strncasecmp(mapserv->request->ParamNames[i], "qstring", 7) == 0) + continue; - if(strncasecmp(mapserv->request->ParamNames[i],"map_",4) == 0 || strncasecmp(mapserv->request->ParamNames[i],"map.",4) == 0) { /* check to see if there are any additions to the mapfile */ - if(msUpdateMapFromURL(map, mapserv->request->ParamNames[i], mapserv->request->ParamValues[i]) != MS_SUCCESS) { + if (strncasecmp(mapserv->request->ParamNames[i], "map_", 4) == 0 || + strncasecmp(mapserv->request->ParamNames[i], "map.", 4) == + 0) { /* check to see if there are any additions to the mapfile */ + if (msUpdateMapFromURL(map, mapserv->request->ParamNames[i], + mapserv->request->ParamValues[i]) != MS_SUCCESS) { msFreeMap(map); return NULL; } @@ -200,18 +197,22 @@ msModuleLoadMap(mapservObj *mapserv, mapserver_dir_config *conf) } } - msApplySubstitutions(map, mapserv->request->ParamNames, mapserv->request->ParamValues, mapserv->request->NumParams); + msApplySubstitutions(map, mapserv->request->ParamNames, + mapserv->request->ParamValues, + mapserv->request->NumParams); msApplyDefaultSubstitutions(map); /* check to see if a ogc map context is passed as argument. if there */ /* is one load it */ - for(i=0; irequest->NumParams; i++) { - if(strcasecmp(mapserv->request->ParamNames[i],"context") == 0) { - if(mapserv->request->ParamValues[i] && strlen(mapserv->request->ParamValues[i]) > 0) { - if(strncasecmp(mapserv->request->ParamValues[i],"http",4) == 0) { - if(msGetConfigOption(map, "CGI_CONTEXT_URL")) - msLoadMapContextURL(map, mapserv->request->ParamValues[i], MS_FALSE); + for (i = 0; i < mapserv->request->NumParams; i++) { + if (strcasecmp(mapserv->request->ParamNames[i], "context") == 0) { + if (mapserv->request->ParamValues[i] && + strlen(mapserv->request->ParamValues[i]) > 0) { + if (strncasecmp(mapserv->request->ParamValues[i], "http", 4) == 0) { + if (msGetConfigOption(map, "CGI_CONTEXT_URL")) + msLoadMapContextURL(map, mapserv->request->ParamValues[i], + MS_FALSE); } else msLoadMapContext(map, mapserv->request->ParamValues[i], MS_FALSE); } @@ -225,9 +226,9 @@ msModuleLoadMap(mapservObj *mapserv, mapserver_dir_config *conf) * by an object that is part of the mapObject that would contain * information on the application status (such as cookie). */ - if( mapserv->request->httpcookiedata != NULL ) { - msInsertHashTable( &(map->web.metadata), "http_cookie_data", - mapserv->request->httpcookiedata ); + if (mapserv->request->httpcookiedata != NULL) { + msInsertHashTable(&(map->web.metadata), "http_cookie_data", + mapserv->request->httpcookiedata); } return map; @@ -236,66 +237,66 @@ msModuleLoadMap(mapservObj *mapserv, mapserver_dir_config *conf) /*** * The main request handler. **/ -static int -mapserver_handler (request_rec *r) -{ +static int mapserver_handler(request_rec *r) { /* aquire the apropriate configuration for this directory */ mapserver_dir_config *conf; - conf = (mapserver_dir_config*) ap_get_module_config (r->per_dir_config, - &mapserver_module); + conf = (mapserver_dir_config *)ap_get_module_config(r->per_dir_config, + &mapserver_module); /* decline the request if there's no map configured */ if (!conf || !conf->map) return DECLINED; apr_finfo_t mapstat; - if (apr_stat (&mapstat, conf->mapfile_name, APR_FINFO_MTIME, r->pool) == APR_SUCCESS) { - if (apr_time_sec (mapstat.mtime) > apr_time_sec (conf->mtime)) { - mapObj *newmap = msLoadMap (conf->mapfile_name, NULL); + if (apr_stat(&mapstat, conf->mapfile_name, APR_FINFO_MTIME, r->pool) == + APR_SUCCESS) { + if (apr_time_sec(mapstat.mtime) > apr_time_sec(conf->mtime)) { + mapObj *newmap = msLoadMap(conf->mapfile_name, NULL); if (newmap) { - msFreeMap (conf->map); - conf->map = newmap; + msFreeMap(conf->map); + conf->map = newmap; conf->mtime = mapstat.mtime; } else { - ap_log_error (APLOG_MARK, APLOG_WARNING, 0, NULL, - "unable to reload map file %s", conf->mapfile_name); + ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, + "unable to reload map file %s", conf->mapfile_name); } } } else { - ap_log_error (APLOG_MARK, APLOG_WARNING, 0, NULL, - "%s: unable to stat file %s", __func__, conf->mapfile_name); + ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, + "%s: unable to stat file %s", __func__, conf->mapfile_name); } /* make a copy of the URI so we can modify it safely */ - char *uri = apr_pstrdup (r->pool, r->uri); - int len = strlen (uri); - int conf_uri_len = strlen (conf->uri); + char *uri = apr_pstrdup(r->pool, r->uri); + int len = strlen(uri); + int conf_uri_len = strlen(conf->uri); /* If the URI points to a subdirectory we want to decline. */ if (len > conf_uri_len) return DECLINED; - int argc = 0; - char **ParamNames = NULL; - char **ParamValues = NULL; - char *post_data = NULL; - int szMethod = -1; - char *szContentType = NULL; + int argc = 0; + char **ParamNames = NULL; + char **ParamValues = NULL; + char *post_data = NULL; + int szMethod = -1; + char *szContentType = NULL; mapservObj *mapserv = NULL; /* Try decoding the query string */ if (r->method_number == M_GET) { - argc = mapserver_decode_args (r->pool, (char*) apr_pstrdup (r->pool, r->args), - &ParamNames, &ParamValues); + argc = mapserver_decode_args(r->pool, (char *)apr_pstrdup(r->pool, r->args), + &ParamNames, &ParamValues); szMethod = MS_GET_REQUEST; } else if (r->method_number == M_POST) { - szContentType = (char*) apr_table_get (r->headers_in, "Content-Type"); - post_data = mapserver_read_post_data (r); - szMethod = MS_POST_REQUEST; - if (strcmp (szContentType, "application/x-www-form-urlencoded") == 0) { - argc = mapserver_decode_args (r->pool, (char*) apr_pstrdup (r->pool, r->args), - &ParamNames, &ParamValues); + szContentType = (char *)apr_table_get(r->headers_in, "Content-Type"); + post_data = mapserver_read_post_data(r); + szMethod = MS_POST_REQUEST; + if (strcmp(szContentType, "application/x-www-form-urlencoded") == 0) { + argc = + mapserver_decode_args(r->pool, (char *)apr_pstrdup(r->pool, r->args), + &ParamNames, &ParamValues); } } else return HTTP_METHOD_NOT_ALLOWED; @@ -304,36 +305,34 @@ mapserver_handler (request_rec *r) return HTTP_BAD_REQUEST; /* Now we install the IO redirection. - */ - if (msIO_installApacheRedirect (r) != MS_TRUE) - ap_log_error (APLOG_MARK, APLOG_ERR, 0, NULL, - "%s: could not install apache redirect", __func__); - + */ + if (msIO_installApacheRedirect(r) != MS_TRUE) + ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, + "%s: could not install apache redirect", __func__); mapserv = msAllocMapServObj(); - mapserv->request->NumParams = argc; - mapserv->request->ParamNames = ParamNames; + mapserv->request->NumParams = argc; + mapserv->request->ParamNames = ParamNames; mapserv->request->ParamValues = ParamValues; - mapserv->request->type = (enum MS_REQUEST_TYPE) szMethod; + mapserv->request->type = (enum MS_REQUEST_TYPE)szMethod; mapserv->request->postrequest = post_data; mapserv->request->contenttype = szContentType; - //mapserv->map = msModuleLoadMap(mapserv,conf); + // mapserv->map = msModuleLoadMap(mapserv,conf); mapserv->map = conf->map; - if(!mapserv->map) { + if (!mapserv->map) { msCGIWriteError(mapserv); goto end_request; } - if(msCGIDispatchRequest(mapserv) != MS_SUCCESS) { + if (msCGIDispatchRequest(mapserv) != MS_SUCCESS) { msCGIWriteError(mapserv); goto end_request; } - end_request: - if(mapserv) { - mapserv->request->ParamNames = NULL; + if (mapserv) { + mapserv->request->ParamNames = NULL; mapserv->request->ParamValues = NULL; mapserv->request->postrequest = NULL; mapserv->request->contenttype = NULL; @@ -342,7 +341,6 @@ mapserver_handler (request_rec *r) } msResetErrorList(); - /* Check if status was set inside MapServer functions. If it was, we * return it's value instead of simply OK. This is to support redirects * from maptemplate.c @@ -356,10 +354,8 @@ mapserver_handler (request_rec *r) /* This function will be called on startup to allow us to register our * handler. We don't do anything else yet... */ -static void -mapserver_register_hooks (apr_pool_t *p) -{ - ap_hook_handler (mapserver_handler, NULL, NULL, APR_HOOK_MIDDLE); +static void mapserver_register_hooks(apr_pool_t *p) { + ap_hook_handler(mapserver_handler, NULL, NULL, APR_HOOK_MIDDLE); } /* That's the second part of the overall magic. This function will be called @@ -368,38 +364,38 @@ mapserver_register_hooks (apr_pool_t *p) * We try to load it and store the resulting mapObj in the config of the * current directory. If we fail we throw a message... */ -static const char* -mapserver_set_map (cmd_parms *cmd, void *config, const char *arg) -{ - mapserver_dir_config *conf = (mapserver_dir_config*) config; +static const char *mapserver_set_map(cmd_parms *cmd, void *config, + const char *arg) { + mapserver_dir_config *conf = (mapserver_dir_config *)config; /* if the mapObj already exists the WMS_Map was given more than once - * may be the user forgot to comment something out... */ if (conf->map) { - msWriteError (stderr); - return (char*) apr_psprintf (cmd->temp_pool, - "An MAP-file has already been registered for " - "this URI - not accepting '%s'.", arg ); + msWriteError(stderr); + return (char *)apr_psprintf(cmd->temp_pool, + "An MAP-file has already been registered for " + "this URI - not accepting '%s'.", + arg); } /* Simply try loading the argument as map file. */ conf->mapfile_name = apr_pstrdup(cmd->pool, arg); - conf->map = msLoadMap ((char*) arg, NULL); + conf->map = msLoadMap((char *)arg, NULL); /* Ooops - we failed. We report it and fail. So beware: Always do a * configcheck before really restarting your web server! */ if (!conf->map) { - msWriteError (stderr); - return (char*) apr_psprintf (cmd->temp_pool, - "The given MAP-file '%s' could not be loaded", - arg); + msWriteError(stderr); + return (char *)apr_psprintf( + cmd->temp_pool, "The given MAP-file '%s' could not be loaded", arg); } apr_finfo_t status; - if (apr_stat (&status, conf->mapfile_name, APR_FINFO_MTIME, cmd->pool) != APR_SUCCESS) { - ap_log_error (APLOG_MARK, APLOG_WARNING, 0, NULL, - "%s: unable to stat file %s", __func__, conf->mapfile_name); + if (apr_stat(&status, conf->mapfile_name, APR_FINFO_MTIME, cmd->pool) != + APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, + "%s: unable to stat file %s", __func__, conf->mapfile_name); } conf->mtime = status.mtime; return NULL; @@ -408,21 +404,20 @@ mapserver_set_map (cmd_parms *cmd, void *config, const char *arg) /* This function creates the (default) directory configuration. Well, we have * no defaults to set so we simply alloc the memory... */ -static void* -mapserver_create_dir_config (apr_pool_t *p, char *dir) -{ +static void *mapserver_create_dir_config(apr_pool_t *p, char *dir) { mapserver_dir_config *newconf; - newconf = (mapserver_dir_config*) apr_pcalloc (p, sizeof (mapserver_dir_config)); + newconf = + (mapserver_dir_config *)apr_pcalloc(p, sizeof(mapserver_dir_config)); newconf->config_pool = p; - newconf->uri = apr_pstrdup (p, dir); + newconf->uri = apr_pstrdup(p, dir); newconf->map = NULL; newconf->mapfile_name = NULL; - newconf->mtime = apr_time_from_sec (0); + newconf->mtime = apr_time_from_sec(0); if (dir) { - int len = strlen (dir); - if (len > 1 && dir [len - 1] == '/' ) - newconf->uri [len - 1] = '\0'; + int len = strlen(dir); + if (len > 1 && dir[len - 1] == '/') + newconf->uri[len - 1] = '\0'; } return newconf; } @@ -431,15 +426,9 @@ mapserver_create_dir_config (apr_pool_t *p, char *dir) * argument. */ static const command_rec mapserver_options[] = { - AP_INIT_TAKE1( - "Mapfile", - mapserver_set_map, - NULL, - ACCESS_CONF, - "WMS_Map " - ), - {NULL} -}; + AP_INIT_TAKE1("Mapfile", mapserver_set_map, NULL, ACCESS_CONF, + "WMS_Map "), + {NULL}}; /* The following structure declares everything Apache needs to treat us as * a module. Merging would mean inheriting from the parent directory but that @@ -447,12 +436,11 @@ static const command_rec mapserver_options[] = { */ /* Dispatch list for API hooks */ module AP_MODULE_DECLARE_DATA mapserver_module = { - STANDARD20_MODULE_STUFF, - mapserver_create_dir_config, /* create per-dir config structures */ - NULL, /* merge per-dir config structures */ - NULL, /* create per-server config structures */ - NULL, /* merge per-server config structures */ - mapserver_options, /* table of config file commands */ - mapserver_register_hooks /* register hooks */ + STANDARD20_MODULE_STUFF, + mapserver_create_dir_config, /* create per-dir config structures */ + NULL, /* merge per-dir config structures */ + NULL, /* create per-server config structures */ + NULL, /* merge per-server config structures */ + mapserver_options, /* table of config file commands */ + mapserver_register_hooks /* register hooks */ }; - diff --git a/appveyor.yml b/appveyor.yml index 078e59e17b..e3d0769ab3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,16 +19,16 @@ environment: # VS 2019 VS_VERSION: Visual Studio 16 2019 matrix: - - platform: x86 - Python_ROOT_DIR: c:/python27 - - platform: x64 - Python_ROOT_DIR: c:/python27-x64 - - platform: x64 - Python_ROOT_DIR: c:/python36-x64 - platform: x64 Python_ROOT_DIR: c:/python37-x64 - platform: x64 Python_ROOT_DIR: c:/python38-x64 + - platform: x64 + Python_ROOT_DIR: c:/python39-x64 + - platform: x64 + Python_ROOT_DIR: c:/python310-x64 + - platform: x64 + Python_ROOT_DIR: c:/python311-x64 matrix: fast_finish: true @@ -40,7 +40,7 @@ init: - net start MSSQL$SQL2019 - ps: | if ($env:APPVEYOR_REPO_TAG -ne $TRUE) { - if ("c:/python27-x64","c:/python36-x64" -contains $env:Python_ROOT_DIR -eq $TRUE) { + if ("c:/python37-x64" -contains $env:Python_ROOT_DIR -eq $TRUE) { Write-Host "Skipping build, not a tagged release." Exit-AppVeyorBuild } @@ -49,6 +49,7 @@ init: build_script: - ps: Write-Host "Build tags - $env:APPVEYOR_REPO_TAG $env:APPVEYOR_REPO_TAG_NAME" - rename C:\Python310 Python310_Ignore + - rename C:\Python311 Python311_Ignore - set "BUILD_FOLDER=%APPVEYOR_BUILD_FOLDER:\=/%" - if "%platform%" == "x64" SET VS_FULL=%VS_VERSION% - if "%platform%" == "x64" SET VS_ARCH=x64 @@ -79,25 +80,24 @@ build_script: - cd build - set PATH=%BUILD_FOLDER%/build/Release;%SDK_BIN%;%PATH% - set "PROJECT_BINARY_DIR=%BUILD_FOLDER%/build" - - cmake -G "%VS_FULL%" -A %VS_ARCH% .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%SDK_PREFIX% -DPNG_LIBRARY=%SDK_LIB%/libpng16_static.lib -DHARFBUZZ_INCLUDE_DIR=%SDK_INC%/harfbuzz -DICONV_DLL=%SDK_BIN%/iconv.dll -DFRIBIDI_INCLUDE_DIR=%SDK_INC%/fribidi -DMS_EXTERNAL_LIBS=%SDK_LIB%/harfbuzz.lib;%SDK_LIB%/uriparser.lib -DSVG_LIBRARY=%SDK_LIB%/libsvg.lib -DSVGCAIRO_LIBRARY=%SDK_LIB%/libsvg-cairo.lib -DREGEX_DIR=%REGEX_DIR% -DSWIG_EXECUTABLE=%SWIG_EXECUTABLE% -DPROTOBUFC_COMPILER=%SDK_BIN%/protoc.exe -DPROTOBUFC_LIBRARY=%SDK_LIB%/protobuf-c.lib -DPROTOBUFC_INCLUDE_DIR=%SDK_INC%/protobuf-c -DWITH_CURL=1 -DWITH_KML=1 -DWITH_SVGCAIRO=1 -DWITH_THREAD_SAFETY=1 -DWITH_SOS=1 -DWITH_CLIENT_WFS=1 -DWITH_CLIENT_WMS=1-DWITH_CSHARP=1 -DWITH_PROTOBUFC=1 -DWITH_POSTGIS=0 -DWITH_PERL=0 -DWITH_MSSQL2008=1 -DWITH_PYTHON=1 -DWITH_PHPNG=0 -DWITH_HARFBUZZ=1 -DWITH_PYMAPSCRIPT_ANNOTATIONS=1 -DPROJ_INCLUDE_DIR=%SDK_INC%/proj7 + - cmake -G "%VS_FULL%" -A %VS_ARCH% .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%SDK_PREFIX% -DPNG_LIBRARY=%SDK_LIB%/libpng16_static.lib -DHARFBUZZ_INCLUDE_DIR=%SDK_INC%/harfbuzz -DICONV_DLL=%SDK_BIN%/iconv.dll -DFRIBIDI_INCLUDE_DIR=%SDK_INC%/fribidi -DMS_EXTERNAL_LIBS=%SDK_LIB%/harfbuzz.lib;%SDK_LIB%/uriparser.lib -DSVG_LIBRARY=%SDK_LIB%/libsvg.lib -DSVGCAIRO_LIBRARY=%SDK_LIB%/libsvg-cairo.lib -DREGEX_DIR=%REGEX_DIR% -DSWIG_EXECUTABLE=%SWIG_EXECUTABLE% -DPROTOBUFC_COMPILER=%SDK_BIN%/protoc.exe -DPROTOBUFC_LIBRARY=%SDK_LIB%/protobuf-c.lib -DPROTOBUFC_INCLUDE_DIR=%SDK_INC%/protobuf-c -DWITH_CURL=1 -DWITH_KML=1 -DWITH_SVGCAIRO=1 -DWITH_THREAD_SAFETY=1 -DWITH_SOS=1 -DWITH_CLIENT_WFS=1 -DWITH_CLIENT_WMS=1-DWITH_CSHARP=1 -DWITH_PROTOBUFC=1 -DWITH_POSTGIS=0 -DWITH_PERL=0 -DWITH_MSSQL2008=1 -DWITH_PYTHON=1 -DWITH_PHPNG=0 -DWITH_HARFBUZZ=1 -DWITH_PYMAPSCRIPT_ANNOTATIONS=1 -DPROJ_INCLUDE_DIR=%SDK_INC%/proj9 -DPROJ_LIBRARY=%SDK_LIB%/proj9.lib - cmake --build . --config Release - cd %BUILD_FOLDER%/build - # set the MapScript custom environment variable for py 3.8 + # set the MapScript custom environment variable for python 3.8+ - set MAPSERVER_DLL_PATH=%BUILD_FOLDER%/build/Release;%SDK_BIN% - - set PROJ_LIB=%SDK_BIN%/proj7/SHARE + - set PROJ_LIB=%SDK_BIN%/proj9/SHARE # check the mapserver exe can run - mapserv -v - cmake --build . --target pythonmapscript-wheel --config Release before_test: - - set PATH=%PATH%;%SDK_BIN%/gdal/apps + - set PATH=%SDK_BIN%/gdal/apps;%PATH%; - cd %BUILD_FOLDER%/msautotest - "./mssql/create_mssql_db.bat" - "%Python_ROOT_DIR%/python -m pip install -U -r requirements.txt" - "%Python_ROOT_DIR%/python -m pip install --no-index --find-links=file://%BUILD_FOLDER%/build/mapscript/python/Release/dist mapscript" test_script: - - set PROJ_LIB=%SDK_BIN%/proj7/SHARE - cd %BUILD_FOLDER%/msautotest/mssql - "%Python_ROOT_DIR%/python run_test.py" - cd %BUILD_FOLDER%/msautotest/mspython @@ -119,7 +119,7 @@ artifacts: deploy_script: - ps: | if ($env:APPVEYOR_REPO_TAG -ne $TRUE -or ($env:APPVEYOR_REPO_TAG_NAME -cSplit "-").Count -ne 4) { return } - if ($env:Python_ROOT_DIR -eq "c:/python36-x64") { + if ($env:Python_ROOT_DIR -eq "c:/python310-x64") { Write-Host "Deploying Python source distribution to PyPI. Tag $env:APPVEYOR_REPO_TAG_NAME" cd $env:APPVEYOR_BUILD_FOLDER\build\mapscript\python\Release & "$env:Python_ROOT_DIR/python" setup.py sdist diff --git a/cgiutil.c b/cgiutil.c index 7d9895399e..6e47ae75b5 100644 --- a/cgiutil.c +++ b/cgiutil.c @@ -5,7 +5,8 @@ * Purpose: cgiRequestObj and CGI parameter parsing. * Author: Steve Lime and the MapServer team. * - * Notes: Portions derived from NCSA HTTPd Server's example CGI programs (util.c). + * Notes: Portions derived from NCSA HTTPd Server's example CGI programs + *(util.c). * ****************************************************************************** * Copyright (c) 1996-2005 Regents of the University of Minnesota. @@ -41,8 +42,7 @@ #define LF 10 #define CR 13 -int readPostBody( cgiRequestObj *request, char **data ) -{ +int readPostBody(cgiRequestObj *request, char **data) { size_t data_max, data_len; int chunk_size; @@ -53,26 +53,29 @@ int readPostBody( cgiRequestObj *request, char **data ) /* -------------------------------------------------------------------- */ /* If the length is provided, read in one gulp. */ /* -------------------------------------------------------------------- */ - if( getenv("CONTENT_LENGTH") != NULL ) { - data_max = (size_t) atoi(getenv("CONTENT_LENGTH")); + if (getenv("CONTENT_LENGTH") != NULL) { + data_max = (size_t)atoi(getenv("CONTENT_LENGTH")); /* Test for suspicious CONTENT_LENGTH (negative value or SIZE_MAX) */ - if( data_max >= SIZE_MAX ) { + if (data_max >= SIZE_MAX) { // msIO_setHeader("Content-Type","text/html"); // msIO_sendHeaders(); // msIO_printf("Suspicious Content-Length.\n"); msSetError(MS_WEBERR, "Suspicious Content-Length.", "readPostBody()"); return MS_FAILURE; } - *data = (char *) malloc(data_max+1); - if( *data == NULL ) { + *data = (char *)malloc(data_max + 1); + if (*data == NULL) { // msIO_setHeader("Content-Type","text/html"); // msIO_sendHeaders(); - // msIO_printf("malloc() failed, Content-Length: %u unreasonably large?\n", (unsigned int)data_max ); - msSetError(MS_WEBERR, "malloc() failed, Content-Length: %u unreasonably large?", "readPostBody()", (unsigned int)data_max); + // msIO_printf("malloc() failed, Content-Length: %u unreasonably + // large?\n", (unsigned int)data_max ); + msSetError(MS_WEBERR, + "malloc() failed, Content-Length: %u unreasonably large?", + "readPostBody()", (unsigned int)data_max); return MS_FAILURE; } - if( (int) msIO_fread(*data, 1, data_max, stdin) < (int) data_max ) { + if ((int)msIO_fread(*data, 1, data_max, stdin) < (int)data_max) { // msIO_setHeader("Content-Type","text/html"); // msIO_sendHeaders(); // msIO_printf("POST body is short\n"); @@ -90,24 +93,29 @@ int readPostBody( cgiRequestObj *request, char **data ) data_max = DATA_ALLOC_SIZE; data_len = 0; - *data = (char *) msSmallMalloc(data_max+1); + *data = (char *)msSmallMalloc(data_max + 1); (*data)[data_max] = '\0'; - while( (chunk_size = msIO_fread( *data + data_len, 1, data_max-data_len, stdin )) > 0 ) { + while ((chunk_size = msIO_fread(*data + data_len, 1, data_max - data_len, + stdin)) > 0) { data_len += chunk_size; - if( data_len == data_max ) { + if (data_len == data_max) { /* Realloc buffer, making sure we check for possible size_t overflow */ - if ( data_max > SIZE_MAX - (DATA_ALLOC_SIZE+1) ) { + if (data_max > SIZE_MAX - (DATA_ALLOC_SIZE + 1)) { // msIO_setHeader("Content-Type","text/html"); // msIO_sendHeaders(); - // msIO_printf("Possible size_t overflow, cannot reallocate input buffer, POST body too large?\n" ); - msSetError(MS_WEBERR, "Possible size_t overflow, cannot reallocate input buffer, POST body too large?", "readPostBody()"); + // msIO_printf("Possible size_t overflow, cannot reallocate input + // buffer, POST body too large?\n" ); + msSetError(MS_WEBERR, + "Possible size_t overflow, cannot reallocate input buffer, " + "POST body too large?", + "readPostBody()"); return MS_FAILURE; } data_max = data_max + DATA_ALLOC_SIZE; - *data = (char *) msSmallRealloc(*data, data_max+1); + *data = (char *)msSmallRealloc(*data, data_max + 1); } } @@ -115,27 +123,24 @@ int readPostBody( cgiRequestObj *request, char **data ) return MS_SUCCESS; } -static char* msGetEnv(const char *name, void* thread_context) -{ +static char *msGetEnv(const char *name, void *thread_context) { (void)thread_context; return getenv(name); } int loadParams(cgiRequestObj *request, - char* (*getenv2)(const char*, void* thread_context), - char *raw_post_data, - ms_uint32 raw_post_data_length, - void* thread_context) -{ - register int x,m=0; + char *(*getenv2)(const char *, void *thread_context), + char *raw_post_data, ms_uint32 raw_post_data_length, + void *thread_context) { + register int x, m = 0; char *s, *queryString = NULL, *httpCookie = NULL; int debuglevel; int maxParams = MS_DEFAULT_CGI_PARAMS; - if (getenv2==NULL) + if (getenv2 == NULL) getenv2 = &msGetEnv; - if(getenv2("REQUEST_METHOD", thread_context)==NULL) { + if (getenv2("REQUEST_METHOD", thread_context) == NULL) { msIO_printf("This script can only be used to decode form results and \n"); msIO_printf("should be initiated as a CGI process via a httpd server.\n"); msIO_printf("For other options please try using the --help switch.\n"); @@ -144,138 +149,160 @@ int loadParams(cgiRequestObj *request, debuglevel = (int)msGetGlobalDebugLevel(); - if(strcmp(getenv2("REQUEST_METHOD", thread_context),"POST") == 0 && CPLGetConfigOption("MS_NO_POST", NULL) == NULL) { /* we've got a post from a form */ + if (strcmp(getenv2("REQUEST_METHOD", thread_context), "POST") == 0 && + CPLGetConfigOption("MS_NO_POST", NULL) == + NULL) { /* we've got a post from a form */ char *post_data; int data_len; request->type = MS_POST_REQUEST; - if (request->contenttype == NULL){ - s = getenv2("CONTENT_TYPE", thread_context); - if (s != NULL){ - request->contenttype = msStrdup(s); - } - else { - /* we've to set default Content-Type which is - * application/octet-stream according to - * W3 RFC 2626 section 7.2.1 */ - request->contenttype = msStrdup("application/octet-stream"); - } + if (request->contenttype == NULL) { + s = getenv2("CONTENT_TYPE", thread_context); + if (s != NULL) { + request->contenttype = msStrdup(s); + } else { + /* we've to set default Content-Type which is + * application/octet-stream according to + * W3 RFC 2626 section 7.2.1 */ + request->contenttype = msStrdup("application/octet-stream"); + } } if (raw_post_data) { post_data = msStrdup(raw_post_data); data_len = raw_post_data_length; } else { - if(MS_SUCCESS != readPostBody( request, &post_data )) + if (MS_SUCCESS != readPostBody(request, &post_data)) return -1; data_len = strlen(post_data); } /* if the content_type is application/x-www-form-urlencoded, we have to parse it like the QUERY_STRING variable */ - if(strncmp(request->contenttype, "application/x-www-form-urlencoded", strlen("application/x-www-form-urlencoded")) == 0) { - while( data_len > 0 && isspace(post_data[data_len-1]) ) + if (strncmp(request->contenttype, "application/x-www-form-urlencoded", + strlen("application/x-www-form-urlencoded")) == 0) { + while (data_len > 0 && isspace(post_data[data_len - 1])) post_data[--data_len] = '\0'; - while( post_data[0] ) { - if(m >= maxParams) { + while (post_data[0]) { + if (m >= maxParams) { maxParams *= 2; - request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams); - request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams); + request->ParamNames = (char **)msSmallRealloc( + request->ParamNames, sizeof(char *) * maxParams); + request->ParamValues = (char **)msSmallRealloc( + request->ParamValues, sizeof(char *) * maxParams); } - request->ParamValues[m] = makeword(post_data,'&'); + request->ParamValues[m] = makeword(post_data, '&'); plustospace(request->ParamValues[m]); unescape_url(request->ParamValues[m]); - request->ParamNames[m] = makeword(request->ParamValues[m],'='); + request->ParamNames[m] = makeword(request->ParamValues[m], '='); m++; } - free( post_data ); + free(post_data); } else request->postrequest = post_data; /* check the QUERY_STRING even in the post request since it can contain information. Eg a wfs request with */ s = getenv2("QUERY_STRING", thread_context); - if(s) { + if (s) { if (debuglevel >= MS_DEBUGLEVEL_DEBUG) msDebug("loadParams() QUERY_STRING: %s\n", s); queryString = msStrdup(s); - for(x=0; queryString[0] != '\0'; x++) { - if(m >= maxParams) { + for (x = 0; queryString[0] != '\0'; x++) { + if (m >= maxParams) { maxParams *= 2; - request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams); - request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams); + request->ParamNames = (char **)msSmallRealloc( + request->ParamNames, sizeof(char *) * maxParams); + request->ParamValues = (char **)msSmallRealloc( + request->ParamValues, sizeof(char *) * maxParams); } - request->ParamValues[m] = makeword(queryString,'&'); + request->ParamValues[m] = makeword(queryString, '&'); plustospace(request->ParamValues[m]); unescape_url(request->ParamValues[m]); - request->ParamNames[m] = makeword(request->ParamValues[m],'='); + request->ParamNames[m] = makeword(request->ParamValues[m], '='); m++; } } } else { - if(strcmp(getenv2("REQUEST_METHOD", thread_context),"GET") == 0) { /* we've got a get request */ + if (strcmp(getenv2("REQUEST_METHOD", thread_context), "GET") == + 0) { /* we've got a get request */ request->type = MS_GET_REQUEST; s = getenv2("QUERY_STRING", thread_context); - if(s == NULL) { + if (s == NULL) { // msIO_setHeader("Content-Type","text/html"); // msIO_sendHeaders(); - // msIO_printf("No query information to decode. QUERY_STRING not set.\n"); - msSetError(MS_WEBERR, "No query information to decode. QUERY_STRING not set.", "loadParams()"); + // msIO_printf("No query information to decode. QUERY_STRING not + // set.\n"); + msSetError(MS_WEBERR, + "No query information to decode. QUERY_STRING not set.", + "loadParams()"); return -1; } if (debuglevel >= MS_DEBUGLEVEL_DEBUG) msDebug("loadParams() QUERY_STRING: %s\n", s); - if(strlen(s)==0) { + if (strlen(s) == 0) { // msIO_setHeader("Content-Type","text/html"); // msIO_sendHeaders(); - // msIO_printf("No query information to decode. QUERY_STRING is set, but empty.\n"); - msSetError(MS_WEBERR, "No query information to decode. QUERY_STRING is set, but empty.", "loadParams()"); + // msIO_printf("No query information to decode. QUERY_STRING is set, but + // empty.\n"); + msSetError( + MS_WEBERR, + "No query information to decode. QUERY_STRING is set, but empty.", + "loadParams()"); return -1; } /* don't modify the string returned by getenv2 */ queryString = msStrdup(s); - for(x=0; queryString[0] != '\0'; x++) { - if(m >= maxParams) { + for (x = 0; queryString[0] != '\0'; x++) { + if (m >= maxParams) { maxParams *= 2; - request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams); - request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams); + request->ParamNames = (char **)msSmallRealloc( + request->ParamNames, sizeof(char *) * maxParams); + request->ParamValues = (char **)msSmallRealloc( + request->ParamValues, sizeof(char *) * maxParams); } - request->ParamValues[m] = makeword(queryString,'&'); + request->ParamValues[m] = makeword(queryString, '&'); plustospace(request->ParamValues[m]); unescape_url(request->ParamValues[m]); - request->ParamNames[m] = makeword(request->ParamValues[m],'='); + request->ParamNames[m] = makeword(request->ParamValues[m], '='); m++; } } else { // msIO_setHeader("Content-Type","text/html"); // msIO_sendHeaders(); - // msIO_printf("This script should be referenced with a METHOD of GET or METHOD of POST.\n"); - msSetError(MS_WEBERR, "This script should be referenced with a METHOD of GET or METHOD of POST.", "loadParams()"); + // msIO_printf("This script should be referenced with a METHOD of GET or + // METHOD of POST.\n"); + msSetError(MS_WEBERR, + "This script should be referenced with a METHOD of GET or " + "METHOD of POST.", + "loadParams()"); return -1; } } /* check for any available cookies */ s = getenv2("HTTP_COOKIE", thread_context); - if(s != NULL) { + if (s != NULL) { httpCookie = msStrdup(s); request->httpcookiedata = msStrdup(s); - for(x=0; httpCookie[0] != '\0'; x++) { - if(m >= maxParams) { + for (x = 0; httpCookie[0] != '\0'; x++) { + if (m >= maxParams) { maxParams *= 2; - request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams); - request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams); + request->ParamNames = (char **)msSmallRealloc( + request->ParamNames, sizeof(char *) * maxParams); + request->ParamValues = (char **)msSmallRealloc( + request->ParamValues, sizeof(char *) * maxParams); } - request->ParamValues[m] = makeword(httpCookie,';'); + request->ParamValues[m] = makeword(httpCookie, ';'); plustospace(request->ParamValues[m]); unescape_url(request->ParamValues[m]); - request->ParamNames[m] = makeword_skip(request->ParamValues[m],'=',' '); + request->ParamNames[m] = makeword_skip(request->ParamValues[m], '=', ' '); m++; } } @@ -285,142 +312,144 @@ int loadParams(cgiRequestObj *request, if (httpCookie) free(httpCookie); - return(m); + return (m); } -void getword(char *word, char *line, char stop) -{ - int x = 0,y; +void getword(char *word, char *line, char stop) { + int x = 0, y; - for(x=0; ((line[x]) && (line[x] != stop)); x++) + for (x = 0; ((line[x]) && (line[x] != stop)); x++) word[x] = line[x]; word[x] = '\0'; - if(line[x]) ++x; - y=0; + if (line[x]) + ++x; + y = 0; - while((line[y++] = line[x++])); + while ((line[y++] = line[x++])) + ; } -char *makeword_skip(char *line, char stop, char skip) -{ - int x = 0,y,offset=0; - char *word = (char *) msSmallMalloc(sizeof(char) * (strlen(line) + 1)); +char *makeword_skip(char *line, char stop, char skip) { + int x = 0, y, offset = 0; + char *word = (char *)msSmallMalloc(sizeof(char) * (strlen(line) + 1)); - for(x=0; ((line[x]) && (line[x] == skip)); x++); + for (x = 0; ((line[x]) && (line[x] == skip)); x++) + ; offset = x; - for(x=offset; ((line[x]) && (line[x] != stop)); x++) - word[x-offset] = line[x]; + for (x = offset; ((line[x]) && (line[x] != stop)); x++) + word[x - offset] = line[x]; - word[x-offset] = '\0'; - if(line[x]) ++x; - y=0; + word[x - offset] = '\0'; + if (line[x]) + ++x; + y = 0; - while((line[y++] = line[x++])); + while ((line[y++] = line[x++])) + ; return word; } -char *makeword(char *line, char stop) -{ - int x = 0,y; - char *word = (char *) msSmallMalloc(sizeof(char) * (strlen(line) + 1)); +char *makeword(char *line, char stop) { + int x = 0, y; + char *word = (char *)msSmallMalloc(sizeof(char) * (strlen(line) + 1)); - for(x=0; ((line[x]) && (line[x] != stop)); x++) + for (x = 0; ((line[x]) && (line[x] != stop)); x++) word[x] = line[x]; word[x] = '\0'; - if(line[x]) ++x; - y=0; + if (line[x]) + ++x; + y = 0; - while((line[y++] = line[x++])); + while ((line[y++] = line[x++])) + ; return word; } -char *fmakeword(FILE *f, char stop, int *cl) -{ +char *fmakeword(FILE *f, char stop, int *cl) { int wsize; char *word; int ll; wsize = 102400; - ll=0; - word = (char *) msSmallMalloc(sizeof(char) * (wsize + 1)); + ll = 0; + word = (char *)msSmallMalloc(sizeof(char) * (wsize + 1)); - while(1) { + while (1) { word[ll] = (char)fgetc(f); - if(ll==wsize) { - word[ll+1] = '\0'; - wsize+=102400; - word = (char *)msSmallRealloc(word,sizeof(char)*(wsize+1)); + if (ll == wsize) { + word[ll + 1] = '\0'; + wsize += 102400; + word = (char *)msSmallRealloc(word, sizeof(char) * (wsize + 1)); } --(*cl); - if((word[ll] == stop) || (feof(f)) || (!(*cl))) { - if(word[ll] != stop) ll++; + if ((word[ll] == stop) || (feof(f)) || (!(*cl))) { + if (word[ll] != stop) + ll++; word[ll] = '\0'; - word = (char *) msSmallRealloc(word, ll+1); + word = (char *)msSmallRealloc(word, ll + 1); return word; } ++ll; } } -char x2c(char *what) -{ +char x2c(char *what) { register char digit; - digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); + digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A') + 10 : (what[0] - '0')); digit *= 16; - digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); - return(digit); + digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A') + 10 : (what[1] - '0')); + return (digit); } -void unescape_url(char *url) -{ - register int x,y; +void unescape_url(char *url) { + register int x, y; - for(x=0,y=0; url[y]; ++x,++y) { - if((url[x] = url[y]) == '%') { - url[x] = x2c(&url[y+1]); - y+=2; + for (x = 0, y = 0; url[y]; ++x, ++y) { + if ((url[x] = url[y]) == '%') { + url[x] = x2c(&url[y + 1]); + y += 2; } } url[x] = '\0'; } -void plustospace(char *str) -{ +void plustospace(char *str) { register int x; - for(x=0; str[x]; x++) if(str[x] == '+') str[x] = ' '; + for (x = 0; str[x]; x++) + if (str[x] == '+') + str[x] = ' '; } -int rind(char *s, char c) -{ +int rind(char *s, char c) { register int x; - for(x=strlen(s) - 1; x != -1; x--) - if(s[x] == c) return x; + for (x = strlen(s) - 1; x != -1; x--) + if (s[x] == c) + return x; return -1; } -void send_fd(FILE *f, FILE *fd) -{ +void send_fd(FILE *f, FILE *fd) { int c; while (1) { c = fgetc(f); - if(c == EOF) + if (c == EOF) return; - fputc((char)c,fd); + fputc((char)c, fd); } } -int ind(char *s, char c) -{ +int ind(char *s, char c) { register int x; - for(x=0; s[x]; x++) - if(s[x] == c) return x; + for (x = 0; s[x]; x++) + if (s[x] == c) + return x; return -1; } @@ -428,15 +457,14 @@ int ind(char *s, char c) /* ** patched version according to CERT advisory... */ -void escape_shell_cmd(char *cmd) -{ - register int x,y,l; - - l=strlen(cmd); - for(x=0; cmd[x]; x++) { - if(ind("&;`'\"|*?~<>^()[]{}$\\\n",cmd[x]) != -1) { - for(y=l+1; y>x; y--) - cmd[y] = cmd[y-1]; +void escape_shell_cmd(char *cmd) { + register int x, y, l; + + l = strlen(cmd); + for (x = 0; cmd[x]; x++) { + if (ind("&;`'\"|*?~<>^()[]{}$\\\n", cmd[x]) != -1) { + for (y = l + 1; y > x; y--) + cmd[y] = cmd[y - 1]; l++; /* length has been increased */ cmd[x] = '\\'; x++; /* skip the character */ @@ -447,15 +475,16 @@ void escape_shell_cmd(char *cmd) /* ** Allocate a new request holder structure */ -cgiRequestObj *msAllocCgiObj() -{ +cgiRequestObj *msAllocCgiObj() { cgiRequestObj *request = (cgiRequestObj *)malloc(sizeof(cgiRequestObj)); - if(!request) + if (!request) return NULL; - request->ParamNames = (char **) msSmallMalloc(MS_DEFAULT_CGI_PARAMS*sizeof(char*)); - request->ParamValues = (char **) msSmallMalloc(MS_DEFAULT_CGI_PARAMS*sizeof(char*)); + request->ParamNames = + (char **)msSmallMalloc(MS_DEFAULT_CGI_PARAMS * sizeof(char *)); + request->ParamValues = + (char **)msSmallMalloc(MS_DEFAULT_CGI_PARAMS * sizeof(char *)); request->NumParams = 0; request->type = MS_GET_REQUEST; request->contenttype = NULL; @@ -469,8 +498,7 @@ cgiRequestObj *msAllocCgiObj() return request; } -void msFreeCgiObj(cgiRequestObj *request) -{ +void msFreeCgiObj(cgiRequestObj *request) { msFreeCharArray(request->ParamNames, request->NumParams); msFreeCharArray(request->ParamValues, request->NumParams); request->ParamNames = NULL; @@ -484,7 +512,7 @@ void msFreeCgiObj(cgiRequestObj *request) request->postrequest = NULL; request->httpcookiedata = NULL; - if(request->api_path) { + if (request->api_path) { msFreeCharArray(request->api_path, request->api_path_length); request->api_path = NULL; request->api_path_length = 0; diff --git a/cgiutil.h b/cgiutil.h index 81e818a47b..b8a931c2f2 100644 --- a/cgiutil.h +++ b/cgiutil.h @@ -5,7 +5,8 @@ * Purpose: cgiRequestObj and CGI parsing utility related declarations. * Author: Steve Lime and the MapServer team. * - * Notes: Portions derived from NCSA HTTPd Server's example CGI programs (util.c). + * Notes: Portions derived from NCSA HTTPd Server's example CGI programs + *(util.c). * ****************************************************************************** * Copyright (c) 1996-2005 Regents of the University of Minnesota. @@ -37,9 +38,9 @@ extern "C" { #endif #if defined(_WIN32) && !defined(__CYGWIN__) -# define MS_DLL_EXPORT __declspec(dllexport) +#define MS_DLL_EXPORT __declspec(dllexport) #else -#define MS_DLL_EXPORT +#define MS_DLL_EXPORT #endif /* @@ -47,7 +48,7 @@ extern "C" { */ #define MS_DEFAULT_CGI_PARAMS 100 -enum MS_REQUEST_TYPE {MS_GET_REQUEST, MS_POST_REQUEST}; +enum MS_REQUEST_TYPE { MS_GET_REQUEST, MS_POST_REQUEST }; /** Class for programming OWS services @@ -66,9 +67,10 @@ typedef struct { %mutable; #endif - enum MS_REQUEST_TYPE type; ///< A :ref:`request type constant` - char *contenttype; ///< The content type of the request - char *postrequest; ///< Any POST data request + enum MS_REQUEST_TYPE + type; ///< A :ref:`request type constant` + char *contenttype; ///< The content type of the request + char *postrequest; ///< Any POST data request char *httpcookiedata; ///< Any cookie data associated with the request #ifndef SWIG @@ -78,13 +80,15 @@ typedef struct { #endif } cgiRequestObj; - /* ** Function prototypes */ #ifndef SWIG -MS_DLL_EXPORT int loadParams(cgiRequestObj *request, char* (*getenv2)(const char*, void* thread_context), - char *raw_post_data, ms_uint32 raw_post_data_length, void* thread_context); +MS_DLL_EXPORT int +loadParams(cgiRequestObj *request, + char *(*getenv2)(const char *, void *thread_context), + char *raw_post_data, ms_uint32 raw_post_data_length, + void *thread_context); MS_DLL_EXPORT void getword(char *, char *, char); MS_DLL_EXPORT char *makeword_skip(char *, char, char); MS_DLL_EXPORT char *makeword(char *, char); diff --git a/ci/travis/after_success.sh b/ci/travis/after_success.sh index 61e514f1f2..66768e38d0 100755 --- a/ci/travis/after_success.sh +++ b/ci/travis/after_success.sh @@ -1,7 +1,7 @@ #!/bin/sh set -eu -if [ "$BUILD_NAME" != "PHP_7.4_WITH_ASAN" ]; then +if [ "$BUILD_NAME" != "PHP_8.1_WITH_ASAN" ]; then # Only run coverage when it is safe to do so (not on pull requests), and only on master branch echo "$TRAVIS_SECURE_ENV_VARS" echo "$TRAVIS_BRANCH" diff --git a/ci/travis/before_install.sh b/ci/travis/before_install.sh index 4c27cc123b..7e677f1c90 100755 --- a/ci/travis/before_install.sh +++ b/ci/travis/before_install.sh @@ -15,6 +15,7 @@ sudo apt-get install -y --allow-unauthenticated build-essential protobuf-c-compi sudo apt-get install -y --allow-unauthenticated libmono-system-drawing4.0-cil mono-mcs sudo apt-get install -y --allow-unauthenticated libperl-dev sudo apt-get install -y --allow-unauthenticated openjdk-8-jdk +sudo apt-get install -y --allow-unauthenticated libonig5 #install recent cmake on GH build action if [ -z ${TRAVIS+x} ]; then @@ -25,9 +26,9 @@ else # install recent CMake on Travis DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" mkdir ${DEPS_DIR} && cd ${DEPS_DIR} - wget --no-check-certificate https://cmake.org/files/v3.23/cmake-3.23.1-linux-x86_64.tar.gz - tar -xvf cmake-3.23.1-linux-x86_64.tar.gz > /dev/null - mv cmake-3.23.1-linux-x86_64 cmake-install + wget --no-check-certificate https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-x86_64.tar.gz + tar -xvf cmake-3.26.3-linux-x86_64.tar.gz > /dev/null + mv cmake-3.26.3-linux-x86_64 cmake-install export PATH=${DEPS_DIR}/cmake-install:${DEPS_DIR}/cmake-install/bin:${PATH} cd ${TRAVIS_BUILD_DIR} export MSBUILD_ENV="TRAVIS" @@ -78,7 +79,7 @@ sudo service postgresql restart 12 cd msautotest #upgrade to recent PHPUnit -cd php && curl -LO https://phar.phpunit.de/phpunit-9.5.phar +cd php && curl -LO https://phar.phpunit.de/phpunit-10.phar cd .. python -m pyflakes . ./create_postgis_test_data.sh diff --git a/ci/travis/script.sh b/ci/travis/script.sh index 0ba8e2c69f..3e67ac6ae0 100755 --- a/ci/travis/script.sh +++ b/ci/travis/script.sh @@ -28,16 +28,16 @@ pyenv which pip pyenv which python #pyenv which python-config # check for phpunit & xdebug -php msautotest/php/phpunit-9.5.phar --version +php msautotest/php/phpunit-10.phar --version php -v -if [ "$BUILD_NAME" = "PHP_7.4_WITH_ASAN" ]; then +if [ "$BUILD_NAME" = "PHP_8.1_WITH_ASAN" ]; then # -DNDEBUG to avoid issues with cairo cleanup make cmakebuild MFLAGS="-j2" CMAKE_C_FLAGS="-g -fsanitize=address -DNDEBUG" CMAKE_CXX_FLAGS="-g -fsanitize=address -DNDEBUG" EXTRA_CMAKEFLAGS="-DCMAKE_BUILD_TYPE=None -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address" export AUTOTEST_OPTS="--strict --run_under_asan" # Only run tests that only involve mapserv/map2img binaries. mspython, etc would require LD_PREOLOAD'ing the asan shared object make -j4 asan_compatible_tests -elif [ "$BUILD_NAME" = "PHP_7.4_WITH_PROJ8" ]; then +elif [ "$BUILD_NAME" = "PHP_8.1_WITH_PROJ8" ]; then #runs through GitHub action make cmakebuild MFLAGS="-j2" CMAKE_C_FLAGS="-O2" CMAKE_CXX_FLAGS="-O2" LIBMAPSERVER_EXTRA_FLAGS="-Wall -Werror -Wextra" make mspython-wheel diff --git a/classobject.c b/classobject.c index 36fa328bb9..dc9619df0d 100644 --- a/classobject.c +++ b/classobject.c @@ -31,17 +31,17 @@ #include "mapserver.h" - /* -** Add a label to a classObj (order doesn't matter for labels like it does with styles) +** Add a label to a classObj (order doesn't matter for labels like it does with +*styles) */ -int msAddLabelToClass(classObj *class, labelObj *label) -{ +int msAddLabelToClass(classObj *class, labelObj *label) { if (!label) { msSetError(MS_CHILDERR, "Can't add a NULL label.", "msAddLabelToClass()"); return MS_FAILURE; } - if (msGrowClassLabels(class) == NULL) return MS_FAILURE; + if (msGrowClassLabels(class) == NULL) + return MS_FAILURE; /* msGrowClassLabels will alloc the label, free it in this case */ free(class->labels[class->numlabels]); @@ -54,20 +54,20 @@ int msAddLabelToClass(classObj *class, labelObj *label) /* ** Remove a label from a classObj. */ -labelObj *msRemoveLabelFromClass(classObj *class, int nLabelIndex) -{ +labelObj *msRemoveLabelFromClass(classObj *class, int nLabelIndex) { int i; labelObj *label; if (nLabelIndex < 0 || nLabelIndex >= class->numlabels) { - msSetError(MS_CHILDERR, "Cannot remove label, invalid index %d", "msRemoveLabelFromClass()", nLabelIndex); + msSetError(MS_CHILDERR, "Cannot remove label, invalid index %d", + "msRemoveLabelFromClass()", nLabelIndex); return NULL; } else { - label=class->labels[nLabelIndex]; - for (i=nLabelIndex; inumlabels-1; i++) { - class->labels[i]=class->labels[i+1]; + label = class->labels[nLabelIndex]; + for (i = nLabelIndex; i < class->numlabels - 1; i++) { + class->labels[i] = class->labels[i + 1]; } - class->labels[class->numlabels-1]=NULL; + class->labels[class->numlabels - 1] = NULL; class->numlabels--; MS_REFCNT_DECR(label); return label; @@ -77,47 +77,41 @@ labelObj *msRemoveLabelFromClass(classObj *class, int nLabelIndex) /** * Move the style up inside the array of styles. */ -int msMoveStyleUp(classObj *class, int nStyleIndex) -{ +int msMoveStyleUp(classObj *class, int nStyleIndex) { styleObj *psTmpStyle = NULL; - if (class && nStyleIndex < class->numstyles && nStyleIndex >0) { + if (class && nStyleIndex < class->numstyles && nStyleIndex > 0) { psTmpStyle = (styleObj *)malloc(sizeof(styleObj)); initStyle(psTmpStyle); msCopyStyle(psTmpStyle, class->styles[nStyleIndex]); - msCopyStyle(class->styles[nStyleIndex], - class->styles[nStyleIndex-1]); + msCopyStyle(class->styles[nStyleIndex], class->styles[nStyleIndex - 1]); - msCopyStyle(class->styles[nStyleIndex-1], psTmpStyle); + msCopyStyle(class->styles[nStyleIndex - 1], psTmpStyle); - return(MS_SUCCESS); + return (MS_SUCCESS); } - msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveStyleUp()", - nStyleIndex); + msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveStyleUp()", nStyleIndex); return (MS_FAILURE); } - /** * Move the style down inside the array of styles. */ -int msMoveStyleDown(classObj *class, int nStyleIndex) -{ +int msMoveStyleDown(classObj *class, int nStyleIndex) { styleObj *psTmpStyle = NULL; - if (class && nStyleIndex < class->numstyles-1 && nStyleIndex >=0) { + if (class && nStyleIndex < class->numstyles - 1 && nStyleIndex >= 0) { psTmpStyle = (styleObj *)malloc(sizeof(styleObj)); initStyle(psTmpStyle); msCopyStyle(psTmpStyle, class->styles[nStyleIndex]); - msCopyStyle(class->styles[nStyleIndex], - class->styles[nStyleIndex+1]); + msCopyStyle(class->styles[nStyleIndex], class->styles[nStyleIndex + 1]); - msCopyStyle(class->styles[nStyleIndex+1], psTmpStyle); + msCopyStyle(class->styles[nStyleIndex + 1], psTmpStyle); - return(MS_SUCCESS); + return (MS_SUCCESS); } msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveStyleDown()", nStyleIndex); @@ -129,8 +123,7 @@ int msMoveStyleDown(classObj *class, int nStyleIndex) * Returns the index at which the style was inserted * */ -int msInsertStyle(classObj *class, styleObj *style, int nStyleIndex) -{ +int msInsertStyle(classObj *class, styleObj *style, int nStyleIndex) { int i; if (!style) { @@ -144,39 +137,40 @@ int msInsertStyle(classObj *class, styleObj *style, int nStyleIndex) } /* Catch attempt to insert past end of styles array */ else if (nStyleIndex >= class->numstyles) { - msSetError(MS_CHILDERR, "Cannot insert style beyond index %d", "insertStyle()", class->numstyles-1); + msSetError(MS_CHILDERR, "Cannot insert style beyond index %d", + "insertStyle()", class->numstyles - 1); return -1; } else if (nStyleIndex < 0) { /* Insert at the end by default */ - class->styles[class->numstyles]=style; + class->styles[class->numstyles] = style; MS_REFCNT_INCR(style); class->numstyles++; - return class->numstyles-1; + return class->numstyles - 1; } else { /* Move styles existing at the specified nStyleIndex or greater */ /* to a higher nStyleIndex */ - for (i=class->numstyles-1; i>=nStyleIndex; i--) { - class->styles[i+1] = class->styles[i]; + for (i = class->numstyles - 1; i >= nStyleIndex; i--) { + class->styles[i + 1] = class->styles[i]; } - class->styles[nStyleIndex]=style; + class->styles[nStyleIndex] = style; MS_REFCNT_INCR(style); class->numstyles++; return nStyleIndex; } } -styleObj *msRemoveStyle(classObj *class, int nStyleIndex) -{ +styleObj *msRemoveStyle(classObj *class, int nStyleIndex) { int i; styleObj *style; if (nStyleIndex < 0 || nStyleIndex >= class->numstyles) { - msSetError(MS_CHILDERR, "Cannot remove style, invalid nStyleIndex %d", "removeStyle()", nStyleIndex); + msSetError(MS_CHILDERR, "Cannot remove style, invalid nStyleIndex %d", + "removeStyle()", nStyleIndex); return NULL; } else { - style=class->styles[nStyleIndex]; - for (i=nStyleIndex; inumstyles-1; i++) { - class->styles[i]=class->styles[i+1]; + style = class->styles[nStyleIndex]; + for (i = nStyleIndex; i < class->numstyles - 1; i++) { + class->styles[i] = class->styles[i + 1]; } - class->styles[class->numstyles-1]=NULL; + class->styles[class->numstyles - 1] = NULL; class->numstyles--; MS_REFCNT_DECR(style); return style; @@ -187,19 +181,17 @@ styleObj *msRemoveStyle(classObj *class, int nStyleIndex) * Delete the style identified by the index and shift * styles that follows the deleted style. */ -int msDeleteStyle(classObj *class, int nStyleIndex) -{ - if (class && nStyleIndex < class->numstyles && nStyleIndex >=0) { +int msDeleteStyle(classObj *class, int nStyleIndex) { + if (class && nStyleIndex < class->numstyles && nStyleIndex >= 0) { if (freeStyle(class->styles[nStyleIndex]) == MS_SUCCESS) msFree(class->styles[nStyleIndex]); - for (int i=nStyleIndex; i< class->numstyles-1; i++) { - class->styles[i] = class->styles[i+1]; + for (int i = nStyleIndex; i < class->numstyles - 1; i++) { + class->styles[i] = class->styles[i + 1]; } - class->styles[class->numstyles-1] = NULL; + class->styles[class->numstyles - 1] = NULL; class->numstyles--; - return(MS_SUCCESS); + return (MS_SUCCESS); } - msSetError(MS_CHILDERR, "Invalid index: %d", "msDeleteStyle()", - nStyleIndex); + msSetError(MS_CHILDERR, "Invalid index: %d", "msDeleteStyle()", nStyleIndex); return (MS_FAILURE); } diff --git a/coshp.c b/coshp.c index a78ae3f3a0..ed530893fe 100644 --- a/coshp.c +++ b/coshp.c @@ -33,7 +33,6 @@ #include "mapserver.h" - typedef struct { SHPHandle inSHP, outSHP; DBFHandle inDBF, outDBF; @@ -41,39 +40,37 @@ typedef struct { int numDbfFields; } writeState; -static char* AddFileSuffix ( const char * Filename, const char * Suffix ) -{ - char *pszFullname, *pszBasename; +static char *AddFileSuffix(const char *Filename, const char *Suffix) { + char *pszFullname, *pszBasename; int i; /* -------------------------------------------------------------------- */ /* Compute the base (layer) name. If there is any extension */ /* on the passed in filename we will strip it off. */ /* -------------------------------------------------------------------- */ - pszBasename = (char *) msSmallMalloc(strlen(Filename)+5); - strcpy( pszBasename, Filename ); - for( i = (int)strlen(pszBasename)-1; - i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/' - && pszBasename[i] != '\\'; - i-- ) {} - - if( pszBasename[i] == '.' ) + pszBasename = (char *)msSmallMalloc(strlen(Filename) + 5); + strcpy(pszBasename, Filename); + for (i = (int)strlen(pszBasename) - 1; + i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/' && + pszBasename[i] != '\\'; + i--) { + } + + if (pszBasename[i] == '.') pszBasename[i] = '\0'; /* -------------------------------------------------------------------- */ /* Open the .shp and .shx files. Note that files pulled from */ /* a PC to Unix with upper case filenames won't work! */ /* -------------------------------------------------------------------- */ - pszFullname = (char *) msSmallMalloc(strlen(pszBasename) + 5); - sprintf( pszFullname, "%s%s", pszBasename, Suffix); + pszFullname = (char *)msSmallMalloc(strlen(pszBasename) + 5); + sprintf(pszFullname, "%s%s", pszBasename, Suffix); free(pszBasename); return (pszFullname); } - -static int writeShape(writeState *state, int shapeId) -{ +static int writeShape(writeState *state, int shapeId) { int j = 0; int i = state->currentOutRecord; char fName[20]; @@ -81,33 +78,37 @@ static int writeShape(writeState *state, int shapeId) shapeObj shape; /* Copy the DBF record over */ - for(j=0; jnumDbfFields; j++) { + for (j = 0; j < state->numDbfFields; j++) { - DBFFieldType dbfField = msDBFGetFieldInfo(state->inDBF, j, fName, &fWidth, &fnDecimals); + DBFFieldType dbfField = + msDBFGetFieldInfo(state->inDBF, j, fName, &fWidth, &fnDecimals); switch (dbfField) { - case FTInteger: - msDBFWriteIntegerAttribute(state->outDBF, i, j, + case FTInteger: + msDBFWriteIntegerAttribute( + state->outDBF, i, j, msDBFReadIntegerAttribute(state->inDBF, shapeId, j)); - break; - case FTDouble: - msDBFWriteDoubleAttribute(state->outDBF, i, j, + break; + case FTDouble: + msDBFWriteDoubleAttribute( + state->outDBF, i, j, msDBFReadDoubleAttribute(state->inDBF, shapeId, j)); - break; - case FTString: - msDBFWriteStringAttribute(state->outDBF, i, j, + break; + case FTString: + msDBFWriteStringAttribute( + state->outDBF, i, j, msDBFReadStringAttribute(state->inDBF, shapeId, j)); - break; - default: - fprintf(stderr,"Unsupported data type for field: %s, exiting.\n",fName); - exit(0); + break; + default: + fprintf(stderr, "Unsupported data type for field: %s, exiting.\n", fName); + exit(0); } } /* Copy the SHP record over */ - msSHPReadShape( state->inSHP, shapeId, &shape ); - msSHPWriteShape( state->outSHP, &shape ); - msFreeShape( &shape ); + msSHPReadShape(state->inSHP, shapeId, &shape); + msSHPWriteShape(state->outSHP, &shape); + msFreeShape(&shape); /* Increment output row number */ state->currentOutRecord++; @@ -115,59 +116,59 @@ static int writeShape(writeState *state, int shapeId) return MS_SUCCESS; } - -static int writeNode(writeState *state, treeNodeObj *node) -{ +static int writeNode(writeState *state, treeNodeObj *node) { int i; if (node->ids) { - for(i = 0; i < node->numshapes; i++) { + for (i = 0; i < node->numshapes; i++) { int curRec = state->currentOutRecord; writeShape(state, node->ids[i]); node->ids[i] = curRec; } } - for(i = 0; i < node->numsubnodes; i++) { + for (i = 0; i < node->numsubnodes; i++) { if (node->subnode[i]) writeNode(state, node->subnode[i]); } return MS_SUCCESS; } - -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { treeObj *tree; /* In-memory index */ shapefileObj shapefile; /* Input shapefile */ - SHPHandle outSHP; /* Output SHP */ - DBFHandle outDBF; /* Output DBF */ + SHPHandle outSHP; /* Output SHP */ + DBFHandle outDBF; /* Output DBF */ DBFFieldType dbfField; - writeState state; - int shpType, nShapes; - char fName[20]; - int fWidth, fnDecimals; - char buffer[1024]; - int numFields; - int i; - - if(argc > 1 && strcmp(argv[1], "-v") == 0) { + writeState state; + int shpType, nShapes; + char fName[20]; + int fWidth, fnDecimals; + char buffer[1024]; + int numFields; + int i; + + if (argc > 1 && strcmp(argv[1], "-v") == 0) { printf("%s\n", msGetVersion()); exit(0); } - /* ------------------------------------------------------------------------------- */ - /* Check the number of arguments, return syntax if not correct */ - /* ------------------------------------------------------------------------------- */ - if( argc != 3 ) { - fprintf(stderr,"Syntax: %s [infile] [outfile]\n", argv[0]); + /* ------------------------------------------------------------------------------- + */ + /* Check the number of arguments, return syntax if not correct */ + /* ------------------------------------------------------------------------------- + */ + if (argc != 3) { + fprintf(stderr, "Syntax: %s [infile] [outfile]\n", argv[0]); exit(1); } msSetErrorFile("stderr", NULL); - /* ------------------------------------------------------------------------------- */ - /* Open the shapefile */ - /* ------------------------------------------------------------------------------- */ - if(msShapefileOpen(&shapefile, "rb", argv[1], MS_TRUE) < 0) { + /* ------------------------------------------------------------------------------- + */ + /* Open the shapefile */ + /* ------------------------------------------------------------------------------- + */ + if (msShapefileOpen(&shapefile, "rb", argv[1], MS_TRUE) < 0) { fprintf(stdout, "Error opening shapefile %s.\n", argv[1]); exit(0); } @@ -176,37 +177,45 @@ int main(int argc, char *argv[]) shpType = shapefile.type; numFields = msDBFGetFieldCount(shapefile.hDBF); - /* ------------------------------------------------------------------------------- */ - /* Index the shapefile (auto-calculate depth) */ - /* ------------------------------------------------------------------------------- */ + /* ------------------------------------------------------------------------------- + */ + /* Index the shapefile (auto-calculate depth) */ + /* ------------------------------------------------------------------------------- + */ tree = msCreateTree(&shapefile, 0); msTreeTrim(tree); - /* ------------------------------------------------------------------------------- */ - /* Setup the output .shp/.shx and .dbf files */ - /* ------------------------------------------------------------------------------- */ + /* ------------------------------------------------------------------------------- + */ + /* Setup the output .shp/.shx and .dbf files */ + /* ------------------------------------------------------------------------------- + */ outSHP = msSHPCreate(argv[2], shpType); - if( outSHP == NULL ) { - fprintf( stderr, "Failed to create file '%s'.\n", argv[2] ); - exit( 1 ); + if (outSHP == NULL) { + fprintf(stderr, "Failed to create file '%s'.\n", argv[2]); + exit(1); } - sprintf(buffer,"%s.dbf", argv[2]); + sprintf(buffer, "%s.dbf", argv[2]); outDBF = msDBFCreate(buffer); - if( outDBF == NULL ) { - fprintf( stderr, "Failed to create dbf file '%s'.\n", buffer ); - exit( 1 ); + if (outDBF == NULL) { + fprintf(stderr, "Failed to create dbf file '%s'.\n", buffer); + exit(1); } /* Clone the fields from the input to the output definition */ - for(i=0; iroot); - /* ------------------------------------------------------------------------------- */ - /* Write the spatial index */ - /* ------------------------------------------------------------------------------- */ - msWriteTree(tree, AddFileSuffix(argv[2], MS_INDEX_EXTENSION), MS_NEW_LSB_ORDER); + /* ------------------------------------------------------------------------------- + */ + /* Write the spatial index */ + /* ------------------------------------------------------------------------------- + */ + msWriteTree(tree, AddFileSuffix(argv[2], MS_INDEX_EXTENSION), + MS_NEW_LSB_ORDER); msDestroyTree(tree); - /* ------------------------------------------------------------------------------- */ - /* Close all files */ - /* ------------------------------------------------------------------------------- */ + /* ------------------------------------------------------------------------------- + */ + /* Close all files */ + /* ------------------------------------------------------------------------------- + */ msShapefileClose(&shapefile); msSHPClose(outSHP); msDBFClose(outDBF); - fprintf(stdout, "Wrote %d spatially sorted shapes into shapefile '%s'\n", nShapes, argv[2]); - return(0); + fprintf(stdout, "Wrote %d spatially sorted shapes into shapefile '%s'\n", + nShapes, argv[2]); + return (0); } diff --git a/create_mapaxisorder_csv.py b/create_mapaxisorder_csv.py index b5d2985d93..2e3e4598ff 100644 --- a/create_mapaxisorder_csv.py +++ b/create_mapaxisorder_csv.py @@ -31,7 +31,7 @@ from osgeo import gdal, osr sr = osr.SpatialReference() -print('epsg_code') +print("epsg_code") for code in range(32767): gdal.PushErrorHandler() ret = sr.ImportFromEPSGA(code) diff --git a/dxfcolor.h b/dxfcolor.h index 5de47065ec..1267ae5b6c 100644 --- a/dxfcolor.h +++ b/dxfcolor.h @@ -1,261 +1,69 @@ struct dxfcolor { - int r,g,b; + int r, g, b; }; struct dxfcolor ctable[256] = { - {0, 0, 0}, - {255, 0, 0}, - {255, 255, 0}, - {0, 255, 0}, - {0, 255, 255}, - {0, 0, 255}, - {255, 0, 255}, - {255, 255, 255}, - {128, 128, 128}, - {192, 192, 192}, - {255, 0, 0}, - {255, 127, 127}, - {204, 0, 0}, - {204, 102, 102}, - {153, 0, 0}, - {153, 76, 76}, - {127, 0, 0}, - {127, 63, 63}, - {76, 0, 0}, - {76, 38, 38}, - {255, 63, 0}, - {255, 159, 127}, - {204, 51, 0}, - {204, 127, 102}, - {153, 38, 0}, - {153, 95, 76}, - {127, 31, 0}, - {127, 79, 63}, - {76, 19, 0}, - {76, 47, 38}, - {255, 127, 0}, - {255, 191, 127}, - {204, 102, 0}, - {204, 153, 102}, - {153, 76, 0}, - {153, 114, 76}, - {127, 63, 0}, - {127, 95, 63}, - {76, 38, 0}, - {76, 57, 38}, - {255, 191, 0}, - {255, 223, 127}, - {204, 153, 0}, - {204, 178, 102}, - {153, 114, 0}, - {153, 133, 76}, - {127, 95, 0}, - {127, 111, 63}, - {76, 57, 0}, - {76, 66, 38}, - {255, 255, 0}, - {255, 255, 127}, - {204, 204, 0}, - {204, 204, 102}, - {153, 153, 0}, - {153, 153, 76}, - {127, 127, 0}, - {127, 127, 63}, - {76, 76, 0}, - {76, 76, 38}, - {191, 255, 0}, - {223, 255, 127}, - {153, 204, 0}, - {178, 204, 102}, - {114, 153, 0}, - {133, 153, 76}, - {95, 127, 0}, - {111, 127, 63}, - {57, 76, 0}, - {66, 76, 38}, - {127, 255, 0}, - {191, 255, 127}, - {102, 204, 0}, - {153, 204, 102}, - {76, 153, 0}, - {114, 153, 76}, - {63, 127, 0}, - {95, 127, 63}, - {38, 76, 0}, - {57, 76, 38}, - {63, 255, 0}, - {159, 255, 127}, - {51, 204, 0}, - {127, 204, 102}, - {38, 153, 0}, - {95, 153, 76}, - {31, 127, 0}, - {79, 127, 63}, - {19, 76, 0}, - {47, 76, 38}, - {0, 255, 0}, - {127, 255, 127}, - {0, 204, 0}, - {102, 204, 102}, - {0, 153, 0}, - {76, 153, 76}, - {0, 127, 0}, - {63, 127, 63}, - {0, 76, 0}, - {38, 76, 38}, - {0, 255, 63}, - {127, 255, 159}, - {0, 204, 51}, - {102, 204, 127}, - {0, 153, 38}, - {76, 153, 95}, - {0, 127, 31}, - {63, 127, 79}, - {0, 76, 19}, - {38, 76, 47}, - {0, 255, 127}, - {127, 255, 191}, - {0, 204, 102}, - {102, 204, 153}, - {0, 153, 76}, - {76, 153, 114}, - {0, 127, 63}, - {63, 127, 95}, - {0, 76, 38}, - {38, 76, 57}, - {0, 255, 191}, - {127, 255, 223}, - {0, 204, 153}, - {102, 204, 178}, - {0, 153, 114}, - {76, 153, 133}, - {0, 127, 95}, - {63, 127, 111}, - {0, 76, 57}, - {38, 76, 66}, - {0, 255, 255}, - {127, 255, 255}, - {0, 204, 204}, - {102, 204, 204}, - {0, 153, 153}, - {76, 153, 153}, - {0, 127, 127}, - {63, 127, 127}, - {0, 76, 76}, - {38, 76, 76}, - {0, 191, 255}, - {127, 223, 255}, - {0, 153, 204}, - {102, 178, 204}, - {0, 114, 153}, - {76, 133, 153}, - {0, 95, 127}, - {63, 111, 127}, - {0, 57, 76}, - {38, 66, 76}, - {0, 127, 255}, - {127, 191, 255}, - {0, 102, 204}, - {102, 153, 204}, - {0, 76, 153}, - {76, 114, 153}, - {0, 63, 127}, - {63, 95, 127}, - {0, 38, 76}, - {38, 57, 76}, - {0, 63, 255}, - {127, 159, 255}, - {0, 51, 204}, - {102, 127, 204}, - {0, 38, 153}, - {76, 95, 153}, - {0, 31, 127}, - {63, 79, 127}, - {0, 19, 76}, - {38, 47, 76}, - {0, 0, 255}, - {127, 127, 255}, - {0, 0, 204}, - {102, 102, 204}, - {0, 0, 153}, - {76, 76, 153}, - {0, 0, 127}, - {63, 63, 127}, - {0, 0, 76}, - {38, 38, 76}, - {63, 0, 255}, - {159, 127, 255}, - {51, 0, 204}, - {127, 102, 204}, - {38, 0, 153}, - {95, 76, 153}, - {31, 0, 127}, - {79, 63, 127}, - {19, 0, 76}, - {47, 38, 76}, - {127, 0, 255}, - {191, 127, 255}, - {102, 0, 204}, - {153, 102, 204}, - {76, 0, 153}, - {114, 76, 153}, - {63, 0, 127}, - {95, 63, 127}, - {38, 0, 76}, - {57, 38, 76}, - {191, 0, 255}, - {223, 127, 255}, - {153, 0, 204}, - {178, 102, 204}, - {114, 0, 153}, - {133, 76, 153}, - {95, 0, 127}, - {111, 63, 127}, - {57, 0, 76}, - {66, 38, 76}, - {255, 0, 255}, - {255, 127, 255}, - {204, 0, 204}, - {204, 102, 204}, - {153, 0, 153}, - {153, 76, 153}, - {127, 0, 127}, - {127, 63, 127}, - {76, 0, 76}, - {76, 38, 76}, - {255, 0, 191}, - {255, 127, 223}, - {204, 0, 153}, - {204, 102, 178}, - {153, 0, 114}, - {153, 76, 133}, - {127, 0, 95}, - {127, 63, 111}, - {76, 0, 57}, - {76, 38, 66}, - {255, 0, 127}, - {255, 127, 191}, - {204, 0, 102}, - {204, 102, 153}, - {153, 0, 76}, - {153, 76, 114}, - {127, 0, 63}, - {127, 63, 95}, - {76, 0, 38}, - {76, 38, 57}, - {255, 0, 63}, - {255, 127, 159}, - {204, 0, 51}, - {204, 102, 127}, - {153, 0, 38}, - {153, 76, 95}, - {127, 0, 31}, - {127, 63, 79}, - {76, 0, 19}, - {76, 38, 47}, - {51, 51, 51}, - {91, 91, 91}, - {132, 132, 132}, - {173, 173, 173}, - {214, 214, 214}, - {255, 255, 255}, + {0, 0, 0}, {255, 0, 0}, {255, 255, 0}, {0, 255, 0}, + {0, 255, 255}, {0, 0, 255}, {255, 0, 255}, {255, 255, 255}, + {128, 128, 128}, {192, 192, 192}, {255, 0, 0}, {255, 127, 127}, + {204, 0, 0}, {204, 102, 102}, {153, 0, 0}, {153, 76, 76}, + {127, 0, 0}, {127, 63, 63}, {76, 0, 0}, {76, 38, 38}, + {255, 63, 0}, {255, 159, 127}, {204, 51, 0}, {204, 127, 102}, + {153, 38, 0}, {153, 95, 76}, {127, 31, 0}, {127, 79, 63}, + {76, 19, 0}, {76, 47, 38}, {255, 127, 0}, {255, 191, 127}, + {204, 102, 0}, {204, 153, 102}, {153, 76, 0}, {153, 114, 76}, + {127, 63, 0}, {127, 95, 63}, {76, 38, 0}, {76, 57, 38}, + {255, 191, 0}, {255, 223, 127}, {204, 153, 0}, {204, 178, 102}, + {153, 114, 0}, {153, 133, 76}, {127, 95, 0}, {127, 111, 63}, + {76, 57, 0}, {76, 66, 38}, {255, 255, 0}, {255, 255, 127}, + {204, 204, 0}, {204, 204, 102}, {153, 153, 0}, {153, 153, 76}, + {127, 127, 0}, {127, 127, 63}, {76, 76, 0}, {76, 76, 38}, + {191, 255, 0}, {223, 255, 127}, {153, 204, 0}, {178, 204, 102}, + {114, 153, 0}, {133, 153, 76}, {95, 127, 0}, {111, 127, 63}, + {57, 76, 0}, {66, 76, 38}, {127, 255, 0}, {191, 255, 127}, + {102, 204, 0}, {153, 204, 102}, {76, 153, 0}, {114, 153, 76}, + {63, 127, 0}, {95, 127, 63}, {38, 76, 0}, {57, 76, 38}, + {63, 255, 0}, {159, 255, 127}, {51, 204, 0}, {127, 204, 102}, + {38, 153, 0}, {95, 153, 76}, {31, 127, 0}, {79, 127, 63}, + {19, 76, 0}, {47, 76, 38}, {0, 255, 0}, {127, 255, 127}, + {0, 204, 0}, {102, 204, 102}, {0, 153, 0}, {76, 153, 76}, + {0, 127, 0}, {63, 127, 63}, {0, 76, 0}, {38, 76, 38}, + {0, 255, 63}, {127, 255, 159}, {0, 204, 51}, {102, 204, 127}, + {0, 153, 38}, {76, 153, 95}, {0, 127, 31}, {63, 127, 79}, + {0, 76, 19}, {38, 76, 47}, {0, 255, 127}, {127, 255, 191}, + {0, 204, 102}, {102, 204, 153}, {0, 153, 76}, {76, 153, 114}, + {0, 127, 63}, {63, 127, 95}, {0, 76, 38}, {38, 76, 57}, + {0, 255, 191}, {127, 255, 223}, {0, 204, 153}, {102, 204, 178}, + {0, 153, 114}, {76, 153, 133}, {0, 127, 95}, {63, 127, 111}, + {0, 76, 57}, {38, 76, 66}, {0, 255, 255}, {127, 255, 255}, + {0, 204, 204}, {102, 204, 204}, {0, 153, 153}, {76, 153, 153}, + {0, 127, 127}, {63, 127, 127}, {0, 76, 76}, {38, 76, 76}, + {0, 191, 255}, {127, 223, 255}, {0, 153, 204}, {102, 178, 204}, + {0, 114, 153}, {76, 133, 153}, {0, 95, 127}, {63, 111, 127}, + {0, 57, 76}, {38, 66, 76}, {0, 127, 255}, {127, 191, 255}, + {0, 102, 204}, {102, 153, 204}, {0, 76, 153}, {76, 114, 153}, + {0, 63, 127}, {63, 95, 127}, {0, 38, 76}, {38, 57, 76}, + {0, 63, 255}, {127, 159, 255}, {0, 51, 204}, {102, 127, 204}, + {0, 38, 153}, {76, 95, 153}, {0, 31, 127}, {63, 79, 127}, + {0, 19, 76}, {38, 47, 76}, {0, 0, 255}, {127, 127, 255}, + {0, 0, 204}, {102, 102, 204}, {0, 0, 153}, {76, 76, 153}, + {0, 0, 127}, {63, 63, 127}, {0, 0, 76}, {38, 38, 76}, + {63, 0, 255}, {159, 127, 255}, {51, 0, 204}, {127, 102, 204}, + {38, 0, 153}, {95, 76, 153}, {31, 0, 127}, {79, 63, 127}, + {19, 0, 76}, {47, 38, 76}, {127, 0, 255}, {191, 127, 255}, + {102, 0, 204}, {153, 102, 204}, {76, 0, 153}, {114, 76, 153}, + {63, 0, 127}, {95, 63, 127}, {38, 0, 76}, {57, 38, 76}, + {191, 0, 255}, {223, 127, 255}, {153, 0, 204}, {178, 102, 204}, + {114, 0, 153}, {133, 76, 153}, {95, 0, 127}, {111, 63, 127}, + {57, 0, 76}, {66, 38, 76}, {255, 0, 255}, {255, 127, 255}, + {204, 0, 204}, {204, 102, 204}, {153, 0, 153}, {153, 76, 153}, + {127, 0, 127}, {127, 63, 127}, {76, 0, 76}, {76, 38, 76}, + {255, 0, 191}, {255, 127, 223}, {204, 0, 153}, {204, 102, 178}, + {153, 0, 114}, {153, 76, 133}, {127, 0, 95}, {127, 63, 111}, + {76, 0, 57}, {76, 38, 66}, {255, 0, 127}, {255, 127, 191}, + {204, 0, 102}, {204, 102, 153}, {153, 0, 76}, {153, 76, 114}, + {127, 0, 63}, {127, 63, 95}, {76, 0, 38}, {76, 38, 57}, + {255, 0, 63}, {255, 127, 159}, {204, 0, 51}, {204, 102, 127}, + {153, 0, 38}, {153, 76, 95}, {127, 0, 31}, {127, 63, 79}, + {76, 0, 19}, {76, 38, 47}, {51, 51, 51}, {91, 91, 91}, + {132, 132, 132}, {173, 173, 173}, {214, 214, 214}, {255, 255, 255}, }; diff --git a/etc/mapserver-sample.conf b/etc/mapserver-sample.conf index 54a0d644a7..3391e1d2fd 100644 --- a/etc/mapserver-sample.conf +++ b/etc/mapserver-sample.conf @@ -11,7 +11,7 @@ CONFIG # Limit Mapfile Access # # MS_MAP_NO_PATH "1" - MS_MAP_PATTERN "^/opt/mapserver" ## required + MS_MAP_PATTERN "^/opt/mapserver" ## required when referencing mapfiles by path # MS_MAP_BAD_PATTERN "[/\\]{2}|[/\\]?\\.+[/\\]|," # diff --git a/flatgeobuf/flatgeobuf_c.cpp b/flatgeobuf/flatgeobuf_c.cpp index c959cc6c34..ff783244ec 100644 --- a/flatgeobuf/flatgeobuf_c.cpp +++ b/flatgeobuf/flatgeobuf_c.cpp @@ -15,15 +15,14 @@ uint8_t FLATGEOBUF_MAGICBYTES_SIZE = sizeof(flatgeobuf_magicbytes); uint32_t INIT_BUFFER_SIZE = 1024 * 4; template -char *to_string(uint8_t *data) { +void parse_value(uint8_t *data, char **values, uint16_t i, uint32_t &offset, bool found) +{ using std::to_string; - return msStrdup(to_string(*((T*)data)).c_str()); -} - -template -void parse_value(uint8_t *data, char **values, uint16_t i, uint32_t &offset, bool found) { if (found) - values[i] = to_string(data + offset); + { + msFree(values[i]); + values[i] = msStrdup(to_string(*((T*) (data + offset))).c_str()); + } offset += sizeof(T); } @@ -31,18 +30,24 @@ ctx *flatgeobuf_init_ctx() { ctx *c = (ctx *) malloc(sizeof(ctx)); memset(c, 0, sizeof(ctx)); + c->is_null_geom = false; c->done = false; return c; } void flatgeobuf_free_ctx(ctx *ctx) { - if (ctx->columns) + if (ctx->columns) { + for (uint32_t i = 0; i < ctx->columns_len; i++) + free(ctx->columns[i].name); free(ctx->columns); + } if (ctx->search_result) free(ctx->search_result); if (ctx->buf) free(ctx->buf); + if (ctx->wkt) + free(ctx->wkt); free(ctx); } @@ -72,22 +77,37 @@ void flatgeobuf_ensure_point(ctx *ctx, uint32_t len) } } -void flatgeobuf_ensure_buf(ctx *ctx, uint32_t size) +int flatgeobuf_ensure_buf(ctx *ctx, uint32_t size) { + if (size > 100 * 1024 * 1024) { + msSetError(MS_FGBERR, "Invalid buffer size requested", "flatgeobuf_ensure_buf"); + return -1; + } if (!ctx->buf) { - ctx->buf_size = INIT_BUFFER_SIZE; + ctx->buf_size = std::max(INIT_BUFFER_SIZE, size); ctx->buf = (uint8_t *) malloc(ctx->buf_size); - return; + if (ctx->buf == NULL) { + msSetError(MS_FGBERR, "Failed to allocate buffer", "flatgeobuf_ensure_buf"); + return -1; + } + return 0; } if (ctx->buf_size < size) { - ctx->buf_size = ctx->buf_size * 2; - ctx->buf = (uint8_t *) realloc(ctx->buf, ctx->buf_size); - flatgeobuf_ensure_buf(ctx, size); + ctx->buf_size = std::max(ctx->buf_size * 2, size); + auto buf = (uint8_t *) realloc(ctx->buf, ctx->buf_size); + if (buf == NULL) { + msSetError(MS_FGBERR, "Failed to reallocate buffer", "flatgeobuf_ensure_buf"); + return -1; + } + ctx->buf = buf; } + return 0; } int flatgeobuf_decode_feature(ctx *ctx, layerObj *layer, shapeObj *shape) { + ctx->is_null_geom = false; + uint32_t featureSize; if (VSIFReadL(&featureSize, sizeof(featureSize), 1, ctx->file) != 1) { if (VSIFEofL(ctx->file)) { @@ -98,7 +118,9 @@ int flatgeobuf_decode_feature(ctx *ctx, layerObj *layer, shapeObj *shape) } ctx->offset += sizeof(uoffset_t); - flatgeobuf_ensure_buf(ctx, featureSize); + if (flatgeobuf_ensure_buf(ctx, featureSize) != 0) { + return -1; + } if (VSIFReadL(ctx->buf, 1, featureSize, ctx->file) != featureSize) { msSetError(MS_FGBERR, "Failed to read feature", "flatgeobuf_decode_feature"); @@ -107,10 +129,12 @@ int flatgeobuf_decode_feature(ctx *ctx, layerObj *layer, shapeObj *shape) ctx->offset += featureSize; auto feature = GetFeature(ctx->buf); const auto geometry = feature->geometry(); - if (geometry) + if (geometry) { GeometryReader(ctx, geometry).read(shape); - else - flatgeobuf_decode_feature(ctx, layer, shape); // skip to next if null geometry + } else { + ctx->is_null_geom = true; + return 0; + } auto properties = feature->properties(); if (properties && properties->size() != 0) { ctx->properties = (uint8_t *) properties->data(); @@ -125,9 +149,6 @@ int flatgeobuf_decode_feature(ctx *ctx, layerObj *layer, shapeObj *shape) int flatgeobuf_decode_properties(ctx *ctx, layerObj *layer, shapeObj *shape) { - uint16_t i; - int32_t ii; - flatgeobuf_column column; uint8_t type; uint32_t offset = 0; uint8_t *data = ctx->properties; @@ -139,10 +160,8 @@ int flatgeobuf_decode_properties(ctx *ctx, layerObj *layer, shapeObj *shape) if (numvalues == 0) return 0; - values = (char **) malloc(sizeof(char *) * numvalues); - - //memset(values, 0, sizeof(char *) * numvalues); - + values = (char **) msSmallCalloc(sizeof(char *), numvalues); + if (shape->values) msFreeCharArray(shape->values, shape->numvalues); shape->numvalues = numvalues; shape->values = values; @@ -151,49 +170,50 @@ int flatgeobuf_decode_properties(ctx *ctx, layerObj *layer, shapeObj *shape) return -1; } while (offset + 1 < size) { + uint16_t i; memcpy(&i, data + offset, sizeof(uint16_t)); offset += sizeof(uint16_t); if (i >= ctx->columns_len) { msSetError(MS_FGBERR, "Column index out of range", "flatgeobuf_decode_properties"); return -1; } - column = ctx->columns[i]; - ii = column.itemindex; + const auto& column = ctx->columns[i]; + const int32_t ii = column.itemindex; found = ii != -1; type = column.type; switch (type) { case flatgeobuf_column_type_bool: - parse_value(data + offset, values, ii, offset, found); + parse_value(data, values, ii, offset, found); break; case flatgeobuf_column_type_byte: - parse_value(data + offset, values, ii, offset, found); + parse_value(data, values, ii, offset, found); break; case flatgeobuf_column_type_ubyte: - parse_value(data + offset, values, ii, offset, found); + parse_value(data, values, ii, offset, found); break; case flatgeobuf_column_type_short: - parse_value(data + offset, values, ii, offset, found); + parse_value(data, values, ii, offset, found); break; case flatgeobuf_column_type_ushort: - parse_value(data + offset, values, ii, offset, found); + parse_value(data, values, ii, offset, found); break; case flatgeobuf_column_type_int: - parse_value(data + offset, values, ii, offset, found); - break; + parse_value(data, values, ii, offset, found); + break; case flatgeobuf_column_type_uint: - parse_value(data + offset, values, ii, offset, found); + parse_value(data, values, ii, offset, found); break; case flatgeobuf_column_type_long: - parse_value(data + offset, values, ii, offset, found); - break; + parse_value(data, values, ii, offset, found); + break; case flatgeobuf_column_type_ulong: - parse_value(data + offset, values, ii, offset, found); + parse_value(data, values, ii, offset, found); break; case flatgeobuf_column_type_float: - parse_value(data + offset, values, ii, offset, found); + parse_value(data, values, ii, offset, found); break; case flatgeobuf_column_type_double: - parse_value(data + offset, values, ii, offset, found); + parse_value(data, values, ii, offset, found); break; case flatgeobuf_column_type_datetime: case flatgeobuf_column_type_string: { @@ -205,9 +225,10 @@ int flatgeobuf_decode_properties(ctx *ctx, layerObj *layer, shapeObj *shape) memcpy(&len, data + offset, sizeof(uint32_t)); offset += sizeof(len); if (found) { - char *str = (char *) malloc(len + 1); + char *str = (char *) msSmallMalloc(len + 1); memcpy(str, data + offset, len); str[len] = '\0'; + msFree(values[ii]); values[ii] = str; } offset += len; @@ -215,7 +236,13 @@ int flatgeobuf_decode_properties(ctx *ctx, layerObj *layer, shapeObj *shape) } } } - // TODO: set missing (null) values to msStrdup("")? + + for(int i = 0; i < shape->numvalues; i++) + { + if( shape->values[i] == NULL) + shape->values[i] = msStrdup(""); + } + return 0; } @@ -225,7 +252,8 @@ int flatgeobuf_check_magicbytes(ctx *ctx) msSetError(MS_FGBERR, "Unexpected offset", "flatgeobuf_check_magicbytes"); return -1; } - ctx->buf = (uint8_t *) malloc(FLATGEOBUF_MAGICBYTES_SIZE); + if (flatgeobuf_ensure_buf(ctx, FLATGEOBUF_MAGICBYTES_SIZE) != 0) + return -1; if (VSIFReadL(ctx->buf, 8, 1, ctx->file) != 1) { msSetError(MS_FGBERR, "Failed to read magicbytes", "flatgeobuf_check_magicbytes"); return -1; @@ -257,7 +285,9 @@ int flatgeobuf_decode_header(ctx *ctx) return -1; } ctx->offset += sizeof(uoffset_t); - flatgeobuf_ensure_buf(ctx, headerSize); + if (flatgeobuf_ensure_buf(ctx, headerSize) != 0) { + return -1; + } if (VSIFReadL(ctx->buf, 1, headerSize, ctx->file) != headerSize) { msSetError(MS_FGBERR, "Failed to read header", "flatgeobuf_decode_header"); return -1; @@ -285,8 +315,12 @@ int flatgeobuf_decode_header(ctx *ctx) ctx->has_tm = header->has_tm(); ctx->index_node_size = header->index_node_size(); auto crs = header->crs(); - if (crs != nullptr) + if (crs != nullptr) { ctx->srid = crs->code(); + auto wkt = crs->wkt(); + if (wkt != nullptr) + ctx->wkt = msStrdup(wkt->c_str()); + } auto columns = header->columns(); if (columns != nullptr) { auto size = columns->size(); @@ -295,7 +329,7 @@ int flatgeobuf_decode_header(ctx *ctx) ctx->columns_len = size; for (uint32_t i = 0; i < size; i++) { auto column = columns->Get(i); - ctx->columns[i].name = column->name()->c_str(); + ctx->columns[i].name = msStrdup(column->name()->c_str()); ctx->columns[i].type = (uint8_t) column->type(); ctx->columns[i].itemindex = -1; } @@ -344,11 +378,9 @@ int flatgeobuf_index_skip(ctx *ctx) int flatgeobuf_read_feature_offset(ctx *ctx, uint64_t index, uint64_t *featureOffset) { - try - { - const auto treeSize = PackedRTree::size(ctx->features_count, ctx->index_node_size); + try { const auto levelBounds = PackedRTree::generateLevelBounds(ctx->features_count, ctx->index_node_size); - const auto bottomLevelOffset = ctx->index_offset - treeSize + (levelBounds.front().first * sizeof(NodeItem)); + const auto bottomLevelOffset = ctx->index_offset + (levelBounds.front().first * sizeof(NodeItem)); const auto nodeItemOffset = bottomLevelOffset + (index * sizeof(NodeItem)); const auto featureOffsetOffset = nodeItemOffset + (sizeof(double) * 4); if (VSIFSeekL(ctx->file, featureOffsetOffset, SEEK_SET) == -1) { diff --git a/flatgeobuf/flatgeobuf_c.h b/flatgeobuf/flatgeobuf_c.h index 20fd4f3d90..32d804ac12 100644 --- a/flatgeobuf/flatgeobuf_c.h +++ b/flatgeobuf/flatgeobuf_c.h @@ -33,7 +33,7 @@ extern uint8_t FLATGEOBUF_MAGICBYTES_SIZE; typedef struct flatgeobuf_column { - const char *name; + char *name; uint8_t type; const char *title; const char *description; @@ -87,6 +87,7 @@ typedef struct flatgeobuf_ctx bool has_tm; uint16_t index_node_size; int32_t srid; + char *wkt; flatgeobuf_column *columns; uint16_t columns_len; @@ -105,6 +106,8 @@ typedef struct flatgeobuf_ctx pointObj *point; uint32_t point_len; + bool is_null_geom; + uint64_t feature_index; int ms_type; uint8_t *properties; uint32_t properties_size; @@ -113,7 +116,7 @@ typedef struct flatgeobuf_ctx flatgeobuf_ctx *flatgeobuf_init_ctx(); void flatgeobuf_free_ctx(flatgeobuf_ctx *ctx); -void flatgeobuf_ensure_buf(flatgeobuf_ctx *ctx, uint32_t size); +int flatgeobuf_ensure_buf(flatgeobuf_ctx *ctx, uint32_t size); void flatgeobuf_ensure_line(flatgeobuf_ctx *ctx, uint32_t len); void flatgeobuf_ensure_point(flatgeobuf_ctx *ctx, uint32_t len); diff --git a/flatgeobuf/include/flatbuffers/base.h b/flatgeobuf/include/flatbuffers/base.h index 4c9ed9b342..c276236a82 100644 --- a/flatgeobuf/include/flatbuffers/base.h +++ b/flatgeobuf/include/flatbuffers/base.h @@ -236,7 +236,7 @@ namespace flatbuffers { } } #define FLATBUFFERS_HAS_STRING_VIEW 1 // Check for absl::string_view - #elif __has_include("absl/strings/string_view.h") + #elif __has_include("absl/strings/string_view.h") && (__cplusplus >= 201411) #include "absl/strings/string_view.h" namespace mapserver { namespace flatbuffers { diff --git a/fontcache.c b/fontcache.c index 434665bfbc..43f836bc38 100644 --- a/fontcache.c +++ b/fontcache.c @@ -26,7 +26,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ - #include "mapserver.h" #include "mapthread.h" #include "fontcache.h" @@ -42,86 +41,85 @@ typedef struct { #ifdef USE_THREAD typedef struct ft_thread_cache ft_thread_cache; -struct ft_thread_cache{ - void* thread_id; +struct ft_thread_cache { + void *thread_id; ft_thread_cache *next; ft_cache cache; }; ft_thread_cache *ft_caches; int use_global_ft_cache; #else - ft_cache global_ft_cache; +ft_cache global_ft_cache; #endif - void msInitFontCache(ft_cache *c) { - memset(c,0,sizeof(ft_cache)); + memset(c, 0, sizeof(ft_cache)); FT_Init_FreeType(&c->library); } void msFreeFontCache(ft_cache *c) { /* ... TODO ... */ - face_element *cur_face,*tmp_face; + face_element *cur_face, *tmp_face; glyph_element *cur_bitmap, *tmp_bitmap; UT_HASH_ITER(hh, c->face_cache, cur_face, tmp_face) { - index_element *cur_index,*tmp_index; - outline_element *cur_outline,*tmp_outline; - glyph_element *cur_glyph,*tmp_glyph; - UT_HASH_ITER(hh, cur_face->index_cache, cur_index, tmp_index) { - UT_HASH_DEL(cur_face->index_cache,cur_index); - free(cur_index); - } - UT_HASH_ITER(hh, cur_face->outline_cache, cur_outline, tmp_outline) { - UT_HASH_DEL(cur_face->outline_cache,cur_outline); - FT_Outline_Done(c->library,&cur_outline->outline); - free(cur_outline); - } - UT_HASH_ITER(hh, cur_face->glyph_cache, cur_glyph, tmp_glyph) { - UT_HASH_DEL(cur_face->glyph_cache,cur_glyph); - free(cur_glyph); - } + index_element *cur_index, *tmp_index; + outline_element *cur_outline, *tmp_outline; + glyph_element *cur_glyph, *tmp_glyph; + UT_HASH_ITER(hh, cur_face->index_cache, cur_index, tmp_index) { + UT_HASH_DEL(cur_face->index_cache, cur_index); + free(cur_index); + } + UT_HASH_ITER(hh, cur_face->outline_cache, cur_outline, tmp_outline) { + UT_HASH_DEL(cur_face->outline_cache, cur_outline); + FT_Outline_Done(c->library, &cur_outline->outline); + free(cur_outline); + } + UT_HASH_ITER(hh, cur_face->glyph_cache, cur_glyph, tmp_glyph) { + UT_HASH_DEL(cur_face->glyph_cache, cur_glyph); + free(cur_glyph); + } #ifdef USE_HARFBUZZ - if(cur_face->hbfont) { - hb_font_destroy(cur_face->hbfont->hbfont); - hb_font_destroy(cur_face->hbfont->hbparentfont); - hb_font_funcs_destroy(cur_face->hbfont->funcs); - free(cur_face->hbfont); - } + if (cur_face->hbfont) { + hb_font_destroy(cur_face->hbfont->hbfont); + hb_font_destroy(cur_face->hbfont->hbparentfont); + hb_font_funcs_destroy(cur_face->hbfont->funcs); + free(cur_face->hbfont); + } #endif - FT_Done_Face(cur_face->face); - free(cur_face->font); - UT_HASH_DEL(c->face_cache,cur_face); - free(cur_face); + FT_Done_Face(cur_face->face); + free(cur_face->font); + UT_HASH_DEL(c->face_cache, cur_face); + free(cur_face); } FT_Done_FreeType(c->library); - UT_HASH_ITER(hh,c->bitmap_glyph_cache, cur_bitmap, tmp_bitmap) { + UT_HASH_ITER(hh, c->bitmap_glyph_cache, cur_bitmap, tmp_bitmap) { UT_HASH_DEL(c->bitmap_glyph_cache, cur_bitmap); free(cur_bitmap); } - memset(c,0,sizeof(ft_cache)); + memset(c, 0, sizeof(ft_cache)); } -ft_cache* msGetFontCache() { +ft_cache *msGetFontCache() { #ifndef USE_THREAD return &global_ft_cache; #else - void* nThreadId = 0; + void *nThreadId = 0; ft_thread_cache *prev = NULL, *cur = ft_caches; if (!use_global_ft_cache) nThreadId = msGetThreadId(); - if( cur != NULL && cur->thread_id == nThreadId ) + if (cur != NULL && cur->thread_id == nThreadId) return &cur->cache; /* -------------------------------------------------------------------- */ /* Search for cache for this thread */ /* -------------------------------------------------------------------- */ - msAcquireLock( TLOCK_TTF ); + msAcquireLock(TLOCK_TTF); cur = ft_caches; - while( cur != NULL && cur->thread_id != nThreadId ) { + while (cur != NULL && cur->thread_id != nThreadId) { prev = cur; cur = cur->next; } @@ -130,14 +128,14 @@ ft_cache* msGetFontCache() { /* If we found it, make sure it is pushed to the front of the */ /* link for faster finding next time, and return it. */ /* -------------------------------------------------------------------- */ - if( cur != NULL ) { - if( prev != NULL ) { + if (cur != NULL) { + if (prev != NULL) { prev->next = cur->next; cur->next = ft_caches; ft_caches = cur; } - msReleaseLock( TLOCK_TTF ); + msReleaseLock(TLOCK_TTF); return &cur->cache; } @@ -151,7 +149,7 @@ ft_cache* msGetFontCache() { cur->next = ft_caches; ft_caches = cur; - msReleaseLock( TLOCK_TTF ); + msReleaseLock(TLOCK_TTF); return &cur->cache; #endif @@ -162,7 +160,8 @@ void msFontCacheSetup() { ft_cache *c = msGetFontCache(); msInitFontCache(c); #else - const char *use_global_cache = CPLGetConfigOption("MS_USE_GLOBAL_FT_CACHE", NULL); + const char *use_global_cache = + CPLGetConfigOption("MS_USE_GLOBAL_FT_CACHE", NULL); if (use_global_cache) use_global_ft_cache = atoi(use_global_cache); else @@ -177,64 +176,66 @@ void msFontCacheCleanup() { ft_cache *c = msGetFontCache(); msFreeFontCache(c); #else - ft_thread_cache *cur,*next; - msAcquireLock( TLOCK_TTF ); - cur = ft_caches; - while( cur != NULL ) { + ft_thread_cache *cur, *next; + msAcquireLock(TLOCK_TTF); + cur = ft_caches; + while (cur != NULL) { msFreeFontCache(&cur->cache); next = cur->next; free(cur); cur = next; } ft_caches = NULL; - msReleaseLock( TLOCK_TTF ); + msReleaseLock(TLOCK_TTF); #endif } unsigned int msGetGlyphIndex(face_element *face, unsigned int unicode) { index_element *ic; - if(face->face->charmap && face->face->charmap->encoding == FT_ENCODING_MS_SYMBOL) { + if (face->face->charmap && + face->face->charmap->encoding == FT_ENCODING_MS_SYMBOL) { unicode |= 0xf000; /* why? */ } #ifdef USE_THREAD if (use_global_ft_cache) - msAcquireLock(TLOCK_TTF); -#endif - UT_HASH_FIND_INT(face->index_cache,&unicode,ic); - if(!ic) { + msAcquireLock(TLOCK_TTF); +#endif + UT_HASH_FIND_INT(face->index_cache, &unicode, ic); + if (!ic) { ic = msSmallMalloc(sizeof(index_element)); - ic->codepoint = FT_Get_Char_Index(face->face,unicode); + ic->codepoint = FT_Get_Char_Index(face->face, unicode); ic->unicode = unicode; - UT_HASH_ADD_INT(face->index_cache,unicode,ic); + UT_HASH_ADD_INT(face->index_cache, unicode, ic); } #ifdef USE_THREAD if (use_global_ft_cache) - msReleaseLock(TLOCK_TTF); -#endif + msReleaseLock(TLOCK_TTF); +#endif return ic->codepoint; } #define MS_DEFAULT_FONT_KEY "_ms_default_" -face_element* msGetFontFace(char *key, fontSetObj *fontset) { +face_element *msGetFontFace(char *key, fontSetObj *fontset) { face_element *fc; int error; ft_cache *cache = msGetFontCache(); - if(!key) { + if (!key) { key = MS_DEFAULT_FONT_KEY; } #ifdef USE_THREAD if (use_global_ft_cache) msAcquireLock(TLOCK_TTF); #endif - UT_HASH_FIND_STR(cache->face_cache,key,fc); - if(!fc) { + UT_HASH_FIND_STR(cache->face_cache, key, fc); + if (!fc) { const char *fontfile = NULL; - fc = msSmallCalloc(1,sizeof(face_element)); - if(fontset && strcmp(key,MS_DEFAULT_FONT_KEY)) { - fontfile = msLookupHashTable(&(fontset->fonts),key); - if(!fontfile) { - msSetError(MS_MISCERR, "Could not find font with key \"%s\" in fontset", "msGetFontFace()", key); + fc = msSmallCalloc(1, sizeof(face_element)); + if (fontset && strcmp(key, MS_DEFAULT_FONT_KEY)) { + fontfile = msLookupHashTable(&(fontset->fonts), key); + if (!fontfile) { + msSetError(MS_MISCERR, "Could not find font with key \"%s\" in fontset", + "msGetFontFace()", key); free(fc); #ifdef USE_THREAD if (use_global_ft_cache) @@ -242,12 +243,15 @@ face_element* msGetFontFace(char *key, fontSetObj *fontset) { #endif return NULL; } - error = FT_New_Face(cache->library,fontfile,0, &(fc->face)); + error = FT_New_Face(cache->library, fontfile, 0, &(fc->face)); } else { - error = FT_New_Memory_Face(cache->library,dejavu_sans_condensed_ttf, dejavu_sans_condensed_ttf_len , 0, &(fc->face)); + error = FT_New_Memory_Face(cache->library, dejavu_sans_condensed_ttf, + dejavu_sans_condensed_ttf_len, 0, &(fc->face)); } - if(error) { - msSetError(MS_MISCERR, "Freetype was unable to load font file \"%s\" for key \"%s\"", "msGetFontFace()", fontfile, key); + if (error) { + msSetError(MS_MISCERR, + "Freetype was unable to load font file \"%s\" for key \"%s\"", + "msGetFontFace()", fontfile, key); free(fc); #ifdef USE_THREAD if (use_global_ft_cache) @@ -255,14 +259,15 @@ face_element* msGetFontFace(char *key, fontSetObj *fontset) { #endif return NULL; } - if(!fc->face->charmap) { + if (!fc->face->charmap) { /* The font file has no unicode charmap, select an alternate one */ - if( FT_Select_Charmap(fc->face, FT_ENCODING_MS_SYMBOL) ) + if (FT_Select_Charmap(fc->face, FT_ENCODING_MS_SYMBOL)) FT_Select_Charmap(fc->face, FT_ENCODING_APPLE_ROMAN); - /* the previous calls may have failed, we ignore as there's nothing much left to do */ + /* the previous calls may have failed, we ignore as there's nothing much + * left to do */ } fc->font = msStrdup(key); - UT_HASH_ADD_KEYPTR(hh,cache->face_cache,fc->font, strlen(key), fc); + UT_HASH_ADD_KEYPTR(hh, cache->face_cache, fc->font, strlen(key), fc); } #ifdef USE_THREAD if (use_global_ft_cache) @@ -271,86 +276,106 @@ face_element* msGetFontFace(char *key, fontSetObj *fontset) { return fc; } -glyph_element* msGetGlyphByIndex(face_element *face, unsigned int size, unsigned int codepoint) { +glyph_element *msGetGlyphByIndex(face_element *face, unsigned int size, + unsigned int codepoint) { glyph_element *gc; glyph_element_key key; - memset(&key,0,sizeof(glyph_element_key)); + memset(&key, 0, sizeof(glyph_element_key)); key.codepoint = codepoint; key.size = size; #ifdef USE_THREAD if (use_global_ft_cache) msAcquireLock(TLOCK_TTF); -#endif - UT_HASH_FIND(hh,face->glyph_cache,&key,sizeof(glyph_element_key),gc); - if(!gc) { +#endif + UT_HASH_FIND(hh, face->glyph_cache, &key, sizeof(glyph_element_key), gc); + if (!gc) { FT_Error error; gc = msSmallMalloc(sizeof(glyph_element)); - if(MS_NINT(size * 96.0/72.0) != face->face->size->metrics.x_ppem) { - FT_Set_Pixel_Sizes(face->face,0,MS_NINT(size * 96/72.0)); + if (MS_NINT(size * 96.0 / 72.0) != face->face->size->metrics.x_ppem) { + FT_Set_Pixel_Sizes(face->face, 0, MS_NINT(size * 96 / 72.0)); } - error = FT_Load_Glyph(face->face,key.codepoint,FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING|FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); + error = + FT_Load_Glyph(face->face, key.codepoint, + FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING | + FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); if (error) { - msDebug("Unable to load glyph %u for font \"%s\". Using ? as fallback.\n", key.codepoint, face->font); + msDebug("Unable to load glyph %u for font \"%s\". Using ? as fallback.\n", + key.codepoint, face->font); // If we can't find a glyph then try to fallback to a question mark. unsigned int fallbackCodepoint = msGetGlyphIndex(face, 0x3F); - error = FT_Load_Glyph(face->face,fallbackCodepoint,FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING|FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); + error = FT_Load_Glyph(face->face, fallbackCodepoint, + FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP | + FT_LOAD_NO_HINTING | + FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); } - if(error) { - msSetError(MS_MISCERR, "unable to load glyph %u for font \"%s\"", "msGetGlyphByIndex()",key.codepoint, face->font); + if (error) { + msSetError(MS_MISCERR, "unable to load glyph %u for font \"%s\"", + "msGetGlyphByIndex()", key.codepoint, face->font); free(gc); #ifdef USE_THREAD if (use_global_ft_cache) msReleaseLock(TLOCK_TTF); -#endif +#endif return NULL; } gc->metrics.minx = face->face->glyph->metrics.horiBearingX / 64.0; - gc->metrics.maxx = gc->metrics.minx + face->face->glyph->metrics.width / 64.0; + gc->metrics.maxx = + gc->metrics.minx + face->face->glyph->metrics.width / 64.0; gc->metrics.maxy = face->face->glyph->metrics.horiBearingY / 64.0; - gc->metrics.miny = gc->metrics.maxy - face->face->glyph->metrics.height / 64.0; + gc->metrics.miny = + gc->metrics.maxy - face->face->glyph->metrics.height / 64.0; gc->metrics.advance = face->face->glyph->metrics.horiAdvance / 64.0; gc->key = key; - UT_HASH_ADD(hh,face->glyph_cache,key,sizeof(glyph_element_key), gc); + UT_HASH_ADD(hh, face->glyph_cache, key, sizeof(glyph_element_key), gc); } #ifdef USE_THREAD if (use_global_ft_cache) msReleaseLock(TLOCK_TTF); -#endif +#endif return gc; } -outline_element* msGetGlyphOutline(face_element *face, glyph_element *glyph) { +outline_element *msGetGlyphOutline(face_element *face, glyph_element *glyph) { outline_element *oc; outline_element_key key; ft_cache *cache = msGetFontCache(); - memset(&key,0,sizeof(outline_element_key)); + memset(&key, 0, sizeof(outline_element_key)); key.glyph = glyph; #ifdef USE_THREAD if (use_global_ft_cache) msAcquireLock(TLOCK_TTF); #endif - UT_HASH_FIND(hh,face->outline_cache,&key, sizeof(outline_element_key),oc); - if(!oc) { + UT_HASH_FIND(hh, face->outline_cache, &key, sizeof(outline_element_key), oc); + if (!oc) { FT_Matrix matrix; FT_Vector pen; FT_Error error; oc = msSmallMalloc(sizeof(outline_element)); - if(MS_NINT(glyph->key.size * 96.0/72.0) != face->face->size->metrics.x_ppem) { - FT_Set_Pixel_Sizes(face->face,0,MS_NINT(glyph->key.size * 96/72.0)); + if (MS_NINT(glyph->key.size * 96.0 / 72.0) != + face->face->size->metrics.x_ppem) { + FT_Set_Pixel_Sizes(face->face, 0, MS_NINT(glyph->key.size * 96 / 72.0)); } matrix.xx = matrix.yy = 0x10000L; matrix.xy = matrix.yx = 0x00000L; pen.x = pen.y = 0; FT_Set_Transform(face->face, &matrix, &pen); - error = FT_Load_Glyph(face->face,glyph->key.codepoint,FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP/*|FT_LOAD_IGNORE_TRANSFORM*/|FT_LOAD_NO_HINTING|FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); + error = FT_Load_Glyph( + face->face, glyph->key.codepoint, + FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP /*|FT_LOAD_IGNORE_TRANSFORM*/ | + FT_LOAD_NO_HINTING | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); if (error) { - msDebug("Unable to load glyph %u for font \"%s\". Using ? as fallback.\n", glyph->key.codepoint, face->font); + msDebug("Unable to load glyph %u for font \"%s\". Using ? as fallback.\n", + glyph->key.codepoint, face->font); // If we can't find a glyph then try to fallback to a question mark. unsigned int fallbackCodepoint = msGetGlyphIndex(face, 0x3F); - error = FT_Load_Glyph(face->face,fallbackCodepoint,FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP/*|FT_LOAD_IGNORE_TRANSFORM*/|FT_LOAD_NO_HINTING|FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); + error = FT_Load_Glyph( + face->face, fallbackCodepoint, + FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP /*|FT_LOAD_IGNORE_TRANSFORM*/ | + FT_LOAD_NO_HINTING | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); } - if(error) { - msSetError(MS_MISCERR, "unable to load glyph %u for font \"%s\"", "msGetGlyphOutline()",glyph->key.codepoint, face->font); + if (error) { + msSetError(MS_MISCERR, "unable to load glyph %u for font \"%s\"", + "msGetGlyphOutline()", glyph->key.codepoint, face->font); #ifdef USE_THREAD if (use_global_ft_cache) msReleaseLock(TLOCK_TTF); @@ -358,11 +383,11 @@ outline_element* msGetGlyphOutline(face_element *face, glyph_element *glyph) { return NULL; } error = FT_Outline_New(cache->library, face->face->glyph->outline.n_points, - face->face->glyph->outline.n_contours, &oc->outline); + face->face->glyph->outline.n_contours, &oc->outline); (void)error; FT_Outline_Copy(&face->face->glyph->outline, &oc->outline); oc->key = key; - UT_HASH_ADD(hh,face->outline_cache,key,sizeof(outline_element_key), oc); + UT_HASH_ADD(hh, face->outline_cache, key, sizeof(outline_element_key), oc); } #ifdef USE_THREAD if (use_global_ft_cache) @@ -373,8 +398,9 @@ outline_element* msGetGlyphOutline(face_element *face, glyph_element *glyph) { int msIsGlyphASpace(glyphObj *glyph) { /* space or tab, for now */ - unsigned int space,tab; - space = msGetGlyphIndex(glyph->face,0x20); - tab = msGetGlyphIndex(glyph->face,0x9); - return glyph->glyph->key.codepoint == space || glyph->glyph->key.codepoint == tab; + unsigned int space, tab; + space = msGetGlyphIndex(glyph->face, 0x20); + tab = msGetGlyphIndex(glyph->face, 0x9); + return glyph->glyph->key.codepoint == space || + glyph->glyph->key.codepoint == tab; } diff --git a/fontcache.h b/fontcache.h index 828298bbd5..8b60079f38 100644 --- a/fontcache.h +++ b/fontcache.h @@ -7,14 +7,13 @@ #include FT_OUTLINE_H #ifdef USE_FRIBIDI - #if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(HAVE_FRIBIDI2) - #include "fribidi.h" - #else - #include - #endif - #include +#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(HAVE_FRIBIDI2) +#include "fribidi.h" +#else +#include +#endif +#include #endif - #ifdef __cplusplus extern "C" { @@ -38,7 +37,7 @@ typedef struct { unsigned int size; } glyph_element_key; -struct glyph_element{ +struct glyph_element { glyph_element_key key; glyph_metrics metrics; UT_hash_handle hh; @@ -64,7 +63,7 @@ typedef struct { UT_hash_handle hh; } bitmap_element; -struct face_element{ +struct face_element { char *font; FT_Face face; index_element *index_cache; @@ -74,12 +73,13 @@ struct face_element{ UT_hash_handle hh; }; - -face_element* msGetFontFace(char *key, fontSetObj *fontset); -outline_element* msGetGlyphOutline(face_element *face, glyph_element *glyph); -glyph_element* msGetBitmapGlyph(rendererVTableObj *renderer, unsigned int size, unsigned int unicode); +face_element *msGetFontFace(char *key, fontSetObj *fontset); +outline_element *msGetGlyphOutline(face_element *face, glyph_element *glyph); +glyph_element *msGetBitmapGlyph(rendererVTableObj *renderer, unsigned int size, + unsigned int unicode); unsigned int msGetGlyphIndex(face_element *face, unsigned int unicode); -glyph_element* msGetGlyphByIndex(face_element *face, unsigned int size, unsigned int codepoint); +glyph_element *msGetGlyphByIndex(face_element *face, unsigned int size, + unsigned int codepoint); int msIsGlyphASpace(glyphObj *glyph); #ifdef __cplusplus diff --git a/fuzzers/shapefuzzer.c b/fuzzers/shapefuzzer.c index 4e0f10894a..7f34166f56 100644 --- a/fuzzers/shapefuzzer.c +++ b/fuzzers/shapefuzzer.c @@ -7,9 +7,8 @@ extern int LLVMFuzzerTestOneInput(GByte *data, size_t size); -static VSILFILE * -SegmentFile(const char *filename, GByte **data_p, size_t *size_p) -{ +static VSILFILE *SegmentFile(const char *filename, GByte **data_p, + size_t *size_p) { GByte *data = *data_p; size_t size = *size_p; @@ -25,13 +24,12 @@ SegmentFile(const char *filename, GByte **data_p, size_t *size_p) return VSIFileFromMemBuffer(filename, data, size, false); } -int -LLVMFuzzerTestOneInput(GByte *data, size_t size) -{ +int LLVMFuzzerTestOneInput(GByte *data, size_t size) { /* this fuzzer expects three files concatenated, separated by the string "deadbeef"; you can generate such a file by typing: - { cat foo.shp; echo -n "deadbeef"; cat foo.shx; echo -n "deadbeef"; cat foo.dbf; } >/tmp/corpus/start + { cat foo.shp; echo -n "deadbeef"; cat foo.shx; echo -n "deadbeef"; cat + foo.dbf; } >/tmp/corpus/start then run the fuzzer: @@ -43,7 +41,8 @@ LLVMFuzzerTestOneInput(GByte *data, size_t size) VSILFILE *dbf = SegmentFile("/vsimem/foo.dbf", &data, &size); shapefileObj file; - if (msShapefileOpenVirtualFile(&file, "/vsimem/foo.shp", shp, shx, dbf, false) == 0) { + if (msShapefileOpenVirtualFile(&file, "/vsimem/foo.shp", shp, shx, dbf, + false) == 0) { for (int i = 0; i < file.numshapes; ++i) { shapeObj shape; msInitShape(&shape); diff --git a/github_issue_no_activity_closer.py b/github_issue_no_activity_closer.py deleted file mode 100644 index 85c5af1325..0000000000 --- a/github_issue_no_activity_closer.py +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env python - -import datetime -import getpass -import json -import re -import time - -import requests - -AUTOCLOSE_MESSAGE = """\ -### This is an automated comment - -This issue has been closed due to lack of activity. This doesn't mean the \ -issue is invalid, it simply got no attention within the last year. Please \ -reopen with missing/relevant information if still valid. - -Typically, issues fall in this state for one of the following reasons: -- Hard, impossible or not enough information to reproduce -- Missing test case -- Lack of a champion with interest and/or funding to address the issue -""" - -AUTOCLOSE_LABEL = "No Recent Activity" - - -def fetch_issues(headers): - issues = [] - url = ("https://api.github.com/repos/mapserver/mapserver/issues?" - "per_page=100") - - while url: - print "Fetching %s" % url - r = requests.get(url, headers=headers) - r.raise_for_status() - time.sleep(1) - issues.extend(r.json()) - - match = re.match(r'<(.*?)>; rel="next"', r.headers['Link'] or '') - url = match.group(1) if match else None - - return issues - - -def close_issue(issue, headers): - """Attempt to close an issue and return whether it succeeded.""" - r = requests.post("https://api.github.com/repos/mapserver/mapserver/" - "issues/%s" % issue['number'], - data=json.dumps({'state': 'closed'}), headers=headers) - - try: - r.raise_for_status() - time.sleep(1) - return True - except requests.HTTPError: - return False - - -def post_issue_comment(issue, comment_text, headers): - """Attempt to post an issue comment and return whether it succeeded.""" - r = requests.post("https://api.github.com/repos/mapserver/mapserver/" - "issues/%s/comments" % issue['number'], - data=json.dumps({'body': comment_text}), headers=headers) - - try: - r.raise_for_status() - time.sleep(1) - return True - except requests.HTTPError: - return False - - -def add_issue_label(issue, label, headers): - """Attempt to add a label to the issue and return whether it succeeded.""" - r = requests.post("https://api.github.com/repos/mapserver/mapserver/" - "issues/%s/labels" % issue['number'], - data=json.dumps([label]), headers=headers) - - try: - r.raise_for_status() - time.sleep(1) - return True - except requests.HTTPError: - return False - - -def close_old_issues(close_before, headers): - all_issues = fetch_issues(headers) - - for issue in all_issues: - issue_last_activity = datetime.datetime.strptime( - issue['updated_at'], "%Y-%m-%dT%H:%M:%SZ") - - print "Processing issue %s with last activity at %s" % (issue['number'], issue_last_activity) - - if issue_last_activity < close_before and issue["state"] == "open": - if post_issue_comment(issue, AUTOCLOSE_MESSAGE, headers): - print " Added comment to old issue %s" % issue['number'] - else: - print " Error adding comment to old issue %s" % issue['number'] - continue - - if add_issue_label(issue, AUTOCLOSE_LABEL, headers): - print " Added label to old issue %s" % issue['number'] - else: - print " Error adding label to old issue %s" % issue['number'] - - if close_issue(issue, headers): - print " Closed old issue %s" % issue['number'] - else: - print " Error closing old issue %s" % issue['number'] - - -if __name__ == '__main__': - close_before = datetime.datetime.today() - datetime.timedelta(days=366) - - print - print "This script closes all issues with no activity within the last year." - print - - github_token = getpass.getpass("Please provide an oauth token: ") - print - - headers = {"Authorization": "token %s" % github_token} - close_old_issues(close_before, headers) diff --git a/hittest.c b/hittest.c index 56f86d53fb..ab1bc8019f 100644 --- a/hittest.c +++ b/hittest.c @@ -28,7 +28,6 @@ #include "mapserver.h" - void initStyleHitTests(styleObj *s, style_hittest *sh, int default_status) { (void)s; sh->status = default_status; @@ -36,51 +35,51 @@ void initStyleHitTests(styleObj *s, style_hittest *sh, int default_status) { void initLabelHitTests(labelObj *l, label_hittest *lh, int default_status) { int i; - lh->stylehits = msSmallCalloc(l->numstyles,sizeof(style_hittest)); + lh->stylehits = msSmallCalloc(l->numstyles, sizeof(style_hittest)); lh->status = default_status; - for(i=0; inumstyles; i++) { - initStyleHitTests(l->styles[i],&lh->stylehits[i],default_status); + for (i = 0; i < l->numstyles; i++) { + initStyleHitTests(l->styles[i], &lh->stylehits[i], default_status); } } void initClassHitTests(classObj *c, class_hittest *ch, int default_status) { int i; - ch->stylehits = msSmallCalloc(c->numstyles,sizeof(style_hittest)); - ch->labelhits = msSmallCalloc(c->numlabels,sizeof(label_hittest)); + ch->stylehits = msSmallCalloc(c->numstyles, sizeof(style_hittest)); + ch->labelhits = msSmallCalloc(c->numlabels, sizeof(label_hittest)); ch->status = default_status; - for(i=0; inumstyles; i++) { - initStyleHitTests(c->styles[i],&ch->stylehits[i],default_status); + for (i = 0; i < c->numstyles; i++) { + initStyleHitTests(c->styles[i], &ch->stylehits[i], default_status); } - for(i=0; inumlabels; i++) { - initLabelHitTests(c->labels[i],&ch->labelhits[i],default_status); + for (i = 0; i < c->numlabels; i++) { + initLabelHitTests(c->labels[i], &ch->labelhits[i], default_status); } } void initLayerHitTests(layerObj *l, layer_hittest *lh) { - int i,default_status; - lh->classhits = msSmallCalloc(l->numclasses,sizeof(class_hittest)); + int i, default_status; + lh->classhits = msSmallCalloc(l->numclasses, sizeof(class_hittest)); - switch(l->type) { - case MS_LAYER_POLYGON: - case MS_LAYER_POINT: - case MS_LAYER_LINE: - case MS_LAYER_ANNOTATION: - default_status = 0; /* needs testing */ - break; - default: - default_status = 1; /* no hittesting needed, use traditional mode */ - break; + switch (l->type) { + case MS_LAYER_POLYGON: + case MS_LAYER_POINT: + case MS_LAYER_LINE: + case MS_LAYER_ANNOTATION: + default_status = 0; /* needs testing */ + break; + default: + default_status = 1; /* no hittesting needed, use traditional mode */ + break; } lh->status = default_status; - for(i=0; inumclasses; i++) { - initClassHitTests(l->class[i],&lh->classhits[i], default_status); + for (i = 0; i < l->numclasses; i++) { + initClassHitTests(l->class[i], &lh -> classhits[i], default_status); } } void initMapHitTests(mapObj *map, map_hittest *mh) { int i; - mh->layerhits = msSmallCalloc(map->numlayers,sizeof(layer_hittest)); - for(i=0; inumlayers; i++) { - initLayerHitTests(GET_LAYER(map,i),&mh->layerhits[i]); + mh->layerhits = msSmallCalloc(map->numlayers, sizeof(layer_hittest)); + for (i = 0; i < map->numlayers; i++) { + initLayerHitTests(GET_LAYER(map, i), &mh->layerhits[i]); } } @@ -91,45 +90,47 @@ void freeLabelHitTests(labelObj *l, label_hittest *lh) { void freeClassHitTests(classObj *c, class_hittest *ch) { int i; - for(i=0; inumlabels; i++) { - freeLabelHitTests(c->labels[i],&ch->labelhits[i]); + for (i = 0; i < c->numlabels; i++) { + freeLabelHitTests(c->labels[i], &ch->labelhits[i]); } free(ch->stylehits); free(ch->labelhits); } void freeLayerHitTests(layerObj *l, layer_hittest *lh) { int i; - for(i=0; inumclasses; i++) { - freeClassHitTests(l->class[i],&lh->classhits[i]); + for (i = 0; i < l->numclasses; i++) { + freeClassHitTests(l->class[i], &lh -> classhits[i]); } free(lh->classhits); } void freeMapHitTests(mapObj *map, map_hittest *mh) { int i; - for(i=0; inumlayers; i++) { - freeLayerHitTests(GET_LAYER(map,i),&mh->layerhits[i]); + for (i = 0; i < map->numlayers; i++) { + freeLayerHitTests(GET_LAYER(map, i), &mh->layerhits[i]); } free(mh->layerhits); } -int msHitTestShape(mapObj *map, layerObj *layer, shapeObj *shape, int drawmode, class_hittest *hittest) { +int msHitTestShape(mapObj *map, layerObj *layer, shapeObj *shape, int drawmode, + class_hittest *hittest) { int i; classObj *cp = layer->class[shape->classindex]; - if(MS_DRAW_FEATURES(drawmode)) { - for(i=0;inumstyles;i++) { + if (MS_DRAW_FEATURES(drawmode)) { + for (i = 0; i < cp->numstyles; i++) { styleObj *sp = cp->styles[i]; - if(msScaleInBounds(map->scaledenom,sp->minscaledenom,sp->maxscaledenom)) { + if (msScaleInBounds(map->scaledenom, sp->minscaledenom, + sp->maxscaledenom)) { hittest->stylehits[i].status = 1; } } } - if(MS_DRAW_LABELS(drawmode)) { - for(i=0;inumlabels;i++) { + if (MS_DRAW_LABELS(drawmode)) { + for (i = 0; i < cp->numlabels; i++) { labelObj *l = cp->labels[i]; - if(msGetLabelStatus(map,layer,shape,l) == MS_ON) { + if (msGetLabelStatus(map, layer, shape, l) == MS_ON) { int s; hittest->labelhits[i].status = 1; - for(s=0; snumstyles;s++) { + for (s = 0; s < l->numstyles; s++) { hittest->labelhits[i].stylehits[s].status = 1; } } @@ -143,59 +144,66 @@ int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) { #ifdef USE_GEOS shapeObj searchpoly; #endif - if(!msLayerIsVisible(map,layer)) { + if (!msLayerIsVisible(map, layer)) { hittest->status = 0; return MS_SUCCESS; } - if(layer->type == MS_LAYER_LINE || layer->type == MS_LAYER_POLYGON || layer->type == MS_LAYER_POINT || layer->type == MS_LAYER_ANNOTATION) { - int maxfeatures=msLayerGetMaxFeaturesToDraw(layer, NULL); + if (layer->type == MS_LAYER_LINE || layer->type == MS_LAYER_POLYGON || + layer->type == MS_LAYER_POINT || layer->type == MS_LAYER_ANNOTATION) { + int maxfeatures = msLayerGetMaxFeaturesToDraw(layer, NULL); int annotate = msEvalContext(map, layer, layer->labelrequires); shapeObj shape; - int nclasses,featuresdrawn = 0; + int nclasses, featuresdrawn = 0; int *classgroup; rectObj searchrect; - int minfeaturesize=-1; - if(map->scaledenom > 0) { - if((layer->labelmaxscaledenom != -1) && (map->scaledenom >= layer->labelmaxscaledenom)) annotate = MS_FALSE; - if((layer->labelminscaledenom != -1) && (map->scaledenom < layer->labelminscaledenom)) annotate = MS_FALSE; + int minfeaturesize = -1; + if (map->scaledenom > 0) { + if ((layer->labelmaxscaledenom != -1) && + (map->scaledenom >= layer->labelmaxscaledenom)) + annotate = MS_FALSE; + if ((layer->labelminscaledenom != -1) && + (map->scaledenom < layer->labelminscaledenom)) + annotate = MS_FALSE; } status = msLayerOpen(layer); - if(status != MS_SUCCESS) return MS_FAILURE; + if (status != MS_SUCCESS) + return MS_FAILURE; /* build item list */ status = msLayerWhichItems(layer, MS_FALSE, NULL); - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { msLayerClose(layer); return MS_FAILURE; } /* identify target shapes */ - if(layer->transform == MS_TRUE) { + if (layer->transform == MS_TRUE) { searchrect = map->extent; - if((map->projection.numargs > 0) && (layer->projection.numargs > 0)) - msProjectRect(&map->projection, &layer->projection, &searchrect); /* project the searchrect to source coords */ - } - else { + if ((map->projection.numargs > 0) && (layer->projection.numargs > 0)) + msProjectRect( + &map->projection, &layer->projection, + &searchrect); /* project the searchrect to source coords */ + } else { searchrect.minx = searchrect.miny = 0; - searchrect.maxx = map->width-1; - searchrect.maxy = map->height-1; + searchrect.maxx = map->width - 1; + searchrect.maxy = map->height - 1; } #ifdef USE_GEOS msInitShape(&searchpoly); - msRectToPolygon(searchrect,&searchpoly); + msRectToPolygon(searchrect, &searchpoly); #endif status = msLayerWhichShapes(layer, searchrect, MS_FALSE); - if(status == MS_DONE) { /* no overlap */ + if (status == MS_DONE) { /* no overlap */ #ifdef USE_GEOS msFreeShape(&searchpoly); #endif msLayerClose(layer); hittest->status = 0; return MS_SUCCESS; - } else if(status != MS_SUCCESS) { + } else if (status != MS_SUCCESS) { #ifdef USE_GEOS msFreeShape(&searchpoly); #endif @@ -208,32 +216,33 @@ int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) { nclasses = 0; classgroup = NULL; - if(layer->classgroup && layer->numclasses > 0) + if (layer->classgroup && layer->numclasses > 0) classgroup = msAllocateValidClassGroups(layer, &nclasses); - if(layer->minfeaturesize > 0) + if (layer->minfeaturesize > 0) minfeaturesize = Pix2LayerGeoref(map, layer, layer->minfeaturesize); - while((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) { + while ((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) { int drawmode = MS_DRAWMODE_FEATURES; #ifdef USE_GEOS - if(!msGEOSIntersects(&shape,&searchpoly)) { + if (!msGEOSIntersects(&shape, &searchpoly)) { msFreeShape(&shape); continue; } #else - if(shape.type == MS_SHAPE_POLYGON) { + if (shape.type == MS_SHAPE_POLYGON) { msClipPolygonRect(&shape, map->extent); } else { msClipPolylineRect(&shape, map->extent); } - if(shape.numlines == 0) { + if (shape.numlines == 0) { msFreeShape(&shape); continue; } #endif /* Check if the shape size is ok to be drawn, we need to clip */ - if((shape.type == MS_SHAPE_LINE || shape.type == MS_SHAPE_POLYGON) && (minfeaturesize > 0)) { + if ((shape.type == MS_SHAPE_LINE || shape.type == MS_SHAPE_POLYGON) && + (minfeaturesize > 0)) { msTransformShape(&shape, map->extent, map->cellsize, NULL); msComputeBounds(&shape); if (msShapeCheckSize(&shape, minfeaturesize) == MS_FALSE) { @@ -242,26 +251,30 @@ int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) { } } - shape.classindex = msShapeGetClass(layer, map, &shape, classgroup, nclasses); - if((shape.classindex == -1) || (layer->class[shape.classindex]->status == MS_OFF)) { + shape.classindex = + msShapeGetClass(layer, map, &shape, classgroup, nclasses); + if ((shape.classindex == -1) || + (layer->class[shape.classindex] -> status == MS_OFF)) { msFreeShape(&shape); continue; } hittest->classhits[shape.classindex].status = 1; hittest->status = 1; - if(maxfeatures >=0 && featuresdrawn >= maxfeatures) { + if (maxfeatures >= 0 && featuresdrawn >= maxfeatures) { msFreeShape(&shape); status = MS_DONE; break; } featuresdrawn++; - if(annotate && layer->class[shape.classindex]->numlabels > 0) { + if (annotate && layer->class[shape.classindex] -> numlabels > 0) { drawmode |= MS_DRAWMODE_LABELS; } - status = msHitTestShape(map, layer, &shape, drawmode, &hittest->classhits[shape.classindex]); /* all styles */ + status = msHitTestShape( + map, layer, &shape, drawmode, + &hittest->classhits[shape.classindex]); /* all styles */ msFreeShape(&shape); } @@ -272,7 +285,7 @@ int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) { if (classgroup) msFree(classgroup); - if(status != MS_DONE) { + if (status != MS_DONE) { msLayerClose(layer); return MS_FAILURE; } @@ -280,21 +293,23 @@ int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) { return MS_SUCCESS; } else { - /* we don't hittest these layers, skip as they already have been initialised */ + /* we don't hittest these layers, skip as they already have been initialised + */ return MS_SUCCESS; } } int msHitTestMap(mapObj *map, map_hittest *hittest) { - int i,status; - map->cellsize = msAdjustExtent(&(map->extent),map->width,map->height); - status = msCalculateScale(map->extent,map->units,map->width,map->height, map->resolution, &map->scaledenom); - if(status != MS_SUCCESS) { + int i, status; + map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height); + status = msCalculateScale(map->extent, map->units, map->width, map->height, + map->resolution, &map->scaledenom); + if (status != MS_SUCCESS) { return MS_FAILURE; } - for(i=0; inumlayers; i++) { + for (i = 0; i < map->numlayers; i++) { layerObj *lp = map->layers[i]; - status = msHitTestLayer(map,lp,&hittest->layerhits[i]); - if(status != MS_SUCCESS) { + status = msHitTestLayer(map, lp, &hittest->layerhits[i]); + if (status != MS_SUCCESS) { return MS_FAILURE; } } diff --git a/hittest.h b/hittest.h index c4ab89c03a..7d48d3c3bd 100644 --- a/hittest.h +++ b/hittest.h @@ -26,7 +26,6 @@ * DEALINGS IN THE SOFTWARE. ****************************************************************************/ - #ifndef HITTEST_H #define HITTEST_H @@ -50,7 +49,7 @@ typedef struct { int status; } layer_hittest; -typedef struct map_hittest{ +typedef struct map_hittest { layer_hittest *layerhits; } map_hittest; diff --git a/idw.c b/idw.c index 5520397648..2961db4766 100644 --- a/idw.c +++ b/idw.c @@ -32,45 +32,51 @@ #define EPSILON 0.000000001 #include -void msIdw(float *xyz, int width, int height, int npoints, interpolationProcessingParams *interpParams, unsigned char *iValues) { - int i,j,index; - int radius = interpParams->radius; - float power = interpParams->power; - for (j=0; j < height; j++) { - for (i=0; i < width; i++) { - double den = EPSILON, num = 0; - for(index = 0; index < npoints*3; index += 3){ - double d = (xyz[index] - i)*(xyz[index] - i)+(xyz[index+1] - j)*(xyz[index+1] - j); - if(radius*radius > d) { - double w = 1.0/(pow(d, power) + EPSILON); - num += w*xyz[index+2]; - den += w; - } - } - iValues[j*width + i] = num/den; +void msIdw(float *xyz, int width, int height, int npoints, + interpolationProcessingParams *interpParams, + unsigned char *iValues) { + int i, j, index; + int radius = interpParams->radius; + float power = interpParams->power; + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + double den = EPSILON, num = 0; + for (index = 0; index < npoints * 3; index += 3) { + double d = (xyz[index] - i) * (xyz[index] - i) + + (xyz[index + 1] - j) * (xyz[index + 1] - j); + if (radius * radius > d) { + double w = 1.0 / (pow(d, power) + EPSILON); + num += w * xyz[index + 2]; + den += w; } + } + iValues[j * width + i] = num / den; } + } } -void msIdwProcessing(layerObj *layer, interpolationProcessingParams *interpParams) { - const char *interpParamsProcessing = msLayerGetProcessingKey( layer, "IDW_POWER" ); - if(interpParamsProcessing) { - interpParams->power = atof(interpParamsProcessing); - } else{ - interpParams->power = 1.0; - } +void msIdwProcessing(layerObj *layer, + interpolationProcessingParams *interpParams) { + const char *interpParamsProcessing = + msLayerGetProcessingKey(layer, "IDW_POWER"); + if (interpParamsProcessing) { + interpParams->power = atof(interpParamsProcessing); + } else { + interpParams->power = 1.0; + } - interpParamsProcessing = msLayerGetProcessingKey( layer, "IDW_RADIUS" ); - if(interpParamsProcessing){ - interpParams->radius = atof(interpParamsProcessing); - } else { - interpParams->radius = MAX(layer->map->width,layer->map->height); - } + interpParamsProcessing = msLayerGetProcessingKey(layer, "IDW_RADIUS"); + if (interpParamsProcessing) { + interpParams->radius = atof(interpParamsProcessing); + } else { + interpParams->radius = MAX(layer->map->width, layer->map->height); + } - interpParamsProcessing = msLayerGetProcessingKey( layer, "IDW_COMPUTE_BORDERS" ); - if(interpParamsProcessing && strcasecmp(interpParamsProcessing,"OFF")){ - interpParams->expand_searchrect = 1; - } else { - interpParams->expand_searchrect = 0; - } + interpParamsProcessing = + msLayerGetProcessingKey(layer, "IDW_COMPUTE_BORDERS"); + if (interpParamsProcessing && strcasecmp(interpParamsProcessing, "OFF")) { + interpParams->expand_searchrect = 1; + } else { + interpParams->expand_searchrect = 0; + } } diff --git a/interpolation.c b/interpolation.c index 65aca8d0a4..60e3585d22 100644 --- a/interpolation.c +++ b/interpolation.c @@ -35,225 +35,258 @@ /****************************************************************************** * kernel density. ******************************************************************************/ -void msKernelDensity(imageObj *image, float *values, int width, int height, int npoints, - interpolationProcessingParams *interpParams, unsigned char *iValues); -void msKernelDensityProcessing(layerObj *layer, interpolationProcessingParams *interpParams); +void msKernelDensity(imageObj *image, float *values, int width, int height, + int npoints, interpolationProcessingParams *interpParams, + unsigned char *iValues); +void msKernelDensityProcessing(layerObj *layer, + interpolationProcessingParams *interpParams); /****************************************************************************** * kernel density. ******************************************************************************/ void msIdw(float *xyz, int width, int height, int npoints, - interpolationProcessingParams *interpParams, unsigned char *iValues); -void msIdwProcessing(layerObj *layer, interpolationProcessingParams *interpParams); + interpolationProcessingParams *interpParams, unsigned char *iValues); +void msIdwProcessing(layerObj *layer, + interpolationProcessingParams *interpParams); //---------------------------------------------------------------------------// -int msInterpolationDataset(mapObj *map, imageObj *image, layerObj *interpolation_layer, void **hDSvoid, void **cleanup_ptr) { +int msInterpolationDataset(mapObj *map, imageObj *image, + layerObj *interpolation_layer, void **hDSvoid, + void **cleanup_ptr) { - int status, layer_idx, i, nclasses=0, npoints=0, length=0; - rectObj searchrect; - shapeObj shape; - layerObj *layer = NULL; - float *values = NULL,*xyz_values=NULL; - int im_width = image->width, im_height = image->height; - double invcellsize = 1.0 / map->cellsize, georadius=0; - unsigned char *iValues; - GDALDatasetH hDS; - interpolationProcessingParams interpParams; - int *classgroup = NULL; + int status, layer_idx, i, nclasses = 0, npoints = 0, length = 0; + rectObj searchrect; + shapeObj shape; + layerObj *layer = NULL; + float *values = NULL, *xyz_values = NULL; + int im_width = image->width, im_height = image->height; + double invcellsize = 1.0 / map->cellsize, georadius = 0; + unsigned char *iValues; + GDALDatasetH hDS; + interpolationProcessingParams interpParams; + int *classgroup = NULL; - memset(&interpParams, 0, sizeof(interpParams)); + memset(&interpParams, 0, sizeof(interpParams)); - assert(interpolation_layer->connectiontype == MS_KERNELDENSITY || - interpolation_layer->connectiontype == MS_IDW); - *cleanup_ptr = NULL; + assert(interpolation_layer->connectiontype == MS_KERNELDENSITY || + interpolation_layer->connectiontype == MS_IDW); + *cleanup_ptr = NULL; - if(!interpolation_layer->connection || !*interpolation_layer->connection) { - msSetError(MS_MISCERR, "msInterpolationDataset()", "Interpolation layer has no CONNECTION defined"); - return MS_FAILURE; - } + if (!interpolation_layer->connection || !*interpolation_layer->connection) { + msSetError(MS_MISCERR, "msInterpolationDataset()", + "Interpolation layer has no CONNECTION defined"); + return MS_FAILURE; + } - if (interpolation_layer->connectiontype == MS_KERNELDENSITY) { - msKernelDensityProcessing(interpolation_layer, &interpParams); - } else if(interpolation_layer->connectiontype == MS_IDW) { - msIdwProcessing(interpolation_layer, &interpParams); - } + if (interpolation_layer->connectiontype == MS_KERNELDENSITY) { + msKernelDensityProcessing(interpolation_layer, &interpParams); + } else if (interpolation_layer->connectiontype == MS_IDW) { + msIdwProcessing(interpolation_layer, &interpParams); + } - layer_idx = msGetLayerIndex(map, interpolation_layer->connection); - if(layer_idx == -1) { - int nLayers, *aLayers; - aLayers = msGetLayersIndexByGroup(map, interpolation_layer->connection, &nLayers); - if(!aLayers || !nLayers) { - msSetError(MS_MISCERR, "Interpolation layer (%s) references unknown layer (%s)", "msInterpolationDataset()", - interpolation_layer->name,interpolation_layer->connection); - return (MS_FAILURE); - } - for(i=0; iscaledenom, layer->minscaledenom, layer->maxscaledenom)) - break; - } - free(aLayers); - if(i == nLayers) { - msSetError(MS_MISCERR, "Interpolation layer (%s) references no layer for current scale", "msInterpolationDataset()", - interpolation_layer->name); - return (MS_FAILURE); - } - } else { - layer = GET_LAYER(map, layer_idx); + layer_idx = msGetLayerIndex(map, interpolation_layer->connection); + if (layer_idx == -1) { + int nLayers, *aLayers; + aLayers = + msGetLayersIndexByGroup(map, interpolation_layer->connection, &nLayers); + if (!aLayers || !nLayers) { + msSetError(MS_MISCERR, + "Interpolation layer (%s) references unknown layer (%s)", + "msInterpolationDataset()", interpolation_layer->name, + interpolation_layer->connection); + return (MS_FAILURE); } - /* open the linked layer */ - status = msLayerOpen(layer); - if(status != MS_SUCCESS) return MS_FAILURE; - - status = msLayerWhichItems(layer, MS_FALSE, NULL); - if(status != MS_SUCCESS) { - msLayerClose(layer); - return MS_FAILURE; + for (i = 0; i < nLayers; i++) { + layer_idx = aLayers[i]; + layer = GET_LAYER(map, layer_idx); + if (msScaleInBounds(map->scaledenom, layer->minscaledenom, + layer->maxscaledenom)) + break; } + free(aLayers); + if (i == nLayers) { + msSetError( + MS_MISCERR, + "Interpolation layer (%s) references no layer for current scale", + "msInterpolationDataset()", interpolation_layer->name); + return (MS_FAILURE); + } + } else { + layer = GET_LAYER(map, layer_idx); + } + /* open the linked layer */ + status = msLayerOpen(layer); + if (status != MS_SUCCESS) + return MS_FAILURE; - /* identify target shapes */ - if(layer->transform == MS_TRUE) { - searchrect = map->extent; - if(interpParams.expand_searchrect) { - georadius = interpParams.radius * map->cellsize; - searchrect.minx -= georadius; - searchrect.miny -= georadius; - searchrect.maxx += georadius; - searchrect.maxy += georadius; - im_width += 2 * interpParams.radius; - im_height += 2 * interpParams.radius; - } - } else { - searchrect.minx = searchrect.miny = 0; - searchrect.maxx = map->width-1; - searchrect.maxy = map->height-1; + status = msLayerWhichItems(layer, MS_FALSE, NULL); + if (status != MS_SUCCESS) { + msLayerClose(layer); + return MS_FAILURE; + } + + /* identify target shapes */ + if (layer->transform == MS_TRUE) { + searchrect = map->extent; + if (interpParams.expand_searchrect) { + georadius = interpParams.radius * map->cellsize; + searchrect.minx -= georadius; + searchrect.miny -= georadius; + searchrect.maxx += georadius; + searchrect.maxy += georadius; + im_width += 2 * interpParams.radius; + im_height += 2 * interpParams.radius; } + } else { + searchrect.minx = searchrect.miny = 0; + searchrect.maxx = map->width - 1; + searchrect.maxy = map->height - 1; + } - layer->project = msProjectionsDiffer(&(layer->projection), &(map->projection)); - if(layer->project) - msProjectRect(&map->projection, &layer->projection, &searchrect); /* project the searchrect to source coords */ + layer->project = + msProjectionsDiffer(&(layer->projection), &(map->projection)); + if (layer->project) + msProjectRect(&map->projection, &layer->projection, + &searchrect); /* project the searchrect to source coords */ - status = msLayerWhichShapes(layer, searchrect, MS_FALSE); - /* nothing to do */ - if(status == MS_SUCCESS) { /* at least one sample may have overlapped */ + status = msLayerWhichShapes(layer, searchrect, MS_FALSE); + /* nothing to do */ + if (status == MS_SUCCESS) { /* at least one sample may have overlapped */ - if(layer->classgroup && layer->numclasses > 0) - classgroup = msAllocateValidClassGroups(layer, &nclasses); + if (layer->classgroup && layer->numclasses > 0) + classgroup = msAllocateValidClassGroups(layer, &nclasses); - msInitShape(&shape); - while((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) { - int l,p,s,c; - double weight = 1.0; - if(!values){ /* defer allocation until we effectively have a feature */ - values = (float*) msSmallCalloc(im_width * im_height, sizeof(float)); - xyz_values = (float*) msSmallCalloc(im_width * im_height, sizeof(float)); - } - if(layer->project) - msProjectShape(&layer->projection, &map->projection, &shape); + msInitShape(&shape); + while ((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) { + int l, p, s, c; + double weight = 1.0; + if (!values) { /* defer allocation until we effectively have a feature */ + values = (float *)msSmallCalloc(im_width * im_height, sizeof(float)); + xyz_values = + (float *)msSmallCalloc(im_width * im_height, sizeof(float)); + } + if (layer->project) + msProjectShape(&layer->projection, &map->projection, &shape); - /* the weight for the sample is set to 1.0 by default. If the - * layer has some classes defined, we will read the weight from - * the class->style->size (which can be binded to an attribute) - */ - if(layer->numclasses > 0) { - c = msShapeGetClass(layer, map, &shape, classgroup, nclasses); - if((c == -1) || (layer->class[c]->status == MS_OFF)) { - goto nextshape; /* no class matched, skip */ - } - for (s = 0; s < layer->class[c]->numstyles; s++) { - if (msScaleInBounds(map->scaledenom, - layer->class[c]->styles[s]->minscaledenom, - layer->class[c]->styles[s]->maxscaledenom)) { - if(layer->class[c]->styles[s]->bindings[MS_STYLE_BINDING_SIZE].index != -1) { - weight = atof(shape.values[layer->class[c]->styles[s]->bindings[MS_STYLE_BINDING_SIZE].index]); - } else { - weight = layer->class[c]->styles[s]->size; - } - break; - } - } - if(s == layer->class[c]->numstyles) { - /* no style in scale bounds */ - goto nextshape; - } - } - for(l=0; lextent.minx - georadius, invcellsize); - int y = MS_MAP2IMAGE_YCELL_IC(shape.line[l].point[p].y, map->extent.maxy + georadius, invcellsize); - if(x>=0 && y>=0 && xstyle->size (which can be binded to an attribute) + */ + if (layer->numclasses > 0) { + c = msShapeGetClass(layer, map, &shape, classgroup, nclasses); + if ((c == -1) || (layer->class[c] -> status == MS_OFF)) { + goto nextshape; /* no class matched, skip */ + } + for (s = 0; s < layer->class[c] -> numstyles; s++) { + if (msScaleInBounds( + map->scaledenom, + layer->class[c] -> styles[s] -> minscaledenom, + layer -> class[c] -> styles[s] -> maxscaledenom)) { + if (layer->class[c] -> styles[s] + -> bindings[MS_STYLE_BINDING_SIZE].index != -1) { + weight = + atof(shape.values[layer->class[c] -> styles[s] + -> bindings[MS_STYLE_BINDING_SIZE].index]); + } else { + weight = layer->class[c]->styles[s]->size; } - -nextshape: - msFreeShape(&shape); + break; + } } - //number of layer points. - npoints = length/3; - } else if(status != MS_DONE) { - msLayerClose(layer); - return MS_FAILURE; - } + if (s == layer->class[c] -> numstyles) { + /* no style in scale bounds */ + goto nextshape; + } + } + for (l = 0; l < shape.numlines; l++) { + for (p = 0; p < shape.line[l].numpoints; p++) { + int x = + MS_MAP2IMAGE_XCELL_IC(shape.line[l].point[p].x, + map->extent.minx - georadius, invcellsize); + int y = + MS_MAP2IMAGE_YCELL_IC(shape.line[l].point[p].y, + map->extent.maxy + georadius, invcellsize); + if (x >= 0 && y >= 0 && x < im_width && y < im_height) { + float *value = values + y * im_width + x; + (*value) += weight; + xyz_values[length++] = x; + xyz_values[length++] = y; + xyz_values[length++] = (*value); + } + } + } - /* status == MS_DONE */ + nextshape: + msFreeShape(&shape); + } + // number of layer points. + npoints = length / 3; + } else if (status != MS_DONE) { msLayerClose(layer); - status = MS_SUCCESS; + return MS_FAILURE; + } - if(npoints > 0 && interpParams.expand_searchrect) { - iValues = msSmallMalloc(image->width*image->height*sizeof(unsigned char)); - } else { - iValues = msSmallCalloc(1,image->width*image->height*sizeof(unsigned char)); - } + /* status == MS_DONE */ + msLayerClose(layer); + status = MS_SUCCESS; - if(npoints > 0) { /* no use applying the filtering kernel if we have no samples */ - if (interpolation_layer->connectiontype == MS_KERNELDENSITY) { - msKernelDensity(image, values, im_width, im_height, npoints, &interpParams, iValues); - } else if(interpolation_layer->connectiontype == MS_IDW) { - msIdw(xyz_values, image->width, image->height, npoints, &interpParams, iValues); - } - } + if (npoints > 0 && interpParams.expand_searchrect) { + iValues = + msSmallMalloc(image->width * image->height * sizeof(unsigned char)); + } else { + iValues = + msSmallCalloc(1, image->width * image->height * sizeof(unsigned char)); + } - free(values); - free(xyz_values); + if (npoints > + 0) { /* no use applying the filtering kernel if we have no samples */ + if (interpolation_layer->connectiontype == MS_KERNELDENSITY) { + msKernelDensity(image, values, im_width, im_height, npoints, + &interpParams, iValues); + } else if (interpolation_layer->connectiontype == MS_IDW) { + msIdw(xyz_values, image->width, image->height, npoints, &interpParams, + iValues); + } + } + free(values); + free(xyz_values); - char pointer[64]; - char ds_string [1024]; - double adfGeoTransform[6]; - memset(pointer, 0, sizeof(pointer)); - CPLPrintPointer(pointer, iValues, sizeof(pointer)); - snprintf(ds_string,1024,"MEM:::DATAPOINTER=%s,PIXELS=%d,LINES=%d,BANDS=1,DATATYPE=Byte,PIXELOFFSET=1,LINEOFFSET=%d", - pointer,image->width,image->height,image->width); - hDS = GDALOpenShared( ds_string, GA_ReadOnly ); - if(hDS == NULL) { - msSetError(MS_MISCERR,"msInterpolationDataset()","failed to create in-memory gdal dataset for interpolated data"); - status = MS_FAILURE; - free(iValues); - } - adfGeoTransform[0] = map->extent.minx - map->cellsize * 0.5; /* top left x */ - adfGeoTransform[1] = map->cellsize;/* w-e pixel resolution */ - adfGeoTransform[2] = 0; /* 0 */ - adfGeoTransform[3] = map->extent.maxy + map->cellsize * 0.5;/* top left y */ - adfGeoTransform[4] = 0; /* 0 */ - adfGeoTransform[5] = -map->cellsize;/* n-s pixel resolution (negative value) */ - GDALSetGeoTransform(hDS,adfGeoTransform); - *hDSvoid = hDS; - *cleanup_ptr = (void*)iValues; + char pointer[64]; + char ds_string[1024]; + double adfGeoTransform[6]; + memset(pointer, 0, sizeof(pointer)); + CPLPrintPointer(pointer, iValues, sizeof(pointer)); + snprintf(ds_string, 1024, + "MEM:::DATAPOINTER=%s,PIXELS=%d,LINES=%d,BANDS=1,DATATYPE=Byte," + "PIXELOFFSET=1,LINEOFFSET=%d", + pointer, image->width, image->height, image->width); + hDS = GDALOpenShared(ds_string, GA_ReadOnly); + if (hDS == NULL) { + msSetError(MS_MISCERR, "msInterpolationDataset()", + "failed to create in-memory gdal dataset for interpolated data"); + status = MS_FAILURE; + free(iValues); + } + adfGeoTransform[0] = map->extent.minx - map->cellsize * 0.5; /* top left x */ + adfGeoTransform[1] = map->cellsize; /* w-e pixel resolution */ + adfGeoTransform[2] = 0; /* 0 */ + adfGeoTransform[3] = map->extent.maxy + map->cellsize * 0.5; /* top left y */ + adfGeoTransform[4] = 0; /* 0 */ + adfGeoTransform[5] = + -map->cellsize; /* n-s pixel resolution (negative value) */ + GDALSetGeoTransform(hDS, adfGeoTransform); + *hDSvoid = hDS; + *cleanup_ptr = (void *)iValues; - return status; + return status; } -int msCleanupInterpolationDataset(mapObj *map, imageObj *image, layerObj *layer, void *cleanup_ptr) { - (void)map; - (void)image; - (void)layer; - free(cleanup_ptr); - return MS_SUCCESS; +int msCleanupInterpolationDataset(mapObj *map, imageObj *image, layerObj *layer, + void *cleanup_ptr) { + (void)map; + (void)image; + (void)layer; + free(cleanup_ptr); + return MS_SUCCESS; } diff --git a/kerneldensity.c b/kerneldensity.c index 46691826b0..45ae51d153 100644 --- a/kerneldensity.c +++ b/kerneldensity.c @@ -32,128 +32,138 @@ #include "gdal.h" -static -void gaussian_blur(float *values, int width, int height, int radius) { - float *tmp = (float*)msSmallMalloc(width*height*sizeof(float)); - int length = radius*2+1; - float *kernel = (float*)msSmallMalloc(length*sizeof(float)); - float sigma=radius/3.0; - float a=1.0/ sqrt(2.0*M_PI*sigma*sigma); - float den=2.0*sigma*sigma; - int i,x,y; - - for (i=0; iradius = atoi(interpParamsProcessing); - } else { - interpParams->radius = 10; - } - - interpParamsProcessing = msLayerGetProcessingKey( layer, "KERNELDENSITY_COMPUTE_BORDERS" ); - if(interpParamsProcessing && strcasecmp(interpParamsProcessing,"OFF")) { - interpParams->expand_searchrect = 1; +void msKernelDensityProcessing(layerObj *layer, + interpolationProcessingParams *interpParams) { + const char *interpParamsProcessing = + msLayerGetProcessingKey(layer, "KERNELDENSITY_RADIUS"); + if (interpParamsProcessing) { + interpParams->radius = atoi(interpParamsProcessing); + } else { + interpParams->radius = 10; + } + + interpParamsProcessing = + msLayerGetProcessingKey(layer, "KERNELDENSITY_COMPUTE_BORDERS"); + if (interpParamsProcessing && strcasecmp(interpParamsProcessing, "OFF")) { + interpParams->expand_searchrect = 1; + } else { + interpParams->expand_searchrect = 0; + } + + interpParamsProcessing = + msLayerGetProcessingKey(layer, "KERNELDENSITY_NORMALIZATION"); + if (!interpParamsProcessing || !strcasecmp(interpParamsProcessing, "AUTO")) { + interpParams->normalization_scale = 0.0; + } else { + interpParams->normalization_scale = atof(interpParamsProcessing); + if (interpParams->normalization_scale != 0) { + interpParams->normalization_scale = + 1.0 / interpParams->normalization_scale; } else { - interpParams->expand_searchrect = 0; - } - - interpParamsProcessing = msLayerGetProcessingKey( layer, "KERNELDENSITY_NORMALIZATION" ); - if(!interpParamsProcessing || !strcasecmp(interpParamsProcessing,"AUTO")) { - interpParams->normalization_scale = 0.0; - } else { - interpParams->normalization_scale = atof(interpParamsProcessing); - if(interpParams->normalization_scale != 0) { - interpParams->normalization_scale = 1.0 / interpParams->normalization_scale; - } else { - interpParams->normalization_scale = 1.0; - } + interpParams->normalization_scale = 1.0; } + } } -void msKernelDensity(imageObj *image, float *values, int width, int height, int npoints, - interpolationProcessingParams *interpParams, unsigned char *iValues) { - int i,j; - float valmax=FLT_MIN, valmin=FLT_MAX; - int radius = interpParams->radius; - float normalization_scale = interpParams->normalization_scale; - int expand_searchrect = interpParams->expand_searchrect; - - gaussian_blur(values, width, height, radius); - - if(normalization_scale == 0.0) { /* auto normalization */ - for (j = radius; j < height-radius; j++) { - for (i = radius; i < width-radius; i++) { - float val = values[j*width + i]; - if(val >0 && val>valmax) { - valmax = val; - } - if(val>0 && valradius; + float normalization_scale = interpParams->normalization_scale; + int expand_searchrect = interpParams->expand_searchrect; + + gaussian_blur(values, width, height, radius); + + if (normalization_scale == 0.0) { /* auto normalization */ + for (j = radius; j < height - radius; j++) { + for (i = radius; i < width - radius; i++) { + float val = values[j * width + i]; + if (val > 0 && val > valmax) { + valmax = val; } - } else { - valmin = 0; - valmax = normalization_scale; - } - - if(expand_searchrect) { - for (j=0; j < image->height; j++) { - for (i=0; i < image->width; i++) { - float norm = (values[(j+radius)*width + i + radius] - valmin) / valmax; - int v = 255 * norm; - if (v<0) v=0; - else if (v>255) v = 255; - iValues[j*image->width + i] = v; - } + if (val > 0 && val < valmin) { + valmin = val; } - } else { - if(npoints > 0) { - for (j=radius; j < image->height-radius; j++) { - for (i=radius; i < image->width-radius; i++) { - float norm=(values[j*width + i] - valmin) / valmax; - int v=255 * norm; - if (v<0) v=0; - else if (v>255) v=255; - iValues[j*image->width + i]=v; - } - } + } + } + } else { + valmin = 0; + valmax = normalization_scale; + } + + if (expand_searchrect) { + for (j = 0; j < image->height; j++) { + for (i = 0; i < image->width; i++) { + float norm = + (values[(j + radius) * width + i + radius] - valmin) / valmax; + int v = 255 * norm; + if (v < 0) + v = 0; + else if (v > 255) + v = 255; + iValues[j * image->width + i] = v; + } + } + } else { + if (npoints > 0) { + for (j = radius; j < image->height - radius; j++) { + for (i = radius; i < image->width - radius; i++) { + float norm = (values[j * width + i] - valmin) / valmax; + int v = 255 * norm; + if (v < 0) + v = 0; + else if (v > 255) + v = 255; + iValues[j * image->width + i] = v; } + } } + } } diff --git a/layerobject.c b/layerobject.c index 569e6cf141..2a0c147acb 100644 --- a/layerobject.c +++ b/layerobject.c @@ -31,15 +31,13 @@ #include "mapserver.h" - /* =========================================================================== msInsertClass Returns the index at which the class was inserted. ======================================================================== */ -int msInsertClass(layerObj *layer, classObj *classobj, int nIndex) -{ +int msInsertClass(layerObj *layer, classObj *classobj, int nIndex) { int i; if (!classobj) { @@ -54,36 +52,36 @@ int msInsertClass(layerObj *layer, classObj *classobj, int nIndex) /* Catch attempt to insert past end of styles array */ else if (nIndex >= layer->numclasses) { msSetError(MS_CHILDERR, "Cannot insert class beyond index %d", - "msInsertClass()", layer->numclasses-1); + "msInsertClass()", layer->numclasses - 1); return -1; } else if (nIndex < 0) { /* Insert at the end by default */ #ifndef __cplusplus - layer->class[layer->numclasses]=classobj; + layer->class[layer->numclasses] = classobj; #else - layer->_class[layer->numclasses]=classobj; + layer->_class[layer->numclasses] = classobj; #endif /* set parent pointer */ - classobj->layer=layer; + classobj->layer = layer; MS_REFCNT_INCR(classobj); layer->numclasses++; - return layer->numclasses-1; + return layer->numclasses - 1; } else { /* Copy classes existing at the specified nIndex or greater */ /* to an index one higher */ #ifndef __cplusplus - for (i=layer->numclasses-1; i>=nIndex; i--) - layer->class[i+1] = layer->class[i]; - layer->class[nIndex]=classobj; + for (i = layer->numclasses - 1; i >= nIndex; i--) + layer->class[i + 1] = layer->class[i]; + layer->class[nIndex] = classobj; #else - for (i=layer->numclasses-1; i>=nIndex; i--) - layer->_class[i+1] = layer->_class[i]; - layer->_class[nIndex]=classobj; + for (i = layer->numclasses - 1; i >= nIndex; i--) + layer->_class[i + 1] = layer->_class[i]; + layer->_class[nIndex] = classobj; #endif /* set parent pointer */ - classobj->layer=layer; + classobj->layer = layer; MS_REFCNT_INCR(classobj); /* increment number of classes and return */ layer->numclasses++; @@ -97,8 +95,7 @@ int msInsertClass(layerObj *layer, classObj *classobj, int nIndex) remove the class at an index from a layer, returning a copy ======================================================================== */ -classObj *msRemoveClass(layerObj *layer, int nIndex) -{ +classObj *msRemoveClass(layerObj *layer, int nIndex) { int i; classObj *classobj; @@ -108,25 +105,25 @@ classObj *msRemoveClass(layerObj *layer, int nIndex) return NULL; } else { #ifndef __cplusplus - classobj=layer->class[nIndex]; + classobj = layer->class[nIndex]; #else - classobj=layer->_class[nIndex]; + classobj = layer->_class[nIndex]; #endif - classobj->layer=NULL; + classobj->layer = NULL; MS_REFCNT_DECR(classobj); /* Iteratively copy the higher index classes down one index */ - for (i=nIndex; inumclasses-1; i++) { + for (i = nIndex; i < layer->numclasses - 1; i++) { #ifndef __cplusplus - layer->class[i]=layer->class[i+1]; + layer->class[i] = layer->class[i + 1]; #else - layer->_class[i]=layer->_class[i+1]; + layer->_class[i] = layer->_class[i + 1]; #endif } #ifndef __cplusplus - layer->class[i]=NULL; + layer->class[i] = NULL; #else - layer->_class[i]=NULL; + layer->_class[i] = NULL; #endif /* decrement number of layers and return copy of removed layer */ @@ -138,38 +135,34 @@ classObj *msRemoveClass(layerObj *layer, int nIndex) /** * Move the class up inside the array of classes. */ -int msMoveClassUp(layerObj *layer, int nClassIndex) -{ +int msMoveClassUp(layerObj *layer, int nClassIndex) { classObj *psTmpClass = NULL; - if (layer && nClassIndex < layer->numclasses && nClassIndex >0) { - psTmpClass=layer->class[nClassIndex]; + if (layer && nClassIndex < layer->numclasses && nClassIndex > 0) { + psTmpClass = layer->class[nClassIndex]; - layer->class[nClassIndex] = layer->class[nClassIndex-1]; + layer->class[nClassIndex] = layer->class[nClassIndex - 1]; - layer->class[nClassIndex-1] = psTmpClass; + layer->class[nClassIndex - 1] = psTmpClass; - return(MS_SUCCESS); + return (MS_SUCCESS); } - msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveClassUp()", - nClassIndex); + msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveClassUp()", nClassIndex); return (MS_FAILURE); } - /** * Move the class down inside the array of classes. */ -int msMoveClassDown(layerObj *layer, int nClassIndex) -{ +int msMoveClassDown(layerObj *layer, int nClassIndex) { classObj *psTmpClass = NULL; - if (layer && nClassIndex < layer->numclasses-1 && nClassIndex >=0) { - psTmpClass=layer->class[nClassIndex]; + if (layer && nClassIndex < layer->numclasses - 1 && nClassIndex >= 0) { + psTmpClass = layer->class[nClassIndex]; - layer->class[nClassIndex] = layer->class[nClassIndex+1]; + layer->class[nClassIndex] = layer->class[nClassIndex + 1]; - layer->class[nClassIndex+1] = psTmpClass; + layer->class[nClassIndex + 1] = psTmpClass; - return(MS_SUCCESS); + return (MS_SUCCESS); } msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveClassDown()", nClassIndex); @@ -180,9 +173,8 @@ int msMoveClassDown(layerObj *layer, int nClassIndex) * Set the extent of a layer. */ -int msLayerSetExtent( layerObj *layer, - double minx, double miny, double maxx, double maxy) -{ +int msLayerSetExtent(layerObj *layer, double minx, double miny, double maxx, + double maxy) { layer->extent.minx = minx; layer->extent.miny = miny; @@ -190,12 +182,16 @@ int msLayerSetExtent( layerObj *layer, layer->extent.maxy = maxy; if (minx == -1.0 && miny == -1.0 && maxx == -1.0 && maxy == -1.0) - return(MS_SUCCESS); + return (MS_SUCCESS); if (!MS_VALID_EXTENT(layer->extent)) { - msSetError(MS_MISCERR, "Given layer extent is invalid. minx=%lf, miny=%lf, maxx=%lf, maxy=%lf.", "msLayerSetExtent()", layer->extent.minx, layer->extent.miny, layer->extent.maxx, layer->extent.maxy); - return(MS_FAILURE); + msSetError(MS_MISCERR, + "Given layer extent is invalid. minx=%lf, miny=%lf, maxx=%lf, " + "maxy=%lf.", + "msLayerSetExtent()", layer->extent.minx, layer->extent.miny, + layer->extent.maxx, layer->extent.maxy); + return (MS_FAILURE); } - return(MS_SUCCESS); + return (MS_SUCCESS); } diff --git a/legend.c b/legend.c index 4b1bed2445..63881c78a3 100644 --- a/legend.c +++ b/legend.c @@ -29,32 +29,29 @@ #include "mapserver.h" - - -int main(int argc, char *argv[]) -{ - mapObj *map=NULL; - imageObj *img=NULL; +int main(int argc, char *argv[]) { + mapObj *map = NULL; + imageObj *img = NULL; msSetup(); - if(argc > 1 && strcmp(argv[1], "-v") == 0) { + if (argc > 1 && strcmp(argv[1], "-v") == 0) { printf("%s\n", msGetVersion()); exit(0); } - if( argc < 3 ) { - fprintf(stdout,"Syntax: legend [mapfile] [output image]\n" ); + if (argc < 3) { + fprintf(stdout, "Syntax: legend [mapfile] [output image]\n"); exit(0); } map = msLoadMap(argv[1], NULL, NULL); - if(!map) { + if (!map) { msWriteError(stderr); exit(0); } img = msDrawLegend(map, MS_FALSE, NULL); - if(!img) { + if (!img) { msWriteError(stderr); exit(0); } @@ -64,5 +61,5 @@ int main(int argc, char *argv[]) msFreeImage(img); msFreeMap(map); - return(MS_TRUE); + return (MS_TRUE); } diff --git a/map2img.c b/map2img.c index c8ed3229ef..de25a4c179 100644 --- a/map2img.c +++ b/map2img.c @@ -34,65 +34,70 @@ #include "limits.h" -int main(int argc, char *argv[]) -{ - int i,j,k; +int main(int argc, char *argv[]) { + int i, j, k; - mapObj *map=NULL; - imageObj *image = NULL; - configObj* config = NULL; + mapObj *map = NULL; + imageObj *image = NULL; + configObj *config = NULL; - char **layers=NULL; - int num_layers=0; + char **layers = NULL; + int num_layers = 0; - int layer_found=0; + int layer_found = 0; - char *outfile=NULL; /* no -o sends image to STDOUT */ + char *outfile = NULL; /* no -o sends image to STDOUT */ int iterations = 1; int draws = 0; /* ---- output version info and exit --- */ - if(argc > 1 && strcmp(argv[1], "-v") == 0) { + if (argc > 1 && strcmp(argv[1], "-v") == 0) { printf("%s\n", msGetVersion()); exit(0); } - + /* ---- check the number of arguments, return syntax if not correct ---- */ - if( argc < 3 ) { + if (argc < 3) { fprintf(stdout, "\nPurpose: convert a mapfile to an image\n\n"); - fprintf(stdout, - "Syntax: map2img -m mapfile [-o image] [-e minx miny maxx maxy] [-s sizex sizey]\n" - " [-l \"layer1 [layers2...]\"] [-i format]\n" - " [-all_debug n] [-map_debug n] [-layer_debug n] [-p n] [-c n] [-d layername datavalue]\n" - " [-conf filename]\n"); - fprintf(stdout," -m mapfile: Map file to operate on - required\n" ); - fprintf(stdout," -i format: Override the IMAGETYPE value to pick output format\n" ); - fprintf(stdout," -o image: output filename (stdout if not provided)\n"); - fprintf(stdout," -e minx miny maxx maxy: extents to render\n"); - fprintf(stdout," -s sizex sizey: output image size\n"); - fprintf(stdout," -l layers: layers / groups to enable - make sure they are quoted and space separated if more than one listed\n" ); - fprintf(stdout," -all_debug n: Set debug level for map and all layers\n" ); - fprintf(stdout," -map_debug n: Set map debug level\n" ); - fprintf(stdout," -layer_debug layer_name n: Set layer debug level\n" ); - fprintf(stdout," -c n: draw map n number of times\n" ); - fprintf(stdout," -p n: pause for n seconds after reading the map\n" ); - fprintf(stdout," -d layername datavalue: change DATA value for layer\n" ); - fprintf(stdout," -conf filename: filename of the MapServer configuration file.\n" ); + fprintf(stdout, "Syntax: map2img -m mapfile [-o image] [-e minx miny maxx " + "maxy] [-s sizex sizey]\n" + " [-l \"layer1 [layers2...]\"] [-i format]\n" + " [-all_debug n] [-map_debug n] " + "[-layer_debug n] [-p n] [-c n] [-d layername datavalue]\n" + " [-conf filename]\n"); + fprintf(stdout, " -m mapfile: Map file to operate on - required\n"); + fprintf( + stdout, + " -i format: Override the IMAGETYPE value to pick output format\n"); + fprintf(stdout, " -o image: output filename (stdout if not provided)\n"); + fprintf(stdout, " -e minx miny maxx maxy: extents to render\n"); + fprintf(stdout, " -s sizex sizey: output image size\n"); + fprintf(stdout, " -l layers: layers / groups to enable - make sure they " + "are quoted and space separated if more than one listed\n"); + fprintf(stdout, " -all_debug n: Set debug level for map and all layers\n"); + fprintf(stdout, " -map_debug n: Set map debug level\n"); + fprintf(stdout, " -layer_debug layer_name n: Set layer debug level\n"); + fprintf(stdout, " -c n: draw map n number of times\n"); + fprintf(stdout, " -p n: pause for n seconds after reading the map\n"); + fprintf(stdout, " -d layername datavalue: change DATA value for layer\n"); + fprintf( + stdout, + " -conf filename: filename of the MapServer configuration file.\n"); exit(0); } - if ( msSetup() != MS_SUCCESS ) { + if (msSetup() != MS_SUCCESS) { msWriteError(stderr); exit(1); } bool some_debug_requested = FALSE; - const char* config_filename = NULL; - for(i=1; i INT_MAX - 1 ) { + const char *config_filename = NULL; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-c") == 0) { /* user specified number of draws */ + iterations = atoi(argv[i + 1]); + if (iterations < 0 || iterations > INT_MAX - 1) { printf("Invalid number of iterations"); return 1; } @@ -100,7 +105,7 @@ int main(int argc, char *argv[]) continue; } - if(i < argc-1 && strcmp(argv[i], "-all_debug") == 0) { /* global debug */ + if (i < argc - 1 && strcmp(argv[i], "-all_debug") == 0) { /* global debug */ int debug_level = atoi(argv[++i]); some_debug_requested = TRUE; @@ -110,21 +115,21 @@ int main(int argc, char *argv[]) continue; } - if(i < argc-1 && (strcmp(argv[i], "-map_debug") == 0 || - strcmp(argv[i], "-layer_debug") == 0)) { + if (i < argc - 1 && (strcmp(argv[i], "-map_debug") == 0 || + strcmp(argv[i], "-layer_debug") == 0)) { some_debug_requested = TRUE; continue; } - if(i < argc-1 && strcmp(argv[i], "-conf") == 0) { - config_filename = argv[i+1]; + if (i < argc - 1 && strcmp(argv[i], "-conf") == 0) { + config_filename = argv[i + 1]; ++i; continue; } } - if( some_debug_requested ) { + if (some_debug_requested) { /* Send output to stderr by default */ if (msGetErrorFile() == NULL) msSetErrorFile("stderr", NULL); @@ -132,31 +137,30 @@ int main(int argc, char *argv[]) config = msLoadConfig(config_filename); - for(draws=0; draws= MS_DEBUGLEVEL_TUNING) + if (msGetGlobalDebugLevel() >= MS_DEBUGLEVEL_TUNING) msGettimeofday(&requeststarttime, NULL); - /* Use PROJ_LIB env vars if set */ - msProjLibInitFromEnv(); + /* Use PROJ_DATA/PROJ_LIB env vars if set */ + msProjDataInitFromEnv(); /* Use MS_ERRORFILE and MS_DEBUGLEVEL env vars if set */ - if ( msDebugInitFromEnv() != MS_SUCCESS ) { + if (msDebugInitFromEnv() != MS_SUCCESS) { msWriteError(stderr); msCleanup(); msFreeConfig(config); exit(1); } + for (i = 1; i < argc; + i++) { /* Step though the user arguments, 1st to find map file */ - - for(i=1; iimagetype ); - map->imagetype = msStrdup( argv[i+1] ); - msApplyOutputFormat( &(map->outputformat), format, MS_NOOVERRIDE); + msFree((char *)map->imagetype); + map->imagetype = msStrdup(argv[i + 1]); + msApplyOutputFormat(&(map->outputformat), format, MS_NOOVERRIDE); } - i+=1; + i += 1; } - if(strcmp(argv[i],"-d") == 0) { /* swap layer data */ - for(j=0; jnumlayers; j++) { - if(strcmp(GET_LAYER(map, j)->name, argv[i+1]) == 0) { + if (strcmp(argv[i], "-d") == 0) { /* swap layer data */ + for (j = 0; j < map->numlayers; j++) { + if (strcmp(GET_LAYER(map, j)->name, argv[i + 1]) == 0) { free(GET_LAYER(map, j)->data); - GET_LAYER(map, j)->data = msStrdup(argv[i+2]); + GET_LAYER(map, j)->data = msStrdup(argv[i + 2]); break; } } - i+=2; + i += 2; } - if(i < argc-1 && strcmp(argv[i], "-all_debug") == 0) { /* global debug */ + if (i < argc - 1 && + strcmp(argv[i], "-all_debug") == 0) { /* global debug */ int debug_level = atoi(argv[++i]); /* msSetGlobalDebugLevel() already called. Just need to force debug * level in map and all layers */ map->debug = debug_level; - for(j=0; jnumlayers; j++) { + for (j = 0; j < map->numlayers; j++) { GET_LAYER(map, j)->debug = debug_level; } - } - if(i < argc-1 && strcmp(argv[i], "-map_debug") == 0) { /* debug */ + if (i < argc - 1 && strcmp(argv[i], "-map_debug") == 0) { /* debug */ map->debug = atoi(argv[++i]); } - if(i < argc-1 && strcmp(argv[i], "-layer_debug") == 0) { /* debug */ + if (i < argc - 1 && strcmp(argv[i], "-layer_debug") == 0) { /* debug */ const char *layer_name = argv[++i]; int debug_level = atoi(argv[++i]); int got_layer = 0; - for(j=0; jnumlayers; j++) { - if(strcmp(GET_LAYER(map, j)->name,layer_name) == 0 ) { + for (j = 0; j < map->numlayers; j++) { + if (strcmp(GET_LAYER(map, j)->name, layer_name) == 0) { GET_LAYER(map, j)->debug = debug_level; got_layer = 1; } } - if( !got_layer ) - fprintf( stderr, - " Did not find layer '%s' from -layer_debug switch.\n", - layer_name ); + if (!got_layer) + fprintf(stderr, + " Did not find layer '%s' from -layer_debug switch.\n", + layer_name); } - if(strcmp(argv[i],"-e") == 0) { /* change extent */ - if( argc <= i+4 ) { - fprintf( stderr, - "Argument -e needs 4 space separated numbers as argument.\n" ); + if (strcmp(argv[i], "-e") == 0) { /* change extent */ + if (argc <= i + 4) { + fprintf(stderr, + "Argument -e needs 4 space separated numbers as argument.\n"); msCleanup(); msFreeConfig(config); exit(1); } - map->extent.minx = atof(argv[i+1]); - map->extent.miny = atof(argv[i+2]); - map->extent.maxx = atof(argv[i+3]); - map->extent.maxy = atof(argv[i+4]); - i+=4; + map->extent.minx = atof(argv[i + 1]); + map->extent.miny = atof(argv[i + 2]); + map->extent.maxx = atof(argv[i + 3]); + map->extent.maxy = atof(argv[i + 4]); + i += 4; } if (strcmp(argv[i], "-s") == 0) { - msMapSetSize(map, atoi(argv[i+1]), atoi(argv[i+2])); - i+=2; + msMapSetSize(map, atoi(argv[i + 1]), atoi(argv[i + 2])); + i += 2; } - if(strcmp(argv[i],"-l") == 0) { /* load layer list */ - layers = msStringSplit(argv[i+1], ' ', &(num_layers)); + if (strcmp(argv[i], "-l") == 0) { /* load layer list */ + layers = msStringSplit(argv[i + 1], ' ', &(num_layers)); - for(j=0; jnumlayers; k++) { - if((GET_LAYER(map, k)->name && strcasecmp(GET_LAYER(map, k)->name, layers[j]) == 0) || (GET_LAYER(map, k)->group && strcasecmp(GET_LAYER(map, k)->group, layers[j]) == 0)) { + for (j = 0; j < num_layers; j++) { /* loop over -l */ + layer_found = 0; + for (k = 0; k < map->numlayers; k++) { + if ((GET_LAYER(map, k)->name && + strcasecmp(GET_LAYER(map, k)->name, layers[j]) == 0) || + (GET_LAYER(map, k)->group && + strcasecmp(GET_LAYER(map, k)->group, layers[j]) == 0)) { layer_found = 1; break; } } - if (layer_found==0) { + if (layer_found == 0) { fprintf(stderr, "Layer (-l) \"%s\" not found\n", layers[j]); msCleanup(); msFreeConfig(config); @@ -295,14 +302,16 @@ int main(int argc, char *argv[]) } } - for(j=0; jnumlayers; j++) { - if(GET_LAYER(map, j)->status == MS_DEFAULT) + for (j = 0; j < map->numlayers; j++) { + if (GET_LAYER(map, j)->status == MS_DEFAULT) continue; else { GET_LAYER(map, j)->status = MS_OFF; - for(k=0; kname && strcasecmp(GET_LAYER(map, j)->name, layers[k]) == 0) || - (GET_LAYER(map, j)->group && strcasecmp(GET_LAYER(map, j)->group, layers[k]) == 0)) { + for (k = 0; k < num_layers; k++) { + if ((GET_LAYER(map, j)->name && + strcasecmp(GET_LAYER(map, j)->name, layers[k]) == 0) || + (GET_LAYER(map, j)->group && + strcasecmp(GET_LAYER(map, j)->group, layers[k]) == 0)) { GET_LAYER(map, j)->status = MS_ON; break; } @@ -312,13 +321,13 @@ int main(int argc, char *argv[]) msFreeCharArray(layers, num_layers); - i+=1; + i += 1; } } image = msDrawMap(map, MS_FALSE); - if(!image) { + if (!image) { msWriteError(stderr); msFreeMap(map); @@ -327,22 +336,22 @@ int main(int argc, char *argv[]) exit(1); } - if( msSaveImage(map, image, outfile) != MS_SUCCESS ) { + if (msSaveImage(map, image, outfile) != MS_SUCCESS) { msWriteError(stderr); } msFreeImage(image); msFreeMap(map); - if(msGetGlobalDebugLevel() >= MS_DEBUGLEVEL_TUNING) { + if (msGetGlobalDebugLevel() >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&requestendtime, NULL); msDebug("map2img total time: %.3fs\n", - (requestendtime.tv_sec+requestendtime.tv_usec/1.0e6)- - (requeststarttime.tv_sec+requeststarttime.tv_usec/1.0e6) ); + (requestendtime.tv_sec + requestendtime.tv_usec / 1.0e6) - + (requeststarttime.tv_sec + requeststarttime.tv_usec / 1.0e6)); } } /* for(draws=0; draws blender_pre; -typedef mapserver::comp_op_adaptor_rgba_pre compop_blender_pre; - -typedef mapserver::pixfmt_alpha_blend_rgba pixel_format; -typedef mapserver::pixfmt_custom_blend_rgba compop_pixel_format; +typedef mapserver::comp_op_adaptor_rgba_pre + compop_blender_pre; + +typedef mapserver::pixfmt_alpha_blend_rgba< + blender_pre, mapserver::rendering_buffer, pixel_type> + pixel_format; +typedef mapserver::pixfmt_custom_blend_rgba + compop_pixel_format; typedef mapserver::rendering_buffer rendering_buffer; typedef mapserver::renderer_base renderer_base; typedef mapserver::renderer_base compop_renderer_base; typedef mapserver::renderer_scanline_aa_solid renderer_scanline; -typedef mapserver::renderer_scanline_bin_solid renderer_scanline_aliased; +typedef mapserver::renderer_scanline_bin_solid + renderer_scanline_aliased; typedef mapserver::rasterizer_scanline_aa<> rasterizer_scanline; typedef mapserver::font_engine_freetype_int16 font_engine_type; typedef mapserver::font_cache_manager font_manager_type; -typedef mapserver::conv_curve font_curve_type; +typedef mapserver::conv_curve + font_curve_type; typedef mapserver::glyph_raster_bin glyph_gen; static const color_type AGG_NO_COLOR = color_type(0, 0, 0, 0); -#define aggColor(c) mapserver::rgba8_pre((c)->red, (c)->green, (c)->blue, (c)->alpha) +#define aggColor(c) \ + mapserver::rgba8_pre((c)->red, (c)->green, (c)->blue, (c)->alpha) -class aggRendererCache -{ +class aggRendererCache { public: font_engine_type m_feng; font_manager_type m_fman; - aggRendererCache(): m_fman(m_feng) {} + aggRendererCache() : m_fman(m_feng) {} }; -class AGG2Renderer -{ +class AGG2Renderer { public: std::vector buffer{}; rendering_buffer m_rendering_buffer; @@ -120,74 +126,70 @@ class AGG2Renderer renderer_scanline_aliased m_renderer_scanline_aliased; rasterizer_scanline m_rasterizer_aa; rasterizer_scanline m_rasterizer_aa_gamma; - mapserver::scanline_p8 sl_poly; /*packed scanlines, works faster when the area is larger - than the perimeter, in number of pixels*/ - mapserver::scanline_u8 sl_line; /*unpacked scanlines, works faster if the area is roughly - equal to the perimeter, in number of pixels*/ + mapserver::scanline_p8 sl_poly; /*packed scanlines, works faster when the area + is larger than the perimeter, in number of pixels*/ + mapserver::scanline_u8 sl_line; /*unpacked scanlines, works faster if the area + is roughly equal to the perimeter, in number of pixels*/ bool use_alpha = false; std::unique_ptr> stroke{}; std::unique_ptr> dash{}; - std::unique_ptr >> stroke_dash{}; + std::unique_ptr>> + stroke_dash{}; double default_gamma = 0.0; mapserver::gamma_linear gamma_function; }; -#define AGG_RENDERER(image) ((AGG2Renderer*) (image)->img.plugin) +#define AGG_RENDERER(image) ((AGG2Renderer *)(image)->img.plugin) -template -static void applyCJC(VertexSource &stroke, int caps, int joins) -{ +template +static void applyCJC(VertexSource &stroke, int caps, int joins) { switch (joins) { - case MS_CJC_ROUND: - stroke.line_join(mapserver::round_join); - break; - case MS_CJC_MITER: - stroke.line_join(mapserver::miter_join); - break; - case MS_CJC_BEVEL: - case MS_CJC_NONE: - stroke.line_join(mapserver::bevel_join); - break; + case MS_CJC_ROUND: + stroke.line_join(mapserver::round_join); + break; + case MS_CJC_MITER: + stroke.line_join(mapserver::miter_join); + break; + case MS_CJC_BEVEL: + case MS_CJC_NONE: + stroke.line_join(mapserver::bevel_join); + break; } switch (caps) { - case MS_CJC_BUTT: - case MS_CJC_NONE: - stroke.line_cap(mapserver::butt_cap); - break; - case MS_CJC_ROUND: - stroke.line_cap(mapserver::round_cap); - break; - case MS_CJC_SQUARE: - stroke.line_cap(mapserver::square_cap); - break; + case MS_CJC_BUTT: + case MS_CJC_NONE: + stroke.line_cap(mapserver::butt_cap); + break; + case MS_CJC_ROUND: + stroke.line_cap(mapserver::round_cap); + break; + case MS_CJC_SQUARE: + stroke.line_cap(mapserver::square_cap); + break; } } -int agg2RenderLine(imageObj *img, shapeObj *p, strokeStyleObj *style) -{ +int agg2RenderLine(imageObj *img, shapeObj *p, strokeStyleObj *style) { AGG2Renderer *r = AGG_RENDERER(img); line_adaptor lines = line_adaptor(p); r->m_rasterizer_aa.reset(); r->m_rasterizer_aa.filling_rule(mapserver::fill_non_zero); - if (style->antialiased== MS_FALSE) - { + if (style->antialiased == MS_FALSE) { r->m_renderer_scanline_aliased.color(aggColor(style->color)); - } - else - { + } else { r->m_renderer_scanline.color(aggColor(style->color)); } if (style->patternlength <= 0) { - if(!r->stroke) { + if (!r->stroke) { r->stroke.reset(new mapserver::conv_stroke(lines)); } else { r->stroke->attach(lines); } r->stroke->width(style->width); - if(style->width>1) { + if (style->width > 1) { applyCJC(*r->stroke, style->linecap, style->linejoin); } else { r->stroke->inner_join(mapserver::inner_bevel); @@ -195,34 +197,36 @@ int agg2RenderLine(imageObj *img, shapeObj *p, strokeStyleObj *style) } r->m_rasterizer_aa.add_path(*r->stroke); } else { - if(!r->dash) { + if (!r->dash) { r->dash.reset(new mapserver::conv_dash(lines)); } else { r->dash->remove_all_dashes(); r->dash->dash_start(0.0); r->dash->attach(lines); } - if(!r->stroke_dash) { - r->stroke_dash.reset(new mapserver::conv_stroke > (*r->dash)); + if (!r->stroke_dash) { + r->stroke_dash.reset( + new mapserver::conv_stroke>( + *r->dash)); } else { r->stroke_dash->attach(*r->dash); } int patt_length = 0; for (int i = 0; i < style->patternlength; i += 2) { if (i < style->patternlength - 1) { - r->dash->add_dash(MS_MAX(1,MS_NINT(style->pattern[i])), - MS_MAX(1,MS_NINT(style->pattern[i + 1]))); - if(style->patternoffset) { - patt_length += MS_MAX(1,MS_NINT(style->pattern[i])) + - MS_MAX(1,MS_NINT(style->pattern[i + 1])); + r->dash->add_dash(MS_MAX(1, MS_NINT(style->pattern[i])), + MS_MAX(1, MS_NINT(style->pattern[i + 1]))); + if (style->patternoffset) { + patt_length += MS_MAX(1, MS_NINT(style->pattern[i])) + + MS_MAX(1, MS_NINT(style->pattern[i + 1])); } } } - if(style->patternoffset > 0) { + if (style->patternoffset > 0) { r->dash->dash_start(patt_length - style->patternoffset); } r->stroke_dash->width(style->width); - if(style->width>1) { + if (style->width > 1) { applyCJC(*r->stroke_dash, style->linecap, style->linejoin); } else { r->stroke_dash->inner_join(mapserver::inner_bevel); @@ -231,19 +235,25 @@ int agg2RenderLine(imageObj *img, shapeObj *p, strokeStyleObj *style) r->m_rasterizer_aa.add_path(*r->stroke_dash); } if (style->antialiased == MS_FALSE) - mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_line, r->m_renderer_scanline_aliased); - else - mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_line, r->m_renderer_scanline); + mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_line, + r->m_renderer_scanline_aliased); + else + mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_line, + r->m_renderer_scanline); return MS_SUCCESS; } -int agg2RenderLineTiled(imageObj *img, shapeObj *p, imageObj * tile) -{ +int agg2RenderLineTiled(imageObj *img, shapeObj *p, imageObj *tile) { mapserver::pattern_filter_bilinear_rgba8 fltr; - typedef mapserver::line_image_pattern pattern_type; - typedef mapserver::renderer_outline_image renderer_img_type; - typedef mapserver::rasterizer_outline_aa rasterizer_img_type; + typedef mapserver::line_image_pattern< + mapserver::pattern_filter_bilinear_rgba8> + pattern_type; + typedef mapserver::renderer_outline_image + renderer_img_type; + typedef mapserver::rasterizer_outline_aa + rasterizer_img_type; pattern_type patt(fltr); AGG2Renderer *r = AGG_RENDERER(img); @@ -258,264 +268,270 @@ int agg2RenderLineTiled(imageObj *img, shapeObj *p, imageObj * tile) return MS_SUCCESS; } -int agg2RenderPolygon(imageObj *img, shapeObj *p, colorObj * color) -{ +int agg2RenderPolygon(imageObj *img, shapeObj *p, colorObj *color) { AGG2Renderer *r = AGG_RENDERER(img); polygon_adaptor polygons(p); r->m_rasterizer_aa_gamma.reset(); r->m_rasterizer_aa_gamma.filling_rule(mapserver::fill_even_odd); r->m_rasterizer_aa_gamma.add_path(polygons); r->m_renderer_scanline.color(aggColor(color)); - mapserver::render_scanlines(r->m_rasterizer_aa_gamma, r->sl_poly, r->m_renderer_scanline); + mapserver::render_scanlines(r->m_rasterizer_aa_gamma, r->sl_poly, + r->m_renderer_scanline); return MS_SUCCESS; } -static inline double int26p6_to_dbl(int p) - { - return double(p) / 64.0; +static inline double int26p6_to_dbl(int p) { return double(p) / 64.0; } + +template +bool decompose_ft_outline(const FT_Outline &outline, bool flip_y, + const mapserver::trans_affine &mtx, + PathStorage &path) { + double x1, y1, x2, y2, x3, y3; + + FT_Vector *point; + FT_Vector *limit; + char *tags; + + int n; // index of contour in outline + int first; // index of first point in contour + char tag; // current point's state + + first = 0; + + for (n = 0; n < outline.n_contours; n++) { + int last; // index of last point in contour + + last = outline.contours[n]; + limit = outline.points + last; + + FT_Vector v_start = outline.points[first]; + + FT_Vector v_control = v_start; + + point = outline.points + first; + tags = outline.tags + first; + tag = FT_CURVE_TAG(tags[0]); + + // A contour cannot start with a cubic control point! + if (tag == FT_CURVE_TAG_CUBIC) + return false; + + // check first point to determine origin + if (tag == FT_CURVE_TAG_CONIC) { + const FT_Vector v_last = outline.points[last]; + + // first point is conic control. Yes, this happens. + if (FT_CURVE_TAG(outline.tags[last]) == FT_CURVE_TAG_ON) { + // start at last point if it is on the curve + v_start = v_last; + limit--; + } else { + // if both first and last points are conic, + // start at their middle and record its position + // for closure + v_start.x = (v_start.x + v_last.x) / 2; + v_start.y = (v_start.y + v_last.y) / 2; + } + point--; + tags--; } -template - bool decompose_ft_outline(const FT_Outline& outline, - bool flip_y, - const mapserver::trans_affine& mtx, - PathStorage& path) - { - double x1, y1, x2, y2, x3, y3; - - FT_Vector* point; - FT_Vector* limit; - char* tags; - - int n; // index of contour in outline - int first; // index of first point in contour - char tag; // current point's state - - first = 0; - - for(n = 0; n < outline.n_contours; n++) - { - int last; // index of last point in contour - - last = outline.contours[n]; - limit = outline.points + last; - - FT_Vector v_start = outline.points[first]; - - FT_Vector v_control = v_start; - - point = outline.points + first; - tags = outline.tags + first; - tag = FT_CURVE_TAG(tags[0]); - - // A contour cannot start with a cubic control point! - if(tag == FT_CURVE_TAG_CUBIC) return false; - - // check first point to determine origin - if( tag == FT_CURVE_TAG_CONIC) - { - const FT_Vector v_last = outline.points[last]; - - // first point is conic control. Yes, this happens. - if(FT_CURVE_TAG(outline.tags[last]) == FT_CURVE_TAG_ON) - { - // start at last point if it is on the curve - v_start = v_last; - limit--; - } - else - { - // if both first and last points are conic, - // start at their middle and record its position - // for closure - v_start.x = (v_start.x + v_last.x) / 2; - v_start.y = (v_start.y + v_last.y) / 2; - } - point--; - tags--; - } + x1 = int26p6_to_dbl(v_start.x); + y1 = int26p6_to_dbl(v_start.y); + if (flip_y) + y1 = -y1; + mtx.transform(&x1, &y1); + path.move_to(x1, y1); + + while (point < limit) { + point++; + tags++; + + tag = FT_CURVE_TAG(tags[0]); + switch (tag) { + case FT_CURVE_TAG_ON: // emit a single line_to + { + x1 = int26p6_to_dbl(point->x); + y1 = int26p6_to_dbl(point->y); + if (flip_y) + y1 = -y1; + mtx.transform(&x1, &y1); + path.line_to(x1, y1); + // path.line_to(conv(point->x), flip_y ? -conv(point->y) : + // conv(point->y)); + continue; + } - x1 = int26p6_to_dbl(v_start.x); - y1 = int26p6_to_dbl(v_start.y); - if(flip_y) y1 = -y1; - mtx.transform(&x1, &y1); - path.move_to(x1,y1); - - while(point < limit) - { - point++; - tags++; - - tag = FT_CURVE_TAG(tags[0]); - switch(tag) - { - case FT_CURVE_TAG_ON: // emit a single line_to - { - x1 = int26p6_to_dbl(point->x); - y1 = int26p6_to_dbl(point->y); - if(flip_y) y1 = -y1; - mtx.transform(&x1, &y1); - path.line_to(x1,y1); - //path.line_to(conv(point->x), flip_y ? -conv(point->y) : conv(point->y)); - continue; - } - - case FT_CURVE_TAG_CONIC: // consume conic arcs - { - v_control.x = point->x; - v_control.y = point->y; - - Do_Conic: - if(point < limit) - { - FT_Vector vec; - FT_Vector v_middle; - - point++; - tags++; - tag = FT_CURVE_TAG(tags[0]); - - vec.x = point->x; - vec.y = point->y; - - if(tag == FT_CURVE_TAG_ON) - { - x1 = int26p6_to_dbl(v_control.x); - y1 = int26p6_to_dbl(v_control.y); - x2 = int26p6_to_dbl(vec.x); - y2 = int26p6_to_dbl(vec.y); - if(flip_y) { y1 = -y1; y2 = -y2; } - mtx.transform(&x1, &y1); - mtx.transform(&x2, &y2); - path.curve3(x1,y1,x2,y2); - continue; - } - - if(tag != FT_CURVE_TAG_CONIC) return false; - - v_middle.x = (v_control.x + vec.x) / 2; - v_middle.y = (v_control.y + vec.y) / 2; - - x1 = int26p6_to_dbl(v_control.x); - y1 = int26p6_to_dbl(v_control.y); - x2 = int26p6_to_dbl(v_middle.x); - y2 = int26p6_to_dbl(v_middle.y); - if(flip_y) { y1 = -y1; y2 = -y2; } - mtx.transform(&x1, &y1); - mtx.transform(&x2, &y2); - path.curve3(x1,y1,x2,y2); - - //path.curve3(conv(v_control.x), - // flip_y ? -conv(v_control.y) : conv(v_control.y), - // conv(v_middle.x), - // flip_y ? -conv(v_middle.y) : conv(v_middle.y)); - - v_control = vec; - goto Do_Conic; - } - - x1 = int26p6_to_dbl(v_control.x); - y1 = int26p6_to_dbl(v_control.y); - x2 = int26p6_to_dbl(v_start.x); - y2 = int26p6_to_dbl(v_start.y); - if(flip_y) { y1 = -y1; y2 = -y2; } - mtx.transform(&x1, &y1); - mtx.transform(&x2, &y2); - path.curve3(x1,y1,x2,y2); - - //path.curve3(conv(v_control.x), - // flip_y ? -conv(v_control.y) : conv(v_control.y), - // conv(v_start.x), - // flip_y ? -conv(v_start.y) : conv(v_start.y)); - goto Close; - } - - default: // FT_CURVE_TAG_CUBIC - { - FT_Vector vec1, vec2; - - if(point + 1 > limit || FT_CURVE_TAG(tags[1]) != FT_CURVE_TAG_CUBIC) - { - return false; - } - - vec1.x = point[0].x; - vec1.y = point[0].y; - vec2.x = point[1].x; - vec2.y = point[1].y; - - point += 2; - tags += 2; - - if(point <= limit) - { - FT_Vector vec; - - vec.x = point->x; - vec.y = point->y; - - x1 = int26p6_to_dbl(vec1.x); - y1 = int26p6_to_dbl(vec1.y); - x2 = int26p6_to_dbl(vec2.x); - y2 = int26p6_to_dbl(vec2.y); - x3 = int26p6_to_dbl(vec.x); - y3 = int26p6_to_dbl(vec.y); - if(flip_y) { y1 = -y1; y2 = -y2; y3 = -y3; } - mtx.transform(&x1, &y1); - mtx.transform(&x2, &y2); - mtx.transform(&x3, &y3); - path.curve4(x1,y1,x2,y2,x3,y3); - - //path.curve4(conv(vec1.x), - // flip_y ? -conv(vec1.y) : conv(vec1.y), - // conv(vec2.x), - // flip_y ? -conv(vec2.y) : conv(vec2.y), - // conv(vec.x), - // flip_y ? -conv(vec.y) : conv(vec.y)); - continue; - } - - x1 = int26p6_to_dbl(vec1.x); - y1 = int26p6_to_dbl(vec1.y); - x2 = int26p6_to_dbl(vec2.x); - y2 = int26p6_to_dbl(vec2.y); - x3 = int26p6_to_dbl(v_start.x); - y3 = int26p6_to_dbl(v_start.y); - if(flip_y) { y1 = -y1; y2 = -y2; y3 = -y3; } - mtx.transform(&x1, &y1); - mtx.transform(&x2, &y2); - mtx.transform(&x3, &y3); - path.curve4(x1,y1,x2,y2,x3,y3); - - //path.curve4(conv(vec1.x), - // flip_y ? -conv(vec1.y) : conv(vec1.y), - // conv(vec2.x), - // flip_y ? -conv(vec2.y) : conv(vec2.y), - // conv(v_start.x), - // flip_y ? -conv(v_start.y) : conv(v_start.y)); - goto Close; - } - } + case FT_CURVE_TAG_CONIC: // consume conic arcs + { + v_control.x = point->x; + v_control.y = point->y; + + Do_Conic: + if (point < limit) { + FT_Vector vec; + FT_Vector v_middle; + + point++; + tags++; + tag = FT_CURVE_TAG(tags[0]); + + vec.x = point->x; + vec.y = point->y; + + if (tag == FT_CURVE_TAG_ON) { + x1 = int26p6_to_dbl(v_control.x); + y1 = int26p6_to_dbl(v_control.y); + x2 = int26p6_to_dbl(vec.x); + y2 = int26p6_to_dbl(vec.y); + if (flip_y) { + y1 = -y1; + y2 = -y2; } + mtx.transform(&x1, &y1); + mtx.transform(&x2, &y2); + path.curve3(x1, y1, x2, y2); + continue; + } + + if (tag != FT_CURVE_TAG_CONIC) + return false; + + v_middle.x = (v_control.x + vec.x) / 2; + v_middle.y = (v_control.y + vec.y) / 2; + + x1 = int26p6_to_dbl(v_control.x); + y1 = int26p6_to_dbl(v_control.y); + x2 = int26p6_to_dbl(v_middle.x); + y2 = int26p6_to_dbl(v_middle.y); + if (flip_y) { + y1 = -y1; + y2 = -y2; + } + mtx.transform(&x1, &y1); + mtx.transform(&x2, &y2); + path.curve3(x1, y1, x2, y2); + + // path.curve3(conv(v_control.x), + // flip_y ? -conv(v_control.y) : conv(v_control.y), + // conv(v_middle.x), + // flip_y ? -conv(v_middle.y) : conv(v_middle.y)); - path.close_polygon(); + v_control = vec; + goto Do_Conic; + } + + x1 = int26p6_to_dbl(v_control.x); + y1 = int26p6_to_dbl(v_control.y); + x2 = int26p6_to_dbl(v_start.x); + y2 = int26p6_to_dbl(v_start.y); + if (flip_y) { + y1 = -y1; + y2 = -y2; + } + mtx.transform(&x1, &y1); + mtx.transform(&x2, &y2); + path.curve3(x1, y1, x2, y2); + + // path.curve3(conv(v_control.x), + // flip_y ? -conv(v_control.y) : conv(v_control.y), + // conv(v_start.x), + // flip_y ? -conv(v_start.y) : conv(v_start.y)); + goto Close; + } + + default: // FT_CURVE_TAG_CUBIC + { + FT_Vector vec1, vec2; + + if (point + 1 > limit || FT_CURVE_TAG(tags[1]) != FT_CURVE_TAG_CUBIC) { + return false; + } - Close: - first = last + 1; + vec1.x = point[0].x; + vec1.y = point[0].y; + vec2.x = point[1].x; + vec2.y = point[1].y; + + point += 2; + tags += 2; + + if (point <= limit) { + FT_Vector vec; + + vec.x = point->x; + vec.y = point->y; + + x1 = int26p6_to_dbl(vec1.x); + y1 = int26p6_to_dbl(vec1.y); + x2 = int26p6_to_dbl(vec2.x); + y2 = int26p6_to_dbl(vec2.y); + x3 = int26p6_to_dbl(vec.x); + y3 = int26p6_to_dbl(vec.y); + if (flip_y) { + y1 = -y1; + y2 = -y2; + y3 = -y3; + } + mtx.transform(&x1, &y1); + mtx.transform(&x2, &y2); + mtx.transform(&x3, &y3); + path.curve4(x1, y1, x2, y2, x3, y3); + + // path.curve4(conv(vec1.x), + // flip_y ? -conv(vec1.y) : conv(vec1.y), + // conv(vec2.x), + // flip_y ? -conv(vec2.y) : conv(vec2.y), + // conv(vec.x), + // flip_y ? -conv(vec.y) : conv(vec.y)); + continue; } - return true; + x1 = int26p6_to_dbl(vec1.x); + y1 = int26p6_to_dbl(vec1.y); + x2 = int26p6_to_dbl(vec2.x); + y2 = int26p6_to_dbl(vec2.y); + x3 = int26p6_to_dbl(v_start.x); + y3 = int26p6_to_dbl(v_start.y); + if (flip_y) { + y1 = -y1; + y2 = -y2; + y3 = -y3; + } + mtx.transform(&x1, &y1); + mtx.transform(&x2, &y2); + mtx.transform(&x3, &y3); + path.curve4(x1, y1, x2, y2, x3, y3); + + // path.curve4(conv(vec1.x), + // flip_y ? -conv(vec1.y) : conv(vec1.y), + // conv(vec2.x), + // flip_y ? -conv(vec2.y) : conv(vec2.y), + // conv(v_start.x), + // flip_y ? -conv(v_start.y) : conv(v_start.y)); + goto Close; + } + } } -int agg2RenderPolygonTiled(imageObj *img, shapeObj *p, imageObj * tile) -{ + path.close_polygon(); + + Close: + first = last + 1; + } + + return true; +} + +int agg2RenderPolygonTiled(imageObj *img, shapeObj *p, imageObj *tile) { assert(img->format->renderer == tile->format->renderer); AGG2Renderer *r = AGG_RENDERER(img); AGG2Renderer *tileRenderer = AGG_RENDERER(tile); polygon_adaptor polygons(p); typedef mapserver::wrap_mode_repeat wrap_type; - typedef mapserver::image_accessor_wrap img_source_type; + typedef mapserver::image_accessor_wrap + img_source_type; typedef mapserver::span_pattern_rgba span_gen_type; mapserver::span_allocator sa; r->m_rasterizer_aa.reset(); @@ -523,79 +539,82 @@ int agg2RenderPolygonTiled(imageObj *img, shapeObj *p, imageObj * tile) img_source_type img_src(tileRenderer->m_pixel_format); span_gen_type sg(img_src, 0, 0); r->m_rasterizer_aa.add_path(polygons); - mapserver::render_scanlines_aa(r->m_rasterizer_aa, r->sl_poly, r->m_renderer_base, sa , sg); + mapserver::render_scanlines_aa(r->m_rasterizer_aa, r->sl_poly, + r->m_renderer_base, sa, sg); return MS_SUCCESS; } -int agg2RenderGlyphsPath(imageObj *img, const textSymbolObj *ts, colorObj *c, colorObj *oc, int ow, int /*isMarker*/) { - +int agg2RenderGlyphsPath(imageObj *img, const textSymbolObj *ts, colorObj *c, + colorObj *oc, int ow, int /*isMarker*/) { + const textPathObj *tp = ts->textpath; mapserver::path_storage glyphs; mapserver::trans_affine trans; AGG2Renderer *r = AGG_RENDERER(img); r->m_rasterizer_aa.filling_rule(mapserver::fill_non_zero); - for(int i=0; inumglyphs; i++) { - glyphObj *gl = tp->glyphs + i; + for (int i = 0; i < tp->numglyphs; i++) { + glyphObj *gl = tp->glyphs + i; trans.reset(); trans.rotate(-gl->rot); trans.translate(gl->pnt.x, gl->pnt.y); - outline_element *ol = msGetGlyphOutline(gl->face,gl->glyph); - if(!ol) { + outline_element *ol = msGetGlyphOutline(gl->face, gl->glyph); + if (!ol) { return MS_FAILURE; } - decompose_ft_outline(ol->outline,true,trans,glyphs); + decompose_ft_outline(ol->outline, true, trans, glyphs); } mapserver::conv_curve m_curves(glyphs); if (oc) { r->m_rasterizer_aa.reset(); r->m_rasterizer_aa.filling_rule(mapserver::fill_non_zero); - mapserver::conv_contour > cc(m_curves); + mapserver::conv_contour> cc( + m_curves); cc.width(ow + 1); r->m_rasterizer_aa.add_path(cc); r->m_renderer_scanline.color(aggColor(oc)); - mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_line, r->m_renderer_scanline); + mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_line, + r->m_renderer_scanline); } - if(c) { + if (c) { r->m_rasterizer_aa.reset(); r->m_rasterizer_aa.filling_rule(mapserver::fill_non_zero); r->m_rasterizer_aa.add_path(m_curves); r->m_renderer_scanline.color(aggColor(c)); - mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_line, r->m_renderer_scanline); + mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_line, + r->m_renderer_scanline); } return MS_SUCCESS; } -mapserver::path_storage imageVectorSymbol(symbolObj *symbol) -{ +mapserver::path_storage imageVectorSymbol(symbolObj *symbol) { mapserver::path_storage path; - int is_new=1; + int is_new = 1; - for(int i=0; i < symbol->numpoints; i++) { - if((symbol->points[i].x == -99) && (symbol->points[i].y == -99)) - is_new=1; + for (int i = 0; i < symbol->numpoints; i++) { + if ((symbol->points[i].x == -99) && (symbol->points[i].y == -99)) + is_new = 1; else { - if(is_new) { - path.move_to(symbol->points[i].x,symbol->points[i].y); - is_new=0; + if (is_new) { + path.move_to(symbol->points[i].x, symbol->points[i].y); + is_new = 0; } else { - path.line_to(symbol->points[i].x,symbol->points[i].y); + path.line_to(symbol->points[i].x, symbol->points[i].y); } } } return path; } -int agg2RenderVectorSymbol(imageObj *img, double x, double y, - symbolObj *symbol, symbolStyleObj * style) -{ +int agg2RenderVectorSymbol(imageObj *img, double x, double y, symbolObj *symbol, + symbolStyleObj *style) { AGG2Renderer *r = AGG_RENDERER(img); double ox = symbol->sizex * 0.5; double oy = symbol->sizey * 0.5; mapserver::path_storage path = imageVectorSymbol(symbol); mapserver::trans_affine mtx; - mtx *= mapserver::trans_affine_translation(-ox,-oy); + mtx *= mapserver::trans_affine_translation(-ox, -oy); mtx *= mapserver::trans_affine_scaling(style->scale); mtx *= mapserver::trans_affine_rotation(-style->rotation); mtx *= mapserver::trans_affine_translation(x, y); @@ -605,40 +624,43 @@ int agg2RenderVectorSymbol(imageObj *img, double x, double y, r->m_rasterizer_aa.filling_rule(mapserver::fill_even_odd); r->m_rasterizer_aa.add_path(path); r->m_renderer_scanline.color(aggColor(style->color)); - mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_poly, r->m_renderer_scanline); + mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_poly, + r->m_renderer_scanline); } - if(style->outlinecolor) { + if (style->outlinecolor) { r->m_rasterizer_aa.reset(); r->m_rasterizer_aa.filling_rule(mapserver::fill_non_zero); r->m_renderer_scanline.color(aggColor(style->outlinecolor)); mapserver::conv_stroke stroke(path); stroke.width(style->outlinewidth); r->m_rasterizer_aa.add_path(stroke); - mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_poly, r->m_renderer_scanline); + mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_poly, + r->m_renderer_scanline); } return MS_SUCCESS; } -int agg2RenderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj * style) -{ +int agg2RenderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, + symbolStyleObj *style) { AGG2Renderer *r = AGG_RENDERER(img); rasterBufferObj *pixmap = symbol->pixmap_buffer; assert(pixmap->type == MS_BUFFER_BYTE_RGBA); - rendering_buffer b(pixmap->data.rgba.pixels,pixmap->width,pixmap->height,pixmap->data.rgba.row_step); + rendering_buffer b(pixmap->data.rgba.pixels, pixmap->width, pixmap->height, + pixmap->data.rgba.row_step); pixel_format pf(b); r->m_rasterizer_aa.reset(); r->m_rasterizer_aa.filling_rule(mapserver::fill_non_zero); - if ( (style->rotation != 0 && style->rotation != MS_PI*2.)|| style->scale != 1) { + if ((style->rotation != 0 && style->rotation != MS_PI * 2.) || + style->scale != 1) { mapserver::trans_affine image_mtx; - image_mtx *= mapserver::trans_affine_translation(-(pf.width()/2.),-(pf.height()/2.)); + image_mtx *= mapserver::trans_affine_translation(-(pf.width() / 2.), + -(pf.height() / 2.)); /*agg angles are antitrigonometric*/ image_mtx *= mapserver::trans_affine_rotation(-style->rotation); image_mtx *= mapserver::trans_affine_scaling(style->scale); - - - image_mtx *= mapserver::trans_affine_translation(x,y); + image_mtx *= mapserver::trans_affine_translation(x, y); image_mtx.invert(); typedef mapserver::span_interpolator_linear<> interpolator_type; interpolator_type interpolator(image_mtx); @@ -646,63 +668,72 @@ int agg2RenderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, // "hardcoded" bilinear filter //------------------------------------------ - typedef mapserver::span_image_filter_rgba_bilinear_clip span_gen_type; - span_gen_type sg(pf, mapserver::rgba(0,0,0,0), interpolator); + typedef mapserver::span_image_filter_rgba_bilinear_clip + span_gen_type; + span_gen_type sg(pf, mapserver::rgba(0, 0, 0, 0), interpolator); mapserver::path_storage pixmap_bbox; - int ims_2 = MS_NINT(MS_MAX(pixmap->width,pixmap->height)*style->scale*1.415)/2+1; + int ims_2 = + MS_NINT(MS_MAX(pixmap->width, pixmap->height) * style->scale * 1.415) / + 2 + + 1; - pixmap_bbox.move_to(x-ims_2,y-ims_2); - pixmap_bbox.line_to(x+ims_2,y-ims_2); - pixmap_bbox.line_to(x+ims_2,y+ims_2); - pixmap_bbox.line_to(x-ims_2,y+ims_2); + pixmap_bbox.move_to(x - ims_2, y - ims_2); + pixmap_bbox.line_to(x + ims_2, y - ims_2); + pixmap_bbox.line_to(x + ims_2, y + ims_2); + pixmap_bbox.line_to(x - ims_2, y + ims_2); r->m_rasterizer_aa.add_path(pixmap_bbox); - mapserver::render_scanlines_aa(r->m_rasterizer_aa, r->sl_poly, r->m_renderer_base, sa, sg); + mapserver::render_scanlines_aa(r->m_rasterizer_aa, r->sl_poly, + r->m_renderer_base, sa, sg); } else { - //just copy the image at the correct location (we place the pixmap on - //the nearest integer pixel to avoid blurring) - r->m_renderer_base.blend_from(pf,0,MS_NINT(x-pixmap->width/2.),MS_NINT(y-pixmap->height/2.)); + // just copy the image at the correct location (we place the pixmap on + // the nearest integer pixel to avoid blurring) + r->m_renderer_base.blend_from(pf, 0, MS_NINT(x - pixmap->width / 2.), + MS_NINT(y - pixmap->height / 2.)); } return MS_SUCCESS; } int agg2RenderEllipseSymbol(imageObj *image, double x, double y, - symbolObj *symbol, symbolStyleObj * style) -{ + symbolObj *symbol, symbolStyleObj *style) { AGG2Renderer *r = AGG_RENDERER(image); mapserver::path_storage path; - mapserver::ellipse ellipse(x,y,symbol->sizex*style->scale/2,symbol->sizey*style->scale/2); + mapserver::ellipse ellipse(x, y, symbol->sizex * style->scale / 2, + symbol->sizey * style->scale / 2); path.concat_path(ellipse); - if( style->rotation != 0) { + if (style->rotation != 0) { mapserver::trans_affine mtx; - mtx *= mapserver::trans_affine_translation(-x,-y); + mtx *= mapserver::trans_affine_translation(-x, -y); /*agg angles are antitrigonometric*/ mtx *= mapserver::trans_affine_rotation(-style->rotation); - mtx *= mapserver::trans_affine_translation(x,y); + mtx *= mapserver::trans_affine_translation(x, y); path.transform(mtx); } - if(style->color) { + if (style->color) { r->m_rasterizer_aa.reset(); r->m_rasterizer_aa.filling_rule(mapserver::fill_even_odd); r->m_rasterizer_aa.add_path(path); r->m_renderer_scanline.color(aggColor(style->color)); - mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_line, r->m_renderer_scanline); + mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_line, + r->m_renderer_scanline); } - if(style->outlinewidth) { + if (style->outlinewidth) { r->m_rasterizer_aa.reset(); r->m_rasterizer_aa.filling_rule(mapserver::fill_non_zero); mapserver::conv_stroke stroke(path); stroke.width(style->outlinewidth); r->m_rasterizer_aa.add_path(stroke); r->m_renderer_scanline.color(aggColor(style->outlinecolor)); - mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_poly, r->m_renderer_scanline); + mapserver::render_scanlines(r->m_rasterizer_aa, r->sl_poly, + r->m_renderer_scanline); } return MS_SUCCESS; } -int agg2RenderTile(imageObj * /*img*/, imageObj * /*tile*/, double /*x*/, double /*y*/) -{ +int agg2RenderTile(imageObj * /*img*/, imageObj * /*tile*/, double /*x*/, + double /*y*/) { /* AGG2Renderer *imgRenderer = agg2GetRenderer(img); AGG2Renderer *tileRenderer = agg2GetRenderer(tile); @@ -710,30 +741,27 @@ int agg2RenderTile(imageObj * /*img*/, imageObj * /*tile*/, double /*x*/, double return MS_FAILURE; } -int aggInitializeRasterBuffer(rasterBufferObj *rb, int width, int height, int mode) -{ +int aggInitializeRasterBuffer(rasterBufferObj *rb, int width, int height, + int mode) { rb->type = MS_BUFFER_BYTE_RGBA; rb->data.rgba.pixel_step = 4; rb->data.rgba.row_step = rb->data.rgba.pixel_step * width; rb->width = width; rb->height = height; int nBytes = rb->data.rgba.row_step * height; - rb->data.rgba.pixels = (band_type*)msSmallCalloc(nBytes,sizeof(band_type)); + rb->data.rgba.pixels = (band_type *)msSmallCalloc(nBytes, sizeof(band_type)); rb->data.rgba.r = &(rb->data.rgba.pixels[band_order::R]); rb->data.rgba.g = &(rb->data.rgba.pixels[band_order::G]); rb->data.rgba.b = &(rb->data.rgba.pixels[band_order::B]); - if(mode == MS_IMAGEMODE_RGBA) { + if (mode == MS_IMAGEMODE_RGBA) { rb->data.rgba.a = &(rb->data.rgba.pixels[band_order::A]); } return MS_SUCCESS; } - - -int aggGetRasterBufferHandle(imageObj *img, rasterBufferObj * rb) -{ +int aggGetRasterBufferHandle(imageObj *img, rasterBufferObj *rb) { AGG2Renderer *r = AGG_RENDERER(img); - rb->type =MS_BUFFER_BYTE_RGBA; + rb->type = MS_BUFFER_BYTE_RGBA; rb->data.rgba.pixels = r->buffer.data(); rb->data.rgba.row_step = r->m_rendering_buffer.stride(); rb->data.rgba.pixel_step = 4; @@ -742,68 +770,72 @@ int aggGetRasterBufferHandle(imageObj *img, rasterBufferObj * rb) rb->data.rgba.r = &(r->buffer[band_order::R]); rb->data.rgba.g = &(r->buffer[band_order::G]); rb->data.rgba.b = &(r->buffer[band_order::B]); - if(r->use_alpha) + if (r->use_alpha) rb->data.rgba.a = &(r->buffer[band_order::A]); else rb->data.rgba.a = NULL; return MS_SUCCESS; } -int aggGetRasterBufferCopy(imageObj *img, rasterBufferObj *rb) -{ +int aggGetRasterBufferCopy(imageObj *img, rasterBufferObj *rb) { AGG2Renderer *r = AGG_RENDERER(img); aggInitializeRasterBuffer(rb, img->width, img->height, MS_IMAGEMODE_RGBA); - int nBytes = r->m_rendering_buffer.stride()*r->m_rendering_buffer.height(); - memcpy(rb->data.rgba.pixels,r->buffer.data(), nBytes); + int nBytes = r->m_rendering_buffer.stride() * r->m_rendering_buffer.height(); + memcpy(rb->data.rgba.pixels, r->buffer.data(), nBytes); return MS_SUCCESS; } - - -int agg2MergeRasterBuffer(imageObj *dest, rasterBufferObj *overlay, double opacity, int srcX, int srcY, - int dstX, int dstY, int width, int height) -{ +int agg2MergeRasterBuffer(imageObj *dest, rasterBufferObj *overlay, + double opacity, int srcX, int srcY, int dstX, + int dstY, int width, int height) { assert(overlay->type == MS_BUFFER_BYTE_RGBA); - rendering_buffer b(overlay->data.rgba.pixels, overlay->width, overlay->height, overlay->data.rgba.row_step); + rendering_buffer b(overlay->data.rgba.pixels, overlay->width, overlay->height, + overlay->data.rgba.row_step); pixel_format pf(b); AGG2Renderer *r = AGG_RENDERER(dest); - mapserver::rect_base src_rect(srcX,srcY,srcX+width,srcY+height); - r->m_renderer_base.blend_from(pf,&src_rect, dstX-srcX, dstY-srcY, unsigned(opacity * 255)); + mapserver::rect_base src_rect(srcX, srcY, srcX + width, srcY + height); + r->m_renderer_base.blend_from(pf, &src_rect, dstX - srcX, dstY - srcY, + unsigned(opacity * 255)); return MS_SUCCESS; } /* image i/o */ -imageObj *agg2CreateImage(int width, int height, outputFormatObj *format, colorObj * bg) -{ +imageObj *agg2CreateImage(int width, int height, outputFormatObj *format, + colorObj *bg) { imageObj *image = NULL; - if (format->imagemode != MS_IMAGEMODE_RGB && format->imagemode != MS_IMAGEMODE_RGBA) { + if (format->imagemode != MS_IMAGEMODE_RGB && + format->imagemode != MS_IMAGEMODE_RGBA) { msSetError(MS_MISCERR, - "AGG2 driver only supports RGB or RGBA pixel models.", "agg2CreateImage()"); + "AGG2 driver only supports RGB or RGBA pixel models.", + "agg2CreateImage()"); return image; } if (width > 0 && height > 0) { - image = (imageObj *) calloc(1, sizeof (imageObj)); - MS_CHECK_ALLOC(image, sizeof (imageObj), NULL); + image = (imageObj *)calloc(1, sizeof(imageObj)); + MS_CHECK_ALLOC(image, sizeof(imageObj), NULL); AGG2Renderer *r = new AGG2Renderer(); - - /* Compute size on 64bit and check that it is compatible of the platform size_t */ + + /* Compute size on 64bit and check that it is compatible of the platform + * size_t */ AGG_INT64U bufSize64 = (AGG_INT64U)width * height * 4 * sizeof(band_type); size_t bufSize = (size_t)bufSize64; - if( (AGG_INT64U)bufSize != bufSize64 ) { - msSetError(MS_MEMERR, "%s: %d: Out of memory allocating " AGG_INT64U_FRMT " bytes.\n", "agg2CreateImage()", - __FILE__, __LINE__, bufSize64); + if ((AGG_INT64U)bufSize != bufSize64) { + msSetError(MS_MEMERR, + "%s: %d: Out of memory allocating " AGG_INT64U_FRMT + " bytes.\n", + "agg2CreateImage()", __FILE__, __LINE__, bufSize64); free(image); delete r; return NULL; } - try - { + try { r->buffer.resize(bufSize / sizeof(band_type)); - } - catch( const std::bad_alloc& ) { - msSetError(MS_MEMERR, "%s: %d: Out of memory allocating " AGG_INT64U_FRMT " bytes.\n", "agg2CreateImage()", - __FILE__, __LINE__, bufSize64); + } catch (const std::bad_alloc &) { + msSetError(MS_MEMERR, + "%s: %d: Out of memory allocating " AGG_INT64U_FRMT + " bytes.\n", + "agg2CreateImage()", __FILE__, __LINE__, bufSize64); free(image); delete r; return NULL; @@ -815,23 +847,23 @@ imageObj *agg2CreateImage(int width, int height, outputFormatObj *format, colorO r->m_compop_renderer_base.attach(r->m_compop_pixel_format); r->m_renderer_scanline.attach(r->m_renderer_base); r->m_renderer_scanline_aliased.attach(r->m_renderer_base); - r->default_gamma = atof(msGetOutputFormatOption( format, "GAMMA", "0.75" )); - if(r->default_gamma <= 0.0 || r->default_gamma >= 1.0) { + r->default_gamma = atof(msGetOutputFormatOption(format, "GAMMA", "0.75")); + if (r->default_gamma <= 0.0 || r->default_gamma >= 1.0) { r->default_gamma = 0.75; } - r->gamma_function.set(0,r->default_gamma); + r->gamma_function.set(0, r->default_gamma); r->m_rasterizer_aa_gamma.gamma(r->gamma_function); - if( bg && !format->transparent ) + if (bg && !format->transparent) r->m_renderer_base.clear(aggColor(bg)); else r->m_renderer_base.clear(AGG_NO_COLOR); - if (!bg || format->transparent || format->imagemode == MS_IMAGEMODE_RGBA ) { + if (!bg || format->transparent || format->imagemode == MS_IMAGEMODE_RGBA) { r->use_alpha = true; } else { r->use_alpha = false; } - image->img.plugin = (void*) r; + image->img.plugin = (void *)r; } else { msSetError(MS_RENDERERERR, "Cannot create cairo image of size %dx%d.", "msImageCreateCairo()", width, height); @@ -840,200 +872,204 @@ imageObj *agg2CreateImage(int width, int height, outputFormatObj *format, colorO return image; } -int agg2SaveImage(imageObj * /*img*/, mapObj* /*map*/, FILE * /*fp*/, outputFormatObj * /*format*/) -{ - +int agg2SaveImage(imageObj * /*img*/, mapObj * /*map*/, FILE * /*fp*/, + outputFormatObj * /*format*/) { return MS_FAILURE; } -int agg2StartNewLayer(imageObj *img, mapObj* /*map*/, layerObj *layer) -{ +int agg2StartNewLayer(imageObj *img, mapObj * /*map*/, layerObj *layer) { AGG2Renderer *r = AGG_RENDERER(img); - const char *sgamma = msLayerGetProcessingKey( layer, "GAMMA" ); + const char *sgamma = msLayerGetProcessingKey(layer, "GAMMA"); double gamma; - if(sgamma) { + if (sgamma) { gamma = atof(sgamma); - if(gamma <= 0 || gamma >= 1) gamma = 0.75; + if (gamma <= 0 || gamma >= 1) + gamma = 0.75; } else { gamma = r->default_gamma; } - if(r->gamma_function.end() != gamma) { + if (r->gamma_function.end() != gamma) { r->gamma_function.end(gamma); r->m_rasterizer_aa_gamma.gamma(r->gamma_function); } return MS_SUCCESS; } -int agg2CloseNewLayer(imageObj * /*img*/, mapObj * /*map*/, layerObj * /*layer*/) -{ +int agg2CloseNewLayer(imageObj * /*img*/, mapObj * /*map*/, + layerObj * /*layer*/) { return MS_SUCCESS; } -int agg2FreeImage(imageObj * image) -{ +int agg2FreeImage(imageObj *image) { AGG2Renderer *r = AGG_RENDERER(image); delete r; image->img.plugin = NULL; return MS_SUCCESS; } -int agg2FreeSymbol(symbolObj * /*symbol*/) -{ - return MS_SUCCESS; -} +int agg2FreeSymbol(symbolObj * /*symbol*/) { return MS_SUCCESS; } -int agg2InitCache(void **vcache) -{ +int agg2InitCache(void **vcache) { aggRendererCache *cache = new aggRendererCache(); - *vcache = (void*)cache; + *vcache = (void *)cache; return MS_SUCCESS; } -int agg2Cleanup(void *vcache) -{ - aggRendererCache *cache = (aggRendererCache*)vcache; +int agg2Cleanup(void *vcache) { + aggRendererCache *cache = (aggRendererCache *)vcache; delete cache; return MS_SUCCESS; } - // ------------------------------------------------------------------------ // Function to create a custom hatch symbol based on an arbitrary angle. // ------------------------------------------------------------------------ -static mapserver::path_storage createHatch(double ox, double oy, - double rx, double ry, - int sx, int sy, double angle, double step) -{ +static mapserver::path_storage createHatch(double ox, double oy, double rx, + double ry, int sx, int sy, + double angle, double step) { mapserver::path_storage path; - //restrict the angle to [0 180[, i.e ]-pi/2,pi/2] in radians + // restrict the angle to [0 180[, i.e ]-pi/2,pi/2] in radians angle = fmod(angle, 360.0); - if(angle < 0) angle += 360; - if(angle >= 180) angle -= 180; - - //treat 2 easy cases which would cause divide by 0 in generic case - if(angle==0) { - double y0 = step-fmod(oy-ry,step); - if((oy - ry) < 0) { + if (angle < 0) + angle += 360; + if (angle >= 180) + angle -= 180; + + // treat 2 easy cases which would cause divide by 0 in generic case + if (angle == 0) { + double y0 = step - fmod(oy - ry, step); + if ((oy - ry) < 0) { y0 -= step; } - for(double y=y0; y=0&&y<=sy) { - pt[2*inter]=x; - pt[2*inter+1]=y; + // parametrize each line as r = x.cos(theta) + y.sin(theta) + for (double r = r0; r < rmax; r += step) { + int inter = 0; + double x, y; + double pt[4]; // array to store the coordinates of intersection of the line + // with the sides + // in the general case there will only be two intersections + // so pt[4] should be sufficient to store the coordinates of the + // intersection, but we allocate pt[8] to treat the special and + // rare/unfortunate case when the line is a perfect diagonal (and therfore + // intersects all four sides) note that the order for testing is important + // in this case so that the first two intersection points actually + // correspond to the diagonal and not a degenerate line + + // test for intersection with each side + + y = r * invst; + x = 0; // test for intersection with left of image + if (y >= 0 && y <= sy) { + pt[2 * inter] = x; + pt[2 * inter + 1] = y; inter++; } - x=sx; - y=(r-sx*ct)*invst;// test for intersection with right of image - if(y>=0&&y<=sy) { - pt[2*inter]=x; - pt[2*inter+1]=y; + x = sx; + y = (r - sx * ct) * invst; // test for intersection with right of image + if (y >= 0 && y <= sy) { + pt[2 * inter] = x; + pt[2 * inter + 1] = y; inter++; } - if(inter<2) { - y=0; - x=r*invct;// test for intersection with top of image - if(x>=0&&x<=sx) { - pt[2*inter]=x; - pt[2*inter+1]=y; + if (inter < 2) { + y = 0; + x = r * invct; // test for intersection with top of image + if (x >= 0 && x <= sx) { + pt[2 * inter] = x; + pt[2 * inter + 1] = y; inter++; } } - if(inter<2) { - y=sy; - x=(r-sy*st)*invct;// test for intersection with bottom of image - if(x>=0&&x<=sx) { - pt[2*inter]=x; - pt[2*inter+1]=y; + if (inter < 2) { + y = sy; + x = (r - sy * st) * invct; // test for intersection with bottom of image + if (x >= 0 && x <= sx) { + pt[2 * inter] = x; + pt[2 * inter + 1] = y; inter++; } } - if(inter==2 && (pt[0]!=pt[2] || pt[1]!=pt[3])) { - //the line intersects with two sides of the image, it should therefore be drawn - if(angle<90) { - path.move_to(pt[0],pt[1]); - path.line_to(pt[2],pt[3]); + if (inter == 2 && (pt[0] != pt[2] || pt[1] != pt[3])) { + // the line intersects with two sides of the image, it should therefore be + // drawn + if (angle < 90) { + path.move_to(pt[0], pt[1]); + path.line_to(pt[2], pt[3]); } else { - path.move_to(pt[0],sy-pt[1]); - path.line_to(pt[2],sy-pt[3]); + path.move_to(pt[0], sy - pt[1]); + path.line_to(pt[2], sy - pt[3]); } } } return path; } -template int renderPolygonHatches(imageObj *img,VertexSource &clipper, colorObj *color) -{ - if(img->format->renderer == MS_RENDER_WITH_AGG) { +template +int renderPolygonHatches(imageObj *img, VertexSource &clipper, + colorObj *color) { + if (img->format->renderer == MS_RENDER_WITH_AGG) { AGG2Renderer *r = AGG_RENDERER(img); r->m_rasterizer_aa_gamma.reset(); r->m_rasterizer_aa_gamma.filling_rule(mapserver::fill_non_zero); r->m_rasterizer_aa_gamma.add_path(clipper); r->m_renderer_scanline.color(aggColor(color)); - mapserver::render_scanlines(r->m_rasterizer_aa_gamma, r->sl_poly, r->m_renderer_scanline); + mapserver::render_scanlines(r->m_rasterizer_aa_gamma, r->sl_poly, + r->m_renderer_scanline); } else { shapeObj shape; msInitShape(&shape); @@ -1041,37 +1077,40 @@ template int renderPolygonHatches(imageObj *img,VertexSource lineObj line; shape.line = &line; shape.numlines = 1; - shape.line[0].point = (pointObj*)msSmallCalloc(allocated,sizeof(pointObj)); + shape.line[0].point = + (pointObj *)msSmallCalloc(allocated, sizeof(pointObj)); shape.line[0].numpoints = 0; - double x=0,y=0; + double x = 0, y = 0; unsigned int cmd; clipper.rewind(0); - while((cmd = clipper.vertex(&x,&y)) != mapserver::path_cmd_stop) { - switch(cmd) { - case mapserver::path_cmd_line_to: - if(shape.line[0].numpoints == allocated) { - allocated *= 2; - shape.line[0].point = (pointObj*)msSmallRealloc(shape.line[0].point, allocated*sizeof(pointObj)); - } - shape.line[0].point[shape.line[0].numpoints].x = x; - shape.line[0].point[shape.line[0].numpoints].y = y; - shape.line[0].numpoints++; - break; - case mapserver::path_cmd_move_to: - shape.line[0].point[0].x = x; - shape.line[0].point[0].y = y; - shape.line[0].numpoints = 1; - break; - case mapserver::path_cmd_end_poly|mapserver::path_flags_close: - if(shape.line[0].numpoints > 2) { - if(MS_UNLIKELY(MS_FAILURE == MS_IMAGE_RENDERER(img)->renderPolygon(img,&shape,color))) { - free(shape.line[0].point); - return MS_FAILURE; - } + while ((cmd = clipper.vertex(&x, &y)) != mapserver::path_cmd_stop) { + switch (cmd) { + case mapserver::path_cmd_line_to: + if (shape.line[0].numpoints == allocated) { + allocated *= 2; + shape.line[0].point = (pointObj *)msSmallRealloc( + shape.line[0].point, allocated * sizeof(pointObj)); + } + shape.line[0].point[shape.line[0].numpoints].x = x; + shape.line[0].point[shape.line[0].numpoints].y = y; + shape.line[0].numpoints++; + break; + case mapserver::path_cmd_move_to: + shape.line[0].point[0].x = x; + shape.line[0].point[0].y = y; + shape.line[0].numpoints = 1; + break; + case mapserver::path_cmd_end_poly | mapserver::path_flags_close: + if (shape.line[0].numpoints > 2) { + if (MS_UNLIKELY(MS_FAILURE == MS_IMAGE_RENDERER(img)->renderPolygon( + img, &shape, color))) { + free(shape.line[0].point); + return MS_FAILURE; } - break; - default: - assert(0); //WTF? + } + break; + default: + assert(0); // WTF? } } free(shape.line[0].point); @@ -1079,8 +1118,9 @@ template int renderPolygonHatches(imageObj *img,VertexSource return MS_SUCCESS; } -int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double *pattern, int patternlength, double angle, colorObj *color) -{ +int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, + double *pattern, int patternlength, double angle, + colorObj *color) { assert(MS_RENDERER_PLUGIN(img->format)); msComputeBounds(poly); @@ -1088,236 +1128,246 @@ int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double exp = width * 0.7072; /* width and height of the bounding box we will be creating the hatch in */ - int pw=(int)(poly->bounds.maxx-poly->bounds.minx+exp*2)+1; - int ph=(int)(poly->bounds.maxy-poly->bounds.miny+exp*2)+1; + int pw = (int)(poly->bounds.maxx - poly->bounds.minx + exp * 2) + 1; + int ph = (int)(poly->bounds.maxy - poly->bounds.miny + exp * 2) + 1; /* position of the top-left corner of the bounding box */ double ox = poly->bounds.minx - exp; double oy = poly->bounds.miny - exp; - //create a rectangular hatch of size pw,ph starting at 0,0 - //the created hatch is of the size of the shape's bounding box - mapserver::path_storage hatch = createHatch(ox,oy, - img->refpt.x,img->refpt.y,pw,ph,angle,spacing); - if(hatch.total_vertices()<=0) return MS_SUCCESS; + // create a rectangular hatch of size pw,ph starting at 0,0 + // the created hatch is of the size of the shape's bounding box + mapserver::path_storage hatch = + createHatch(ox, oy, img->refpt.x, img->refpt.y, pw, ph, angle, spacing); + if (hatch.total_vertices() <= 0) + return MS_SUCCESS; - //translate the hatch so it overlaps the current shape - hatch.transform(mapserver::trans_affine_translation(ox,oy)); + // translate the hatch so it overlaps the current shape + hatch.transform(mapserver::trans_affine_translation(ox, oy)); polygon_adaptor polygons(poly); - - - if(patternlength>1) { - //dash the color-hatch and render it clipped by the shape - mapserver::conv_dash dash(hatch); - mapserver::conv_stroke > stroke(dash); - for (int i=0; i 1) { + // dash the color-hatch and render it clipped by the shape + mapserver::conv_dash dash(hatch); + mapserver::conv_stroke> + stroke(dash); + for (int i = 0; i < patternlength; i += 2) { + if (i < patternlength - 1) { + dash.add_dash(pattern[i], pattern[i + 1]); } } stroke.width(width); stroke.line_cap(mapserver::butt_cap); - mapserver::conv_clipper > > clipper(polygons,stroke, mapserver::clipper_and); - renderPolygonHatches(img,clipper,color); + mapserver::conv_clipper< + polygon_adaptor, + mapserver::conv_stroke>> + clipper(polygons, stroke, mapserver::clipper_and); + renderPolygonHatches(img, clipper, color); } else { - //render the hatch clipped by the shape - mapserver::conv_stroke stroke(hatch); + // render the hatch clipped by the shape + mapserver::conv_stroke stroke(hatch); stroke.width(width); stroke.line_cap(mapserver::butt_cap); - mapserver::conv_clipper > clipper(polygons,stroke, mapserver::clipper_and); - renderPolygonHatches(img,clipper,color); + mapserver::conv_clipper> + clipper(polygons, stroke, mapserver::clipper_and); + renderPolygonHatches(img, clipper, color); } - - //assert(prevCmd == mapserver::path_cmd_line_to); - //delete lines; + // assert(prevCmd == mapserver::path_cmd_line_to); + // delete lines; return MS_SUCCESS; } #ifdef USE_PIXMAN static pixman_op_t ms2pixman_compop(CompositingOperation c) { - switch(c) { - case MS_COMPOP_CLEAR: - return PIXMAN_OP_CLEAR; - case MS_COMPOP_SRC: - return PIXMAN_OP_SRC; - case MS_COMPOP_DST: - return PIXMAN_OP_DST; - case MS_COMPOP_SRC_OVER: - return PIXMAN_OP_OVER; - case MS_COMPOP_DST_OVER: - return PIXMAN_OP_OVER_REVERSE; - case MS_COMPOP_SRC_IN: - return PIXMAN_OP_IN; - case MS_COMPOP_DST_IN: - return PIXMAN_OP_IN_REVERSE; - case MS_COMPOP_SRC_OUT: - return PIXMAN_OP_OUT; - case MS_COMPOP_DST_OUT: - return PIXMAN_OP_OUT_REVERSE; - case MS_COMPOP_SRC_ATOP: - return PIXMAN_OP_ATOP; - case MS_COMPOP_DST_ATOP: - return PIXMAN_OP_ATOP_REVERSE; - case MS_COMPOP_XOR: - return PIXMAN_OP_XOR; - case MS_COMPOP_PLUS: - return PIXMAN_OP_ADD; - case MS_COMPOP_MULTIPLY: - return PIXMAN_OP_MULTIPLY; - case MS_COMPOP_SCREEN: - return PIXMAN_OP_SCREEN; - case MS_COMPOP_OVERLAY: - return PIXMAN_OP_OVERLAY; - case MS_COMPOP_DARKEN: - return PIXMAN_OP_DARKEN; - case MS_COMPOP_LIGHTEN: - return PIXMAN_OP_LIGHTEN; - case MS_COMPOP_COLOR_DODGE: - return PIXMAN_OP_COLOR_DODGE; - case MS_COMPOP_COLOR_BURN: - return PIXMAN_OP_COLOR_DODGE; - case MS_COMPOP_HARD_LIGHT: - return PIXMAN_OP_HARD_LIGHT; - case MS_COMPOP_SOFT_LIGHT: - return PIXMAN_OP_SOFT_LIGHT; - case MS_COMPOP_DIFFERENCE: - return PIXMAN_OP_DIFFERENCE; - case MS_COMPOP_EXCLUSION: - return PIXMAN_OP_EXCLUSION; - case MS_COMPOP_INVERT: - case MS_COMPOP_INVERT_RGB: - case MS_COMPOP_MINUS: - case MS_COMPOP_CONTRAST: - default: - return PIXMAN_OP_OVER; + switch (c) { + case MS_COMPOP_CLEAR: + return PIXMAN_OP_CLEAR; + case MS_COMPOP_SRC: + return PIXMAN_OP_SRC; + case MS_COMPOP_DST: + return PIXMAN_OP_DST; + case MS_COMPOP_SRC_OVER: + return PIXMAN_OP_OVER; + case MS_COMPOP_DST_OVER: + return PIXMAN_OP_OVER_REVERSE; + case MS_COMPOP_SRC_IN: + return PIXMAN_OP_IN; + case MS_COMPOP_DST_IN: + return PIXMAN_OP_IN_REVERSE; + case MS_COMPOP_SRC_OUT: + return PIXMAN_OP_OUT; + case MS_COMPOP_DST_OUT: + return PIXMAN_OP_OUT_REVERSE; + case MS_COMPOP_SRC_ATOP: + return PIXMAN_OP_ATOP; + case MS_COMPOP_DST_ATOP: + return PIXMAN_OP_ATOP_REVERSE; + case MS_COMPOP_XOR: + return PIXMAN_OP_XOR; + case MS_COMPOP_PLUS: + return PIXMAN_OP_ADD; + case MS_COMPOP_MULTIPLY: + return PIXMAN_OP_MULTIPLY; + case MS_COMPOP_SCREEN: + return PIXMAN_OP_SCREEN; + case MS_COMPOP_OVERLAY: + return PIXMAN_OP_OVERLAY; + case MS_COMPOP_DARKEN: + return PIXMAN_OP_DARKEN; + case MS_COMPOP_LIGHTEN: + return PIXMAN_OP_LIGHTEN; + case MS_COMPOP_COLOR_DODGE: + return PIXMAN_OP_COLOR_DODGE; + case MS_COMPOP_COLOR_BURN: + return PIXMAN_OP_COLOR_DODGE; + case MS_COMPOP_HARD_LIGHT: + return PIXMAN_OP_HARD_LIGHT; + case MS_COMPOP_SOFT_LIGHT: + return PIXMAN_OP_SOFT_LIGHT; + case MS_COMPOP_DIFFERENCE: + return PIXMAN_OP_DIFFERENCE; + case MS_COMPOP_EXCLUSION: + return PIXMAN_OP_EXCLUSION; + case MS_COMPOP_INVERT: + case MS_COMPOP_INVERT_RGB: + case MS_COMPOP_MINUS: + case MS_COMPOP_CONTRAST: + default: + return PIXMAN_OP_OVER; } } #else static mapserver::comp_op_e ms2agg_compop(CompositingOperation c) { - switch(c) { - case MS_COMPOP_CLEAR: - return mapserver::comp_op_clear; - case MS_COMPOP_SRC: - return mapserver::comp_op_src; - case MS_COMPOP_DST: - return mapserver::comp_op_dst; - case MS_COMPOP_SRC_OVER: - return mapserver::comp_op_src_over; - case MS_COMPOP_DST_OVER: - return mapserver::comp_op_dst_over; - case MS_COMPOP_SRC_IN: - return mapserver::comp_op_src_in; - case MS_COMPOP_DST_IN: - return mapserver::comp_op_dst_in; - case MS_COMPOP_SRC_OUT: - return mapserver::comp_op_src_out; - case MS_COMPOP_DST_OUT: - return mapserver::comp_op_dst_out; - case MS_COMPOP_SRC_ATOP: - return mapserver::comp_op_src_atop; - case MS_COMPOP_DST_ATOP: - return mapserver::comp_op_dst_atop; - case MS_COMPOP_XOR: - return mapserver::comp_op_xor; - case MS_COMPOP_PLUS: - return mapserver::comp_op_plus; - case MS_COMPOP_MINUS: - return mapserver::comp_op_minus; - case MS_COMPOP_MULTIPLY: - return mapserver::comp_op_multiply; - case MS_COMPOP_SCREEN: - return mapserver::comp_op_screen; - case MS_COMPOP_OVERLAY: - return mapserver::comp_op_overlay; - case MS_COMPOP_DARKEN: - return mapserver::comp_op_darken; - case MS_COMPOP_LIGHTEN: - return mapserver::comp_op_lighten; - case MS_COMPOP_COLOR_DODGE: - return mapserver::comp_op_color_dodge; - case MS_COMPOP_COLOR_BURN: - return mapserver::comp_op_color_burn; - case MS_COMPOP_HARD_LIGHT: - return mapserver::comp_op_hard_light; - case MS_COMPOP_SOFT_LIGHT: - return mapserver::comp_op_soft_light; - case MS_COMPOP_DIFFERENCE: - return mapserver::comp_op_difference; - case MS_COMPOP_EXCLUSION: - return mapserver::comp_op_exclusion; - case MS_COMPOP_CONTRAST: - return mapserver::comp_op_contrast; - case MS_COMPOP_INVERT: - return mapserver::comp_op_invert; - case MS_COMPOP_INVERT_RGB: - return mapserver::comp_op_invert_rgb; - default: - return mapserver::comp_op_src_over; + switch (c) { + case MS_COMPOP_CLEAR: + return mapserver::comp_op_clear; + case MS_COMPOP_SRC: + return mapserver::comp_op_src; + case MS_COMPOP_DST: + return mapserver::comp_op_dst; + case MS_COMPOP_SRC_OVER: + return mapserver::comp_op_src_over; + case MS_COMPOP_DST_OVER: + return mapserver::comp_op_dst_over; + case MS_COMPOP_SRC_IN: + return mapserver::comp_op_src_in; + case MS_COMPOP_DST_IN: + return mapserver::comp_op_dst_in; + case MS_COMPOP_SRC_OUT: + return mapserver::comp_op_src_out; + case MS_COMPOP_DST_OUT: + return mapserver::comp_op_dst_out; + case MS_COMPOP_SRC_ATOP: + return mapserver::comp_op_src_atop; + case MS_COMPOP_DST_ATOP: + return mapserver::comp_op_dst_atop; + case MS_COMPOP_XOR: + return mapserver::comp_op_xor; + case MS_COMPOP_PLUS: + return mapserver::comp_op_plus; + case MS_COMPOP_MINUS: + return mapserver::comp_op_minus; + case MS_COMPOP_MULTIPLY: + return mapserver::comp_op_multiply; + case MS_COMPOP_SCREEN: + return mapserver::comp_op_screen; + case MS_COMPOP_OVERLAY: + return mapserver::comp_op_overlay; + case MS_COMPOP_DARKEN: + return mapserver::comp_op_darken; + case MS_COMPOP_LIGHTEN: + return mapserver::comp_op_lighten; + case MS_COMPOP_COLOR_DODGE: + return mapserver::comp_op_color_dodge; + case MS_COMPOP_COLOR_BURN: + return mapserver::comp_op_color_burn; + case MS_COMPOP_HARD_LIGHT: + return mapserver::comp_op_hard_light; + case MS_COMPOP_SOFT_LIGHT: + return mapserver::comp_op_soft_light; + case MS_COMPOP_DIFFERENCE: + return mapserver::comp_op_difference; + case MS_COMPOP_EXCLUSION: + return mapserver::comp_op_exclusion; + case MS_COMPOP_CONTRAST: + return mapserver::comp_op_contrast; + case MS_COMPOP_INVERT: + return mapserver::comp_op_invert; + case MS_COMPOP_INVERT_RGB: + return mapserver::comp_op_invert_rgb; + default: + return mapserver::comp_op_src_over; } } #endif -int aggCompositeRasterBuffer(imageObj *dest, rasterBufferObj *overlay, CompositingOperation comp, int opacity) { +int aggCompositeRasterBuffer(imageObj *dest, rasterBufferObj *overlay, + CompositingOperation comp, int opacity) { assert(overlay->type == MS_BUFFER_BYTE_RGBA); AGG2Renderer *r = AGG_RENDERER(dest); #ifdef USE_PIXMAN - pixman_image_t *si = pixman_image_create_bits(PIXMAN_a8r8g8b8,overlay->width,overlay->height, - (uint32_t*)overlay->data.rgba.pixels,overlay->data.rgba.row_step); - pixman_image_t *bi = pixman_image_create_bits(PIXMAN_a8r8g8b8,dest->width,dest->height, - reinterpret_cast(&(r->buffer[0])),dest->width*4); - pixman_image_t *alpha_mask_i=NULL, *alpha_mask_i_ptr; - pixman_image_set_filter(si,PIXMAN_FILTER_NEAREST, NULL, 0); + pixman_image_t *si = pixman_image_create_bits( + PIXMAN_a8r8g8b8, overlay->width, overlay->height, + (uint32_t *)overlay->data.rgba.pixels, overlay->data.rgba.row_step); + pixman_image_t *bi = pixman_image_create_bits( + PIXMAN_a8r8g8b8, dest->width, dest->height, + reinterpret_cast(&(r->buffer[0])), dest->width * 4); + pixman_image_t *alpha_mask_i = NULL, *alpha_mask_i_ptr; + pixman_image_set_filter(si, PIXMAN_FILTER_NEAREST, NULL, 0); unsigned char *alpha_mask = NULL; - if(opacity > 0) { - if(opacity == 100) { - alpha_mask_i_ptr = NULL; - } else { - unsigned char alpha = (unsigned char)(opacity * 2.55); - if(!alpha_mask_i) { - alpha_mask = (unsigned char*)msSmallMalloc(dest->width * dest->height); - alpha_mask_i = pixman_image_create_bits(PIXMAN_a8,dest->width,dest->height, - (uint32_t*)alpha_mask,dest->width); - } - memset(alpha_mask,alpha,dest->width*dest->height); - alpha_mask_i_ptr = alpha_mask_i; + if (opacity > 0) { + if (opacity == 100) { + alpha_mask_i_ptr = NULL; + } else { + unsigned char alpha = (unsigned char)(opacity * 2.55); + if (!alpha_mask_i) { + alpha_mask = (unsigned char *)msSmallMalloc(dest->width * dest->height); + alpha_mask_i = + pixman_image_create_bits(PIXMAN_a8, dest->width, dest->height, + (uint32_t *)alpha_mask, dest->width); } - pixman_image_composite (ms2pixman_compop(comp), si, alpha_mask_i_ptr, bi, - 0, 0, 0, 0, 0, 0, dest->width,dest->height); + memset(alpha_mask, alpha, dest->width * dest->height); + alpha_mask_i_ptr = alpha_mask_i; } + pixman_image_composite(ms2pixman_compop(comp), si, alpha_mask_i_ptr, bi, 0, + 0, 0, 0, 0, 0, dest->width, dest->height); + } pixman_image_unref(si); pixman_image_unref(bi); - if(alpha_mask_i) { + if (alpha_mask_i) { pixman_image_unref(alpha_mask_i); msFree(alpha_mask); } return MS_SUCCESS; #else - rendering_buffer b(overlay->data.rgba.pixels, overlay->width, overlay->height, overlay->data.rgba.row_step); + rendering_buffer b(overlay->data.rgba.pixels, overlay->width, overlay->height, + overlay->data.rgba.row_step); pixel_format pf(b); mapserver::comp_op_e comp_op = ms2agg_compop(comp); - if(comp_op == mapserver::comp_op_src_over) { - r->m_renderer_base.blend_from(pf,0,0,0,unsigned(opacity * 2.55)); + if (comp_op == mapserver::comp_op_src_over) { + r->m_renderer_base.blend_from(pf, 0, 0, 0, unsigned(opacity * 2.55)); } else { compop_pixel_format pixf(r->m_rendering_buffer); compop_renderer_base ren(pixf); pixf.comp_op(comp_op); - ren.blend_from(pf,0,0,0,unsigned(opacity * 2.55)); + ren.blend_from(pf, 0, 0, 0, unsigned(opacity * 2.55)); } return MS_SUCCESS; #endif } -void msApplyBlurringCompositingFilter(rasterBufferObj *rb, unsigned int radius) { - rendering_buffer b(rb->data.rgba.pixels, rb->width, rb->height, rb->data.rgba.row_step); +void msApplyBlurringCompositingFilter(rasterBufferObj *rb, + unsigned int radius) { + rendering_buffer b(rb->data.rgba.pixels, rb->width, rb->height, + rb->data.rgba.row_step); pixel_format pf(b); - mapserver::stack_blur_rgba32(pf,radius,radius); + mapserver::stack_blur_rgba32(pf, radius, radius); } -int msPopulateRendererVTableAGG(rendererVTableObj * renderer) -{ +int msPopulateRendererVTableAGG(rendererVTableObj *renderer) { renderer->compositeRasterBuffer = &aggCompositeRasterBuffer; renderer->supports_pixel_buffer = 1; renderer->use_imagecache = 0; diff --git a/mapagg.h b/mapagg.h index f2478df818..b968bd0dc0 100644 --- a/mapagg.h +++ b/mapagg.h @@ -34,29 +34,31 @@ * interface to a shapeObj representing lines, providing the functions * needed by the agg rasterizer. treats shapeObjs with multiple linestrings. */ -class line_adaptor -{ +class line_adaptor { public: - explicit line_adaptor(shapeObj *shape):s(shape) { - m_line=s->line; /*first line*/ - m_point=m_line->point; /*current vertex is first vertex of first line*/ - m_lend=&(s->line[s->numlines]); /*pointer to after last line*/ - m_pend=&(m_line->point[m_line->numpoints]); /*pointer to after last vertex of first line*/ + explicit line_adaptor(shapeObj *shape) : s(shape) { + m_line = s->line; /*first line*/ + m_point = m_line->point; /*current vertex is first vertex of first line*/ + m_lend = &(s->line[s->numlines]); /*pointer to after last line*/ + m_pend = &(m_line->point[m_line->numpoints]); /*pointer to after last vertex + of first line*/ } /* a class with virtual functions should also provide a virtual destructor */ virtual ~line_adaptor() {} void rewind(unsigned) { - m_line=s->line; /*first line*/ - m_point=m_line->point; /*current vertex is first vertex of first line*/ - m_pend=&(m_line->point[m_line->numpoints]); /*pointer to after last vertex of first line*/ + m_line = s->line; /*first line*/ + m_point = m_line->point; /*current vertex is first vertex of first line*/ + m_pend = &(m_line->point[m_line->numpoints]); /*pointer to after last vertex + of first line*/ } - virtual unsigned vertex(double* x, double* y) { - if(m_point < m_pend) { + virtual unsigned vertex(double *x, double *y) { + if (m_point < m_pend) { /*here we treat the case where a real vertex is returned*/ - bool first = m_point == m_line->point; /*is this the first vertex of a line*/ + bool first = + m_point == m_line->point; /*is this the first vertex of a line*/ *x = m_point->x; *y = m_point->y; m_point++; @@ -65,34 +67,35 @@ class line_adaptor /*if here, we're at the end of a line*/ m_line++; *x = *y = 0.0; - if(m_line>=m_lend) /*is this the last line of the shapObj. normally, - (m_line==m_lend) should be a sufficient test, as the caller should not call - this function if a previous call returned path_cmd_stop.*/ + if (m_line >= m_lend) /*is this the last line of the shapObj. normally, + (m_line==m_lend) should be a sufficient test, as the caller should + not call this function if a previous call returned path_cmd_stop.*/ return mapserver::path_cmd_stop; /*no more points to process*/ /*if here, there are more lines in the shapeObj, continue with next one*/ - m_point=m_line->point; /*pointer to first point of next line*/ - m_pend=&(m_line->point[m_line->numpoints]); /*pointer to after last point of next line*/ + m_point = m_line->point; /*pointer to first point of next line*/ + m_pend = &(m_line->point[m_line->numpoints]); /*pointer to after last point + of next line*/ - return vertex(x,y); /*this will return the first point of the next line*/ + return vertex(x, y); /*this will return the first point of the next line*/ } + protected: shapeObj *s; - lineObj *m_line, /*current line pointer*/ - *m_lend; /*points to after the last line*/ + lineObj *m_line, /*current line pointer*/ + *m_lend; /*points to after the last line*/ pointObj *m_point, /*current point*/ - *m_pend; /*points to after last point of current line*/ + *m_pend; /*points to after last point of current line*/ }; - -class polygon_adaptor -{ +class polygon_adaptor { public: - explicit polygon_adaptor(shapeObj *shape):s(shape) { - m_line=s->line; /*first lines*/ - m_point=m_line->point; /*first vertex of first line*/ - m_lend=&(s->line[s->numlines]); /*pointer to after last line*/ - m_pend=&(m_line->point[m_line->numpoints]); /*pointer to after last vertex of first line*/ + explicit polygon_adaptor(shapeObj *shape) : s(shape) { + m_line = s->line; /*first lines*/ + m_point = m_line->point; /*first vertex of first line*/ + m_lend = &(s->line[s->numlines]); /*pointer to after last line*/ + m_pend = &(m_line->point[m_line->numpoints]); /*pointer to after last vertex + of first line*/ } /* a class with virtual functions should also provide a virtual destructor */ @@ -100,14 +103,14 @@ class polygon_adaptor void rewind(unsigned) { /*reset pointers*/ - m_stop=false; - m_line=s->line; - m_point=m_line->point; - m_pend=&(m_line->point[m_line->numpoints]); + m_stop = false; + m_line = s->line; + m_point = m_line->point; + m_pend = &(m_line->point[m_line->numpoints]); } - virtual unsigned vertex(double* x, double* y) { - if(m_point < m_pend) { + virtual unsigned vertex(double *x, double *y) { + if (m_point < m_pend) { /*if here, we have a real vertex*/ bool first = m_point == m_line->point; *x = m_point->x; @@ -116,36 +119,38 @@ class polygon_adaptor return first ? mapserver::path_cmd_move_to : mapserver::path_cmd_line_to; } *x = *y = 0.0; - if(!m_stop) { + if (!m_stop) { /*if here, we're after the last vertex of the current line * we return the command to close the current polygon*/ m_line++; - if(m_line>=m_lend) { + if (m_line >= m_lend) { /*if here, we've finished all the vertexes of the shape. * we still return the command to close the current polygon, * but set m_stop so the subsequent call to vertex() will return * the stop command*/ - m_stop=true; + m_stop = true; return mapserver::path_cmd_end_poly; } - /*if here, there's another line in the shape, so we set the pointers accordingly - * and return the command to close the current polygon*/ - m_point=m_line->point; /*first vertex of next line*/ - m_pend=&(m_line->point[m_line->numpoints]); /*pointer to after last vertex of next line*/ + /*if here, there's another line in the shape, so we set the pointers + * accordingly and return the command to close the current polygon*/ + m_point = m_line->point; /*first vertex of next line*/ + m_pend = &(m_line->point[m_line->numpoints]); /*pointer to after last + vertex of next line*/ return mapserver::path_cmd_end_poly; } - /*if here, a previous call to vertex informed us that we'd consumed all the vertexes - * of the shape. return the command to stop processing this shape*/ + /*if here, a previous call to vertex informed us that we'd consumed all the + * vertexes of the shape. return the command to stop processing this shape*/ return mapserver::path_cmd_stop; } + protected: shapeObj *s; double ox = 0.0; double oy = 0.0; - lineObj *m_line, /*pointer to current line*/ - *m_lend; /*pointer to after last line of the shape*/ - pointObj *m_point, /*pointer to current vertex*/ - *m_pend; /*pointer to after last vertex of current line*/ + lineObj *m_line, /*pointer to current line*/ + *m_lend; /*pointer to after last line of the shape*/ + pointObj *m_point, /*pointer to current vertex*/ + *m_pend; /*pointer to after last vertex of current line*/ bool m_stop = false; /*should next call return stop command*/ }; diff --git a/mapaxisorder.h b/mapaxisorder.h index 97181de452..f3b3dd8aff 100644 --- a/mapaxisorder.h +++ b/mapaxisorder.h @@ -14,7 +14,7 @@ * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in + * The above copyright notice and this permission notice shall be included in * all copies of this Software or works derived from this Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS @@ -25,4116 +25,4115 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************/ - + /* * Generated file * * This file was generated from by means of a script. Do not edit manually. */ - + #ifdef __cplusplus extern "C" { #endif - + static const unsigned char axisOrientationEpsgCodes[] = { - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, - 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0 -}; - + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 1 << 6 | 1 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 1 << 7 | 1 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0, + 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 0 << 1 | 0 << 0}; + #ifdef __cplusplus } #endif diff --git a/mapbits.c b/mapbits.c index 18a6c5617a..42b4a5607c 100644 --- a/mapbits.c +++ b/mapbits.c @@ -32,8 +32,6 @@ #include "mapserver.h" - - #include /* @@ -41,24 +39,23 @@ * See function msGetNextBit for another hardcoded value. */ -/* #define msGetBit(array, index) (*((array) + (index)/MS_ARRAY_BIT) & ( 1 << ((index) % MS_ARRAY_BIT))) */ +/* #define msGetBit(array, index) (*((array) + (index)/MS_ARRAY_BIT) & ( 1 << + * ((index) % MS_ARRAY_BIT))) */ -size_t msGetBitArraySize(int numbits) -{ - return((numbits + MS_ARRAY_BIT - 1) / MS_ARRAY_BIT); +size_t msGetBitArraySize(int numbits) { + return ((numbits + MS_ARRAY_BIT - 1) / MS_ARRAY_BIT); } -ms_bitarray msAllocBitArray(int numbits) -{ - ms_bitarray array = calloc((numbits + MS_ARRAY_BIT - 1) / MS_ARRAY_BIT, MS_ARRAY_BIT); +ms_bitarray msAllocBitArray(int numbits) { + ms_bitarray array = + calloc((numbits + MS_ARRAY_BIT - 1) / MS_ARRAY_BIT, MS_ARRAY_BIT); - return(array); + return (array); } -int msGetBit(ms_const_bitarray array, int index) -{ +int msGetBit(ms_const_bitarray array, int index) { array += index / MS_ARRAY_BIT; - return (*array & (1 << (index % MS_ARRAY_BIT))) != 0; /* 0 or 1 */ + return (*array & (1U << (index % MS_ARRAY_BIT))) != 0; /* 0 or 1 */ } /* @@ -68,17 +65,16 @@ int msGetBit(ms_const_bitarray array, int index) ** If hits end of bitmap without finding set bit, will return -1. ** */ -int msGetNextBit(ms_const_bitarray array, int i, int size) -{ +int msGetNextBit(ms_const_bitarray array, int i, int size) { register ms_uint32 b; - while(i < size) { - b = *(array + (i/MS_ARRAY_BIT)); - if( b && (b >> (i % MS_ARRAY_BIT)) ) { + while (i < size) { + b = *(array + (i / MS_ARRAY_BIT)); + if (b && (b >> (i % MS_ARRAY_BIT))) { /* There is something in this byte */ /* And it is not to the right of us */ - if( b & ( 1 << (i % MS_ARRAY_BIT)) ) { + if (b & (1U << (i % MS_ARRAY_BIT))) { /* There is something at this bit! */ return i; } else { @@ -94,25 +90,22 @@ int msGetNextBit(ms_const_bitarray array, int i, int size) return -1; } -void msSetBit(ms_bitarray array, int index, int value) -{ +void msSetBit(ms_bitarray array, int index, int value) { array += index / MS_ARRAY_BIT; if (value) - *array |= 1 << (index % MS_ARRAY_BIT); /* set bit */ + *array |= 1U << (index % MS_ARRAY_BIT); /* set bit */ else - *array &= ~(1 << (index % MS_ARRAY_BIT)); /* clear bit */ + *array &= ~(1U << (index % MS_ARRAY_BIT)); /* clear bit */ } -void msSetAllBits(ms_bitarray array, int numbits, int value) -{ +void msSetAllBits(ms_bitarray array, int numbits, int value) { if (value) - memset(array, 0xff, ((numbits + 7) / 8) ); /* set bit */ + memset(array, 0xff, ((numbits + 7) / 8)); /* set bit */ else - memset(array, 0x0, ((numbits + 7) / 8) ); /* clear bit */ + memset(array, 0x0, ((numbits + 7) / 8)); /* clear bit */ } -void msFlipBit(ms_bitarray array, int index) -{ +void msFlipBit(ms_bitarray array, int index) { array += index / MS_ARRAY_BIT; - *array ^= 1 << (index % MS_ARRAY_BIT); /* flip bit */ + *array ^= 1U << (index % MS_ARRAY_BIT); /* flip bit */ } diff --git a/mapcairo.c b/mapcairo.c index aada546c63..f3caac79e1 100644 --- a/mapcairo.c +++ b/mapcairo.c @@ -44,14 +44,14 @@ #include #else #ifdef USE_RSVG - #include - #ifndef LIBRSVG_CHECK_VERSION - #include - #endif - #ifndef RSVG_CAIRO_H - #include - #endif - #include +#include +#ifndef LIBRSVG_CHECK_VERSION +#include +#endif +#ifndef RSVG_CAIRO_H +#include +#endif +#include #endif #endif @@ -61,7 +61,7 @@ #include "fontcache.h" -# include +#include /* #include #include @@ -93,46 +93,41 @@ typedef struct { cairo_t *dummycr; } cairoCacheData; -void initializeCache(void **vcache) -{ - cairoCacheData *cache = (cairoCacheData*)malloc(sizeof(cairoCacheData)); +void initializeCache(void **vcache) { + cairoCacheData *cache = (cairoCacheData *)malloc(sizeof(cairoCacheData)); *vcache = cache; cache->cairofacecache = NULL; /* dummy surface and context */ - cache->dummysurface = cairo_image_surface_create_for_data(cache->dummydata, CAIRO_FORMAT_ARGB32, 1,1,4); + cache->dummysurface = cairo_image_surface_create_for_data( + cache->dummydata, CAIRO_FORMAT_ARGB32, 1, 1, 4); cache->dummycr = cairo_create(cache->dummysurface); } -int cleanupCairo(void *cache) -{ - cairoCacheData *ccache = (cairoCacheData*)cache; +int cleanupCairo(void *cache) { + cairoCacheData *ccache = (cairoCacheData *)cache; - if(ccache->dummycr) { + if (ccache->dummycr) { cairo_destroy(ccache->dummycr); } - if(ccache->dummysurface) { + if (ccache->dummysurface) { cairo_surface_destroy(ccache->dummysurface); } - if(ccache->cairofacecache) { - cairoFaceCache *next,*cur; + if (ccache->cairofacecache) { + cairoFaceCache *next, *cur; cur = ccache->cairofacecache; do { next = cur->next; freeCairoFaceCache(cur); free(cur); - cur=next; - } while(cur); + cur = next; + } while (cur); } free(ccache); return MS_SUCCESS; } - - - - typedef struct { cairo_surface_t *surface; cairo_t *cr; @@ -140,18 +135,15 @@ typedef struct { int use_alpha; } cairo_renderer; +#define CAIRO_RENDERER(im) ((cairo_renderer *)(im->img.plugin)) -#define CAIRO_RENDERER(im) ((cairo_renderer*)(im->img.plugin)) - - -int freeImageCairo(imageObj *img) -{ +int freeImageCairo(imageObj *img) { cairo_renderer *r = CAIRO_RENDERER(img); - if(r) { + if (r) { cairo_destroy(r->cr); cairo_surface_finish(r->surface); cairo_surface_destroy(r->surface); - if(r->outputStream) { + if (r->outputStream) { msBufferFree(r->outputStream); free(r->outputStream); } @@ -160,10 +152,11 @@ int freeImageCairo(imageObj *img) return MS_SUCCESS; } -static cairoFaceCache* getCairoFontFace(cairoCacheData *cache, FT_Face ftface) { +static cairoFaceCache *getCairoFontFace(cairoCacheData *cache, FT_Face ftface) { cairoFaceCache *cur = cache->cairofacecache; - while(cur) { - if(cur->ftface == ftface) return cur; + while (cur) { + if (cur->ftface == ftface) + return cur; cur = cur->next; } cur = msSmallMalloc(sizeof(cairoFaceCache)); @@ -172,62 +165,64 @@ static cairoFaceCache* getCairoFontFace(cairoCacheData *cache, FT_Face ftface) { cur->ftface = ftface; cur->face = cairo_ft_font_face_create_for_ft_face(ftface, 0); cur->options = cairo_font_options_create(); - cairo_font_options_set_hint_style(cur->options,CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_hint_style(cur->options, CAIRO_HINT_STYLE_NONE); return cur; } -#define msCairoSetSourceColor(cr, c) cairo_set_source_rgba((cr),(c)->red/255.0,(c)->green/255.0,(c)->blue/255.0,(c)->alpha/255.0); +#define msCairoSetSourceColor(cr, c) \ + cairo_set_source_rgba((cr), (c)->red / 255.0, (c)->green / 255.0, \ + (c)->blue / 255.0, (c)->alpha / 255.0); -int renderLineCairo(imageObj *img, shapeObj *p, strokeStyleObj *stroke) -{ - int i,j; +int renderLineCairo(imageObj *img, shapeObj *p, strokeStyleObj *stroke) { + int i, j; cairo_renderer *r = CAIRO_RENDERER(img); assert(stroke->color); cairo_new_path(r->cr); - msCairoSetSourceColor(r->cr,stroke->color); - for(i=0; inumlines; i++) { + msCairoSetSourceColor(r->cr, stroke->color); + for (i = 0; i < p->numlines; i++) { lineObj *l = &(p->line[i]); - if(l->numpoints == 0) continue; - cairo_move_to(r->cr,l->point[0].x,l->point[0].y); - for(j=1; jnumpoints; j++) { - cairo_line_to(r->cr,l->point[j].x,l->point[j].y); + if (l->numpoints == 0) + continue; + cairo_move_to(r->cr, l->point[0].x, l->point[0].y); + for (j = 1; j < l->numpoints; j++) { + cairo_line_to(r->cr, l->point[j].x, l->point[j].y); } } - if(stroke->patternlength>0) { - cairo_set_dash(r->cr,stroke->pattern,stroke->patternlength,-stroke->patternoffset); + if (stroke->patternlength > 0) { + cairo_set_dash(r->cr, stroke->pattern, stroke->patternlength, + -stroke->patternoffset); } - switch(stroke->linecap) { - case MS_CJC_BUTT: - cairo_set_line_cap(r->cr,CAIRO_LINE_CAP_BUTT); - break; - case MS_CJC_SQUARE: - cairo_set_line_cap(r->cr,CAIRO_LINE_CAP_SQUARE); - break; - case MS_CJC_ROUND: - case MS_CJC_NONE: - default: - cairo_set_line_cap(r->cr,CAIRO_LINE_CAP_ROUND); + switch (stroke->linecap) { + case MS_CJC_BUTT: + cairo_set_line_cap(r->cr, CAIRO_LINE_CAP_BUTT); + break; + case MS_CJC_SQUARE: + cairo_set_line_cap(r->cr, CAIRO_LINE_CAP_SQUARE); + break; + case MS_CJC_ROUND: + case MS_CJC_NONE: + default: + cairo_set_line_cap(r->cr, CAIRO_LINE_CAP_ROUND); } - cairo_set_line_width (r->cr, stroke->width); - cairo_stroke (r->cr); - if(stroke->patternlength>0) { - cairo_set_dash(r->cr,stroke->pattern,0,0); + cairo_set_line_width(r->cr, stroke->width); + cairo_stroke(r->cr); + if (stroke->patternlength > 0) { + cairo_set_dash(r->cr, stroke->pattern, 0, 0); } return MS_SUCCESS; } -int renderPolygonCairo(imageObj *img, shapeObj *p, colorObj *c) -{ +int renderPolygonCairo(imageObj *img, shapeObj *p, colorObj *c) { cairo_renderer *r = CAIRO_RENDERER(img); - int i,j; + int i, j; cairo_new_path(r->cr); - cairo_set_fill_rule(r->cr,CAIRO_FILL_RULE_EVEN_ODD); - msCairoSetSourceColor(r->cr,c); - for(i=0; inumlines; i++) { + cairo_set_fill_rule(r->cr, CAIRO_FILL_RULE_EVEN_ODD); + msCairoSetSourceColor(r->cr, c); + for (i = 0; i < p->numlines; i++) { lineObj *l = &(p->line[i]); - cairo_move_to(r->cr,l->point[0].x,l->point[0].y); - for(j=1; jnumpoints; j++) { - cairo_line_to(r->cr,l->point[j].x,l->point[j].y); + cairo_move_to(r->cr, l->point[0].x, l->point[0].y); + for (j = 1; j < l->numpoints; j++) { + cairo_line_to(r->cr, l->point[j].x, l->point[j].y); } cairo_close_path(r->cr); } @@ -235,12 +230,12 @@ int renderPolygonCairo(imageObj *img, shapeObj *p, colorObj *c) return MS_SUCCESS; } -int renderPolygonTiledCairo(imageObj *img, shapeObj *p, imageObj *tile) -{ - int i,j; +int renderPolygonTiledCairo(imageObj *img, shapeObj *p, imageObj *tile) { + int i, j; cairo_renderer *r = CAIRO_RENDERER(img); cairo_renderer *tileRenderer = CAIRO_RENDERER(tile); - cairo_pattern_t *pattern = cairo_pattern_create_for_surface(tileRenderer->surface); + cairo_pattern_t *pattern = + cairo_pattern_create_for_surface(tileRenderer->surface); cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); cairo_set_source(r->cr, pattern); @@ -257,76 +252,72 @@ int renderPolygonTiledCairo(imageObj *img, shapeObj *p, imageObj *tile) return MS_SUCCESS; } -cairo_surface_t *createSurfaceFromBuffer(rasterBufferObj *b) -{ +cairo_surface_t *createSurfaceFromBuffer(rasterBufferObj *b) { assert(b->type == MS_BUFFER_BYTE_RGBA); - return cairo_image_surface_create_for_data (b->data.rgba.pixels, - CAIRO_FORMAT_ARGB32, - b->width, - b->height, - b->data.rgba.row_step); + return cairo_image_surface_create_for_data(b->data.rgba.pixels, + CAIRO_FORMAT_ARGB32, b->width, + b->height, b->data.rgba.row_step); } - -int renderPixmapSymbolCairo(imageObj *img, double x, double y,symbolObj *symbol, - symbolStyleObj *style) -{ +int renderPixmapSymbolCairo(imageObj *img, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { cairo_renderer *r = CAIRO_RENDERER(img); cairo_surface_t *im; rasterBufferObj *b = symbol->pixmap_buffer; assert(b); - if(!symbol->renderer_cache) { - symbol->renderer_cache = (void*)createSurfaceFromBuffer(b); + if (!symbol->renderer_cache) { + symbol->renderer_cache = (void *)createSurfaceFromBuffer(b); } assert(symbol->renderer_cache); - im=(cairo_surface_t*)symbol->renderer_cache; + im = (cairo_surface_t *)symbol->renderer_cache; cairo_save(r->cr); - if(style->rotation != 0 || style->scale != 1) { - cairo_translate (r->cr, x,y); - cairo_rotate (r->cr, -style->rotation); - cairo_scale (r->cr, style->scale,style->scale); - cairo_translate (r->cr, -0.5*b->width, -0.5*b->height); + if (style->rotation != 0 || style->scale != 1) { + cairo_translate(r->cr, x, y); + cairo_rotate(r->cr, -style->rotation); + cairo_scale(r->cr, style->scale, style->scale); + cairo_translate(r->cr, -0.5 * b->width, -0.5 * b->height); } else { - cairo_translate (r->cr, MS_NINT(x-0.5*b->width),MS_NINT(y-0.5*b->height)); + cairo_translate(r->cr, MS_NINT(x - 0.5 * b->width), + MS_NINT(y - 0.5 * b->height)); } - cairo_set_source_surface (r->cr, im, 0, 0); - cairo_paint (r->cr); + cairo_set_source_surface(r->cr, im, 0, 0); + cairo_paint(r->cr); cairo_restore(r->cr); return MS_SUCCESS; } -int renderVectorSymbolCairo(imageObj *img, double x, double y, symbolObj *symbol, - symbolStyleObj *style) -{ +int renderVectorSymbolCairo(imageObj *img, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { cairo_renderer *r = CAIRO_RENDERER(img); - double ox=symbol->sizex*0.5,oy=symbol->sizey*0.5; - int is_new = 1,i; + double ox = symbol->sizex * 0.5, oy = symbol->sizey * 0.5; + int is_new = 1, i; cairo_new_path(r->cr); cairo_save(r->cr); - cairo_translate(r->cr,x,y); - cairo_scale(r->cr,style->scale,style->scale); - cairo_rotate(r->cr,-style->rotation); - cairo_translate(r->cr,-ox,-oy); + cairo_translate(r->cr, x, y); + cairo_scale(r->cr, style->scale, style->scale); + cairo_rotate(r->cr, -style->rotation); + cairo_translate(r->cr, -ox, -oy); for (i = 0; i < symbol->numpoints; i++) { - if ((symbol->points[i].x == -99) && (symbol->points[i].y == -99)) { /* (PENUP) */ + if ((symbol->points[i].x == -99) && + (symbol->points[i].y == -99)) { /* (PENUP) */ is_new = 1; } else { if (is_new) { - cairo_move_to(r->cr,symbol->points[i].x,symbol->points[i].y); + cairo_move_to(r->cr, symbol->points[i].x, symbol->points[i].y); is_new = 0; } else { - cairo_line_to(r->cr,symbol->points[i].x,symbol->points[i].y); + cairo_line_to(r->cr, symbol->points[i].x, symbol->points[i].y); } } } cairo_restore(r->cr); - if(style->color) { - msCairoSetSourceColor(r->cr,style->color); + if (style->color) { + msCairoSetSourceColor(r->cr, style->color); cairo_fill_preserve(r->cr); } - if(style->outlinewidth>0) { - msCairoSetSourceColor(r->cr,style->outlinecolor); - cairo_set_line_width (r->cr, style->outlinewidth); + if (style->outlinewidth > 0) { + msCairoSetSourceColor(r->cr, style->outlinecolor); + cairo_set_line_width(r->cr, style->outlinewidth); cairo_stroke_preserve(r->cr); } cairo_new_path(r->cr); @@ -341,38 +332,37 @@ struct svg_symbol_cache { #else svg_cairo_t *svgc; #endif - double scale,rotation; -} ; + double scale, rotation; +}; #endif int renderSVGSymbolCairo(imageObj *img, double x, double y, symbolObj *symbol, - symbolStyleObj *style) -{ + symbolStyleObj *style) { #if defined(USE_SVG_CAIRO) || defined(USE_RSVG) struct svg_symbol_cache *cache; cairo_renderer *r = CAIRO_RENDERER(img); - - msPreloadSVGSymbol(symbol); assert(symbol->renderer_cache); cache = symbol->renderer_cache; cairo_save(r->cr); - cairo_translate(r->cr,x,y); - cairo_scale(r->cr,style->scale,style->scale); + cairo_translate(r->cr, x, y); + cairo_scale(r->cr, style->scale, style->scale); if (style->rotation != 0) { cairo_rotate(r->cr, -style->rotation); - cairo_translate (r->cr, -(int)(symbol->sizex/2), -(int)(symbol->sizey/2)); + cairo_translate(r->cr, -(int)(symbol->sizex / 2), + -(int)(symbol->sizey / 2)); } else - cairo_translate (r->cr, -(int)(symbol->sizex/2), -(int)(symbol->sizey/2)); + cairo_translate(r->cr, -(int)(symbol->sizex / 2), + -(int)(symbol->sizey / 2)); #ifdef USE_SVG_CAIRO { svg_cairo_status_t status; status = svg_cairo_render(cache->svgc, r->cr); - if(status != SVG_CAIRO_STATUS_SUCCESS) { + if (status != SVG_CAIRO_STATUS_SUCCESS) { cairo_restore(r->cr); return MS_FAILURE; } @@ -385,30 +375,30 @@ int renderSVGSymbolCairo(imageObj *img, double x, double y, symbolObj *symbol, return MS_SUCCESS; - #else - msSetError(MS_MISCERR, "SVG Symbols requested but is not built with libsvgcairo", + msSetError(MS_MISCERR, + "SVG Symbols requested but is not built with libsvgcairo", "renderSVGSymbolCairo()"); return MS_FAILURE; #endif } -int renderTileCairo(imageObj *img, imageObj *tile, double x, double y) -{ +int renderTileCairo(imageObj *img, imageObj *tile, double x, double y) { cairo_renderer *r = CAIRO_RENDERER(img); cairo_surface_t *im = CAIRO_RENDERER(tile)->surface; - int w = cairo_image_surface_get_width (im); - int h = cairo_image_surface_get_height (im); + int w = cairo_image_surface_get_width(im); + int h = cairo_image_surface_get_height(im); cairo_save(r->cr); - cairo_translate(r->cr, MS_NINT(x-0.5 * w), MS_NINT(y -0.5 * h)); + cairo_translate(r->cr, MS_NINT(x - 0.5 * w), MS_NINT(y - 0.5 * h)); cairo_set_source_surface(r->cr, im, 0, 0); - cairo_pattern_set_filter (cairo_get_source (r->cr), CAIRO_FILTER_NEAREST); + cairo_pattern_set_filter(cairo_get_source(r->cr), CAIRO_FILTER_NEAREST); cairo_paint(r->cr); cairo_restore(r->cr); return MS_SUCCESS; } -int renderGlyphs2Cairo(imageObj *img, const textSymbolObj *ts, colorObj *c, colorObj *oc, int ow, int isMarker) { +int renderGlyphs2Cairo(imageObj *img, const textSymbolObj *ts, colorObj *c, + colorObj *oc, int ow, int isMarker) { const textPathObj *tp = ts->textpath; cairo_renderer *r = CAIRO_RENDERER(img); cairoCacheData *cache = MS_IMAGE_RENDERER_CACHE(img); @@ -417,25 +407,25 @@ int renderGlyphs2Cairo(imageObj *img, const textSymbolObj *ts, colorObj *c, colo int g; (void)isMarker; - cairo_set_font_size(r->cr,MS_NINT(tp->glyph_size * 96.0/72.0)); - for(g=0;gnumglyphs;g++) { + cairo_set_font_size(r->cr, MS_NINT(tp->glyph_size * 96.0 / 72.0)); + for (g = 0; g < tp->numglyphs; g++) { glyphObj *gl = &tp->glyphs[g]; cairo_glyph_t glyph; /* load the glyph's face into cairo, if not already present */ - if(gl->face->face != prevface) { - cairo_face = getCairoFontFace(cache,gl->face->face); + if (gl->face->face != prevface) { + cairo_face = getCairoFontFace(cache, gl->face->face); cairo_set_font_face(r->cr, cairo_face->face); - cairo_set_font_options(r->cr,cairo_face->options); + cairo_set_font_options(r->cr, cairo_face->options); prevface = gl->face->face; - cairo_set_font_size(r->cr,MS_NINT(tp->glyph_size * 96.0/72.0)); + cairo_set_font_size(r->cr, MS_NINT(tp->glyph_size * 96.0 / 72.0)); } cairo_save(r->cr); - cairo_translate(r->cr,gl->pnt.x,gl->pnt.y); - if(gl->rot != 0.0) + cairo_translate(r->cr, gl->pnt.x, gl->pnt.y); + if (gl->rot != 0.0) cairo_rotate(r->cr, -gl->rot); glyph.x = glyph.y = 0; glyph.index = gl->glyph->key.codepoint; - cairo_glyph_path(r->cr,&glyph,1); + cairo_glyph_path(r->cr, &glyph, 1); cairo_restore(r->cr); } if (oc) { @@ -445,7 +435,7 @@ int renderGlyphs2Cairo(imageObj *img, const textSymbolObj *ts, colorObj *c, colo cairo_stroke_preserve(r->cr); cairo_restore(r->cr); } - if(c) { + if (c) { msCairoSetSourceColor(r->cr, c); cairo_fill(r->cr); } @@ -453,85 +443,88 @@ int renderGlyphs2Cairo(imageObj *img, const textSymbolObj *ts, colorObj *c, colo return MS_SUCCESS; } -cairo_status_t _stream_write_fn(void *b, const unsigned char *data, unsigned int length) -{ - msBufferAppend((bufferObj*)b,(void*)data,length); +cairo_status_t _stream_write_fn(void *b, const unsigned char *data, + unsigned int length) { + msBufferAppend((bufferObj *)b, (void *)data, length); return CAIRO_STATUS_SUCCESS; } -imageObj* createImageCairo(int width, int height, outputFormatObj *format,colorObj* bg) -{ +imageObj *createImageCairo(int width, int height, outputFormatObj *format, + colorObj *bg) { imageObj *image = NULL; - cairo_renderer *r=NULL; - if (format->imagemode != MS_IMAGEMODE_RGB && format->imagemode!= MS_IMAGEMODE_RGBA) { + cairo_renderer *r = NULL; + if (format->imagemode != MS_IMAGEMODE_RGB && + format->imagemode != MS_IMAGEMODE_RGBA) { msSetError(MS_MISCERR, - "Cairo driver only supports RGB or RGBA pixel models.","msImageCreateCairo()"); + "Cairo driver only supports RGB or RGBA pixel models.", + "msImageCreateCairo()"); return image; } if (width > 0 && height > 0) { - image = (imageObj *) calloc(1, sizeof(imageObj)); - r = (cairo_renderer*)calloc(1,sizeof(cairo_renderer)); - if(!strcasecmp(format->driver,"cairo/pdf")) { - r->outputStream = (bufferObj*)malloc(sizeof(bufferObj)); + image = (imageObj *)calloc(1, sizeof(imageObj)); + r = (cairo_renderer *)calloc(1, sizeof(cairo_renderer)); + if (!strcasecmp(format->driver, "cairo/pdf")) { + r->outputStream = (bufferObj *)malloc(sizeof(bufferObj)); msBufferInit(r->outputStream); r->surface = cairo_pdf_surface_create_for_stream( - _stream_write_fn, - r->outputStream, - width,height); -#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,15,10) + _stream_write_fn, r->outputStream, width, height); +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 15, 10) { - const char *msPDFCreationDate = CPLGetConfigOption("MS_PDF_CREATION_DATE", NULL); - if( msPDFCreationDate ) - { - cairo_pdf_surface_set_metadata (r->surface, - CAIRO_PDF_METADATA_CREATE_DATE, - msPDFCreationDate); - } + const char *msPDFCreationDate = + CPLGetConfigOption("MS_PDF_CREATION_DATE", NULL); + if (msPDFCreationDate) { + cairo_pdf_surface_set_metadata( + r->surface, CAIRO_PDF_METADATA_CREATE_DATE, msPDFCreationDate); + } } #endif - } else if(!strcasecmp(format->driver,"cairo/svg")) { - r->outputStream = (bufferObj*)malloc(sizeof(bufferObj)); + } else if (!strcasecmp(format->driver, "cairo/svg")) { + r->outputStream = (bufferObj *)malloc(sizeof(bufferObj)); msBufferInit(r->outputStream); r->surface = cairo_svg_surface_create_for_stream( - _stream_write_fn, - r->outputStream, - width,height); - } else if(!strcasecmp(format->driver,"cairo/winGDI") && format->device) { + _stream_write_fn, r->outputStream, width, height); + } else if (!strcasecmp(format->driver, "cairo/winGDI") && format->device) { #if CAIRO_HAS_WIN32_SURFACE r->outputStream = NULL; r->surface = cairo_win32_surface_create(format->device); #else - msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.", + msSetError(MS_RENDERERERR, + "Cannot create cairo image. Cairo was not compiled with " + "support for the win32 backend.", "msImageCreateCairo()"); #endif - } else if(!strcasecmp(format->driver,"cairo/winGDIPrint") && format->device) { + } else if (!strcasecmp(format->driver, "cairo/winGDIPrint") && + format->device) { #if CAIRO_HAS_WIN32_SURFACE r->outputStream = NULL; r->surface = cairo_win32_printing_surface_create(format->device); #else - msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.", + msSetError(MS_RENDERERERR, + "Cannot create cairo image. Cairo was not compiled with " + "support for the win32 backend.", "msImageCreateCairo()"); #endif } else { r->outputStream = NULL; - r->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + r->surface = + cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); } r->cr = cairo_create(r->surface); - if(format->transparent || !bg || !MS_VALID_COLOR(*bg)) { + if (format->transparent || !bg || !MS_VALID_COLOR(*bg)) { r->use_alpha = 1; - cairo_set_source_rgba (r->cr, 0,0,0,0); + cairo_set_source_rgba(r->cr, 0, 0, 0, 0); } else { r->use_alpha = 0; - msCairoSetSourceColor(r->cr,bg); + msCairoSetSourceColor(r->cr, bg); } - cairo_save (r->cr); - cairo_set_operator (r->cr, CAIRO_OPERATOR_SOURCE); - cairo_paint (r->cr); - cairo_restore (r->cr); - - cairo_set_line_cap (r->cr,CAIRO_LINE_CAP_ROUND); - cairo_set_line_join(r->cr,CAIRO_LINE_JOIN_ROUND); - image->img.plugin = (void*)r; + cairo_save(r->cr); + cairo_set_operator(r->cr, CAIRO_OPERATOR_SOURCE); + cairo_paint(r->cr); + cairo_restore(r->cr); + + cairo_set_line_cap(r->cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join(r->cr, CAIRO_LINE_JOIN_ROUND); + image->img.plugin = (void *)r; } else { msSetError(MS_RENDERERERR, "Cannot create cairo image of size %dx%d.", "msImageCreateCairo()", width, height); @@ -539,23 +532,27 @@ imageObj* createImageCairo(int width, int height, outputFormatObj *format,colorO return image; } -/* msSaveImagePostPDFProcessing() will call the GDAL PDF driver to add geospatial */ -/* information to the regular PDF generated by cairo. This is only triggered if the */ -/* GEO_ENCODING outputformat option is set (to ISO32000 or OGC_BP). Additionnal */ +/* msSaveImagePostPDFProcessing() will call the GDAL PDF driver to add + * geospatial */ +/* information to the regular PDF generated by cairo. This is only triggered if + * the */ +/* GEO_ENCODING outputformat option is set (to ISO32000 or OGC_BP). Additionnal + */ /* options can be provided by specifying outputformat options starting with */ /* METADATA_ITEM: prefix. For example METADATA_ITEM:PRODUCER=MapServer */ -/* Those options are AUTHOR, CREATOR, CREATION_DATE, KEYWORDS, PRODUCER, SUBJECT, TITLE */ +/* Those options are AUTHOR, CREATOR, CREATION_DATE, KEYWORDS, PRODUCER, + * SUBJECT, TITLE */ /* See http://gdal.org/frmt_pdf.html documentation. */ -static void msTransformToGeospatialPDF(imageObj *img, mapObj *map, cairo_renderer *r) -{ +static void msTransformToGeospatialPDF(imageObj *img, mapObj *map, + cairo_renderer *r) { GDALDatasetH hDS = NULL; - const char* pszGEO_ENCODING = NULL; + const char *pszGEO_ENCODING = NULL; GDALDriverH hPDFDriver = NULL; - const char* pszVirtualIO = NULL; + const char *pszVirtualIO = NULL; int bVirtualIO = FALSE; - char* pszTmpFilename = NULL; - VSILFILE* fp = NULL; + char *pszTmpFilename = NULL; + VSILFILE *fp = NULL; if (map == NULL) return; @@ -572,7 +569,7 @@ static void msTransformToGeospatialPDF(imageObj *img, mapObj *map, cairo_rendere /* When compiled against libpoppler, the PDF driver is VirtualIO capable */ /* but not, when it is compiled against libpodofo. */ - pszVirtualIO = GDALGetMetadataItem( hPDFDriver, GDAL_DCAP_VIRTUALIO, NULL ); + pszVirtualIO = GDALGetMetadataItem(hPDFDriver, GDAL_DCAP_VIRTUALIO, NULL); if (pszVirtualIO) bVirtualIO = CSLTestBoolean(pszVirtualIO); @@ -592,20 +589,19 @@ static void msTransformToGeospatialPDF(imageObj *img, mapObj *map, cairo_rendere fp = NULL; hDS = GDALOpen(pszTmpFilename, GA_Update); - if ( hDS != NULL ) { - char* pszWKT = msProjectionObj2OGCWKT( &(map->projection) ); - if( pszWKT != NULL ) { + if (hDS != NULL) { + char *pszWKT = msProjectionObj2OGCWKT(&(map->projection)); + if (pszWKT != NULL) { double adfGeoTransform[6]; int i; /* Add user-specified options */ - for( i = 0; i < img->format->numformatoptions; i++ ) { - const char* pszOption = img->format->formatoptions[i]; - if( strncasecmp(pszOption,"METADATA_ITEM:",14) == 0 ) { - char* pszKey = NULL; - const char* pszValue = CPLParseNameValue(pszOption + 14, - &pszKey); - if( pszKey != NULL ) { + for (i = 0; i < img->format->numformatoptions; i++) { + const char *pszOption = img->format->formatoptions[i]; + if (strncasecmp(pszOption, "METADATA_ITEM:", 14) == 0) { + char *pszKey = NULL; + const char *pszValue = CPLParseNameValue(pszOption + 14, &pszKey); + if (pszKey != NULL) { GDALSetMetadataItem(hDS, pszKey, pszValue, NULL); CPLFree(pszKey); } @@ -615,12 +611,14 @@ static void msTransformToGeospatialPDF(imageObj *img, mapObj *map, cairo_rendere /* We need to rescale the geotransform because GDAL will not necessary */ /* open the PDF with the DPI that was used to generate it */ memcpy(adfGeoTransform, map->gt.geotransform, 6 * sizeof(double)); - adfGeoTransform[1] = adfGeoTransform[1] * map->width / GDALGetRasterXSize(hDS); - adfGeoTransform[5] = adfGeoTransform[5] * map->height / GDALGetRasterYSize(hDS); + adfGeoTransform[1] = + adfGeoTransform[1] * map->width / GDALGetRasterXSize(hDS); + adfGeoTransform[5] = + adfGeoTransform[5] * map->height / GDALGetRasterYSize(hDS); GDALSetGeoTransform(hDS, adfGeoTransform); GDALSetProjection(hDS, pszWKT); - msFree( pszWKT ); + msFree(pszWKT); pszWKT = NULL; CPLSetThreadLocalConfigOption("GDAL_PDF_GEO_ENCODING", pszGEO_ENCODING); @@ -632,7 +630,7 @@ static void msTransformToGeospatialPDF(imageObj *img, mapObj *map, cairo_rendere /* We need to replace the buffer with the content of the GDAL file */ fp = VSIFOpenL(pszTmpFilename, "rb"); - if( fp != NULL ) { + if (fp != NULL) { int nFileSize; VSIFSeekL(fp, 0, SEEK_END); @@ -641,7 +639,8 @@ static void msTransformToGeospatialPDF(imageObj *img, mapObj *map, cairo_rendere msBufferResize(r->outputStream, nFileSize); VSIFSeekL(fp, 0, SEEK_SET); - r->outputStream->size = VSIFReadL(r->outputStream->data, 1, nFileSize, fp); + r->outputStream->size = + VSIFReadL(r->outputStream->data, 1, nFileSize, fp); VSIFCloseL(fp); fp = NULL; @@ -649,7 +648,7 @@ static void msTransformToGeospatialPDF(imageObj *img, mapObj *map, cairo_rendere } } - if ( hDS != NULL ) + if (hDS != NULL) GDALClose(hDS); VSIUnlink(pszTmpFilename); @@ -657,55 +656,57 @@ static void msTransformToGeospatialPDF(imageObj *img, mapObj *map, cairo_rendere msFree(pszTmpFilename); } -int saveImageCairo(imageObj *img, mapObj *map, FILE *fp, outputFormatObj *format_unused) -{ +int saveImageCairo(imageObj *img, mapObj *map, FILE *fp, + outputFormatObj *format_unused) { (void)format_unused; cairo_renderer *r = CAIRO_RENDERER(img); - if(!strcasecmp(img->format->driver,"cairo/pdf") || !strcasecmp(img->format->driver,"cairo/svg")) { - cairo_surface_finish (r->surface); + if (!strcasecmp(img->format->driver, "cairo/pdf") || + !strcasecmp(img->format->driver, "cairo/svg")) { + cairo_surface_finish(r->surface); - if (map != NULL && !strcasecmp(img->format->driver,"cairo/pdf")) + if (map != NULL && !strcasecmp(img->format->driver, "cairo/pdf")) msTransformToGeospatialPDF(img, map, r); - msIO_fwrite(r->outputStream->data,r->outputStream->size,1,fp); + msIO_fwrite(r->outputStream->data, r->outputStream->size, 1, fp); } else { /* not supported */ } return MS_SUCCESS; } -unsigned char* saveImageBufferCairo(imageObj *img, int *size_ptr, outputFormatObj *format_unused) -{ +unsigned char *saveImageBufferCairo(imageObj *img, int *size_ptr, + outputFormatObj *format_unused) { (void)format_unused; cairo_renderer *r = CAIRO_RENDERER(img); unsigned char *data; - assert(!strcasecmp(img->format->driver,"cairo/pdf") || !strcasecmp(img->format->driver,"cairo/svg")); - cairo_surface_finish (r->surface); + assert(!strcasecmp(img->format->driver, "cairo/pdf") || + !strcasecmp(img->format->driver, "cairo/svg")); + cairo_surface_finish(r->surface); data = msSmallMalloc(r->outputStream->size); - memcpy(data,r->outputStream->data,r->outputStream->size); + memcpy(data, r->outputStream->data, r->outputStream->size); *size_ptr = (int)r->outputStream->size; return data; } -int renderEllipseSymbolCairo(imageObj *img, double x, double y, symbolObj *symbol, - symbolStyleObj *style) -{ +int renderEllipseSymbolCairo(imageObj *img, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { cairo_renderer *r = CAIRO_RENDERER(img); cairo_save(r->cr); cairo_set_line_cap(r->cr, CAIRO_LINE_CAP_BUTT); cairo_set_line_join(r->cr, CAIRO_LINE_JOIN_MITER); - cairo_translate(r->cr,x,y); - cairo_rotate(r->cr,-style->rotation); - cairo_scale(r->cr,symbol->sizex*style->scale/2,symbol->sizey*style->scale/2); - cairo_arc (r->cr, 0,0,1, 0, 2 * MS_PI); + cairo_translate(r->cr, x, y); + cairo_rotate(r->cr, -style->rotation); + cairo_scale(r->cr, symbol->sizex * style->scale / 2, + symbol->sizey * style->scale / 2); + cairo_arc(r->cr, 0, 0, 1, 0, 2 * MS_PI); cairo_restore(r->cr); - if(style->color) { + if (style->color) { msCairoSetSourceColor(r->cr, style->color); cairo_fill_preserve(r->cr); } - if(style->outlinewidth > 0) { - cairo_set_line_width (r->cr, style->outlinewidth); + if (style->outlinewidth > 0) { + cairo_set_line_width(r->cr, style->outlinewidth); msCairoSetSourceColor(r->cr, style->outlinecolor); cairo_stroke_preserve(r->cr); } @@ -713,83 +714,76 @@ int renderEllipseSymbolCairo(imageObj *img, double x, double y, symbolObj *symbo return MS_SUCCESS; } - - -int startLayerVectorCairo(imageObj *img, mapObj *map, layerObj *layer) -{ +int startLayerVectorCairo(imageObj *img, mapObj *map, layerObj *layer) { (void)map; - if(layer->compositer && layer->compositer->opacity<100) { + if (layer->compositer && layer->compositer->opacity < 100) { cairo_renderer *r = CAIRO_RENDERER(img); - cairo_push_group (r->cr); + cairo_push_group(r->cr); } return MS_SUCCESS; } -int closeLayerVectorCairo(imageObj *img, mapObj *map, layerObj *layer) -{ +int closeLayerVectorCairo(imageObj *img, mapObj *map, layerObj *layer) { (void)map; - if(layer->compositer && layer->compositer->opacity<100) { + if (layer->compositer && layer->compositer->opacity < 100) { cairo_renderer *r = CAIRO_RENDERER(img); - cairo_pop_group_to_source (r->cr); - cairo_paint_with_alpha (r->cr, layer->compositer->opacity*0.01); + cairo_pop_group_to_source(r->cr); + cairo_paint_with_alpha(r->cr, layer->compositer->opacity * 0.01); } return MS_SUCCESS; } -int startLayerRasterCairo(imageObj *img, mapObj *map, layerObj *layer) -{ +int startLayerRasterCairo(imageObj *img, mapObj *map, layerObj *layer) { (void)img; (void)map; (void)layer; return MS_SUCCESS; } -int closeLayerRasterCairo(imageObj *img, mapObj *map, layerObj *layer) -{ +int closeLayerRasterCairo(imageObj *img, mapObj *map, layerObj *layer) { (void)img; (void)map; (void)layer; return MS_SUCCESS; } - -int getRasterBufferHandleCairo(imageObj *img, rasterBufferObj *rb) -{ +int getRasterBufferHandleCairo(imageObj *img, rasterBufferObj *rb) { unsigned char *pb; cairo_renderer *r = CAIRO_RENDERER(img); rb->type = MS_BUFFER_BYTE_RGBA; pb = cairo_image_surface_get_data(r->surface); rb->data.rgba.pixels = pb; rb->data.rgba.row_step = cairo_image_surface_get_stride(r->surface); - rb->data.rgba.pixel_step=4; + rb->data.rgba.pixel_step = 4; rb->width = cairo_image_surface_get_width(r->surface); rb->height = cairo_image_surface_get_height(r->surface); rb->data.rgba.r = &(pb[2]); rb->data.rgba.g = &(pb[1]); rb->data.rgba.b = &(pb[0]); - if(r->use_alpha) + if (r->use_alpha) rb->data.rgba.a = &(pb[3]); else rb->data.rgba.a = NULL; return MS_SUCCESS; } -int getRasterBufferCopyCairo(imageObj *img, rasterBufferObj *rb) -{ +int getRasterBufferCopyCairo(imageObj *img, rasterBufferObj *rb) { cairo_renderer *r = CAIRO_RENDERER(img); unsigned char *pb; rb->type = MS_BUFFER_BYTE_RGBA; rb->data.rgba.row_step = cairo_image_surface_get_stride(r->surface); - rb->data.rgba.pixel_step=4; + rb->data.rgba.pixel_step = 4; rb->width = cairo_image_surface_get_width(r->surface); rb->height = cairo_image_surface_get_height(r->surface); - pb = (unsigned char*)malloc(rb->height * rb->data.rgba.row_step * sizeof(unsigned char)); - memcpy(pb,cairo_image_surface_get_data(r->surface),rb->height * rb->data.rgba.row_step); + pb = (unsigned char *)malloc(rb->height * rb->data.rgba.row_step * + sizeof(unsigned char)); + memcpy(pb, cairo_image_surface_get_data(r->surface), + rb->height * rb->data.rgba.row_step); rb->data.rgba.pixels = pb; rb->data.rgba.r = &(pb[2]); rb->data.rgba.g = &(pb[1]); rb->data.rgba.b = &(pb[0]); - if(r->use_alpha) + if (r->use_alpha) rb->data.rgba.a = &(pb[3]); else rb->data.rgba.a = NULL; @@ -797,166 +791,167 @@ int getRasterBufferCopyCairo(imageObj *img, rasterBufferObj *rb) } static cairo_operator_t ms2cairo_compop(CompositingOperation op) { - switch(op) { - case MS_COMPOP_CLEAR: - return CAIRO_OPERATOR_CLEAR; - case MS_COMPOP_SRC: - return CAIRO_OPERATOR_SOURCE; - case MS_COMPOP_DST: - return CAIRO_OPERATOR_DEST; - case MS_COMPOP_SRC_OVER: - return CAIRO_OPERATOR_OVER; - case MS_COMPOP_DST_OVER: - return CAIRO_OPERATOR_DEST_OVER; - case MS_COMPOP_SRC_IN: - return CAIRO_OPERATOR_IN; - case MS_COMPOP_DST_IN: - return CAIRO_OPERATOR_DEST_IN; - case MS_COMPOP_SRC_OUT: - return CAIRO_OPERATOR_OUT; - case MS_COMPOP_DST_OUT: - return CAIRO_OPERATOR_DEST_OUT; - case MS_COMPOP_SRC_ATOP: - return CAIRO_OPERATOR_ATOP; - case MS_COMPOP_DST_ATOP: - return CAIRO_OPERATOR_DEST_ATOP; - case MS_COMPOP_XOR: - return CAIRO_OPERATOR_XOR; - case MS_COMPOP_PLUS: - return CAIRO_OPERATOR_ADD; - case MS_COMPOP_MULTIPLY: - return CAIRO_OPERATOR_MULTIPLY; - case MS_COMPOP_SCREEN: - return CAIRO_OPERATOR_SCREEN; - case MS_COMPOP_OVERLAY: - return CAIRO_OPERATOR_OVERLAY; - case MS_COMPOP_DARKEN: - return CAIRO_OPERATOR_DARKEN; - case MS_COMPOP_LIGHTEN: - return CAIRO_OPERATOR_LIGHTEN; - case MS_COMPOP_COLOR_DODGE: - return CAIRO_OPERATOR_COLOR_DODGE; - case MS_COMPOP_COLOR_BURN: - return CAIRO_OPERATOR_COLOR_BURN; - case MS_COMPOP_HARD_LIGHT: - return CAIRO_OPERATOR_HARD_LIGHT; - case MS_COMPOP_SOFT_LIGHT: - return CAIRO_OPERATOR_SOFT_LIGHT; - case MS_COMPOP_DIFFERENCE: - return CAIRO_OPERATOR_DIFFERENCE; - case MS_COMPOP_EXCLUSION: - return CAIRO_OPERATOR_EXCLUSION; - case MS_COMPOP_INVERT: - case MS_COMPOP_INVERT_RGB: - case MS_COMPOP_MINUS: - case MS_COMPOP_CONTRAST: - default: - return CAIRO_OPERATOR_OVER; + switch (op) { + case MS_COMPOP_CLEAR: + return CAIRO_OPERATOR_CLEAR; + case MS_COMPOP_SRC: + return CAIRO_OPERATOR_SOURCE; + case MS_COMPOP_DST: + return CAIRO_OPERATOR_DEST; + case MS_COMPOP_SRC_OVER: + return CAIRO_OPERATOR_OVER; + case MS_COMPOP_DST_OVER: + return CAIRO_OPERATOR_DEST_OVER; + case MS_COMPOP_SRC_IN: + return CAIRO_OPERATOR_IN; + case MS_COMPOP_DST_IN: + return CAIRO_OPERATOR_DEST_IN; + case MS_COMPOP_SRC_OUT: + return CAIRO_OPERATOR_OUT; + case MS_COMPOP_DST_OUT: + return CAIRO_OPERATOR_DEST_OUT; + case MS_COMPOP_SRC_ATOP: + return CAIRO_OPERATOR_ATOP; + case MS_COMPOP_DST_ATOP: + return CAIRO_OPERATOR_DEST_ATOP; + case MS_COMPOP_XOR: + return CAIRO_OPERATOR_XOR; + case MS_COMPOP_PLUS: + return CAIRO_OPERATOR_ADD; + case MS_COMPOP_MULTIPLY: + return CAIRO_OPERATOR_MULTIPLY; + case MS_COMPOP_SCREEN: + return CAIRO_OPERATOR_SCREEN; + case MS_COMPOP_OVERLAY: + return CAIRO_OPERATOR_OVERLAY; + case MS_COMPOP_DARKEN: + return CAIRO_OPERATOR_DARKEN; + case MS_COMPOP_LIGHTEN: + return CAIRO_OPERATOR_LIGHTEN; + case MS_COMPOP_COLOR_DODGE: + return CAIRO_OPERATOR_COLOR_DODGE; + case MS_COMPOP_COLOR_BURN: + return CAIRO_OPERATOR_COLOR_BURN; + case MS_COMPOP_HARD_LIGHT: + return CAIRO_OPERATOR_HARD_LIGHT; + case MS_COMPOP_SOFT_LIGHT: + return CAIRO_OPERATOR_SOFT_LIGHT; + case MS_COMPOP_DIFFERENCE: + return CAIRO_OPERATOR_DIFFERENCE; + case MS_COMPOP_EXCLUSION: + return CAIRO_OPERATOR_EXCLUSION; + case MS_COMPOP_INVERT: + case MS_COMPOP_INVERT_RGB: + case MS_COMPOP_MINUS: + case MS_COMPOP_CONTRAST: + default: + return CAIRO_OPERATOR_OVER; } } -int cairoCompositeRasterBuffer(imageObj *img, rasterBufferObj *rb, CompositingOperation comp, int opacity) { +int cairoCompositeRasterBuffer(imageObj *img, rasterBufferObj *rb, + CompositingOperation comp, int opacity) { cairo_surface_t *src; cairo_renderer *r; - if(rb->type != MS_BUFFER_BYTE_RGBA) { + if (rb->type != MS_BUFFER_BYTE_RGBA) { return MS_FAILURE; } r = CAIRO_RENDERER(img); - src = cairo_image_surface_create_for_data(rb->data.rgba.pixels,CAIRO_FORMAT_ARGB32, - rb->width,rb->height, - rb->data.rgba.row_step); + src = cairo_image_surface_create_for_data(rb->data.rgba.pixels, + CAIRO_FORMAT_ARGB32, rb->width, + rb->height, rb->data.rgba.row_step); - cairo_set_source_surface (r->cr,src,0,0); + cairo_set_source_surface(r->cr, src, 0, 0); cairo_set_operator(r->cr, ms2cairo_compop(comp)); - cairo_paint_with_alpha(r->cr,opacity/100.0); + cairo_paint_with_alpha(r->cr, opacity / 100.0); cairo_surface_finish(src); cairo_surface_destroy(src); - cairo_set_operator(r->cr,CAIRO_OPERATOR_OVER); + cairo_set_operator(r->cr, CAIRO_OPERATOR_OVER); return MS_SUCCESS; } int mergeRasterBufferCairo(imageObj *img, rasterBufferObj *rb, double opacity, - int srcX, int srcY, int dstX, int dstY, - int width, int height) -{ + int srcX, int srcY, int dstX, int dstY, int width, + int height) { cairo_surface_t *src; cairo_renderer *r; /* not implemented for src,dst,width and height */ - if(rb->type != MS_BUFFER_BYTE_RGBA) { + if (rb->type != MS_BUFFER_BYTE_RGBA) { return MS_FAILURE; } r = CAIRO_RENDERER(img); - src = cairo_image_surface_create_for_data(rb->data.rgba.pixels,CAIRO_FORMAT_ARGB32, - rb->width,rb->height, - rb->data.rgba.row_step); + src = cairo_image_surface_create_for_data(rb->data.rgba.pixels, + CAIRO_FORMAT_ARGB32, rb->width, + rb->height, rb->data.rgba.row_step); - if(dstX||dstY||srcX||srcY||width!=img->width||height!=img->height) { - cairo_set_source_surface (r->cr, src, dstX - srcX, dstY - srcY); - cairo_rectangle (r->cr, dstX, dstY, width, height); - cairo_fill (r->cr); + if (dstX || dstY || srcX || srcY || width != img->width || + height != img->height) { + cairo_set_source_surface(r->cr, src, dstX - srcX, dstY - srcY); + cairo_rectangle(r->cr, dstX, dstY, width, height); + cairo_fill(r->cr); } else { - cairo_set_source_surface (r->cr,src,0,0); - cairo_paint_with_alpha(r->cr,opacity); + cairo_set_source_surface(r->cr, src, 0, 0); + cairo_paint_with_alpha(r->cr, opacity); } cairo_surface_finish(src); cairo_surface_destroy(src); return MS_SUCCESS; } - void freeSVGCache(symbolObj *s) { #if defined(USE_SVG_CAIRO) || defined(USE_RSVG) - struct svg_symbol_cache *cache = s->renderer_cache; - if(!cache) return; - assert(cache->svgc); + struct svg_symbol_cache *cache = s->renderer_cache; + if (!cache) + return; + assert(cache->svgc); #ifdef USE_SVG_CAIRO - svg_cairo_destroy(cache->svgc); + svg_cairo_destroy(cache->svgc); +#else +#if LIBRSVG_CHECK_VERSION(2, 35, 0) + g_object_unref(cache->svgc); #else - #if LIBRSVG_CHECK_VERSION(2,35,0) - g_object_unref(cache->svgc); - #else - rsvg_handle_free(cache->svgc); - #endif + rsvg_handle_free(cache->svgc); #endif - if(cache->pixmap_buffer) { - msFreeRasterBuffer(cache->pixmap_buffer); - free(cache->pixmap_buffer); - } - msFree(s->renderer_cache); - s->renderer_cache = NULL; +#endif + if (cache->pixmap_buffer) { + msFreeRasterBuffer(cache->pixmap_buffer); + free(cache->pixmap_buffer); + } + msFree(s->renderer_cache); + s->renderer_cache = NULL; #endif } -int freeSymbolCairo(symbolObj *s) -{ - if(!s->renderer_cache) +int freeSymbolCairo(symbolObj *s) { + if (!s->renderer_cache) return MS_SUCCESS; - switch(s->type) { - case MS_SYMBOL_VECTOR: - cairo_path_destroy(s->renderer_cache); - break; - case MS_SYMBOL_PIXMAP: - cairo_surface_destroy(s->renderer_cache); - break; - case MS_SYMBOL_SVG: - freeSVGCache(s); - break; + switch (s->type) { + case MS_SYMBOL_VECTOR: + cairo_path_destroy(s->renderer_cache); + break; + case MS_SYMBOL_PIXMAP: + cairo_surface_destroy(s->renderer_cache); + break; + case MS_SYMBOL_SVG: + freeSVGCache(s); + break; } - s->renderer_cache=NULL; + s->renderer_cache = NULL; return MS_SUCCESS; } -int initializeRasterBufferCairo(rasterBufferObj *rb, int width, int height, int mode) -{ +int initializeRasterBufferCairo(rasterBufferObj *rb, int width, int height, + int mode) { (void)mode; rb->type = MS_BUFFER_BYTE_RGBA; rb->width = width; rb->height = height; rb->data.rgba.pixel_step = 4; rb->data.rgba.row_step = width * 4; - rb->data.rgba.pixels = (unsigned char*)calloc(width*height*4,sizeof(unsigned char)); + rb->data.rgba.pixels = + (unsigned char *)calloc(width * height * 4, sizeof(unsigned char)); rb->data.rgba.r = &(rb->data.rgba.pixels[2]); rb->data.rgba.g = &(rb->data.rgba.pixels[1]); rb->data.rgba.b = &(rb->data.rgba.pixels[0]); @@ -964,19 +959,17 @@ int initializeRasterBufferCairo(rasterBufferObj *rb, int width, int height, int return MS_SUCCESS; } - -int msPreloadSVGSymbol(symbolObj *symbol) -{ +int msPreloadSVGSymbol(symbolObj *symbol) { #if defined(USE_SVG_CAIRO) || defined(USE_RSVG) struct svg_symbol_cache *cache; - if(!symbol->renderer_cache) { - cache = msSmallCalloc(1,sizeof(struct svg_symbol_cache)); + if (!symbol->renderer_cache) { + cache = msSmallCalloc(1, sizeof(struct svg_symbol_cache)); symbol->renderer_free_func = &freeSVGCache; } else { cache = symbol->renderer_cache; } - if(cache->svgc) + if (cache->svgc) return MS_SUCCESS; #ifdef USE_SVG_CAIRO @@ -985,17 +978,20 @@ int msPreloadSVGSymbol(symbolObj *symbol) int status; status = svg_cairo_create(&cache->svgc); if (status) { - msSetError(MS_RENDERERERR, "problem creating cairo svg", "msPreloadSVGSymbol()"); + msSetError(MS_RENDERERERR, "problem creating cairo svg", + "msPreloadSVGSymbol()"); return MS_FAILURE; } status = svg_cairo_parse(cache->svgc, symbol->full_pixmap_path); if (status) { - msSetError(MS_RENDERERERR, "problem parsing svg symbol", "msPreloadSVGSymbol()"); + msSetError(MS_RENDERERERR, "problem parsing svg symbol", + "msPreloadSVGSymbol()"); return MS_FAILURE; } - svg_cairo_get_size (cache->svgc, &svg_width, &svg_height); + svg_cairo_get_size(cache->svgc, &svg_width, &svg_height); if (svg_width == 0 || svg_height == 0) { - msSetError(MS_RENDERERERR, "problem parsing svg symbol", "msPreloadSVGSymbol()"); + msSetError(MS_RENDERERERR, "problem parsing svg symbol", + "msPreloadSVGSymbol()"); return MS_FAILURE; } @@ -1004,39 +1000,37 @@ int msPreloadSVGSymbol(symbolObj *symbol) } #else { - cache->svgc = rsvg_handle_new_from_file(symbol->full_pixmap_path,NULL); - if(!cache->svgc) { - msSetError(MS_RENDERERERR,"failed to load svg file %s", "msPreloadSVGSymbol()", symbol->full_pixmap_path); + cache->svgc = rsvg_handle_new_from_file(symbol->full_pixmap_path, NULL); + if (!cache->svgc) { + msSetError(MS_RENDERERERR, "failed to load svg file %s", + "msPreloadSVGSymbol()", symbol->full_pixmap_path); return MS_FAILURE; } -#if LIBRSVG_CHECK_VERSION(2,46,0) +#if LIBRSVG_CHECK_VERSION(2, 46, 0) /* rsvg_handle_get_dimensions_sub() is deprecated since librsvg 2.46 */ /* It seems rsvg_handle_get_intrinsic_dimensions() is the best equivalent */ - /* when the root node includes a width and height attributes in pixels */ + /* when the root node includes a width and height attributes in pixels + */ gboolean has_width = FALSE; RsvgLength width = {0, RSVG_UNIT_PX}; gboolean has_height = FALSE; RsvgLength height = {0, RSVG_UNIT_PX}; - rsvg_handle_get_intrinsic_dimensions(cache->svgc, - &has_width, &width, - &has_height, &height, - NULL, NULL); - if( has_width && width.unit == RSVG_UNIT_PX && - has_height && height.unit == RSVG_UNIT_PX ) - { - symbol->sizex = width.length; - symbol->sizey = height.length; - } - else - { - RsvgRectangle ink_rect = { 0, 0, 0, 0 }; - rsvg_handle_get_geometry_for_element (cache->svgc, NULL, &ink_rect, NULL, NULL); - symbol->sizex = ink_rect.width; - symbol->sizey = ink_rect.height; + rsvg_handle_get_intrinsic_dimensions(cache->svgc, &has_width, &width, + &has_height, &height, NULL, NULL); + if (has_width && width.unit == RSVG_UNIT_PX && has_height && + height.unit == RSVG_UNIT_PX) { + symbol->sizex = width.length; + symbol->sizey = height.length; + } else { + RsvgRectangle ink_rect = {0, 0, 0, 0}; + rsvg_handle_get_geometry_for_element(cache->svgc, NULL, &ink_rect, NULL, + NULL); + symbol->sizex = ink_rect.width; + symbol->sizey = ink_rect.height; } #else RsvgDimensionData dim; - rsvg_handle_get_dimensions_sub (cache->svgc, &dim, NULL); + rsvg_handle_get_dimensions_sub(cache->svgc, &dim, NULL); symbol->sizex = dim.width; symbol->sizey = dim.height; #endif @@ -1048,16 +1042,15 @@ int msPreloadSVGSymbol(symbolObj *symbol) return MS_SUCCESS; #else - msSetError(MS_MISCERR, "SVG Symbols requested but is not built with libsvgcairo", + msSetError(MS_MISCERR, + "SVG Symbols requested but is not built with libsvgcairo", "msPreloadSVGSymbol()"); return MS_FAILURE; #endif } - - -int msRenderRasterizedSVGSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style) -{ +int msRenderRasterizedSVGSymbol(imageObj *img, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { #if defined(USE_SVG_CAIRO) || defined(USE_RSVG) struct svg_symbol_cache *svg_cache; @@ -1065,24 +1058,25 @@ int msRenderRasterizedSVGSymbol(imageObj *img, double x, double y, symbolObj *sy symbolObj pixsymbol; int status; - if(MS_SUCCESS != msPreloadSVGSymbol(symbol)) + if (MS_SUCCESS != msPreloadSVGSymbol(symbol)) return MS_FAILURE; - svg_cache = (struct svg_symbol_cache*) symbol->renderer_cache; + svg_cache = (struct svg_symbol_cache *)symbol->renderer_cache; - //already rendered at the right size and scale? return - if(svg_cache->scale != style->scale || svg_cache->rotation != style->rotation) { + // already rendered at the right size and scale? return + if (svg_cache->scale != style->scale || + svg_cache->rotation != style->rotation) { cairo_t *cr; cairo_surface_t *surface; unsigned char *pb; int width, height, surface_w, surface_h; /* need to recompute the pixmap */ - if(svg_cache->pixmap_buffer) { + if (svg_cache->pixmap_buffer) { msFreeRasterBuffer(svg_cache->pixmap_buffer); } else { - svg_cache->pixmap_buffer = msSmallCalloc(1,sizeof(rasterBufferObj)); + svg_cache->pixmap_buffer = msSmallCalloc(1, sizeof(rasterBufferObj)); } - //increase pixmap size to accomodate scaling/rotation + // increase pixmap size to accomodate scaling/rotation if (style->scale != 1.0) { width = surface_w = (symbol->sizex * style->scale + 0.5); height = surface_h = (symbol->sizey * style->scale + 0.5); @@ -1094,7 +1088,8 @@ int msRenderRasterizedSVGSymbol(imageObj *img, double x, double y, symbolObj *sy surface_w = surface_h = MS_NINT(MS_MAX(height, width) * 1.415); } - surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, surface_w, surface_h); + surface = + cairo_image_surface_create(CAIRO_FORMAT_ARGB32, surface_w, surface_h); cr = cairo_create(surface); if (style->rotation != 0) { @@ -1106,23 +1101,24 @@ int msRenderRasterizedSVGSymbol(imageObj *img, double x, double y, symbolObj *sy cairo_scale(cr, style->scale, style->scale); } #ifdef USE_SVG_CAIRO - if(svg_cairo_render(svg_cache->svgc, cr) != SVG_CAIRO_STATUS_SUCCESS) { + if (svg_cairo_render(svg_cache->svgc, cr) != SVG_CAIRO_STATUS_SUCCESS) { return MS_FAILURE; } #else - rsvg_handle_render_cairo(svg_cache->svgc, cr); + rsvg_handle_render_cairo(svg_cache->svgc, cr); #endif pb = cairo_image_surface_get_data(surface); - //set up raster - initializeRasterBufferCairo(svg_cache->pixmap_buffer, surface_w, surface_h, 0); - memcpy(svg_cache->pixmap_buffer->data.rgba.pixels, pb, surface_w * surface_h * 4 * sizeof (unsigned char)); + // set up raster + initializeRasterBufferCairo(svg_cache->pixmap_buffer, surface_w, surface_h, + 0); + memcpy(svg_cache->pixmap_buffer->data.rgba.pixels, pb, + surface_w * surface_h * 4 * sizeof(unsigned char)); svg_cache->scale = style->scale; svg_cache->rotation = style->rotation; cairo_destroy(cr); cairo_surface_destroy(surface); } - assert(svg_cache->pixmap_buffer->height && svg_cache->pixmap_buffer->width); pixstyle = *style; pixstyle.rotation = 0.0; @@ -1131,27 +1127,31 @@ int msRenderRasterizedSVGSymbol(imageObj *img, double x, double y, symbolObj *sy pixsymbol.pixmap_buffer = svg_cache->pixmap_buffer; pixsymbol.type = MS_SYMBOL_PIXMAP; - status = MS_IMAGE_RENDERER(img)->renderPixmapSymbol(img,x,y,&pixsymbol,&pixstyle); + if (svg_cache->pixmap_buffer->height && svg_cache->pixmap_buffer->width) + status = MS_IMAGE_RENDERER(img)->renderPixmapSymbol(img, x, y, &pixsymbol, + &pixstyle); + else { + msDebug("SVG symbol with too small size to be rendered"); + status = MS_SUCCESS; + } MS_IMAGE_RENDERER(img)->freeSymbol(&pixsymbol); return status; #else - msSetError(MS_MISCERR, "SVG Symbols requested but MapServer is not built with libsvgcairo", - "renderSVGSymbolCairo()"); + msSetError( + MS_MISCERR, + "SVG Symbols requested but MapServer is not built with libsvgcairo", + "renderSVGSymbolCairo()"); return MS_FAILURE; #endif } -void msCairoCleanup() { - cairo_debug_reset_static_data(); -} +void msCairoCleanup() { cairo_debug_reset_static_data(); } #endif /*USE_CAIRO*/ - -int msPopulateRendererVTableCairoRaster( rendererVTableObj *renderer ) -{ +int msPopulateRendererVTableCairoRaster(rendererVTableObj *renderer) { #ifdef USE_CAIRO - renderer->supports_pixel_buffer=1; + renderer->supports_pixel_buffer = 1; renderer->compositeRasterBuffer = cairoCompositeRasterBuffer; renderer->supports_svg = 1; renderer->default_transform_mode = MS_TRANSFORM_SIMPLIFY; @@ -1159,14 +1159,14 @@ int msPopulateRendererVTableCairoRaster( rendererVTableObj *renderer ) renderer->startLayer = startLayerRasterCairo; renderer->endLayer = closeLayerRasterCairo; renderer->renderLineTiled = NULL; - renderer->renderLine=&renderLineCairo; - renderer->createImage=&createImageCairo; - renderer->saveImage=&saveImageCairo; - renderer->getRasterBufferHandle=&getRasterBufferHandleCairo; - renderer->getRasterBufferCopy=&getRasterBufferCopyCairo; - renderer->renderPolygon=&renderPolygonCairo; - renderer->renderGlyphs=&renderGlyphs2Cairo; - renderer->freeImage=&freeImageCairo; + renderer->renderLine = &renderLineCairo; + renderer->createImage = &createImageCairo; + renderer->saveImage = &saveImageCairo; + renderer->getRasterBufferHandle = &getRasterBufferHandleCairo; + renderer->getRasterBufferCopy = &getRasterBufferCopyCairo; + renderer->renderPolygon = &renderPolygonCairo; + renderer->renderGlyphs = &renderGlyphs2Cairo; + renderer->freeImage = &freeImageCairo; renderer->renderEllipseSymbol = &renderEllipseSymbolCairo; renderer->renderVectorSymbol = &renderVectorSymbolCairo; renderer->renderSVGSymbol = &renderSVGSymbolCairo; @@ -1185,26 +1185,25 @@ int msPopulateRendererVTableCairoRaster( rendererVTableObj *renderer ) #endif } -int populateRendererVTableCairoVector( rendererVTableObj *renderer ) -{ +int populateRendererVTableCairoVector(rendererVTableObj *renderer) { #ifdef USE_CAIRO - renderer->use_imagecache=0; - renderer->supports_pixel_buffer=0; + renderer->use_imagecache = 0; + renderer->supports_pixel_buffer = 0; renderer->compositeRasterBuffer = NULL; renderer->supports_svg = 1; renderer->default_transform_mode = MS_TRANSFORM_SIMPLIFY; initializeCache(&MS_RENDERER_CACHE(renderer)); renderer->startLayer = startLayerVectorCairo; renderer->endLayer = closeLayerVectorCairo; - renderer->renderLine=&renderLineCairo; + renderer->renderLine = &renderLineCairo; renderer->renderLineTiled = NULL; - renderer->createImage=&createImageCairo; - renderer->saveImage=&saveImageCairo; + renderer->createImage = &createImageCairo; + renderer->saveImage = &saveImageCairo; renderer->saveImageBuffer = &saveImageBufferCairo; - renderer->getRasterBufferHandle=&getRasterBufferHandleCairo; - renderer->renderPolygon=&renderPolygonCairo; - renderer->renderGlyphs=&renderGlyphs2Cairo; - renderer->freeImage=&freeImageCairo; + renderer->getRasterBufferHandle = &getRasterBufferHandleCairo; + renderer->renderPolygon = &renderPolygonCairo; + renderer->renderGlyphs = &renderGlyphs2Cairo; + renderer->freeImage = &freeImageCairo; renderer->renderEllipseSymbol = &renderEllipseSymbolCairo; renderer->renderVectorSymbol = &renderVectorSymbolCairo; renderer->renderSVGSymbol = &renderSVGSymbolCairo; @@ -1224,12 +1223,9 @@ int populateRendererVTableCairoVector( rendererVTableObj *renderer ) #endif } -int msPopulateRendererVTableCairoSVG( rendererVTableObj *renderer ) -{ +int msPopulateRendererVTableCairoSVG(rendererVTableObj *renderer) { return populateRendererVTableCairoVector(renderer); } -int msPopulateRendererVTableCairoPDF( rendererVTableObj *renderer ) -{ +int msPopulateRendererVTableCairoPDF(rendererVTableObj *renderer) { return populateRendererVTableCairoVector(renderer); } - diff --git a/mapchart.c b/mapchart.c index bb0be04833..3829fd3430 100644 --- a/mapchart.c +++ b/mapchart.c @@ -27,19 +27,19 @@ * DEALINGS IN THE SOFTWARE. ****************************************************************************/ - #include "mapserver.h" - - #define MS_CHART_TYPE_PIE 1 #define MS_CHART_TYPE_BAR 2 #define MS_CHART_TYPE_VBAR 3 /* -** check if an object of width w and height h placed at point x,y can fit in an image of width mw and height mh +** check if an object of width w and height h placed at point x,y can fit in an +*image of width mw and height mh */ -#define MS_CHART_FITS(x,y,w,h,mw,mh) (((x)-(w)/2.>0.)&&((x)+(w)/2.<(mw))&&((y)-(h)/2.>0.)&&((y)+(h)/2.)<(mh)) +#define MS_CHART_FITS(x, y, w, h, mw, mh) \ + (((x) - (w) / 2. > 0.) && ((x) + (w) / 2. < (mw)) && \ + ((y) - (h) / 2. > 0.) && ((y) + (h) / 2.) < (mh)) /* ** find a point on a shape. check if it fits in image @@ -47,69 +47,85 @@ ** MS_SUCCESS and point coordinates in 'p' if chart fits in image ** MS_FAILURE if no point could be found */ -int findChartPoint(mapObj *map, shapeObj *shape, int width, int height, pointObj *center) -{ - int middle,numpoints; - double invcellsize = 1.0/map->cellsize; /*speed up MAP2IMAGE_X/Y_IC_DBL*/ - switch(shape->type) { - case MS_SHAPE_POINT: - center->x=MS_MAP2IMAGE_X_IC_DBL(shape->line[0].point[0].x, map->extent.minx, invcellsize); - center->y=MS_MAP2IMAGE_Y_IC_DBL(shape->line[0].point[0].y, map->extent.maxy, invcellsize); - - if(MS_CHART_FITS(center->x,center->y,width,height,map->width,map->height)) - return MS_SUCCESS; - else - return MS_FAILURE; - break; - case MS_SHAPE_LINE: - /*loop through line segments starting from middle (alternate between before and after middle point) - **first segment that fits is chosen - */ - middle=shape->line[0].numpoints/2; /*start with middle segment of line*/ - numpoints=shape->line[0].numpoints; - if( 1 <= middle ) { - int idx=middle+1; - if(idxx=(shape->line[0].point[idx-1].x+shape->line[0].point[idx].x)/2.; - center->y=(shape->line[0].point[idx-1].y+shape->line[0].point[idx].y)/2.; - center->x=MS_MAP2IMAGE_X_IC_DBL(center->x, map->extent.minx, invcellsize); - center->y=MS_MAP2IMAGE_Y_IC_DBL(center->y, map->extent.maxy, invcellsize); - - if(MS_CHART_FITS(center->x,center->y,width,height,map->width,map->height)) - return MS_SUCCESS; - - return MS_FAILURE; - } - idx=middle-1; - center->x=(shape->line[0].point[idx].x+shape->line[0].point[idx+1].x)/2; - center->y=(shape->line[0].point[idx].y+shape->line[0].point[idx+1].y)/2; - center->x=MS_MAP2IMAGE_X_IC_DBL(center->x, map->extent.minx, invcellsize); - center->y=MS_MAP2IMAGE_Y_IC_DBL(center->y, map->extent.maxy, invcellsize); - - if(MS_CHART_FITS(center->x,center->y,width,height,map->width,map->height)) +int findChartPoint(mapObj *map, shapeObj *shape, int width, int height, + pointObj *center) { + int middle, numpoints; + double invcellsize = 1.0 / map->cellsize; /*speed up MAP2IMAGE_X/Y_IC_DBL*/ + switch (shape->type) { + case MS_SHAPE_POINT: + center->x = MS_MAP2IMAGE_X_IC_DBL(shape->line[0].point[0].x, + map->extent.minx, invcellsize); + center->y = MS_MAP2IMAGE_Y_IC_DBL(shape->line[0].point[0].y, + map->extent.maxy, invcellsize); + + if (MS_CHART_FITS(center->x, center->y, width, height, map->width, + map->height)) + return MS_SUCCESS; + else + return MS_FAILURE; + break; + case MS_SHAPE_LINE: + /*loop through line segments starting from middle (alternate between before + *and after middle point) *first segment that fits is chosen + */ + middle = shape->line[0].numpoints / 2; /*start with middle segment of line*/ + numpoints = shape->line[0].numpoints; + if (1 <= middle) { + int idx = middle + 1; + if (idx < numpoints) { + center->x = + (shape->line[0].point[idx - 1].x + shape->line[0].point[idx].x) / + 2.; + center->y = + (shape->line[0].point[idx - 1].y + shape->line[0].point[idx].y) / + 2.; + center->x = + MS_MAP2IMAGE_X_IC_DBL(center->x, map->extent.minx, invcellsize); + center->y = + MS_MAP2IMAGE_Y_IC_DBL(center->y, map->extent.maxy, invcellsize); + + if (MS_CHART_FITS(center->x, center->y, width, height, map->width, + map->height)) return MS_SUCCESS; + return MS_FAILURE; } - return MS_FAILURE; - break; - case MS_SHAPE_POLYGON: - msPolygonLabelPoint(shape, center, -1); - center->x=MS_MAP2IMAGE_X_IC_DBL(center->x, map->extent.minx, invcellsize); - center->y=MS_MAP2IMAGE_Y_IC_DBL(center->y, map->extent.maxy, invcellsize); - - if(MS_CHART_FITS(center->x,center->y,width,height,map->width,map->height)) + idx = middle - 1; + center->x = + (shape->line[0].point[idx].x + shape->line[0].point[idx + 1].x) / 2; + center->y = + (shape->line[0].point[idx].y + shape->line[0].point[idx + 1].y) / 2; + center->x = + MS_MAP2IMAGE_X_IC_DBL(center->x, map->extent.minx, invcellsize); + center->y = + MS_MAP2IMAGE_Y_IC_DBL(center->y, map->extent.maxy, invcellsize); + + if (MS_CHART_FITS(center->x, center->y, width, height, map->width, + map->height)) return MS_SUCCESS; - else - return MS_FAILURE; - break; - default: return MS_FAILURE; + } + return MS_FAILURE; + break; + case MS_SHAPE_POLYGON: + msPolygonLabelPoint(shape, center, -1); + center->x = MS_MAP2IMAGE_X_IC_DBL(center->x, map->extent.minx, invcellsize); + center->y = MS_MAP2IMAGE_Y_IC_DBL(center->y, map->extent.maxy, invcellsize); + + if (MS_CHART_FITS(center->x, center->y, width, height, map->width, + map->height)) + return MS_SUCCESS; + else + return MS_FAILURE; + break; + default: + return MS_FAILURE; } } -int WARN_UNUSED drawRectangle(mapObj *map, imageObj *image, double mx, double my, double Mx, double My, - styleObj *style) -{ +int WARN_UNUSED drawRectangle(mapObj *map, imageObj *image, double mx, + double my, double Mx, double My, + styleObj *style) { shapeObj shape; lineObj line; pointObj point[5]; @@ -125,56 +141,56 @@ int WARN_UNUSED drawRectangle(mapObj *map, imageObj *image, double mx, double my /* cppcheck-suppress unreadVariable */ point[2].y = point[3].y = My; - return msDrawShadeSymbol(map,image,&shape,style,1.0); + return msDrawShadeSymbol(map, image, &shape, style, 1.0); } int WARN_UNUSED msDrawVBarChart(mapObj *map, imageObj *image, pointObj *center, - double *values, styleObj **styles, int numvalues, - double barWidth) -{ + double *values, styleObj **styles, + int numvalues, double barWidth) { int c; - double left,bottom,cur; /*shortcut to pixel boundaries of the chart*/ + double left, bottom, cur; /*shortcut to pixel boundaries of the chart*/ double height = 0; - for(c=0; cy+height/2.; - left = center->x-barWidth/2.; + cur = bottom = center->y + height / 2.; + left = center->x - barWidth / 2.; - for(c=0; cy-height/2.; - bottom=center->y+height/2.; - left=center->x-width/2.; - - shapeMaxVal=shapeMinVal=values[0]; - for(c=1; cshapeMaxVal) - shapeMaxVal=values[c]; - if(values[c]y - height / 2.; + bottom = center->y + height / 2.; + left = center->x - width / 2.; + + shapeMaxVal = shapeMinVal = values[0]; + for (c = 1; c < numvalues; c++) { + if (maxVal == NULL || minVal == NULL) { /*compute bounds if not specified*/ + if (values[c] > shapeMaxVal) + shapeMaxVal = values[c]; + if (values[c] < shapeMinVal) + shapeMinVal = values[c]; } } @@ -182,96 +198,106 @@ int msDrawBarChart(mapObj *map, imageObj *image, pointObj *center, * use specified bounds if wanted * if not, always show the origin */ - upperLimit = (maxVal!=NULL)? *maxVal : MS_MAX(shapeMaxVal,0); - lowerLimit = (minVal!=NULL)? *minVal : MS_MIN(shapeMinVal,0); - if(upperLimit==lowerLimit) { + upperLimit = (maxVal != NULL) ? *maxVal : MS_MAX(shapeMaxVal, 0); + lowerLimit = (minVal != NULL) ? *minVal : MS_MIN(shapeMinVal, 0); + if (upperLimit == lowerLimit) { /* treat the case where we would have an unspecified behavior */ - upperLimit+=0.5; - lowerLimit-=0.5; + upperLimit += 0.5; + lowerLimit -= 0.5; } - pixperval=height/(upperLimit-lowerLimit); - vertOrigin=bottom+lowerLimit*pixperval; - vertOriginClipped=(vertOriginbottom) ? bottom : vertOrigin; - horizStart=left; - - for(c=0; c bottom) ? bottom + : vertOrigin; + horizStart = left; + + for (c = 0; c < numvalues; c++) { + double barHeight = values[c] * pixperval; /*clip bars*/ - y=((vertOrigin-barHeight)bottom) ? bottom : vertOrigin-barHeight; - if(y!=vertOriginClipped) { /*don't draw bars of height == 0 (i.e. either values==0, or clipped)*/ - if(values[c]>0) { - if(MS_UNLIKELY(MS_FAILURE == drawRectangle(map, image, horizStart, y, horizStart+barWidth-1, vertOriginClipped, styles[c]))) + y = ((vertOrigin - barHeight) < top) ? top + : (vertOrigin - barHeight > bottom) ? bottom + : vertOrigin - barHeight; + if (y != vertOriginClipped) { /*don't draw bars of height == 0 (i.e. either + values==0, or clipped)*/ + if (values[c] > 0) { + if (MS_UNLIKELY(MS_FAILURE == drawRectangle(map, image, horizStart, y, + horizStart + barWidth - 1, + vertOriginClipped, + styles[c]))) return MS_FAILURE; - } - else { - if(MS_UNLIKELY(MS_FAILURE == drawRectangle(map,image, horizStart, vertOriginClipped, horizStart+barWidth-1 , y, styles[c]))) + } else { + if (MS_UNLIKELY(MS_FAILURE == + drawRectangle(map, image, horizStart, vertOriginClipped, + horizStart + barWidth - 1, y, styles[c]))) return MS_FAILURE; } } - horizStart+=barWidth; + horizStart += barWidth; } return MS_SUCCESS; } -int WARN_UNUSED msDrawPieChart(mapObj *map, imageObj *image, - pointObj *center, double diameter, - double *values, styleObj **styles, int numvalues) -{ +int WARN_UNUSED msDrawPieChart(mapObj *map, imageObj *image, pointObj *center, + double diameter, double *values, + styleObj **styles, int numvalues) { int i; - double dTotal=0.,start=0; + double dTotal = 0., start = 0; - for(i=0; iproject) - { - if( layer->reprojectorLayerToMap == NULL ) - { - layer->reprojectorLayerToMap = msProjectCreateReprojector( - &layer->projection, &map->projection); - if( layer->reprojectorLayerToMap == NULL ) - { - return MS_FAILURE; + if (status == MS_SUCCESS) { + + if (layer->project) { + if (layer->reprojectorLayerToMap == NULL) { + layer->reprojectorLayerToMap = + msProjectCreateReprojector(&layer->projection, &map->projection); + if (layer->reprojectorLayerToMap == NULL) { + return MS_FAILURE; } } msProjectShapeEx(layer->reprojectorLayerToMap, shape); } - if(msBindLayerToShape(layer, shape, MS_DRAWMODE_FEATURES|MS_DRAWMODE_LABELS) != MS_SUCCESS) + if (msBindLayerToShape(layer, shape, + MS_DRAWMODE_FEATURES | MS_DRAWMODE_LABELS) != + MS_SUCCESS) return MS_FAILURE; /* error message is set in msBindLayerToShape() */ *nvalues = 0; - for(c=0; cnumclasses; c++) { - if(msEvalExpression(layer, shape, &(layer->class[c]->expression), layer->classitemindex) == MS_TRUE) { - values[*nvalues]=(layer->class[c]->styles[0]->size); - styles[*nvalues]=layer->class[c]->styles[0]; + for (c = 0; c < layer->numclasses; c++) { + if (msEvalExpression(layer, shape, &(layer->class[c] -> expression), + layer->classitemindex) == MS_TRUE) { + values[*nvalues] = (layer->class[c] -> styles[0] -> size); + styles[*nvalues] = layer->class[c]->styles[0]; (*nvalues)++; } } @@ -280,38 +306,40 @@ int getNextShape(mapObj *map, layerObj *layer, double *values, int *nvalues, sty } /* eventually add a class to the layer to get the diameter from an attribute */ -int pieLayerProcessDynamicDiameter(layerObj *layer) -{ - const char *chartRangeProcessingKey=NULL; +int pieLayerProcessDynamicDiameter(layerObj *layer) { + const char *chartRangeProcessingKey = NULL; char *attrib; - double mindiameter=-1, maxdiameter, minvalue, maxvalue; + double mindiameter = -1, maxdiameter, minvalue, maxvalue; classObj *newclass; styleObj *newstyle; - const char *chartSizeProcessingKey=msLayerGetProcessingKey( layer,"CHART_SIZE" ); - if(chartSizeProcessingKey != NULL) + const char *chartSizeProcessingKey = + msLayerGetProcessingKey(layer, "CHART_SIZE"); + if (chartSizeProcessingKey != NULL) return MS_FALSE; - chartRangeProcessingKey=msLayerGetProcessingKey( layer,"CHART_SIZE_RANGE" ); - if(chartRangeProcessingKey==NULL) + chartRangeProcessingKey = msLayerGetProcessingKey(layer, "CHART_SIZE_RANGE"); + if (chartRangeProcessingKey == NULL) return MS_FALSE; attrib = msStrdup(chartRangeProcessingKey); - char* space = strchr(attrib, ' '); - if( space ) { - *space = '\0'; - switch(sscanf(space+1,"%lf %lf %lf %lf", - &mindiameter,&maxdiameter,&minvalue,&maxvalue)) { - case 4: /*we have the attribute and the four range values*/ - break; - default: - free(attrib); - msSetError(MS_MISCERR, "Chart Layer format error for processing key \"CHART_RANGE\"", "msDrawChartLayer()"); - return MS_FAILURE; - } + char *space = strchr(attrib, ' '); + if (space) { + *space = '\0'; + switch (sscanf(space + 1, "%lf %lf %lf %lf", &mindiameter, &maxdiameter, + &minvalue, &maxvalue)) { + case 4: /*we have the attribute and the four range values*/ + break; + default: + free(attrib); + msSetError(MS_MISCERR, + "Chart Layer format error for processing key \"CHART_RANGE\"", + "msDrawChartLayer()"); + return MS_FAILURE; + } } /*create a new class in the layer containing the wanted attribute * as the SIZE of its first STYLE*/ - newclass=msGrowLayerClasses(layer); - if(newclass==NULL) { + newclass = msGrowLayerClasses(layer); + if (newclass == NULL) { free(attrib); return MS_FAILURE; } @@ -321,112 +349,117 @@ int pieLayerProcessDynamicDiameter(layerObj *layer) /*create and attach a new styleObj to our temp class * and bind the wanted attribute to its SIZE */ - newstyle=msGrowClassStyles(newclass); - if(newstyle==NULL) { + newstyle = msGrowClassStyles(newclass); + if (newstyle == NULL) { free(attrib); return MS_FAILURE; } initStyle(newstyle); newclass->numstyles++; - newclass->name=(char*)msStrdup("__MS_SIZE_ATTRIBUTE_"); - newstyle->bindings[MS_STYLE_BINDING_SIZE].item=msStrdup(attrib); + newclass->name = (char *)msStrdup("__MS_SIZE_ATTRIBUTE_"); + newstyle->bindings[MS_STYLE_BINDING_SIZE].item = msStrdup(attrib); newstyle->numbindings++; free(attrib); return MS_TRUE; - } /* clean up the class added temporarily */ -static void pieLayerCleanupDynamicDiameter(layerObj *layer) -{ - if( layer->numclasses > 0 && EQUALN(layer->class[layer->numclasses - 1]->name, "__MS_SIZE_ATTRIBUTE_", 20) ) { - classObj *c=msRemoveClass(layer, layer->numclasses - 1); +static void pieLayerCleanupDynamicDiameter(layerObj *layer) { + if (layer->numclasses > 0 && + EQUALN(layer->class[layer->numclasses - 1] -> name, + "__MS_SIZE_ATTRIBUTE_", 20)) { + classObj *c = msRemoveClass(layer, layer->numclasses - 1); freeClass(c); msFree(c); } } - -int msDrawPieChartLayer(mapObj *map, layerObj *layer, imageObj *image) -{ - shapeObj shape; - int status=MS_SUCCESS; - const char *chartRangeProcessingKey=NULL; - const char *chartSizeProcessingKey=msLayerGetProcessingKey( layer,"CHART_SIZE" ); - double diameter=0, mindiameter=-1, maxdiameter=0, minvalue=0, maxvalue=0, exponent=0; +int msDrawPieChartLayer(mapObj *map, layerObj *layer, imageObj *image) { + shapeObj shape; + int status = MS_SUCCESS; + const char *chartRangeProcessingKey = NULL; + const char *chartSizeProcessingKey = + msLayerGetProcessingKey(layer, "CHART_SIZE"); + double diameter = 0, mindiameter = -1, maxdiameter = 0, minvalue = 0, + maxvalue = 0, exponent = 0; double *values; styleObj **styles; pointObj center; - int numvalues = layer->numclasses; /* the number of classes to represent in the graph */ + int numvalues = + layer->numclasses; /* the number of classes to represent in the graph */ int numvalues_for_shape = 0; - if(chartSizeProcessingKey==NULL) { - chartRangeProcessingKey=msLayerGetProcessingKey( layer,"CHART_SIZE_RANGE" ); - if(chartRangeProcessingKey==NULL) - diameter=20; + if (chartSizeProcessingKey == NULL) { + chartRangeProcessingKey = + msLayerGetProcessingKey(layer, "CHART_SIZE_RANGE"); + if (chartRangeProcessingKey == NULL) + diameter = 20; else { - sscanf(chartRangeProcessingKey,"%*s %lf %lf %lf %lf %lf", - &mindiameter,&maxdiameter,&minvalue,&maxvalue,&exponent); + sscanf(chartRangeProcessingKey, "%*s %lf %lf %lf %lf %lf", &mindiameter, + &maxdiameter, &minvalue, &maxvalue, &exponent); } } else { - if(sscanf(chartSizeProcessingKey ,"%lf",&diameter)!=1) { - msSetError(MS_MISCERR, "msDrawChart format error for processing key \"CHART_SIZE\"", "msDrawPieChartLayer()"); + if (sscanf(chartSizeProcessingKey, "%lf", &diameter) != 1) { + msSetError(MS_MISCERR, + "msDrawChart format error for processing key \"CHART_SIZE\"", + "msDrawPieChartLayer()"); return MS_FAILURE; } } - layer->project = msProjectionsDiffer(&(layer->projection), &(map->projection)); + layer->project = + msProjectionsDiffer(&(layer->projection), &(map->projection)); /* step through the target shapes */ msInitShape(&shape); - values=(double*)calloc(numvalues,sizeof(double)); - MS_CHECK_ALLOC(values, numvalues*sizeof(double), MS_FAILURE); - styles = (styleObj**)malloc((numvalues)*sizeof(styleObj*)); + values = (double *)calloc(numvalues, sizeof(double)); + MS_CHECK_ALLOC(values, numvalues * sizeof(double), MS_FAILURE); + styles = (styleObj **)malloc((numvalues) * sizeof(styleObj *)); if (styles == NULL) { - msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msDrawPieChartLayer()", - __FILE__, __LINE__, (unsigned int)(numvalues*sizeof(styleObj*))); + msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", + "msDrawPieChartLayer()", __FILE__, __LINE__, + (unsigned int)(numvalues * sizeof(styleObj *))); free(values); return MS_FAILURE; } - while(MS_SUCCESS == getNextShape(map,layer,values,&numvalues_for_shape,styles,&shape)) { - if(chartRangeProcessingKey!=NULL) + while (MS_SUCCESS == getNextShape(map, layer, values, &numvalues_for_shape, + styles, &shape)) { + if (chartRangeProcessingKey != NULL) numvalues_for_shape--; - if(numvalues_for_shape == 0) { + if (numvalues_for_shape == 0) { msFreeShape(&shape); continue; } msDrawStartShape(map, layer, image, &shape); - if(chartRangeProcessingKey!=NULL) { + if (chartRangeProcessingKey != NULL) { diameter = values[numvalues_for_shape]; - if(mindiameter>=0) { - if(diameter<=minvalue) - diameter=mindiameter; - else if(diameter>=maxvalue) - diameter=maxdiameter; + if (mindiameter >= 0) { + if (diameter <= minvalue) + diameter = mindiameter; + else if (diameter >= maxvalue) + diameter = maxdiameter; else { if (exponent <= 0) - diameter=MS_NINT( - mindiameter+ - ((diameter-minvalue)/(maxvalue-minvalue))* - (maxdiameter-mindiameter) - ); + diameter = MS_NINT(mindiameter + + ((diameter - minvalue) / (maxvalue - minvalue)) * + (maxdiameter - mindiameter)); else - diameter=MS_NINT( - mindiameter+ - pow((diameter-minvalue)/(maxvalue-minvalue),1.0/exponent)* - (maxdiameter-mindiameter) - ); + diameter = MS_NINT( + mindiameter + pow((diameter - minvalue) / (maxvalue - minvalue), + 1.0 / exponent) * + (maxdiameter - mindiameter)); } } } - if(findChartPoint(map, &shape, diameter, diameter, ¢er) == MS_SUCCESS) { - status = msDrawPieChart(map,image, ¢er, diameter, - values,styles,numvalues_for_shape); + if (findChartPoint(map, &shape, diameter, diameter, ¢er) == + MS_SUCCESS) { + status = msDrawPieChart(map, image, ¢er, diameter, values, styles, + numvalues_for_shape); } - msDrawEndShape(map,layer,image,&shape); + msDrawEndShape(map, layer, image, &shape); msFreeShape(&shape); } free(values); @@ -434,63 +467,68 @@ int msDrawPieChartLayer(mapObj *map, layerObj *layer, imageObj *image) return status; } -int msDrawVBarChartLayer(mapObj *map, layerObj *layer, imageObj *image) -{ - shapeObj shape; - int status=MS_SUCCESS; - const char *chartSizeProcessingKey=msLayerGetProcessingKey( layer,"CHART_SIZE" ); - const char *chartScaleProcessingKey=msLayerGetProcessingKey( layer,"CHART_SCALE" ); - double barWidth,scale=1.0; +int msDrawVBarChartLayer(mapObj *map, layerObj *layer, imageObj *image) { + shapeObj shape; + int status = MS_SUCCESS; + const char *chartSizeProcessingKey = + msLayerGetProcessingKey(layer, "CHART_SIZE"); + const char *chartScaleProcessingKey = + msLayerGetProcessingKey(layer, "CHART_SCALE"); + double barWidth, scale = 1.0; double *values; styleObj **styles; pointObj center; int numvalues = layer->numclasses; int numvalues_for_shape; - if(chartSizeProcessingKey==NULL) { - barWidth=20; + if (chartSizeProcessingKey == NULL) { + barWidth = 20; } else { - if(sscanf(chartSizeProcessingKey ,"%lf",&barWidth) != 1) { - msSetError(MS_MISCERR, "msDrawChart format error for processing key \"CHART_SIZE\"", "msDrawVBarChartLayer()"); + if (sscanf(chartSizeProcessingKey, "%lf", &barWidth) != 1) { + msSetError(MS_MISCERR, + "msDrawChart format error for processing key \"CHART_SIZE\"", + "msDrawVBarChartLayer()"); return MS_FAILURE; } } - if(chartScaleProcessingKey) { - if(sscanf(chartScaleProcessingKey,"%lf",&scale)!=1) { - msSetError(MS_MISCERR, "Error reading value for processing key \"CHART_SCALE\"", "msDrawVBarChartLayer()"); + if (chartScaleProcessingKey) { + if (sscanf(chartScaleProcessingKey, "%lf", &scale) != 1) { + msSetError(MS_MISCERR, + "Error reading value for processing key \"CHART_SCALE\"", + "msDrawVBarChartLayer()"); return MS_FAILURE; } } msInitShape(&shape); - values=(double*)calloc(numvalues,sizeof(double)); - MS_CHECK_ALLOC(values, numvalues*sizeof(double), MS_FAILURE); - styles = (styleObj**)malloc(numvalues*sizeof(styleObj*)); + values = (double *)calloc(numvalues, sizeof(double)); + MS_CHECK_ALLOC(values, numvalues * sizeof(double), MS_FAILURE); + styles = (styleObj **)malloc(numvalues * sizeof(styleObj *)); if (styles == NULL) { - msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msDrawVBarChartLayer()", - __FILE__, __LINE__, (unsigned int)(numvalues*sizeof(styleObj*))); + msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", + "msDrawVBarChartLayer()", __FILE__, __LINE__, + (unsigned int)(numvalues * sizeof(styleObj *))); free(values); return MS_FAILURE; } - while(MS_SUCCESS == getNextShape(map,layer,values,&numvalues_for_shape,styles,&shape)) { + while (MS_SUCCESS == getNextShape(map, layer, values, &numvalues_for_shape, + styles, &shape)) { int i; - double h=0; - if(numvalues_for_shape == 0) { + double h = 0; + if (numvalues_for_shape == 0) { continue; } - for(i=0; inumclasses; int numvalues_for_shape; - if(chartSizeProcessingKey==NULL) { - width=height=20; + if (chartSizeProcessingKey == NULL) { + width = height = 20; } else { - switch(sscanf(chartSizeProcessingKey ,"%lf %lf",&width,&height)) { - case 2: - break; - case 1: - height = width; - break; - default: - msSetError(MS_MISCERR, "msDrawChart format error for processing key \"CHART_SIZE\"", "msDrawBarChartLayer()"); - return MS_FAILURE; + switch (sscanf(chartSizeProcessingKey, "%lf %lf", &width, &height)) { + case 2: + break; + case 1: + height = width; + break; + default: + msSetError(MS_MISCERR, + "msDrawChart format error for processing key \"CHART_SIZE\"", + "msDrawBarChartLayer()"); + return MS_FAILURE; } } - if(barMax) { - if(sscanf(barMax,"%lf",&barMaxVal)!=1) { - msSetError(MS_MISCERR, "Error reading value for processing key \"CHART_BAR_MAXVAL\"", "msDrawBarChartLayer()"); + if (barMax) { + if (sscanf(barMax, "%lf", &barMaxVal) != 1) { + msSetError(MS_MISCERR, + "Error reading value for processing key \"CHART_BAR_MAXVAL\"", + "msDrawBarChartLayer()"); return MS_FAILURE; } } - if(barMin) { - if(sscanf(barMin,"%lf",&barMinVal)!=1) { - msSetError(MS_MISCERR, "Error reading value for processing key \"CHART_BAR_MINVAL\"", "msDrawBarChartLayer()"); + if (barMin) { + if (sscanf(barMin, "%lf", &barMinVal) != 1) { + msSetError(MS_MISCERR, + "Error reading value for processing key \"CHART_BAR_MINVAL\"", + "msDrawBarChartLayer()"); return MS_FAILURE; } } - if(barMin && barMax && barMinVal>=barMaxVal) { - msSetError(MS_MISCERR, "\"CHART_BAR_MINVAL\" must be less than \"CHART_BAR_MAXVAL\"", "msDrawBarChartLayer()"); + if (barMin && barMax && barMinVal >= barMaxVal) { + msSetError(MS_MISCERR, + "\"CHART_BAR_MINVAL\" must be less than \"CHART_BAR_MAXVAL\"", + "msDrawBarChartLayer()"); return MS_FAILURE; } - barWidth=(double)width/(double)layer->numclasses; - if(!barWidth) { - msSetError(MS_MISCERR, "Specified width of chart too small to fit given number of classes", "msDrawBarChartLayer()"); + barWidth = (double)width / (double)layer->numclasses; + if (!barWidth) { + msSetError( + MS_MISCERR, + "Specified width of chart too small to fit given number of classes", + "msDrawBarChartLayer()"); return MS_FAILURE; } msInitShape(&shape); - values=(double*)calloc(numvalues,sizeof(double)); - MS_CHECK_ALLOC(values, numvalues*sizeof(double), MS_FAILURE); - styles = (styleObj**)malloc(numvalues*sizeof(styleObj*)); + values = (double *)calloc(numvalues, sizeof(double)); + MS_CHECK_ALLOC(values, numvalues * sizeof(double), MS_FAILURE); + styles = (styleObj **)malloc(numvalues * sizeof(styleObj *)); if (styles == NULL) { - msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msDrawBarChartLayer()", - __FILE__, __LINE__, (unsigned int)(numvalues*sizeof(styleObj*))); + msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", + "msDrawBarChartLayer()", __FILE__, __LINE__, + (unsigned int)(numvalues * sizeof(styleObj *))); free(values); return MS_FAILURE; } - while(MS_SUCCESS == getNextShape(map,layer,values,&numvalues_for_shape,styles,&shape)) { - if(numvalues_for_shape == 0 ) continue; + while (MS_SUCCESS == getNextShape(map, layer, values, &numvalues_for_shape, + styles, &shape)) { + if (numvalues_for_shape == 0) + continue; msDrawStartShape(map, layer, image, &shape); - if(findChartPoint(map, &shape, width,height, ¢er)==MS_SUCCESS) { - status = msDrawBarChart(map,image, - ¢er, - values, styles, numvalues_for_shape, - width,height, - (barMax!=NULL)?&barMaxVal:NULL, - (barMin!=NULL)?&barMinVal:NULL, - barWidth); + if (findChartPoint(map, &shape, width, height, ¢er) == MS_SUCCESS) { + status = msDrawBarChart(map, image, ¢er, values, styles, + numvalues_for_shape, width, height, + (barMax != NULL) ? &barMaxVal : NULL, + (barMin != NULL) ? &barMinVal : NULL, barWidth); } - msDrawEndShape(map,layer,image,&shape); + msDrawEndShape(map, layer, image, &shape); msFreeShape(&shape); } free(values); @@ -586,86 +634,93 @@ int msDrawBarChartLayer(mapObj *map, layerObj *layer, imageObj *image) /** * Generic function to render chart layers. */ -int msDrawChartLayer(mapObj *map, layerObj *layer, imageObj *image) -{ +int msDrawChartLayer(mapObj *map, layerObj *layer, imageObj *image) { - rectObj searchrect; - const char *chartTypeProcessingKey=msLayerGetProcessingKey( layer,"CHART_TYPE" ); - int chartType=MS_CHART_TYPE_PIE; + rectObj searchrect; + const char *chartTypeProcessingKey = + msLayerGetProcessingKey(layer, "CHART_TYPE"); + int chartType = MS_CHART_TYPE_PIE; int status = MS_FAILURE; if (image && map) { - if( !(MS_RENDERER_PLUGIN(image->format) )) { - msSetError(MS_MISCERR, "chart drawing currently only supports GD and AGG renderers", "msDrawChartLayer()"); + if (!(MS_RENDERER_PLUGIN(image->format))) { + msSetError(MS_MISCERR, + "chart drawing currently only supports GD and AGG renderers", + "msDrawChartLayer()"); return MS_FAILURE; } - if(chartTypeProcessingKey!=NULL) { - if( strcasecmp(chartTypeProcessingKey,"PIE") == 0 ) { - chartType=MS_CHART_TYPE_PIE; - } else if( strcasecmp(chartTypeProcessingKey,"BAR") == 0 ) { - chartType=MS_CHART_TYPE_BAR; - } else if( strcasecmp(chartTypeProcessingKey,"VBAR") == 0 ) { - chartType=MS_CHART_TYPE_VBAR; + if (chartTypeProcessingKey != NULL) { + if (strcasecmp(chartTypeProcessingKey, "PIE") == 0) { + chartType = MS_CHART_TYPE_PIE; + } else if (strcasecmp(chartTypeProcessingKey, "BAR") == 0) { + chartType = MS_CHART_TYPE_BAR; + } else if (strcasecmp(chartTypeProcessingKey, "VBAR") == 0) { + chartType = MS_CHART_TYPE_VBAR; } else { - msSetError(MS_MISCERR,"unknown chart type for processing key \"CHART_TYPE\", must be one of \"PIE\" or \"BAR\"", "msDrawChartLayer()"); + msSetError(MS_MISCERR, + "unknown chart type for processing key \"CHART_TYPE\", must " + "be one of \"PIE\" or \"BAR\"", + "msDrawChartLayer()"); return MS_FAILURE; } } - if(chartType == MS_CHART_TYPE_PIE) { + if (chartType == MS_CHART_TYPE_PIE) { pieLayerProcessDynamicDiameter(layer); } /* open this layer */ status = msLayerOpen(layer); - if(status != MS_SUCCESS) return MS_FAILURE; + if (status != MS_SUCCESS) + return MS_FAILURE; status = msLayerWhichItems(layer, MS_FALSE, NULL); - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { msLayerClose(layer); return MS_FAILURE; } /* identify target shapes */ - if(layer->transform == MS_TRUE) + if (layer->transform == MS_TRUE) searchrect = map->extent; else { searchrect.minx = searchrect.miny = 0; - searchrect.maxx = map->width-1; - searchrect.maxy = map->height-1; + searchrect.maxx = map->width - 1; + searchrect.maxy = map->height - 1; } - if((map->projection.numargs > 0) && (layer->projection.numargs > 0)) - msProjectRect(&map->projection, &layer->projection, &searchrect); /* project the searchrect to source coords */ + if ((map->projection.numargs > 0) && (layer->projection.numargs > 0)) + msProjectRect(&map->projection, &layer->projection, + &searchrect); /* project the searchrect to source coords */ status = msLayerWhichShapes(layer, searchrect, MS_FALSE); - if(status == MS_DONE) { /* no overlap */ + if (status == MS_DONE) { /* no overlap */ msLayerClose(layer); - if(chartType == MS_CHART_TYPE_PIE) + if (chartType == MS_CHART_TYPE_PIE) pieLayerCleanupDynamicDiameter(layer); return MS_SUCCESS; - } else if(status != MS_SUCCESS) { + } else if (status != MS_SUCCESS) { msLayerClose(layer); - if(chartType == MS_CHART_TYPE_PIE) + if (chartType == MS_CHART_TYPE_PIE) pieLayerCleanupDynamicDiameter(layer); return MS_FAILURE; } - switch(chartType) { - case MS_CHART_TYPE_PIE: - status = msDrawPieChartLayer(map, layer, image); - break; - case MS_CHART_TYPE_BAR: - status = msDrawBarChartLayer(map, layer, image); - break; - case MS_CHART_TYPE_VBAR: - status = msDrawVBarChartLayer(map, layer, image); - break; - default: - return MS_FAILURE;/*shouldn't be here anyways*/ + switch (chartType) { + case MS_CHART_TYPE_PIE: + status = msDrawPieChartLayer(map, layer, image); + break; + case MS_CHART_TYPE_BAR: + status = msDrawBarChartLayer(map, layer, image); + break; + case MS_CHART_TYPE_VBAR: + status = msDrawVBarChartLayer(map, layer, image); + break; + default: + return MS_FAILURE; /*shouldn't be here anyways*/ } msLayerClose(layer); - if(chartType == MS_CHART_TYPE_PIE) + if (chartType == MS_CHART_TYPE_PIE) pieLayerCleanupDynamicDiameter(layer); } return status; diff --git a/mapcluster.c b/mapcluster.c index 548b0e74ed..1467dee3c1 100644 --- a/mapcluster.c +++ b/mapcluster.c @@ -33,36 +33,35 @@ #include #include "mapserver.h" - - - #ifdef USE_CLUSTER_PLUGIN #define USE_CLUSTER_EXTERNAL #endif /* custom attributes provided by this layer data source */ -#define MSCLUSTER_NUMITEMS 3 -#define MSCLUSTER_FEATURECOUNT "Cluster_FeatureCount" -#define MSCLUSTER_FEATURECOUNTINDEX -100 -#define MSCLUSTER_GROUP "Cluster_Group" -#define MSCLUSTER_GROUPINDEX -101 -#define MSCLUSTER_BASEFID "Cluster_BaseFID" -#define MSCLUSTER_BASEFIDINDEX -102 +#define MSCLUSTER_NUMITEMS 3 +#define MSCLUSTER_FEATURECOUNT "Cluster_FeatureCount" +#define MSCLUSTER_FEATURECOUNTINDEX -100 +#define MSCLUSTER_GROUP "Cluster_Group" +#define MSCLUSTER_GROUPINDEX -101 +#define MSCLUSTER_BASEFID "Cluster_BaseFID" +#define MSCLUSTER_BASEFIDINDEX -102 typedef struct cluster_tree_node clusterTreeNode; typedef struct cluster_info clusterInfo; typedef struct cluster_layer_info msClusterLayerInfo; /* forward declarations */ -void msClusterLayerCopyVirtualTable(layerVTableObj* vtable); -static void clusterTreeNodeDestroy(msClusterLayerInfo* layerinfo, clusterTreeNode *node); +void msClusterLayerCopyVirtualTable(layerVTableObj *vtable); +static void clusterTreeNodeDestroy(msClusterLayerInfo *layerinfo, + clusterTreeNode *node); /* cluster compare func */ -typedef int (*clusterCompareRegionFunc)(clusterInfo* current, clusterInfo* other); +typedef int (*clusterCompareRegionFunc)(clusterInfo *current, + clusterInfo *other); /* quadtree constants */ -#define SPLITRATIO 0.55 -#define TREE_MAX_DEPTH 10 +#define SPLITRATIO 0.55 +#define TREE_MAX_DEPTH 10 /* cluster algorithm */ #define MSCLUSTER_ALGORITHM_FULL 0 @@ -70,12 +69,12 @@ typedef int (*clusterCompareRegionFunc)(clusterInfo* current, clusterInfo* other /* cluster data */ struct cluster_info { - double x; /* x position of the current point */ - double y; /* y position of the current point */ - double avgx; /* average x positions of this cluster */ - double avgy; /* average y positions of this cluster */ - double varx; /* variance of the x positions of this cluster */ - double vary; /* variance of the y positions of this cluster */ + double x; /* x position of the current point */ + double y; /* y position of the current point */ + double avgx; /* average x positions of this cluster */ + double avgy; /* average y positions of this cluster */ + double varx; /* variance of the x positions of this cluster */ + double vary; /* variance of the y positions of this cluster */ shapeObj shape; /* current shape */ rectObj bounds; /* clustering region */ /* number of the neighbouring shapes */ @@ -84,13 +83,13 @@ struct cluster_info { int numcollected; int numremoved; int index; - clusterTreeNode* node; + clusterTreeNode *node; /* collection of the siblings */ - clusterInfo* siblings; + clusterInfo *siblings; /* next shape in the linked list */ - clusterInfo* next; + clusterInfo *next; /* current group */ - char* group; + char *group; int filter; }; @@ -102,34 +101,36 @@ struct cluster_tree_node { int numshapes; int index; int position; - clusterInfo* shapes; + clusterInfo *shapes; /* quad tree subnodes */ - clusterTreeNode* subnode[4]; + clusterTreeNode *subnode[4]; }; /* layeinfo */ struct cluster_layer_info { /* array of features (finalized clusters) */ - clusterInfo* finalized; - clusterInfo* finalizedSiblings; - clusterInfo* filtered; + clusterInfo *finalized; + clusterInfo *finalizedSiblings; + clusterInfo *filtered; int numFeatures; int numFinalized; int numFinalizedSiblings; int numFiltered; /* variables for collecting the best cluster and iterating with NextShape */ - clusterInfo* current; + clusterInfo *current; /* check whether all shapes should be returned behind a cluster */ int get_all_shapes; - /* check whether the location of the shapes should be preserved (no averaging) */ + /* check whether the location of the shapes should be preserved (no averaging) + */ int keep_locations; - /* the maxdistance and the buffer parameters are specified in map units (scale independent clustering) */ + /* the maxdistance and the buffer parameters are specified in map units (scale + * independent clustering) */ int use_map_units; double rank; /* root node of the quad tree */ - clusterTreeNode* root; + clusterTreeNode *root; int numNodes; - clusterTreeNode* finalizedNodes; + clusterTreeNode *finalizedNodes; int numFinalizedNodes; /* map extent used for building cluster data */ rectObj searchRect; @@ -143,12 +144,10 @@ struct cluster_layer_info { int algorithm; }; - extern int yyparse(parseObj *p); /* evaluate the filter expression */ -int msClusterEvaluateFilter(expressionObj* expression, shapeObj *shape) -{ +int msClusterEvaluateFilter(expressionObj *expression, shapeObj *shape) { if (expression->type == MS_EXPRESSION) { int status; parseObj p; @@ -161,7 +160,8 @@ int msClusterEvaluateFilter(expressionObj* expression, shapeObj *shape) status = yyparse(&p); if (status != 0) { - msSetError(MS_PARSEERR, "Failed to parse expression: %s", "msClusterEvaluateFilter", expression->string); + msSetError(MS_PARSEERR, "Failed to parse expression: %s", + "msClusterEvaluateFilter", expression->string); return 0; } @@ -172,58 +172,59 @@ int msClusterEvaluateFilter(expressionObj* expression, shapeObj *shape) } /* get the group text when creating the clusters */ -char *msClusterGetGroupText(expressionObj* expression, shapeObj *shape) -{ - char *tmpstr=NULL; - - if(expression->string) { - switch(expression->type) { - case(MS_STRING): - tmpstr = msStrdup(expression->string); - break; - case(MS_EXPRESSION): { - int status; - parseObj p; - - p.shape = shape; - p.expr = expression; - p.expr->curtoken = p.expr->tokens; /* reset */ - p.type = MS_PARSE_TYPE_STRING; - - status = yyparse(&p); - - if (status != 0) { - msSetError(MS_PARSEERR, "Failed to process text expression: %s", "msClusterGetGroupText", expression->string); - return NULL; - } +char *msClusterGetGroupText(expressionObj *expression, shapeObj *shape) { + char *tmpstr = NULL; - tmpstr = p.result.strval; - break; + if (expression->string) { + switch (expression->type) { + case (MS_STRING): + tmpstr = msStrdup(expression->string); + break; + case (MS_EXPRESSION): { + int status; + parseObj p; + + p.shape = shape; + p.expr = expression; + p.expr->curtoken = p.expr->tokens; /* reset */ + p.type = MS_PARSE_TYPE_STRING; + + status = yyparse(&p); + + if (status != 0) { + msSetError(MS_PARSEERR, "Failed to process text expression: %s", + "msClusterGetGroupText", expression->string); + return NULL; } - default: - break; + + tmpstr = p.result.strval; + break; + } + default: + break; } } - return(tmpstr); + return (tmpstr); } -int CompareEllipseRegion(clusterInfo* current, clusterInfo* other) -{ +int CompareEllipseRegion(clusterInfo *current, clusterInfo *other) { if (current->group && other->group && !EQUAL(current->group, other->group)) return MS_FALSE; if ((other->x - current->x) * (other->x - current->x) / - ((current->bounds.maxx - current->x) * (current->bounds.maxx - current->x)) + - (other->y - current->y) * (other->y - current->y) / - ((current->bounds.maxy - current->y) * (current->bounds.maxy - current->y)) > 1) + ((current->bounds.maxx - current->x) * + (current->bounds.maxx - current->x)) + + (other->y - current->y) * (other->y - current->y) / + ((current->bounds.maxy - current->y) * + (current->bounds.maxy - current->y)) > + 1) return MS_FALSE; return MS_TRUE; } -int CompareRectangleRegion(clusterInfo* current, clusterInfo* other) -{ +int CompareRectangleRegion(clusterInfo *current, clusterInfo *other) { if (current->group && other->group && !EQUAL(current->group, other->group)) return MS_FALSE; @@ -239,8 +240,7 @@ int CompareRectangleRegion(clusterInfo* current, clusterInfo* other) return MS_TRUE; } -static void treeSplitBounds( rectObj *in, rectObj *out1, rectObj *out2) -{ +static void treeSplitBounds(rectObj *in, rectObj *out1, rectObj *out2) { double range; /* -------------------------------------------------------------------- */ @@ -253,7 +253,7 @@ static void treeSplitBounds( rectObj *in, rectObj *out1, rectObj *out2) /* -------------------------------------------------------------------- */ /* Split in X direction. */ /* -------------------------------------------------------------------- */ - if((in->maxx - in->minx) > (in->maxy - in->miny)) { + if ((in->maxx - in->minx) > (in->maxy - in->miny)) { range = in->maxx - in->minx; out1->maxx = in->minx + range * SPLITRATIO; @@ -272,9 +272,8 @@ static void treeSplitBounds( rectObj *in, rectObj *out1, rectObj *out2) } /* alloc memory for a new tentative cluster */ -static clusterInfo *clusterInfoCreate(msClusterLayerInfo* layerinfo) -{ - clusterInfo* feature = (clusterInfo*)msSmallMalloc(sizeof(clusterInfo)); +static clusterInfo *clusterInfoCreate(msClusterLayerInfo *layerinfo) { + clusterInfo *feature = (clusterInfo *)msSmallMalloc(sizeof(clusterInfo)); msInitShape(&feature->shape); feature->numsiblings = 0; feature->numcollected = 0; @@ -290,10 +289,10 @@ static clusterInfo *clusterInfoCreate(msClusterLayerInfo* layerinfo) } /* destroy memory of the cluster list */ -static void clusterInfoDestroyList(msClusterLayerInfo* layerinfo, clusterInfo* feature) -{ - clusterInfo* s = feature; - clusterInfo* next; +static void clusterInfoDestroyList(msClusterLayerInfo *layerinfo, + clusterInfo *feature) { + clusterInfo *s = feature; + clusterInfo *next; /* destroy the shapes added to this node */ while (s) { next = s->next; @@ -309,13 +308,15 @@ static void clusterInfoDestroyList(msClusterLayerInfo* layerinfo, clusterInfo* f } /* alloc memory for a new treenode */ -static clusterTreeNode *clusterTreeNodeCreate(msClusterLayerInfo* layerinfo, rectObj rect) -{ - clusterTreeNode* node = (clusterTreeNode*)msSmallMalloc(sizeof(clusterTreeNode)); +static clusterTreeNode *clusterTreeNodeCreate(msClusterLayerInfo *layerinfo, + rectObj rect) { + clusterTreeNode *node = + (clusterTreeNode *)msSmallMalloc(sizeof(clusterTreeNode)); node->rect = rect; node->numshapes = 0; node->shapes = NULL; - node->subnode[0] = node->subnode[1] = node->subnode[2] = node->subnode[3] = NULL; + node->subnode[0] = node->subnode[1] = node->subnode[2] = node->subnode[3] = + NULL; node->index = layerinfo->numNodes; node->position = 0; ++layerinfo->numNodes; @@ -323,8 +324,8 @@ static clusterTreeNode *clusterTreeNodeCreate(msClusterLayerInfo* layerinfo, rec } /* traverse the quadtree and destroy all sub elements */ -static void clusterTreeNodeDestroy(msClusterLayerInfo* layerinfo, clusterTreeNode *node) -{ +static void clusterTreeNodeDestroy(msClusterLayerInfo *layerinfo, + clusterTreeNode *node) { int i; /* destroy the shapes added to this node */ clusterInfoDestroyList(layerinfo, node->shapes); @@ -340,10 +341,10 @@ static void clusterTreeNodeDestroy(msClusterLayerInfo* layerinfo, clusterTreeNod } /* destroy memory of the cluster finalized list (without recursion) */ -static void clusterTreeNodeDestroyList(msClusterLayerInfo* layerinfo, clusterTreeNode *node) -{ - clusterTreeNode* n = node; - clusterTreeNode* next; +static void clusterTreeNodeDestroyList(msClusterLayerInfo *layerinfo, + clusterTreeNode *node) { + clusterTreeNode *n = node; + clusterTreeNode *next; /* destroy the list of nodes */ while (n) { next = n->subnode[0]; @@ -354,8 +355,7 @@ static void clusterTreeNodeDestroyList(msClusterLayerInfo* layerinfo, clusterTre } } -void clusterDestroyData(msClusterLayerInfo *layerinfo) -{ +void clusterDestroyData(msClusterLayerInfo *layerinfo) { if (layerinfo->finalized) { clusterInfoDestroyList(layerinfo, layerinfo->finalized); layerinfo->finalized = NULL; @@ -391,17 +391,16 @@ void clusterDestroyData(msClusterLayerInfo *layerinfo) /* traverse the quadtree to find the neighbouring shapes and update some data on the related shapes (when adding a new feature)*/ -static void findRelatedShapes(msClusterLayerInfo* layerinfo, - clusterTreeNode *node, clusterInfo* current) -{ +static void findRelatedShapes(msClusterLayerInfo *layerinfo, + clusterTreeNode *node, clusterInfo *current) { int i; - clusterInfo* s; + clusterInfo *s; /* -------------------------------------------------------------------- */ /* Does this node overlap the area of interest at all? If not, */ /* return without adding to the list at all. */ /* -------------------------------------------------------------------- */ - if(!msRectOverlap(&node->rect, ¤t->bounds)) + if (!msRectOverlap(&node->rect, ¤t->bounds)) return; /* Modify the feature count of the related shapes */ @@ -410,25 +409,35 @@ static void findRelatedShapes(msClusterLayerInfo* layerinfo, if (layerinfo->fnCompare(current, s)) { ++current->numsiblings; /* calculating the average positions */ - current->avgx = (current->avgx * current->numsiblings + s->x) / (current->numsiblings + 1); - current->avgy = (current->avgy * current->numsiblings + s->y) / (current->numsiblings + 1); + current->avgx = (current->avgx * current->numsiblings + s->x) / + (current->numsiblings + 1); + current->avgy = (current->avgy * current->numsiblings + s->y) / + (current->numsiblings + 1); /* calculating the variance */ - current->varx = current->varx * current->numsiblings / (current->numsiblings + 1) + - (s->x - current->avgx) * (s->x - current->avgx) / (current->numsiblings + 1); - current->vary = current->vary * current->numsiblings / (current->numsiblings + 1) + - (s->y - current->avgy) * (s->y - current->avgy) / (current->numsiblings + 1); + current->varx = + current->varx * current->numsiblings / (current->numsiblings + 1) + + (s->x - current->avgx) * (s->x - current->avgx) / + (current->numsiblings + 1); + current->vary = + current->vary * current->numsiblings / (current->numsiblings + 1) + + (s->y - current->avgy) * (s->y - current->avgy) / + (current->numsiblings + 1); if (layerinfo->fnCompare(s, current)) { /* this feature falls into the region of the other as well */ ++s->numsiblings; /* calculating the average positions */ - s->avgx = (s->avgx * s->numsiblings + current->x) / (s->numsiblings + 1); - s->avgy = (s->avgy * s->numsiblings + current->y) / (s->numsiblings + 1); + s->avgx = + (s->avgx * s->numsiblings + current->x) / (s->numsiblings + 1); + s->avgy = + (s->avgy * s->numsiblings + current->y) / (s->numsiblings + 1); /* calculating the variance */ s->varx = s->varx * s->numsiblings / (s->numsiblings + 1) + - (current->x - s->avgx) * (current->x - s->avgx) / (s->numsiblings + 1); + (current->x - s->avgx) * (current->x - s->avgx) / + (s->numsiblings + 1); s->vary = s->vary * s->numsiblings / (s->numsiblings + 1) + - (current->y - s->avgy) * (current->y - s->avgy) / (s->numsiblings + 1); + (current->y - s->avgy) * (current->y - s->avgy) / + (s->numsiblings + 1); } } s = s->next; @@ -444,18 +453,18 @@ static void findRelatedShapes(msClusterLayerInfo* layerinfo, } } -/* traverse the quadtree to find the neighbouring clusters and update data on the cluster*/ -static void findRelatedShapes2(msClusterLayerInfo* layerinfo, - clusterTreeNode *node, clusterInfo* current) -{ +/* traverse the quadtree to find the neighbouring clusters and update data on + * the cluster*/ +static void findRelatedShapes2(msClusterLayerInfo *layerinfo, + clusterTreeNode *node, clusterInfo *current) { int i; - clusterInfo* s; - + clusterInfo *s; + /* -------------------------------------------------------------------- */ /* Does this node overlap the area of interest at all? If not, */ /* return without adding to the list at all. */ /* -------------------------------------------------------------------- */ - if(!msRectOverlap(&node->rect, ¤t->bounds)) + if (!msRectOverlap(&node->rect, ¤t->bounds)) return; /* Modify the feature count of the related shapes */ @@ -463,17 +472,17 @@ static void findRelatedShapes2(msClusterLayerInfo* layerinfo, while (s) { if (layerinfo->fnCompare(s, current)) { if (layerinfo->rank > 0) { - double r = (current->x - s->x) * (current->x - s->x) + (current->y - s->y) * (current->y - s->y); + double r = (current->x - s->x) * (current->x - s->x) + + (current->y - s->y) * (current->y - s->y); if (r < layerinfo->rank) { layerinfo->current = s; layerinfo->rank = r; } - } - else { + } else { /* no rank was specified, return immediately */ layerinfo->current = s; return; - } + } } s = s->next; } @@ -490,16 +499,17 @@ static void findRelatedShapes2(msClusterLayerInfo* layerinfo, /* traverse the quadtree to find the neighbouring shapes and update some data on the related shapes (when removing a feature) */ -static void findRelatedShapesRemove(msClusterLayerInfo* layerinfo, clusterTreeNode *node, clusterInfo* current) -{ +static void findRelatedShapesRemove(msClusterLayerInfo *layerinfo, + clusterTreeNode *node, + clusterInfo *current) { int i; - clusterInfo* s; + clusterInfo *s; /* -------------------------------------------------------------------- */ /* Does this node overlap the area of interest at all? If not, */ /* return without adding to the list at all. */ /* -------------------------------------------------------------------- */ - if(!msRectOverlap(&node->rect, ¤t->bounds)) + if (!msRectOverlap(&node->rect, ¤t->bounds)) return; /* Modify the feature count of the related shapes */ @@ -508,12 +518,16 @@ static void findRelatedShapesRemove(msClusterLayerInfo* layerinfo, clusterTreeNo if (layerinfo->fnCompare(current, s)) { if (s->numsiblings > 0) { /* calculating the average positions */ - s->avgx = (s->avgx * (s->numsiblings + 1) - current->x) / s->numsiblings; - s->avgy = (s->avgy * (s->numsiblings + 1) - current->y) / s->numsiblings; + s->avgx = + (s->avgx * (s->numsiblings + 1) - current->x) / s->numsiblings; + s->avgy = + (s->avgy * (s->numsiblings + 1) - current->y) / s->numsiblings; /* calculating the variance */ - s->varx = (s->varx - (current->x - s->avgx) * (current->x - s->avgx) / s->numsiblings) * + s->varx = (s->varx - (current->x - s->avgx) * (current->x - s->avgx) / + s->numsiblings) * (s->numsiblings + 1) / s->numsiblings; - s->vary = (s->vary - (current->y - s->avgy) * (current->y - s->avgy) / s->numsiblings) * + s->vary = (s->vary - (current->y - s->avgy) * (current->y - s->avgy) / + s->numsiblings) * (s->numsiblings + 1) / s->numsiblings; --s->numsiblings; ++s->numremoved; @@ -530,10 +544,9 @@ static void findRelatedShapesRemove(msClusterLayerInfo* layerinfo, clusterTreeNo } /* setting the aggregated attributes */ -static void InitShapeAttributes(layerObj* layer, clusterInfo* base) -{ +static void InitShapeAttributes(layerObj *layer, clusterInfo *base) { int i; - int* itemindexes = layer->iteminfo; + int *itemindexes = layer->iteminfo; for (i = 0; i < layer->numitems; i++) { if (base->shape.numvalues <= i) @@ -567,10 +580,10 @@ static void InitShapeAttributes(layerObj* layer, clusterInfo* base) } /* update the shape attributes (aggregate) */ -static void UpdateShapeAttributes(layerObj* layer, clusterInfo* base, clusterInfo* current) -{ +static void UpdateShapeAttributes(layerObj *layer, clusterInfo *base, + clusterInfo *current) { int i; - int* itemindexes = layer->iteminfo; + int *itemindexes = layer->iteminfo; for (i = 0; i < layer->numitems; i++) { if (base->shape.numvalues <= i) @@ -585,8 +598,8 @@ static void UpdateShapeAttributes(layerObj* layer, clusterInfo* base, clusterInf /* setting the base feature index for each cluster member */ if (itemindexes[i] == MSCLUSTER_BASEFIDINDEX) { - msFree(current->shape.values[i]); - current->shape.values[i] = msIntToString(base->shape.index); + msFree(current->shape.values[i]); + current->shape.values[i] = msIntToString(base->shape.index); } if (current->shape.values[i]) { @@ -601,7 +614,8 @@ static void UpdateShapeAttributes(layerObj* layer, clusterInfo* base, clusterInf base->shape.values[i] = msStrdup(current->shape.values[i]); } } else if (EQUALN(layer->items[i], "Sum:", 4)) { - double sum = atof(base->shape.values[i]) + atof(current->shape.values[i]); + double sum = + atof(base->shape.values[i]) + atof(current->shape.values[i]); msFree(base->shape.values[i]); base->shape.values[i] = msDoubleToString(sum, MS_FALSE); } else if (EQUALN(layer->items[i], "Count:", 6)) { @@ -613,16 +627,18 @@ static void UpdateShapeAttributes(layerObj* layer, clusterInfo* base, clusterInf } } -static int BuildFeatureAttributes(layerObj* layer, msClusterLayerInfo* layerinfo, shapeObj* shape) -{ - char** values; +static int BuildFeatureAttributes(layerObj *layer, + msClusterLayerInfo *layerinfo, + shapeObj *shape) { + char **values; int i; - int* itemindexes = layer->iteminfo; + int *itemindexes = layer->iteminfo; if (layer->numitems == layerinfo->srcLayer.numitems) - return MS_SUCCESS; /* we don't have custom attributes, no need to reconstruct the array */ + return MS_SUCCESS; /* we don't have custom attributes, no need to + reconstruct the array */ - values = msSmallMalloc(sizeof(char*) * (layer->numitems)); + values = msSmallMalloc(sizeof(char *) * (layer->numitems)); for (i = 0; i < layer->numitems; i++) { if (itemindexes[i] == MSCLUSTER_FEATURECOUNTINDEX) { @@ -647,11 +663,11 @@ static int BuildFeatureAttributes(layerObj* layer, msClusterLayerInfo* layerinfo } /* traverse the quadtree to find the best renking cluster */ -static void findBestCluster(layerObj* layer, msClusterLayerInfo* layerinfo, clusterTreeNode *node) -{ +static void findBestCluster(layerObj *layer, msClusterLayerInfo *layerinfo, + clusterTreeNode *node) { int i; double rank; - clusterInfo* s = node->shapes; + clusterInfo *s = node->shapes; while (s) { if (s->filter < 0 && layer->cluster.filter.string != NULL) { InitShapeAttributes(layer, s); @@ -665,7 +681,9 @@ static void findBestCluster(layerObj* layer, msClusterLayerInfo* layerinfo, clus } /* calculating the rank */ - rank = (s->x - s->avgx) * (s->x - s->avgx) + (s->y - s->avgy) * (s->y - s->avgy) /*+ s->varx + s->vary*/ + (double)1/ (1 + s->numsiblings); + rank = (s->x - s->avgx) * (s->x - s->avgx) + + (s->y - s->avgy) * (s->y - s->avgy) /*+ s->varx + s->vary*/ + + (double)1 / (1 + s->numsiblings); if (rank < layerinfo->rank) { layerinfo->current = s; @@ -682,18 +700,19 @@ static void findBestCluster(layerObj* layer, msClusterLayerInfo* layerinfo, clus } /* adding the shape based on the shape bounds (point) */ -static int treeNodeAddShape(msClusterLayerInfo* layerinfo, clusterTreeNode* node, clusterInfo* shape, int depth) -{ +static int treeNodeAddShape(msClusterLayerInfo *layerinfo, + clusterTreeNode *node, clusterInfo *shape, + int depth) { int i; /* -------------------------------------------------------------------- */ /* If there are subnodes, then consider whether this object */ /* will fit in them. */ /* -------------------------------------------------------------------- */ - if( depth > 1 && node->subnode[0] != NULL ) { - for(i = 0; i < 4; i++ ) { - if( msRectContained(&shape->shape.bounds, &node->subnode[i]->rect)) { - return treeNodeAddShape( layerinfo, node->subnode[i], shape, depth-1); + if (depth > 1 && node->subnode[0] != NULL) { + for (i = 0; i < 4; i++) { + if (msRectContained(&shape->shape.bounds, &node->subnode[i]->rect)) { + return treeNodeAddShape(layerinfo, node->subnode[i], shape, depth - 1); } } } @@ -702,7 +721,7 @@ static int treeNodeAddShape(msClusterLayerInfo* layerinfo, clusterTreeNode* node /* Otherwise, consider creating four subnodes if could fit into */ /* them, and adding to the appropriate subnode. */ /* -------------------------------------------------------------------- */ - else if( depth > 1 && node->subnode[0] == NULL ) { + else if (depth > 1 && node->subnode[0] == NULL) { rectObj half1, half2, quad1, quad2, quad3, quad4; int subnode = -1; @@ -710,13 +729,13 @@ static int treeNodeAddShape(msClusterLayerInfo* layerinfo, clusterTreeNode* node treeSplitBounds(&half1, &quad1, &quad2); treeSplitBounds(&half2, &quad3, &quad4); - if(msRectContained(&shape->shape.bounds, &quad1)) + if (msRectContained(&shape->shape.bounds, &quad1)) subnode = 0; - else if(msRectContained(&shape->shape.bounds, &quad2)) + else if (msRectContained(&shape->shape.bounds, &quad2)) subnode = 1; - else if(msRectContained(&shape->shape.bounds, &quad3)) + else if (msRectContained(&shape->shape.bounds, &quad3)) subnode = 2; - else if(msRectContained(&shape->shape.bounds, &quad4)) + else if (msRectContained(&shape->shape.bounds, &quad4)) subnode = 3; if (subnode >= 0) { @@ -737,7 +756,8 @@ static int treeNodeAddShape(msClusterLayerInfo* layerinfo, clusterTreeNode* node node->subnode[3]->position = node->position * 4 + 3; /* add to subnode */ - return treeNodeAddShape(layerinfo, node->subnode[subnode], shape, depth-1); + return treeNodeAddShape(layerinfo, node->subnode[subnode], shape, + depth - 1); } } @@ -750,16 +770,17 @@ static int treeNodeAddShape(msClusterLayerInfo* layerinfo, clusterTreeNode* node return MS_SUCCESS; } -/* collecting the cluster shapes, returns true if this subnode must be removed */ -static int collectClusterShapes(msClusterLayerInfo* layerinfo, clusterTreeNode *node, clusterInfo* current) -{ +/* collecting the cluster shapes, returns true if this subnode must be removed + */ +static int collectClusterShapes(msClusterLayerInfo *layerinfo, + clusterTreeNode *node, clusterInfo *current) { int i; - clusterInfo* prev = NULL; - clusterInfo* s = node->shapes; + clusterInfo *prev = NULL; + clusterInfo *s = node->shapes; - if(!msRectOverlap(&node->rect, ¤t->bounds)) - return (!node->shapes && !node->subnode[0] && !node->subnode[1] - && !node->subnode[2] && !node->subnode[3]); + if (!msRectOverlap(&node->rect, ¤t->bounds)) + return (!node->shapes && !node->subnode[0] && !node->subnode[1] && + !node->subnode[2] && !node->subnode[3]); /* removing the shapes from this node if overlap with the cluster */ while (s) { @@ -809,7 +830,8 @@ static int collectClusterShapes(msClusterLayerInfo* layerinfo, clusterTreeNode * /* Recurse to subnodes if they exist */ for (i = 0; i < 4; i++) { - if (node->subnode[i] && collectClusterShapes(layerinfo, node->subnode[i], current)) { + if (node->subnode[i] && + collectClusterShapes(layerinfo, node->subnode[i], current)) { /* placing this empty node to the finalization queue */ node->subnode[i]->subnode[0] = layerinfo->finalizedNodes; layerinfo->finalizedNodes = node->subnode[i]; @@ -819,16 +841,17 @@ static int collectClusterShapes(msClusterLayerInfo* layerinfo, clusterTreeNode * } /* returns true is this subnode must be removed */ - return (!node->shapes && !node->subnode[0] && !node->subnode[1] - && !node->subnode[2] && !node->subnode[3]); + return (!node->shapes && !node->subnode[0] && !node->subnode[1] && + !node->subnode[2] && !node->subnode[3]); } -/* collecting the cluster shapes, returns true if this subnode must be removed */ -static int collectClusterShapes2(layerObj* layer, msClusterLayerInfo* layerinfo, clusterTreeNode *node) -{ +/* collecting the cluster shapes, returns true if this subnode must be removed + */ +static int collectClusterShapes2(layerObj *layer, msClusterLayerInfo *layerinfo, + clusterTreeNode *node) { int i; - clusterInfo* current = NULL; - clusterInfo* s; + clusterInfo *current = NULL; + clusterInfo *s; while (node->shapes) { s = node->shapes; @@ -838,20 +861,20 @@ static int collectClusterShapes2(layerObj* layer, msClusterLayerInfo* layerinfo, InitShapeAttributes(layer, s); if (s->filter) { - s->next = layerinfo->finalized; - layerinfo->finalized = s; - ++layerinfo->numFinalized; + s->next = layerinfo->finalized; + layerinfo->finalized = s; + ++layerinfo->numFinalized; } else { - /* this shape is filtered */ - s->next = layerinfo->filtered; - layerinfo->filtered = s; - ++layerinfo->numFiltered; + /* this shape is filtered */ + s->next = layerinfo->filtered; + layerinfo->filtered = s; + ++layerinfo->numFiltered; } /* update the parameters of the related shapes if any */ if (s->siblings) { current = s->siblings; - while(current) { + while (current) { UpdateShapeAttributes(layer, s, current); /* setting the average position to the cluster position */ @@ -875,7 +898,8 @@ static int collectClusterShapes2(layerObj* layer, msClusterLayerInfo* layerinfo, /* Recurse to subnodes if they exist */ for (i = 0; i < 4; i++) { - if (node->subnode[i] && collectClusterShapes2(layer, layerinfo, node->subnode[i])) { + if (node->subnode[i] && + collectClusterShapes2(layer, layerinfo, node->subnode[i])) { /* placing this empty node to the finalization queue */ node->subnode[i]->subnode[0] = layerinfo->finalizedNodes; layerinfo->finalizedNodes = node->subnode[i]; @@ -885,18 +909,18 @@ static int collectClusterShapes2(layerObj* layer, msClusterLayerInfo* layerinfo, } /* returns true is this subnode must be removed */ - return (!node->shapes && !node->subnode[0] && !node->subnode[1] - && !node->subnode[2] && !node->subnode[3]); + return (!node->shapes && !node->subnode[0] && !node->subnode[1] && + !node->subnode[2] && !node->subnode[3]); } -int selectClusterShape(layerObj* layer, long shapeindex) -{ +int selectClusterShape(layerObj *layer, long shapeindex) { int i; - clusterInfo* current; - msClusterLayerInfo* layerinfo = (msClusterLayerInfo*)layer->layerinfo; + clusterInfo *current; + msClusterLayerInfo *layerinfo = (msClusterLayerInfo *)layer->layerinfo; if (!layerinfo) { - msSetError(MS_MISCERR, "Layer not open: %s", "selectClusterShape()", layer->name); + msSetError(MS_MISCERR, "Layer not open: %s", "selectClusterShape()", + layer->name); return MS_FAILURE; } @@ -912,8 +936,10 @@ int selectClusterShape(layerObj* layer, long shapeindex) layerinfo->current = current; if (layerinfo->keep_locations == MS_FALSE) { - current->shape.line[0].point[0].x = current->shape.bounds.minx = current->shape.bounds.maxx = current->avgx; - current->shape.line[0].point[0].y = current->shape.bounds.miny = current->shape.bounds.maxy = current->avgy; + current->shape.line[0].point[0].x = current->shape.bounds.minx = + current->shape.bounds.maxx = current->avgx; + current->shape.line[0].point[0].y = current->shape.bounds.miny = + current->shape.bounds.maxy = current->avgy; } return MS_SUCCESS; @@ -921,10 +947,10 @@ int selectClusterShape(layerObj* layer, long shapeindex) /* update the parameters from the related shapes */ #ifdef ms_notused -static void UpdateClusterParameters(msClusterLayerInfo* layerinfo, clusterTreeNode *node, clusterInfo *shape) -{ +static void UpdateClusterParameters(msClusterLayerInfo *layerinfo, + clusterTreeNode *node, clusterInfo *shape) { int i; - clusterInfo* s = node->shapes; + clusterInfo *s = node->shapes; while (s) { if (layerinfo->fnCompare(shape, s)) { @@ -942,13 +968,13 @@ static void UpdateClusterParameters(msClusterLayerInfo* layerinfo, clusterTreeNo } } -/* check for the validity of the clusters added to the tree (for debug purposes) */ -static int ValidateTree(msClusterLayerInfo* layerinfo, clusterTreeNode *node) -{ +/* check for the validity of the clusters added to the tree (for debug purposes) + */ +static int ValidateTree(msClusterLayerInfo *layerinfo, clusterTreeNode *node) { int i; int isValid = MS_TRUE; - clusterInfo* s = node->shapes; + clusterInfo *s = node->shapes; while (s) { double avgx = s->avgx; double avgy = s->avgy; @@ -979,7 +1005,8 @@ static int ValidateTree(msClusterLayerInfo* layerinfo, clusterTreeNode *node) /* Recurse to subnodes if they exist */ for (i = 0; i < 4; i++) { - if (node->subnode[i] && ValidateTree(layerinfo, node->subnode[i]) == MS_FALSE) + if (node->subnode[i] && + ValidateTree(layerinfo, node->subnode[i]) == MS_FALSE) return MS_FALSE; } @@ -989,30 +1016,31 @@ static int ValidateTree(msClusterLayerInfo* layerinfo, clusterTreeNode *node) #endif /* rebuild the clusters according to the current extent */ -int RebuildClusters(layerObj *layer, int isQuery) -{ - mapObj* map; - layerObj* srcLayer; +int RebuildClusters(layerObj *layer, int isQuery) { + mapObj *map; + layerObj *srcLayer; double distance, maxDistanceX, maxDistanceY, cellSizeX, cellSizeY; rectObj searchrect; int status; - clusterInfo* current; + clusterInfo *current; int depth; const char *pszProcessing; #ifdef USE_CLUSTER_EXTERNAL int layerIndex; #endif - reprojectionObj* reprojector = NULL; + reprojectionObj *reprojector = NULL; - msClusterLayerInfo* layerinfo = layer->layerinfo; + msClusterLayerInfo *layerinfo = layer->layerinfo; if (!layerinfo) { - msSetError(MS_MISCERR, "Layer is not open: %s", "RebuildClusters()", layer->name); + msSetError(MS_MISCERR, "Layer is not open: %s", "RebuildClusters()", + layer->name); return MS_FAILURE; } if (!layer->map) { - msSetError(MS_MISCERR, "No map associated with this layer: %s", "RebuildClusters()", layer->name); + msSetError(MS_MISCERR, "No map associated with this layer: %s", + "RebuildClusters()", layer->name); return MS_FAILURE; } @@ -1025,37 +1053,37 @@ int RebuildClusters(layerObj *layer, int isQuery) /* check whether the simplified algorithm was selected */ pszProcessing = msLayerGetProcessingKey(layer, "CLUSTER_ALGORITHM"); - if(pszProcessing && !strncasecmp(pszProcessing,"SIMPLE",6)) - layerinfo->algorithm = MSCLUSTER_ALGORITHM_SIMPLE; + if (pszProcessing && !strncasecmp(pszProcessing, "SIMPLE", 6)) + layerinfo->algorithm = MSCLUSTER_ALGORITHM_SIMPLE; else - layerinfo->algorithm = MSCLUSTER_ALGORITHM_FULL; + layerinfo->algorithm = MSCLUSTER_ALGORITHM_FULL; /* check whether all shapes should be returned from a query */ - if(msLayerGetProcessingKey(layer, "CLUSTER_GET_ALL_SHAPES") != NULL) + if (msLayerGetProcessingKey(layer, "CLUSTER_GET_ALL_SHAPES") != NULL) layerinfo->get_all_shapes = MS_TRUE; else layerinfo->get_all_shapes = MS_FALSE; /* check whether the location of the shapes should be preserved */ - if(msLayerGetProcessingKey(layer, "CLUSTER_KEEP_LOCATIONS") != NULL) + if (msLayerGetProcessingKey(layer, "CLUSTER_KEEP_LOCATIONS") != NULL) layerinfo->keep_locations = MS_TRUE; else - layerinfo->keep_locations = MS_FALSE; + layerinfo->keep_locations = MS_FALSE; - /* check whether the maxdistance and the buffer parameters + /* check whether the maxdistance and the buffer parameters are specified in map units (scale independent clustering) */ - if(msLayerGetProcessingKey(layer, "CLUSTER_USE_MAP_UNITS") != NULL) + if (msLayerGetProcessingKey(layer, "CLUSTER_USE_MAP_UNITS") != NULL) layerinfo->use_map_units = MS_TRUE; else layerinfo->use_map_units = MS_FALSE; /* identify the current extent */ - if(layer->transform == MS_TRUE) + if (layer->transform == MS_TRUE) searchrect = map->extent; else { searchrect.minx = searchrect.miny = 0; - searchrect.maxx = map->width-1; - searchrect.maxy = map->height-1; + searchrect.maxx = map->width - 1; + searchrect.maxy = map->height - 1; } if (searchrect.minx == layerinfo->searchRect.minx && @@ -1072,8 +1100,9 @@ int RebuildClusters(layerObj *layer, int isQuery) layerinfo->searchRect = searchrect; /* reproject the rectangle to layer coordinates */ - if((map->projection.numargs > 0) && (layer->projection.numargs > 0)) - msProjectRect(&map->projection, &layer->projection, &searchrect); /* project the searchrect to source coords */ + if ((map->projection.numargs > 0) && (layer->projection.numargs > 0)) + msProjectRect(&map->projection, &layer->projection, + &searchrect); /* project the searchrect to source coords */ /* determine the compare method */ layerinfo->fnCompare = CompareRectangleRegion; @@ -1086,15 +1115,17 @@ int RebuildClusters(layerObj *layer, int isQuery) depth = 0; distance = layer->cluster.maxdistance; if (layerinfo->use_map_units == MS_TRUE) { - while ((distance < (searchrect.maxx - searchrect.minx) || distance < (searchrect.maxy - searchrect.miny)) && depth <= TREE_MAX_DEPTH) { + while ((distance < (searchrect.maxx - searchrect.minx) || + distance < (searchrect.maxy - searchrect.miny)) && + depth <= TREE_MAX_DEPTH) { distance *= 2; ++depth; } cellSizeX = 1; cellSizeY = 1; - } - else { - while ((distance < map->width || distance < map->height) && depth <= TREE_MAX_DEPTH) { + } else { + while ((distance < map->width || distance < map->height) && + depth <= TREE_MAX_DEPTH) { distance *= 2; ++depth; } @@ -1107,7 +1138,8 @@ int RebuildClusters(layerObj *layer, int isQuery) maxDistanceX = layer->cluster.maxdistance * cellSizeX; maxDistanceY = layer->cluster.maxdistance * cellSizeY; - /* increase the search rectangle so that the neighbouring shapes are also retrieved */ + /* increase the search rectangle so that the neighbouring shapes are also + * retrieved */ searchrect.minx -= layer->cluster.buffer * cellSizeX; searchrect.maxx += layer->cluster.buffer * cellSizeX; searchrect.miny -= layer->cluster.buffer * cellSizeY; @@ -1122,28 +1154,31 @@ int RebuildClusters(layerObj *layer, int isQuery) /* start retrieving the shapes */ status = msLayerWhichShapes(srcLayer, searchrect, isQuery); - if(status == MS_DONE) { + if (status == MS_DONE) { /* no overlap */ return MS_SUCCESS; - } else if(status != MS_SUCCESS) { + } else if (status != MS_SUCCESS) { return MS_FAILURE; } - /* step through the source shapes and populate the quadtree with the tentative clusters */ + /* step through the source shapes and populate the quadtree with the tentative + * clusters */ if ((current = clusterInfoCreate(layerinfo)) == NULL) return MS_FAILURE; #if defined(USE_CLUSTER_EXTERNAL) - if(srcLayer->transform == MS_TRUE && srcLayer->project && layer->transform == MS_TRUE && layer->project &&msProjectionsDiffer(&(srcLayer->projection), &(layer->projection))) - { - reprojector = msProjectCreateReprojector(&srcLayer->projection, &layer->projection); - } + if (srcLayer->transform == MS_TRUE && srcLayer->project && + layer->transform == MS_TRUE && layer->project && + msProjectionsDiffer(&(srcLayer->projection), &(layer->projection))) { + reprojector = + msProjectCreateReprojector(&srcLayer->projection, &layer->projection); + } #endif - - while((status = msLayerNextShape(srcLayer, ¤t->shape)) == MS_SUCCESS) { + + while ((status = msLayerNextShape(srcLayer, ¤t->shape)) == MS_SUCCESS) { #if defined(USE_CLUSTER_EXTERNAL) /* transform the shape to the projection of this layer */ - if( reprojector ) + if (reprojector) msProjectShapeEx(reprojector, ¤t->shape); #endif /* set up positions and variance */ @@ -1157,11 +1192,12 @@ int RebuildClusters(layerObj *layer, int isQuery) current->bounds.maxy = current->y + maxDistanceY; /* if the shape doesn't overlap we must skip it to avoid further issues */ - if(!msRectOverlap(&searchrect, ¤t->bounds)) { + if (!msRectOverlap(&searchrect, ¤t->bounds)) { msFreeShape(¤t->shape); msInitShape(¤t->shape); - msDebug("Skipping an invalid shape falling outside of the given extent\n"); + msDebug( + "Skipping an invalid shape falling outside of the given extent\n"); continue; } @@ -1171,20 +1207,21 @@ int RebuildClusters(layerObj *layer, int isQuery) /* evaluate the group expression */ if (layer->cluster.group.string) - current->group = msClusterGetGroupText(&layer->cluster.group, ¤t->shape); + current->group = + msClusterGetGroupText(&layer->cluster.group, ¤t->shape); if (layerinfo->algorithm == MSCLUSTER_ALGORITHM_FULL) { /*start a query for the related shapes */ findRelatedShapes(layerinfo, layerinfo->root, current); /* add this shape to the tree */ - if (treeNodeAddShape(layerinfo, layerinfo->root, current, depth) != MS_SUCCESS) { + if (treeNodeAddShape(layerinfo, layerinfo->root, current, depth) != + MS_SUCCESS) { clusterInfoDestroyList(layerinfo, current); msProjectDestroyReprojector(reprojector); return MS_FAILURE; } - } - else if (layerinfo->algorithm == MSCLUSTER_ALGORITHM_SIMPLE) { + } else if (layerinfo->algorithm == MSCLUSTER_ALGORITHM_SIMPLE) { /* find a related cluster and try to assign */ layerinfo->rank = 0; layerinfo->current = NULL; @@ -1193,10 +1230,10 @@ int RebuildClusters(layerObj *layer, int isQuery) /* store these points until all clusters are created */ current->next = layerinfo->finalizedSiblings; layerinfo->finalizedSiblings = current; - } - else { + } else { /* if not found add this shape as a new cluster */ - if (treeNodeAddShape(layerinfo, layerinfo->root, current, depth) != MS_SUCCESS) { + if (treeNodeAddShape(layerinfo, layerinfo->root, current, depth) != + MS_SUCCESS) { clusterInfoDestroyList(layerinfo, current); msProjectDestroyReprojector(reprojector); return MS_FAILURE; @@ -1224,12 +1261,15 @@ int RebuildClusters(layerObj *layer, int isQuery) /* pick up the best cluster from the tree and do the finalization */ /* the initial rank must be big enough */ - layerinfo->rank = (searchrect.maxx - searchrect.minx) * (searchrect.maxx - searchrect.minx) + - (searchrect.maxy - searchrect.miny) * (searchrect.maxy - searchrect.miny) + 1; - + layerinfo->rank = (searchrect.maxx - searchrect.minx) * + (searchrect.maxx - searchrect.minx) + + (searchrect.maxy - searchrect.miny) * + (searchrect.maxy - searchrect.miny) + + 1; + layerinfo->current = NULL; findBestCluster(layer, layerinfo, layerinfo->root); - + if (layerinfo->current == NULL) { if (layer->debug >= MS_DEBUGLEVEL_VVV) msDebug("Clustering terminated.\n"); @@ -1238,18 +1278,23 @@ int RebuildClusters(layerObj *layer, int isQuery) /* Update the feature count of the shape */ InitShapeAttributes(layer, layerinfo->current); - + /* collecting the shapes of the cluster */ collectClusterShapes(layerinfo, layerinfo->root, layerinfo->current); if (layer->debug >= MS_DEBUGLEVEL_VVV) { - msDebug("processing cluster %p: rank=%lf fcount=%d ncoll=%d nfin=%d nfins=%d nflt=%d bounds={%lf %lf %lf %lf}\n", layerinfo->current, layerinfo->rank, layerinfo->current->numsiblings + 1, - layerinfo->current->numcollected, layerinfo->numFinalized, layerinfo->numFinalizedSiblings, - layerinfo->numFiltered, layerinfo->current->bounds.minx, layerinfo->current->bounds.miny, - layerinfo->current->bounds.maxx, layerinfo->current->bounds.maxy); + msDebug( + "processing cluster %p: rank=%lf fcount=%d ncoll=%d nfin=%d " + "nfins=%d nflt=%d bounds={%lf %lf %lf %lf}\n", + layerinfo->current, layerinfo->rank, + layerinfo->current->numsiblings + 1, + layerinfo->current->numcollected, layerinfo->numFinalized, + layerinfo->numFinalizedSiblings, layerinfo->numFiltered, + layerinfo->current->bounds.minx, layerinfo->current->bounds.miny, + layerinfo->current->bounds.maxx, layerinfo->current->bounds.maxy); if (layerinfo->current->node) { char pszBuffer[TREE_MAX_DEPTH + 1]; - clusterTreeNode* node = layerinfo->current->node; + clusterTreeNode *node = layerinfo->current->node; int position = node->position; int i = 1; while (position > 0 && i <= TREE_MAX_DEPTH) { @@ -1258,11 +1303,14 @@ int RebuildClusters(layerObj *layer, int isQuery) ++i; } pszBuffer[TREE_MAX_DEPTH] = 0; - - msDebug(" ->node %p: count=%d index=%d pos=%s subn={%p %p %p %p} rect={%lf %lf %lf %lf}\n", - node, node->numshapes, node->index, pszBuffer + TREE_MAX_DEPTH - i + 1, - node->subnode[0], node->subnode[1], node->subnode[2], node->subnode[3], - node->rect.minx, node->rect.miny, node->rect.maxx, node->rect.maxy); + + msDebug(" ->node %p: count=%d index=%d pos=%s subn={%p %p %p %p} " + "rect={%lf %lf %lf %lf}\n", + node, node->numshapes, node->index, + pszBuffer + TREE_MAX_DEPTH - i + 1, node->subnode[0], + node->subnode[1], node->subnode[2], node->subnode[3], + node->rect.minx, node->rect.miny, node->rect.maxx, + node->rect.maxy); } } @@ -1275,7 +1323,7 @@ int RebuildClusters(layerObj *layer, int isQuery) if (layerinfo->current->numsiblings > 0) { /* update the parameters due to the shape removal */ findRelatedShapesRemove(layerinfo, layerinfo->root, layerinfo->current); - + if (layerinfo->current->filter == 0) { /* filtered shapes has no siblings */ layerinfo->current->numsiblings = 0; @@ -1286,7 +1334,7 @@ int RebuildClusters(layerObj *layer, int isQuery) /* update the parameters of the related shapes if any */ if (layerinfo->finalizedSiblings) { current = layerinfo->finalizedSiblings; - while(current) { + while (current) { /* update the parameters due to the shape removal */ findRelatedShapesRemove(layerinfo, layerinfo->root, current); UpdateShapeAttributes(layer, layerinfo->current, current); @@ -1305,7 +1353,7 @@ int RebuildClusters(layerObj *layer, int isQuery) current->next = layerinfo->finalized; layerinfo->finalized = layerinfo->finalizedSiblings; } else { - /* preserve the clustered siblings for later use */ + /* preserve the clustered siblings for later use */ layerinfo->current->siblings = layerinfo->finalizedSiblings; } break; @@ -1332,32 +1380,31 @@ int RebuildClusters(layerObj *layer, int isQuery) } #endif } - } - else if (layerinfo->algorithm == MSCLUSTER_ALGORITHM_SIMPLE) { + } else if (layerinfo->algorithm == MSCLUSTER_ALGORITHM_SIMPLE) { /* assingn stired points to clusters */ while (layerinfo->finalizedSiblings) { current = layerinfo->finalizedSiblings; - layerinfo->rank = maxDistanceX * maxDistanceX + maxDistanceY * maxDistanceY; - layerinfo->current = NULL; + layerinfo->rank = + maxDistanceX * maxDistanceX + maxDistanceY * maxDistanceY; + layerinfo->current = NULL; findRelatedShapes2(layerinfo, layerinfo->root, current); if (layerinfo->current) { - clusterInfo* s = layerinfo->current; + clusterInfo *s = layerinfo->current; /* found a matching cluster */ ++s->numsiblings; /* assign to cluster */ layerinfo->finalizedSiblings = current->next; current->next = s->siblings; s->siblings = current; - } - else { + } else { /* this appears to be a bug */ layerinfo->finalizedSiblings = current->next; current->next = layerinfo->filtered; layerinfo->filtered = current; ++layerinfo->numFiltered; - } + } } - + /* collecting the shapes of the cluster */ collectClusterShapes2(layer, layerinfo, layerinfo->root); } @@ -1369,9 +1416,8 @@ int RebuildClusters(layerObj *layer, int isQuery) } /* Close the the combined layer */ -int msClusterLayerClose(layerObj *layer) -{ - msClusterLayerInfo* layerinfo = (msClusterLayerInfo*)layer->layerinfo; +int msClusterLayerClose(layerObj *layer) { + msClusterLayerInfo *layerinfo = (msClusterLayerInfo *)layer->layerinfo; if (!layerinfo) return MS_SUCCESS; @@ -1386,39 +1432,35 @@ int msClusterLayerClose(layerObj *layer) #ifndef USE_CLUSTER_EXTERNAL /* switch back to the source layer vtable */ - if( msInitializeVirtualTable(layer) != MS_SUCCESS ) - return MS_FAILURE; + if (msInitializeVirtualTable(layer) != MS_SUCCESS) + return MS_FAILURE; #endif return MS_SUCCESS; } /* Return MS_TRUE if layer is open, MS_FALSE otherwise. */ -int msClusterLayerIsOpen(layerObj *layer) -{ +int msClusterLayerIsOpen(layerObj *layer) { if (layer->layerinfo) - return(MS_TRUE); + return (MS_TRUE); else - return(MS_FALSE); + return (MS_FALSE); } /* Free the itemindexes array in a layer. */ -void msClusterLayerFreeItemInfo(layerObj *layer) -{ +void msClusterLayerFreeItemInfo(layerObj *layer) { msFree(layer->iteminfo); layer->iteminfo = NULL; } - /* allocate the iteminfo index array - same order as the item list */ -int msClusterLayerInitItemInfo(layerObj *layer) -{ +int msClusterLayerInitItemInfo(layerObj *layer) { int i, numitems; int *itemindexes; - msClusterLayerInfo* layerinfo = (msClusterLayerInfo*)layer->layerinfo; + msClusterLayerInfo *layerinfo = (msClusterLayerInfo *)layer->layerinfo; - if(layer->numitems == 0) { + if (layer->numitems == 0) { return MS_SUCCESS; } @@ -1428,7 +1470,7 @@ int msClusterLayerInitItemInfo(layerObj *layer) /* Cleanup any previous item selection */ msClusterLayerFreeItemInfo(layer); - layer->iteminfo = (int *) msSmallMalloc(sizeof(int) * layer->numitems); + layer->iteminfo = (int *)msSmallMalloc(sizeof(int) * layer->numitems); itemindexes = layer->iteminfo; @@ -1446,7 +1488,7 @@ int msClusterLayerInitItemInfo(layerObj *layer) } msLayerFreeItemInfo(&layerinfo->srcLayer); - if(layerinfo->srcLayer.items) { + if (layerinfo->srcLayer.items) { msFreeCharArray(layerinfo->srcLayer.items, layerinfo->srcLayer.numitems); layerinfo->srcLayer.items = NULL; layerinfo->srcLayer.numitems = 0; @@ -1454,19 +1496,24 @@ int msClusterLayerInitItemInfo(layerObj *layer) if (numitems > 0) { /* now allocate and set the layer item parameters */ - layerinfo->srcLayer.items = (char **)msSmallMalloc(sizeof(char *)*numitems); + layerinfo->srcLayer.items = + (char **)msSmallMalloc(sizeof(char *) * numitems); layerinfo->srcLayer.numitems = numitems; for (i = 0; i < layer->numitems; i++) { if (itemindexes[i] >= 0) { if (EQUALN(layer->items[i], "Min:", 4)) - layerinfo->srcLayer.items[itemindexes[i]] = msStrdup(layer->items[i] + 4); + layerinfo->srcLayer.items[itemindexes[i]] = + msStrdup(layer->items[i] + 4); else if (EQUALN(layer->items[i], "Max:", 4)) - layerinfo->srcLayer.items[itemindexes[i]] = msStrdup(layer->items[i] + 4); + layerinfo->srcLayer.items[itemindexes[i]] = + msStrdup(layer->items[i] + 4); else if (EQUALN(layer->items[i], "Sum:", 4)) - layerinfo->srcLayer.items[itemindexes[i]] = msStrdup(layer->items[i] + 4); + layerinfo->srcLayer.items[itemindexes[i]] = + msStrdup(layer->items[i] + 4); else if (EQUALN(layer->items[i], "Count:", 6)) - layerinfo->srcLayer.items[itemindexes[i]] = msStrdup(layer->items[i] + 6); + layerinfo->srcLayer.items[itemindexes[i]] = + msStrdup(layer->items[i] + 6); else layerinfo->srcLayer.items[itemindexes[i]] = msStrdup(layer->items[i]); } @@ -1480,38 +1527,43 @@ int msClusterLayerInitItemInfo(layerObj *layer) } /* Execute a query for this layer */ -int msClusterLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) -{ +int msClusterLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) { (void)rect; /* rebuild the cluster database */ return RebuildClusters(layer, isQuery); } -static int prepareShape(layerObj* layer, msClusterLayerInfo* layerinfo, clusterInfo* current, shapeObj* shape) -{ +static int prepareShape(layerObj *layer, msClusterLayerInfo *layerinfo, + clusterInfo *current, shapeObj *shape) { (void)layer; if (msCopyShape(&(current->shape), shape) != MS_SUCCESS) { - msSetError(MS_SHPERR, "Cannot retrieve inline shape. There some problem with the shape", "msClusterLayerNextShape()"); + msSetError( + MS_SHPERR, + "Cannot retrieve inline shape. There some problem with the shape", + "msClusterLayerNextShape()"); return MS_FAILURE; } /* update the positions of the cluster shape */ if (layerinfo->keep_locations == MS_FALSE) { - shape->line[0].point[0].x = shape->bounds.minx = shape->bounds.maxx = current->avgx; - shape->line[0].point[0].y = shape->bounds.miny = shape->bounds.maxy = current->avgy; + shape->line[0].point[0].x = shape->bounds.minx = shape->bounds.maxx = + current->avgx; + shape->line[0].point[0].y = shape->bounds.miny = shape->bounds.maxy = + current->avgy; } return MS_SUCCESS; } /* Execute a query on the DB based on fid. */ -int msClusterLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) -{ - clusterInfo* current; - msClusterLayerInfo* layerinfo = (msClusterLayerInfo*)layer->layerinfo; +int msClusterLayerGetShape(layerObj *layer, shapeObj *shape, + resultObj *record) { + clusterInfo *current; + msClusterLayerInfo *layerinfo = (msClusterLayerInfo *)layer->layerinfo; if (!layerinfo) { - msSetError(MS_MISCERR, "Layer not open: %s", "msClusterLayerGetShape()", layer->name); + msSetError(MS_MISCERR, "Layer not open: %s", "msClusterLayerGetShape()", + layer->name); return MS_FAILURE; } @@ -1524,7 +1576,8 @@ int msClusterLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) } if (current == NULL) { - msSetError(MS_SHPERR, "No feature with this index.", "msClusterLayerGetShape()"); + msSetError(MS_SHPERR, "No feature with this index.", + "msClusterLayerGetShape()"); return MS_FAILURE; } @@ -1534,13 +1587,13 @@ int msClusterLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) /* find the next shape with the appropriate shape type */ /* also, load in the attribute data */ /* MS_DONE => no more data */ -int msClusterLayerNextShape(layerObj *layer, shapeObj *shape) -{ +int msClusterLayerNextShape(layerObj *layer, shapeObj *shape) { int rv; - msClusterLayerInfo* layerinfo = (msClusterLayerInfo*)layer->layerinfo; + msClusterLayerInfo *layerinfo = (msClusterLayerInfo *)layer->layerinfo; if (!layerinfo) { - msSetError(MS_MISCERR, "Layer not open: %s", "msClusterLayerNextShape()", layer->name); + msSetError(MS_MISCERR, "Layer not open: %s", "msClusterLayerNextShape()", + layer->name); return MS_FAILURE; } @@ -1555,11 +1608,10 @@ int msClusterLayerNextShape(layerObj *layer, shapeObj *shape) } /* Query for the items collection */ -int msClusterLayerGetItems(layerObj *layer) -{ +int msClusterLayerGetItems(layerObj *layer) { /* we support certain built in attributes */ layer->numitems = MSCLUSTER_NUMITEMS; - layer->items = msSmallMalloc(sizeof(char*) * (layer->numitems)); + layer->items = msSmallMalloc(sizeof(char *) * (layer->numitems)); layer->items[0] = msStrdup(MSCLUSTER_FEATURECOUNT); layer->items[1] = msStrdup(MSCLUSTER_GROUP); layer->items[2] = msStrdup(MSCLUSTER_BASEFID); @@ -1567,10 +1619,8 @@ int msClusterLayerGetItems(layerObj *layer) return msClusterLayerInitItemInfo(layer); } - -int msClusterLayerGetNumFeatures(layerObj *layer) -{ - msClusterLayerInfo* layerinfo = (msClusterLayerInfo*)layer->layerinfo; +int msClusterLayerGetNumFeatures(layerObj *layer) { + msClusterLayerInfo *layerinfo = (msClusterLayerInfo *)layer->layerinfo; if (!layerinfo) return -1; @@ -1579,8 +1629,7 @@ int msClusterLayerGetNumFeatures(layerObj *layer) } static int msClusterLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, - shapeObj* shape) -{ + shapeObj *shape) { (void)map; (void)layer; (void)c; @@ -1589,9 +1638,9 @@ static int msClusterLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, return MS_SUCCESS; } -msClusterLayerInfo* msClusterInitialize(layerObj *layer) -{ - msClusterLayerInfo *layerinfo =(msClusterLayerInfo*)msSmallMalloc(sizeof(msClusterLayerInfo)); +msClusterLayerInfo *msClusterInitialize(layerObj *layer) { + msClusterLayerInfo *layerinfo = + (msClusterLayerInfo *)msSmallMalloc(sizeof(msClusterLayerInfo)); layer->layerinfo = layerinfo; @@ -1620,24 +1669,23 @@ msClusterLayerInfo* msClusterInitialize(layerObj *layer) return layerinfo; } -int msClusterLayerOpen(layerObj *layer) -{ - msClusterLayerInfo* layerinfo; +int msClusterLayerOpen(layerObj *layer) { + msClusterLayerInfo *layerinfo; if (layer->type != MS_LAYER_POINT) { - msSetError(MS_MISCERR, "Only point layers are supported for clustering: %s", "msClusterLayerOpen()", layer->name); + msSetError(MS_MISCERR, "Only point layers are supported for clustering: %s", + "msClusterLayerOpen()", layer->name); return MS_FAILURE; } if (!layer->map) return MS_FAILURE; - if (layer->layerinfo) - { + if (layer->layerinfo) { if (layer->vtable->LayerOpen != msClusterLayerOpen) - msLayerClose(layer); + msLayerClose(layer); else - return MS_SUCCESS; /* already open */ + return MS_SUCCESS; /* already open */ } layerinfo = msClusterInitialize(layer); @@ -1646,7 +1694,7 @@ int msClusterLayerOpen(layerObj *layer) return MS_FAILURE; /* prepare the source layer */ - if(initLayer(&layerinfo->srcLayer, layer->map) == -1) + if (initLayer(&layerinfo->srcLayer, layer->map) == -1) return MS_FAILURE; #ifdef USE_CLUSTER_EXTERNAL @@ -1656,17 +1704,21 @@ int msClusterLayerOpen(layerObj *layer) layerIndex = msGetLayerIndex(layer->map, layer->connection); if (layerIndex < 0 && layerIndex >= layer->map->numlayers) { - msSetError(MS_MISCERR, "No source layers specified in layer: %s", "msClusterLayerOpen()", layer->name); + msSetError(MS_MISCERR, "No source layers specified in layer: %s", + "msClusterLayerOpen()", layer->name); return MS_FAILURE; } if (layer->map->layers[layerIndex]->type != MS_LAYER_POINT) { - msSetError(MS_MISCERR, "Only point layers are supported for cluster data source: %s", "msClusterLayerOpen()", layer->name); + msSetError(MS_MISCERR, + "Only point layers are supported for cluster data source: %s", + "msClusterLayerOpen()", layer->name); return MS_FAILURE; } - if (msCopyLayer(&layerinfo->srcLayer, layer->map->layers[layerIndex]) != MS_SUCCESS) - return(MS_FAILURE); + if (msCopyLayer(&layerinfo->srcLayer, layer->map->layers[layerIndex]) != + MS_SUCCESS) + return (MS_FAILURE); #else /* hook the vtable to this driver, will be restored in LayerClose*/ if (!layer->vtable) { @@ -1677,79 +1729,84 @@ int msClusterLayerOpen(layerObj *layer) msClusterLayerCopyVirtualTable(layer->vtable); if (msCopyLayer(&layerinfo->srcLayer, layer) != MS_SUCCESS) - return(MS_FAILURE); + return (MS_FAILURE); #endif /* disable the connection pool for this layer */ msLayerSetProcessingKey(&layerinfo->srcLayer, "CLOSE_CONNECTION", "ALWAYS"); /* open the source layer */ - if ( !layerinfo->srcLayer.vtable) { + if (!layerinfo->srcLayer.vtable) { if (msInitializeVirtualTable(&layerinfo->srcLayer) != MS_SUCCESS) return MS_FAILURE; } - if (layerinfo->srcLayer.vtable->LayerOpen(&layerinfo->srcLayer) != MS_SUCCESS) { + if (layerinfo->srcLayer.vtable->LayerOpen(&layerinfo->srcLayer) != + MS_SUCCESS) { return MS_FAILURE; } return MS_SUCCESS; } -int msClusterLayerTranslateFilter(layerObj *layer, expressionObj *filter, char *filteritem) -{ +int msClusterLayerTranslateFilter(layerObj *layer, expressionObj *filter, + char *filteritem) { (void)filter; - msClusterLayerInfo* layerinfo = layer->layerinfo; + msClusterLayerInfo *layerinfo = layer->layerinfo; if (!layerinfo) { - msSetError(MS_MISCERR, "Layer is not open: %s", "msClusterLayerTranslateFilter()", layer->name); + msSetError(MS_MISCERR, "Layer is not open: %s", + "msClusterLayerTranslateFilter()", layer->name); return MS_FAILURE; } - if (layerinfo->srcLayer.filter.type == MS_EXPRESSION && layerinfo->srcLayer.filter.tokens == NULL) - msTokenizeExpression(&(layerinfo->srcLayer.filter), layer->items, &(layer->numitems)); + if (layerinfo->srcLayer.filter.type == MS_EXPRESSION && + layerinfo->srcLayer.filter.tokens == NULL) + msTokenizeExpression(&(layerinfo->srcLayer.filter), layer->items, + &(layer->numitems)); - return layerinfo->srcLayer.vtable->LayerTranslateFilter(&layerinfo->srcLayer, &layerinfo->srcLayer.filter, filteritem); + return layerinfo->srcLayer.vtable->LayerTranslateFilter( + &layerinfo->srcLayer, &layerinfo->srcLayer.filter, filteritem); } -char* msClusterLayerEscapeSQLParam(layerObj *layer, const char* pszString) -{ - msClusterLayerInfo* layerinfo = layer->layerinfo; +char *msClusterLayerEscapeSQLParam(layerObj *layer, const char *pszString) { + msClusterLayerInfo *layerinfo = layer->layerinfo; if (!layerinfo) { - msSetError(MS_MISCERR, "Layer is not open: %s", "msClusterLayerEscapeSQLParam()", layer->name); + msSetError(MS_MISCERR, "Layer is not open: %s", + "msClusterLayerEscapeSQLParam()", layer->name); return msStrdup(""); } - return layerinfo->srcLayer.vtable->LayerEscapeSQLParam(&layerinfo->srcLayer, pszString); + return layerinfo->srcLayer.vtable->LayerEscapeSQLParam(&layerinfo->srcLayer, + pszString); } -int msClusterLayerGetAutoProjection(layerObj *layer, projectionObj* projection) -{ - msClusterLayerInfo* layerinfo = layer->layerinfo; +int msClusterLayerGetAutoProjection(layerObj *layer, + projectionObj *projection) { + msClusterLayerInfo *layerinfo = layer->layerinfo; if (!layerinfo) { - msSetError(MS_MISCERR, "Layer is not open: %s", "msClusterLayerGetAutoProjection()", layer->name); + msSetError(MS_MISCERR, "Layer is not open: %s", + "msClusterLayerGetAutoProjection()", layer->name); return MS_FAILURE; } - return layerinfo->srcLayer.vtable->LayerGetAutoProjection(&layerinfo->srcLayer, projection); + return layerinfo->srcLayer.vtable->LayerGetAutoProjection( + &layerinfo->srcLayer, projection); } -int msClusterLayerGetPaging(layerObj *layer) -{ +int msClusterLayerGetPaging(layerObj *layer) { (void)layer; return MS_FALSE; } -void msClusterLayerEnablePaging(layerObj *layer, int value) -{ +void msClusterLayerEnablePaging(layerObj *layer, int value) { (void)layer; (void)value; } -void msClusterLayerCopyVirtualTable(layerVTableObj* vtable) -{ +void msClusterLayerCopyVirtualTable(layerVTableObj *vtable) { vtable->LayerInitItemInfo = msClusterLayerInitItemInfo; vtable->LayerFreeItemInfo = msClusterLayerFreeItemInfo; vtable->LayerOpen = msClusterLayerOpen; @@ -1778,9 +1835,8 @@ void msClusterLayerCopyVirtualTable(layerVTableObj* vtable) #ifdef USE_CLUSTER_PLUGIN -MS_DLL_EXPORT int -PluginInitializeVirtualTable(layerVTableObj* vtable, layerObj *layer) -{ +MS_DLL_EXPORT int PluginInitializeVirtualTable(layerVTableObj *vtable, + layerObj *layer) { assert(layer != NULL); assert(vtable != NULL); @@ -1791,8 +1847,7 @@ PluginInitializeVirtualTable(layerVTableObj* vtable, layerObj *layer) #endif -int msClusterLayerInitializeVirtualTable(layerObj *layer) -{ +int msClusterLayerInitializeVirtualTable(layerObj *layer) { assert(layer != NULL); assert(layer->vtable != NULL); diff --git a/mapcompositingfilter.c b/mapcompositingfilter.c index 0f67eec7c4..d75b82cab8 100644 --- a/mapcompositingfilter.c +++ b/mapcompositingfilter.c @@ -27,194 +27,208 @@ *****************************************************************************/ #include "mapserver.h" #include -#define pixmove(rb,srcx,srcy,dstx,dsty) \ - memcpy(rb->data.rgba.pixels+dsty*rb->data.rgba.row_step+dstx*4,\ - rb->data.rgba.pixels+srcy*rb->data.rgba.row_step+srcx*4,\ - 4) -#define pixerase(rb,x,y) memset(rb->data.rgba.pixels+y*rb->data.rgba.row_step+x*4,0,4) +#define pixmove(rb, srcx, srcy, dstx, dsty) \ + memcpy(rb->data.rgba.pixels + dsty * rb->data.rgba.row_step + dstx * 4, \ + rb->data.rgba.pixels + srcy * rb->data.rgba.row_step + srcx * 4, 4) +#define pixerase(rb, x, y) \ + memset(rb->data.rgba.pixels + y * rb->data.rgba.row_step + x * 4, 0, 4) -void msApplyTranslationCompositingFilter(rasterBufferObj *rb, int xtrans, int ytrans) { - int src_sx,src_sy,dst_sx,dst_sy; - if((unsigned)abs(xtrans)>=rb->width || (unsigned)abs(ytrans)>=rb->height) { - for(unsigned y = 0; yheight; y++) - for(unsigned x = 0; xwidth; x++) - pixerase(rb,x,y); +void msApplyTranslationCompositingFilter(rasterBufferObj *rb, int xtrans, + int ytrans) { + int src_sx, src_sy, dst_sx, dst_sy; + if ((unsigned)abs(xtrans) >= rb->width || + (unsigned)abs(ytrans) >= rb->height) { + for (unsigned y = 0; y < rb->height; y++) + for (unsigned x = 0; x < rb->width; x++) + pixerase(rb, x, y); } - if(xtrans == 0 && ytrans == 0) + if (xtrans == 0 && ytrans == 0) return; - if(xtrans>=0) { - if(ytrans>=0) { + if (xtrans >= 0) { + if (ytrans >= 0) { src_sx = rb->width - xtrans - 1; src_sy = rb->height - ytrans - 1; dst_sx = rb->width - 1; - dst_sy = rb->height -1; - for(int y = src_sy,dst_y= dst_sy;y>=0;y--,dst_y--) { - for(int x = src_sx,dst_x= dst_sx;x>=0;x--,dst_x--) { - pixmove(rb,x,y,dst_x,dst_y); + dst_sy = rb->height - 1; + for (int y = src_sy, dst_y = dst_sy; y >= 0; y--, dst_y--) { + for (int x = src_sx, dst_x = dst_sx; x >= 0; x--, dst_x--) { + pixmove(rb, x, y, dst_x, dst_y); } } - for(int y=0;ywidth;x++) - pixerase(rb,x,y); - for(unsigned y=ytrans;yheight;y++) - for(int x=0;xwidth; x++) + pixerase(rb, x, y); + for (unsigned y = ytrans; y < rb->height; y++) + for (int x = 0; x < xtrans; x++) + pixerase(rb, x, y); } else { src_sx = rb->width - xtrans - 1; - src_sy = - ytrans; + src_sy = -ytrans; dst_sx = rb->width - 1; dst_sy = 0; - for(unsigned y = src_sy,dst_y= dst_sy;yheight;y++,dst_y++) { - for(int x = src_sx,dst_x= dst_sx;x>=0;x--,dst_x--) { - pixmove(rb,x,y,dst_x,dst_y); + for (unsigned y = src_sy, dst_y = dst_sy; y < rb->height; y++, dst_y++) { + for (int x = src_sx, dst_x = dst_sx; x >= 0; x--, dst_x--) { + pixmove(rb, x, y, dst_x, dst_y); } } - for(unsigned y=0;yheight+ytrans;y++) - for(int x=0;xheight+ytrans;yheight;y++) - for(unsigned x=0;xwidth;x++) - pixerase(rb,x,y); + for (unsigned y = 0; y < rb->height + ytrans; y++) + for (int x = 0; x < xtrans; x++) + pixerase(rb, x, y); + for (unsigned y = rb->height + ytrans; y < rb->height; y++) + for (unsigned x = 0; x < rb->width; x++) + pixerase(rb, x, y); } } else { - if(ytrans>=0) { - src_sx = - xtrans; + if (ytrans >= 0) { + src_sx = -xtrans; src_sy = rb->height - ytrans - 1; dst_sx = 0; - dst_sy = rb->height -1; - for(int y = src_sy,dst_y= dst_sy;y>=0;y--,dst_y--) { - for(unsigned x = src_sx,dst_x= dst_sx;xwidth;x++,dst_x++) { - pixmove(rb,x,y,dst_x,dst_y); + dst_sy = rb->height - 1; + for (int y = src_sy, dst_y = dst_sy; y >= 0; y--, dst_y--) { + for (unsigned x = src_sx, dst_x = dst_sx; x < rb->width; x++, dst_x++) { + pixmove(rb, x, y, dst_x, dst_y); } } - for(int y=0;ywidth;x++) - pixerase(rb,x,y); - for(unsigned y=ytrans;yheight;y++) - for(unsigned x=rb->width+xtrans;xwidth;x++) - pixerase(rb,x,y); + for (int y = 0; y < ytrans; y++) + for (unsigned x = 0; x < rb->width; x++) + pixerase(rb, x, y); + for (unsigned y = ytrans; y < rb->height; y++) + for (unsigned x = rb->width + xtrans; x < rb->width; x++) + pixerase(rb, x, y); } else { - src_sx = - xtrans; - src_sy = - ytrans; + src_sx = -xtrans; + src_sy = -ytrans; dst_sx = 0; dst_sy = 0; - for(unsigned y = src_sy,dst_y= dst_sy;yheight;y++,dst_y++) { - for(unsigned x = src_sx,dst_x= dst_sx;xwidth;x++,dst_x++) { - pixmove(rb,x,y,dst_x,dst_y); + for (unsigned y = src_sy, dst_y = dst_sy; y < rb->height; y++, dst_y++) { + for (unsigned x = src_sx, dst_x = dst_sx; x < rb->width; x++, dst_x++) { + pixmove(rb, x, y, dst_x, dst_y); } } - for(unsigned y=0;yheight+ytrans;y++) - for(unsigned x=rb->width+xtrans;xwidth;x++) - pixerase(rb,x,y); - for(unsigned y=rb->height+ytrans;yheight;y++) - for(unsigned x=0;xwidth;x++) - pixerase(rb,x,y); + for (unsigned y = 0; y < rb->height + ytrans; y++) + for (unsigned x = rb->width + xtrans; x < rb->width; x++) + pixerase(rb, x, y); + for (unsigned y = rb->height + ytrans; y < rb->height; y++) + for (unsigned x = 0; x < rb->width; x++) + pixerase(rb, x, y); } } } void msApplyBlackeningCompositingFilter(rasterBufferObj *rb) { - unsigned char *r,*g,*b; - for(unsigned row=0;rowheight;row++) { - r = rb->data.rgba.r + row*rb->data.rgba.row_step; - g = rb->data.rgba.g + row*rb->data.rgba.row_step; - b = rb->data.rgba.b + row*rb->data.rgba.row_step; - for(unsigned col=0;colwidth;col++) { + unsigned char *r, *g, *b; + for (unsigned row = 0; row < rb->height; row++) { + r = rb->data.rgba.r + row * rb->data.rgba.row_step; + g = rb->data.rgba.g + row * rb->data.rgba.row_step; + b = rb->data.rgba.b + row * rb->data.rgba.row_step; + for (unsigned col = 0; col < rb->width; col++) { *r = *g = *b = 0; - r+=4;g+=4;b+=4; - } + r += 4; + g += 4; + b += 4; + } } } void msApplyWhiteningCompositingFilter(rasterBufferObj *rb) { - unsigned char *r,*g,*b,*a; - for(unsigned row=0;rowheight;row++) { - r = rb->data.rgba.r + row*rb->data.rgba.row_step; - g = rb->data.rgba.g + row*rb->data.rgba.row_step; - b = rb->data.rgba.b + row*rb->data.rgba.row_step; - a = rb->data.rgba.a + row*rb->data.rgba.row_step; - for(unsigned col=0;colwidth;col++) { + unsigned char *r, *g, *b, *a; + for (unsigned row = 0; row < rb->height; row++) { + r = rb->data.rgba.r + row * rb->data.rgba.row_step; + g = rb->data.rgba.g + row * rb->data.rgba.row_step; + b = rb->data.rgba.b + row * rb->data.rgba.row_step; + a = rb->data.rgba.a + row * rb->data.rgba.row_step; + for (unsigned col = 0; col < rb->width; col++) { *r = *g = *b = *a; - r+=4;g+=4;b+=4;a+=4; - } + r += 4; + g += 4; + b += 4; + a += 4; + } } } void msApplyGrayscaleCompositingFilter(rasterBufferObj *rb) { - unsigned char *r,*g,*b; - for(unsigned row=0;rowheight;row++) { - r = rb->data.rgba.r + row*rb->data.rgba.row_step; - g = rb->data.rgba.g + row*rb->data.rgba.row_step; - b = rb->data.rgba.b + row*rb->data.rgba.row_step; - for(unsigned col=0;colwidth;col++) { + unsigned char *r, *g, *b; + for (unsigned row = 0; row < rb->height; row++) { + r = rb->data.rgba.r + row * rb->data.rgba.row_step; + g = rb->data.rgba.g + row * rb->data.rgba.row_step; + b = rb->data.rgba.b + row * rb->data.rgba.row_step; + for (unsigned col = 0; col < rb->width; col++) { unsigned int mix = (unsigned int)*r + (unsigned int)*g + (unsigned int)*b; - mix /=3; + mix /= 3; *r = *g = *b = (unsigned char)mix; - r+=4;g+=4;b+=4; - } + r += 4; + g += 4; + b += 4; + } } } -int msApplyCompositingFilter(mapObj *map, rasterBufferObj *rb, CompositingFilter *filter) { +int msApplyCompositingFilter(mapObj *map, rasterBufferObj *rb, + CompositingFilter *filter) { int rstatus; regex_t regex; regmatch_t pmatch[3]; - + /* test for blurring filter */ regcomp(®ex, "blur\\(([0-9]+)\\)", REG_EXTENDED); rstatus = regexec(®ex, filter->filter, 2, pmatch, 0); regfree(®ex); - if(!rstatus) { + if (!rstatus) { char *rad = malloc(pmatch[1].rm_eo - pmatch[1].rm_so + 1); unsigned int irad; - strncpy(rad,filter->filter+pmatch[1].rm_so,pmatch[1].rm_eo-pmatch[1].rm_so); - rad[pmatch[1].rm_eo - pmatch[1].rm_so]=0; - //msDebug("got blur filter with radius %s\n",rad); + strncpy(rad, filter->filter + pmatch[1].rm_so, + pmatch[1].rm_eo - pmatch[1].rm_so); + rad[pmatch[1].rm_eo - pmatch[1].rm_so] = 0; + // msDebug("got blur filter with radius %s\n",rad); irad = atoi(rad); free(rad); - irad = MS_NINT(irad*map->resolution/map->defresolution); - msApplyBlurringCompositingFilter(rb,irad); + irad = MS_NINT(irad * map->resolution / map->defresolution); + msApplyBlurringCompositingFilter(rb, irad); return MS_SUCCESS; } - + /* test for translation filter */ regcomp(®ex, "translate\\((-?[0-9]+),(-?[0-9]+)\\)", REG_EXTENDED); rstatus = regexec(®ex, filter->filter, 3, pmatch, 0); regfree(®ex); - if(!rstatus) { + if (!rstatus) { char *num; - int xtrans,ytrans; + int xtrans, ytrans; num = malloc(pmatch[1].rm_eo - pmatch[1].rm_so + 1); - strncpy(num,filter->filter+pmatch[1].rm_so,pmatch[1].rm_eo-pmatch[1].rm_so); - num[pmatch[1].rm_eo - pmatch[1].rm_so]=0; + strncpy(num, filter->filter + pmatch[1].rm_so, + pmatch[1].rm_eo - pmatch[1].rm_so); + num[pmatch[1].rm_eo - pmatch[1].rm_so] = 0; xtrans = atoi(num); free(num); num = malloc(pmatch[2].rm_eo - pmatch[2].rm_so + 1); - strncpy(num,filter->filter+pmatch[2].rm_so,pmatch[2].rm_eo-pmatch[2].rm_so); - num[pmatch[2].rm_eo - pmatch[2].rm_so]=0; + strncpy(num, filter->filter + pmatch[2].rm_so, + pmatch[2].rm_eo - pmatch[2].rm_so); + num[pmatch[2].rm_eo - pmatch[2].rm_so] = 0; ytrans = atoi(num); free(num); - //msDebug("got translation filter of radius %d,%d\n",xtrans,ytrans); - xtrans = MS_NINT(xtrans*map->resolution/map->defresolution); - ytrans = MS_NINT(ytrans*map->resolution/map->defresolution); - msApplyTranslationCompositingFilter(rb,xtrans,ytrans); + // msDebug("got translation filter of radius %d,%d\n",xtrans,ytrans); + xtrans = MS_NINT(xtrans * map->resolution / map->defresolution); + ytrans = MS_NINT(ytrans * map->resolution / map->defresolution); + msApplyTranslationCompositingFilter(rb, xtrans, ytrans); return MS_SUCCESS; } - + /* test for grayscale filter */ - if(!strncmp(filter->filter,"grayscale()",strlen("grayscale()"))) { + if (!strncmp(filter->filter, "grayscale()", strlen("grayscale()"))) { msApplyGrayscaleCompositingFilter(rb); return MS_SUCCESS; } - if(!strncmp(filter->filter,"blacken()",strlen("blacken()"))) { + if (!strncmp(filter->filter, "blacken()", strlen("blacken()"))) { msApplyBlackeningCompositingFilter(rb); return MS_SUCCESS; } - if(!strncmp(filter->filter,"whiten()",strlen("whiten()"))) { + if (!strncmp(filter->filter, "whiten()", strlen("whiten()"))) { msApplyWhiteningCompositingFilter(rb); return MS_SUCCESS; } - - msSetError(MS_MISCERR,"unknown compositing filter (%s)", "msApplyCompositingFilter()", filter->filter); + + msSetError(MS_MISCERR, "unknown compositing filter (%s)", + "msApplyCompositingFilter()", filter->filter); return MS_FAILURE; } diff --git a/mapcontext.c b/mapcontext.c index e22d941f5c..28cf429402 100644 --- a/mapcontext.c +++ b/mapcontext.c @@ -30,7 +30,7 @@ #include "mapows.h" #include "cpl_vsi.h" - +#include "cpl_conv.h" #if defined(USE_WMS_LYR) @@ -46,16 +46,15 @@ ** Take the filename in argument ** Return value must be freed by caller */ -char * msGetMapContextFileText(char *filename) -{ +static char *msGetMapContextFileText(const char *filename) { char *pszBuffer; VSILFILE *stream; - int nLength; + vsi_l_offset nLength; /* open file */ - if(filename != NULL && strlen(filename) > 0) { + if (filename != NULL && strlen(filename) > 0) { stream = VSIFOpenL(filename, "rb"); - if(!stream) { + if (!stream) { msSetError(MS_IOERR, "(%s)", "msGetMapContextFileText()", filename); return NULL; } @@ -64,31 +63,36 @@ char * msGetMapContextFileText(char *filename) return NULL; } - VSIFSeekL( stream, 0, SEEK_END ); - nLength = (int) VSIFTellL( stream ); - VSIFSeekL( stream, 0, SEEK_SET ); + VSIFSeekL(stream, 0, SEEK_END); + nLength = VSIFTellL(stream); + VSIFSeekL(stream, 0, SEEK_SET); + if (nLength > 100 * 1024 * 1024U) { + msSetError(MS_MEMERR, "(%s): too big file", "msGetMapContextFileText()", + filename); + VSIFCloseL(stream); + return NULL; + } - pszBuffer = (char *) malloc(nLength+1); - if( pszBuffer == NULL ) { + pszBuffer = (char *)malloc((size_t)nLength + 1); + if (pszBuffer == NULL) { msSetError(MS_MEMERR, "(%s)", "msGetMapContextFileText()", filename); - VSIFCloseL( stream ); + VSIFCloseL(stream); return NULL; } - if(VSIFReadL( pszBuffer, nLength, 1, stream ) == 0) { - free( pszBuffer ); - VSIFCloseL( stream ); + if (VSIFReadL(pszBuffer, nLength, 1, stream) == 0) { + free(pszBuffer); + VSIFCloseL(stream); msSetError(MS_IOERR, "(%s)", "msGetMapContextFileText()", filename); return NULL; } pszBuffer[nLength] = '\0'; - VSIFCloseL( stream ); + VSIFCloseL(stream); return pszBuffer; } - #if defined(USE_WMS_LYR) /* @@ -97,15 +101,14 @@ char * msGetMapContextFileText(char *filename) **Get the xml value and put it in the hash table ** */ -int msGetMapContextXMLHashValue( CPLXMLNode *psRoot, const char *pszXMLPath, - hashTableObj *metadata, char *pszMetadata ) -{ +int msGetMapContextXMLHashValue(CPLXMLNode *psRoot, const char *pszXMLPath, + hashTableObj *metadata, char *pszMetadata) { char *pszValue; - pszValue = (char*)CPLGetXMLValue( psRoot, pszXMLPath, NULL); - if(pszValue != NULL) { - if( metadata != NULL ) { - msInsertHashTable(metadata, pszMetadata, pszValue ); + pszValue = (char *)CPLGetXMLValue(psRoot, pszXMLPath, NULL); + if (pszValue != NULL) { + if (metadata != NULL) { + msInsertHashTable(metadata, pszMetadata, pszValue); } else { return MS_FAILURE; } @@ -122,18 +125,17 @@ int msGetMapContextXMLHashValue( CPLXMLNode *psRoot, const char *pszXMLPath, **Get the xml value and put it in the hash table ** */ -int msGetMapContextXMLHashValueDecode( CPLXMLNode *psRoot, - const char *pszXMLPath, - hashTableObj *metadata, - char *pszMetadata ) -{ +int msGetMapContextXMLHashValueDecode(CPLXMLNode *psRoot, + const char *pszXMLPath, + hashTableObj *metadata, + char *pszMetadata) { char *pszValue; - pszValue = (char*)CPLGetXMLValue( psRoot, pszXMLPath, NULL); - if(pszValue != NULL) { - if( metadata != NULL ) { + pszValue = (char *)CPLGetXMLValue(psRoot, pszXMLPath, NULL); + if (pszValue != NULL) { + if (metadata != NULL) { msDecodeHTMLEntities(pszValue); - msInsertHashTable(metadata, pszMetadata, pszValue ); + msInsertHashTable(metadata, pszMetadata, pszValue); } else { return MS_FAILURE; } @@ -144,21 +146,19 @@ int msGetMapContextXMLHashValueDecode( CPLXMLNode *psRoot, return MS_SUCCESS; } - /* **msGetMapContextXMLStringValue() ** **Get the xml value and put it in the string field ** */ -int msGetMapContextXMLStringValue( CPLXMLNode *psRoot, char *pszXMLPath, - char **pszField) -{ +int msGetMapContextXMLStringValue(CPLXMLNode *psRoot, char *pszXMLPath, + char **pszField) { char *pszValue; - pszValue = (char*)CPLGetXMLValue( psRoot, pszXMLPath, NULL); - if(pszValue != NULL) { - if( pszField != NULL ) { + pszValue = (char *)CPLGetXMLValue(psRoot, pszXMLPath, NULL); + if (pszValue != NULL) { + if (pszField != NULL) { *pszField = msStrdup(pszValue); } else { return MS_FAILURE; @@ -170,21 +170,19 @@ int msGetMapContextXMLStringValue( CPLXMLNode *psRoot, char *pszXMLPath, return MS_SUCCESS; } - /* **msGetMapContextXMLStringValue() ** **Get the xml value and put it in the string field ** */ -int msGetMapContextXMLStringValueDecode( CPLXMLNode *psRoot, char *pszXMLPath, - char **pszField) -{ +int msGetMapContextXMLStringValueDecode(CPLXMLNode *psRoot, char *pszXMLPath, + char **pszField) { char *pszValue; - pszValue = (char*)CPLGetXMLValue( psRoot, pszXMLPath, NULL); - if(pszValue != NULL) { - if( pszField != NULL ) { + pszValue = (char *)CPLGetXMLValue(psRoot, pszXMLPath, NULL); + if (pszValue != NULL) { + if (pszField != NULL) { msDecodeHTMLEntities(pszValue); *pszField = msStrdup(pszValue); } else { @@ -197,21 +195,19 @@ int msGetMapContextXMLStringValueDecode( CPLXMLNode *psRoot, char *pszXMLPath, return MS_SUCCESS; } - /* **msGetMapContextXMLFloatValue() ** **Get the xml value and put it in the string field ** */ -int msGetMapContextXMLFloatValue( CPLXMLNode *psRoot, char *pszXMLPath, - double *pszField) -{ +int msGetMapContextXMLFloatValue(CPLXMLNode *psRoot, char *pszXMLPath, + double *pszField) { char *pszValue; - pszValue = (char*)CPLGetXMLValue( psRoot, pszXMLPath, NULL); - if(pszValue != NULL) { - if( pszField != NULL ) { + pszValue = (char *)CPLGetXMLValue(psRoot, pszXMLPath, NULL); + if (pszValue != NULL) { + if (pszField != NULL) { *pszField = atof(pszValue); } else { return MS_FAILURE; @@ -229,28 +225,27 @@ int msGetMapContextXMLFloatValue( CPLXMLNode *psRoot, char *pszXMLPath, ** Take a Node and get the width, height, format and href from it. ** Then put this info in metadatas. */ -int msLoadMapContextURLELements( CPLXMLNode *psRoot, hashTableObj *metadata, - const char *pszMetadataRoot) -{ +int msLoadMapContextURLELements(CPLXMLNode *psRoot, hashTableObj *metadata, + const char *pszMetadataRoot) { char *pszMetadataName; - if( psRoot == NULL || metadata == NULL || pszMetadataRoot == NULL ) + if (psRoot == NULL || metadata == NULL || pszMetadataRoot == NULL) return MS_FAILURE; - pszMetadataName = (char*) malloc( strlen(pszMetadataRoot) + 10 ); + pszMetadataName = (char *)malloc(strlen(pszMetadataRoot) + 10); - sprintf( pszMetadataName, "%s_width", pszMetadataRoot ); - msGetMapContextXMLHashValue( psRoot, "width", metadata, pszMetadataName ); + sprintf(pszMetadataName, "%s_width", pszMetadataRoot); + msGetMapContextXMLHashValue(psRoot, "width", metadata, pszMetadataName); - sprintf( pszMetadataName, "%s_height", pszMetadataRoot ); - msGetMapContextXMLHashValue( psRoot, "height", metadata, pszMetadataName ); + sprintf(pszMetadataName, "%s_height", pszMetadataRoot); + msGetMapContextXMLHashValue(psRoot, "height", metadata, pszMetadataName); - sprintf( pszMetadataName, "%s_format", pszMetadataRoot ); - msGetMapContextXMLHashValue( psRoot, "format", metadata, pszMetadataName ); + sprintf(pszMetadataName, "%s_format", pszMetadataRoot); + msGetMapContextXMLHashValue(psRoot, "format", metadata, pszMetadataName); - sprintf( pszMetadataName, "%s_href", pszMetadataRoot ); - msGetMapContextXMLHashValue( psRoot, "OnlineResource.xlink:href", metadata, - pszMetadataName ); + sprintf(pszMetadataName, "%s_href", pszMetadataRoot); + msGetMapContextXMLHashValue(psRoot, "OnlineResource.xlink:href", metadata, + pszMetadataName); free(pszMetadataName); @@ -262,15 +257,14 @@ int msLoadMapContextURLELements( CPLXMLNode *psRoot, hashTableObj *metadata, ** Put the keywords from a XML node and put them in a metadata. ** psRoot should be set to keywordlist */ -int msLoadMapContextListInMetadata( CPLXMLNode *psRoot, hashTableObj *metadata, - char *pszXMLName, char *pszMetadataName, - char *pszHashDelimiter) -{ +int msLoadMapContextListInMetadata(CPLXMLNode *psRoot, hashTableObj *metadata, + char *pszXMLName, char *pszMetadataName, + char *pszHashDelimiter) { const char *pszHash, *pszXMLValue; char *pszMetadata; - if(psRoot == NULL || psRoot->psChild == NULL || - metadata == NULL || pszMetadataName == NULL || pszXMLName == NULL) + if (psRoot == NULL || psRoot->psChild == NULL || metadata == NULL || + pszMetadataName == NULL || pszXMLName == NULL) return MS_FAILURE; /* Pass from KeywordList to Keyword level */ @@ -282,13 +276,12 @@ int msLoadMapContextListInMetadata( CPLXMLNode *psRoot, hashTableObj *metadata, pszXMLValue = psRoot->psChild->pszValue; pszHash = msLookupHashTable(metadata, pszMetadataName); if (pszHash != NULL) { - pszMetadata = (char*)malloc(strlen(pszHash)+ - strlen(pszXMLValue)+2); - if(pszHashDelimiter == NULL) - sprintf( pszMetadata, "%s%s", pszHash, pszXMLValue ); + pszMetadata = (char *)malloc(strlen(pszHash) + strlen(pszXMLValue) + 2); + if (pszHashDelimiter == NULL) + sprintf(pszMetadata, "%s%s", pszHash, pszXMLValue); else - sprintf( pszMetadata, "%s%s%s", pszHash, pszHashDelimiter, - pszXMLValue ); + sprintf(pszMetadata, "%s%s%s", pszHash, pszHashDelimiter, + pszXMLValue); msInsertHashTable(metadata, pszMetadataName, pszMetadata); free(pszMetadata); } else @@ -305,43 +298,40 @@ int msLoadMapContextListInMetadata( CPLXMLNode *psRoot, hashTableObj *metadata, ** Put the Contact informations from a XML node and put them in a metadata. ** */ -int msLoadMapContextContactInfo( CPLXMLNode *psRoot, hashTableObj *metadata ) -{ - if(psRoot == NULL || metadata == NULL) +int msLoadMapContextContactInfo(CPLXMLNode *psRoot, hashTableObj *metadata) { + if (psRoot == NULL || metadata == NULL) return MS_FAILURE; /* Contact Person primary */ - msGetMapContextXMLHashValue(psRoot, - "ContactPersonPrimary.ContactPerson", + msGetMapContextXMLHashValue(psRoot, "ContactPersonPrimary.ContactPerson", metadata, "wms_contactperson"); msGetMapContextXMLHashValue(psRoot, "ContactPersonPrimary.ContactOrganization", metadata, "wms_contactorganization"); /* Contact Position */ - msGetMapContextXMLHashValue(psRoot, - "ContactPosition", - metadata, "wms_contactposition"); + msGetMapContextXMLHashValue(psRoot, "ContactPosition", metadata, + "wms_contactposition"); /* Contact Address */ - msGetMapContextXMLHashValue(psRoot, "ContactAddress.AddressType", - metadata, "wms_addresstype"); - msGetMapContextXMLHashValue(psRoot, "ContactAddress.Address", - metadata, "wms_address"); - msGetMapContextXMLHashValue(psRoot, "ContactAddress.City", - metadata, "wms_city"); + msGetMapContextXMLHashValue(psRoot, "ContactAddress.AddressType", metadata, + "wms_addresstype"); + msGetMapContextXMLHashValue(psRoot, "ContactAddress.Address", metadata, + "wms_address"); + msGetMapContextXMLHashValue(psRoot, "ContactAddress.City", metadata, + "wms_city"); msGetMapContextXMLHashValue(psRoot, "ContactAddress.StateOrProvince", metadata, "wms_stateorprovince"); - msGetMapContextXMLHashValue(psRoot, "ContactAddress.PostCode", - metadata, "wms_postcode"); - msGetMapContextXMLHashValue(psRoot, "ContactAddress.Country", - metadata, "wms_country"); + msGetMapContextXMLHashValue(psRoot, "ContactAddress.PostCode", metadata, + "wms_postcode"); + msGetMapContextXMLHashValue(psRoot, "ContactAddress.Country", metadata, + "wms_country"); /* Others */ - msGetMapContextXMLHashValue(psRoot, "ContactVoiceTelephone", - metadata, "wms_contactvoicetelephone"); - msGetMapContextXMLHashValue(psRoot, "ContactFacsimileTelephone", - metadata, "wms_contactfacsimiletelephone"); - msGetMapContextXMLHashValue(psRoot, "ContactElectronicMailAddress", - metadata, "wms_contactelectronicmailaddress"); + msGetMapContextXMLHashValue(psRoot, "ContactVoiceTelephone", metadata, + "wms_contactvoicetelephone"); + msGetMapContextXMLHashValue(psRoot, "ContactFacsimileTelephone", metadata, + "wms_contactfacsimiletelephone"); + msGetMapContextXMLHashValue(psRoot, "ContactElectronicMailAddress", metadata, + "wms_contactelectronicmailaddress"); return MS_SUCCESS; } @@ -351,42 +341,35 @@ int msLoadMapContextContactInfo( CPLXMLNode *psRoot, hashTableObj *metadata ) ** ** */ -int msLoadMapContextLayerFormat(CPLXMLNode *psFormat, layerObj *layer) -{ +int msLoadMapContextLayerFormat(CPLXMLNode *psFormat, layerObj *layer) { const char *pszValue; char *pszValue1; - const char* pszHash; + const char *pszHash; - if(psFormat->psChild != NULL && - strcasecmp(psFormat->pszValue, "Format") == 0 ) { - if(psFormat->psChild->psNext == NULL) + if (psFormat->psChild != NULL && + strcasecmp(psFormat->pszValue, "Format") == 0) { + if (psFormat->psChild->psNext == NULL) pszValue = psFormat->psChild->pszValue; else pszValue = psFormat->psChild->psNext->pszValue; } else pszValue = NULL; - if(pszValue != NULL && strcasecmp(pszValue, "") != 0) { + if (pszValue != NULL && strcasecmp(pszValue, "") != 0) { /* wms_format */ - pszValue1 = (char*)CPLGetXMLValue(psFormat, - "current", NULL); - if(pszValue1 != NULL && - (strcasecmp(pszValue1, "1") == 0 || strcasecmp(pszValue1, "true")==0)) - msInsertHashTable(&(layer->metadata), - "wms_format", pszValue); + pszValue1 = (char *)CPLGetXMLValue(psFormat, "current", NULL); + if (pszValue1 != NULL && + (strcasecmp(pszValue1, "1") == 0 || strcasecmp(pszValue1, "true") == 0)) + msInsertHashTable(&(layer->metadata), "wms_format", pszValue); /* wms_formatlist */ - pszHash = msLookupHashTable(&(layer->metadata), - "wms_formatlist"); - if(pszHash != NULL) { - pszValue1 = (char*)malloc(strlen(pszHash)+ - strlen(pszValue)+2); + pszHash = msLookupHashTable(&(layer->metadata), "wms_formatlist"); + if (pszHash != NULL) { + pszValue1 = (char *)malloc(strlen(pszHash) + strlen(pszValue) + 2); sprintf(pszValue1, "%s,%s", pszHash, pszValue); - msInsertHashTable(&(layer->metadata), - "wms_formatlist", pszValue1); + msInsertHashTable(&(layer->metadata), "wms_formatlist", pszValue1); free(pszValue1); } else - msInsertHashTable(&(layer->metadata), - "wms_formatlist", pszValue); + msInsertHashTable(&(layer->metadata), "wms_formatlist", pszValue); } /* Make sure selected format is supported or select another @@ -396,46 +379,43 @@ int msLoadMapContextLayerFormat(CPLXMLNode *psFormat, layerObj *layer) */ pszValue = msLookupHashTable(&(layer->metadata), "wms_format"); - if ( - pszValue && ( + if (pszValue && ( #if !(defined USE_PNG) - strcasecmp(pszValue, "image/png") == 0 || - strcasecmp(pszValue, "PNG") == 0 || + strcasecmp(pszValue, "image/png") == 0 || + strcasecmp(pszValue, "PNG") == 0 || #endif #if !(defined USE_JPEG) - strcasecmp(pszValue, "image/jpeg") == 0 || - strcasecmp(pszValue, "JPEG") == 0 || + strcasecmp(pszValue, "image/jpeg") == 0 || + strcasecmp(pszValue, "JPEG") == 0 || #endif - 0 )) { - char **papszList=NULL; - int i, numformats=0; + 0)) { + char **papszList = NULL; + int i, numformats = 0; - pszValue = msLookupHashTable(&(layer->metadata), - "wms_formatlist"); + pszValue = msLookupHashTable(&(layer->metadata), "wms_formatlist"); papszList = msStringSplit(pszValue, ',', &numformats); - for(i=0; i < numformats; i++) { + for (i = 0; i < numformats; i++) { if ( #if (defined USE_PNG) - strcasecmp(papszList[i], "image/png") == 0 || - strcasecmp(papszList[i], "PNG") == 0 || + strcasecmp(papszList[i], "image/png") == 0 || + strcasecmp(papszList[i], "PNG") == 0 || #endif #if (defined USE_JPEG) - strcasecmp(papszList[i], "image/jpeg") == 0 || - strcasecmp(papszList[i], "JPEG") == 0 || + strcasecmp(papszList[i], "image/jpeg") == 0 || + strcasecmp(papszList[i], "JPEG") == 0 || #endif #ifdef USE_GD_GIF - strcasecmp(papszList[i], "image/gif") == 0 || - strcasecmp(papszList[i], "GIF") == 0 || + strcasecmp(papszList[i], "image/gif") == 0 || + strcasecmp(papszList[i], "GIF") == 0 || #endif - 0 ) { + 0) { /* Found a match */ - msInsertHashTable(&(layer->metadata), - "wms_format", papszList[i]); + msInsertHashTable(&(layer->metadata), "wms_format", papszList[i]); break; } } - if(papszList) + if (papszList) msFreeCharArray(papszList, numformats); } /* end if unsupported format */ @@ -444,81 +424,74 @@ int msLoadMapContextLayerFormat(CPLXMLNode *psFormat, layerObj *layer) } int msLoadMapContextLayerStyle(CPLXMLNode *psStyle, layerObj *layer, - int nStyle) -{ + int nStyle) { char *pszValue, *pszValue1, *pszValue2; const char *pszHash; - char* pszStyle=NULL; + char *pszStyle = NULL; char *pszStyleName; CPLXMLNode *psStyleSLDBody; - pszStyleName =(char*)CPLGetXMLValue(psStyle,"Name",NULL); - if(pszStyleName == NULL) { - pszStyleName = (char*)malloc(20); + pszStyleName = (char *)CPLGetXMLValue(psStyle, "Name", NULL); + if (pszStyleName == NULL) { + pszStyleName = (char *)malloc(20); sprintf(pszStyleName, "Style{%d}", nStyle); } else pszStyleName = msStrdup(pszStyleName); /* wms_style */ - pszValue = (char*)CPLGetXMLValue(psStyle,"current",NULL); - if(pszValue != NULL && - (strcasecmp(pszValue, "1") == 0 || - strcasecmp(pszValue, "true") == 0)) - msInsertHashTable(&(layer->metadata), - "wms_style", pszStyleName); + pszValue = (char *)CPLGetXMLValue(psStyle, "current", NULL); + if (pszValue != NULL && + (strcasecmp(pszValue, "1") == 0 || strcasecmp(pszValue, "true") == 0)) + msInsertHashTable(&(layer->metadata), "wms_style", pszStyleName); /* wms_stylelist */ - pszHash = msLookupHashTable(&(layer->metadata), - "wms_stylelist"); - if(pszHash != NULL) { - pszValue1 = (char*)malloc(strlen(pszHash)+ - strlen(pszStyleName)+2); + pszHash = msLookupHashTable(&(layer->metadata), "wms_stylelist"); + if (pszHash != NULL) { + pszValue1 = (char *)malloc(strlen(pszHash) + strlen(pszStyleName) + 2); sprintf(pszValue1, "%s,%s", pszHash, pszStyleName); - msInsertHashTable(&(layer->metadata), - "wms_stylelist", pszValue1); + msInsertHashTable(&(layer->metadata), "wms_stylelist", pszValue1); free(pszValue1); } else - msInsertHashTable(&(layer->metadata), - "wms_stylelist", pszStyleName); + msInsertHashTable(&(layer->metadata), "wms_stylelist", pszStyleName); /* Title */ - pszStyle = (char*)malloc(strlen(pszStyleName)+20); - sprintf(pszStyle,"wms_style_%s_title",pszStyleName); + pszStyle = (char *)malloc(strlen(pszStyleName) + 20); + sprintf(pszStyle, "wms_style_%s_title", pszStyleName); - if( msGetMapContextXMLHashValue(psStyle, "Title", &(layer->metadata), - pszStyle) == MS_FAILURE ) + if (msGetMapContextXMLHashValue(psStyle, "Title", &(layer->metadata), + pszStyle) == MS_FAILURE) msInsertHashTable(&(layer->metadata), pszStyle, layer->name); free(pszStyle); /* SLD */ - pszStyle = (char*)malloc(strlen(pszStyleName)+15); + pszStyle = (char *)malloc(strlen(pszStyleName) + 15); sprintf(pszStyle, "wms_style_%s_sld", pszStyleName); - msGetMapContextXMLHashValueDecode( psStyle, "SLD.OnlineResource.xlink:href", - &(layer->metadata), pszStyle ); + msGetMapContextXMLHashValueDecode(psStyle, "SLD.OnlineResource.xlink:href", + &(layer->metadata), pszStyle); free(pszStyle); /* SLDBODY */ - pszStyle = (char*)malloc(strlen(pszStyleName)+20); + pszStyle = (char *)malloc(strlen(pszStyleName) + 20); sprintf(pszStyle, "wms_style_%s_sld_body", pszStyleName); psStyleSLDBody = CPLGetXMLNode(psStyle, "SLD.StyledLayerDescriptor"); - /*some clients such as OpenLayers add a name space, which I believe is wrong but - added this additional test for compatibility #3115*/ + /*some clients such as OpenLayers add a name space, which I believe is wrong + but added this additional test for compatibility #3115*/ if (psStyleSLDBody == NULL) psStyleSLDBody = CPLGetXMLNode(psStyle, "SLD.sld:StyledLayerDescriptor"); - if(psStyleSLDBody != NULL && &(layer->metadata) != NULL) { + if (psStyleSLDBody != NULL && &(layer->metadata) != NULL) { pszValue = CPLSerializeXMLTree(psStyleSLDBody); - if(pszValue != NULL) { + if (pszValue != NULL) { /* Before including SLDBody in the mapfile, we must replace the */ /* double quote for single quote. This is to prevent having this: */ /* "metadata" "" */ char *c; - for(c=pszValue; *c != '\0'; c++) - if(*c == '"') + for (c = pszValue; *c != '\0'; c++) + if (*c == '"') *c = '\''; - msInsertHashTable(&(layer->metadata), pszStyle, pszValue ); + msInsertHashTable(&(layer->metadata), pszStyle, pszValue); msFree(pszValue); } } @@ -526,12 +499,11 @@ int msLoadMapContextLayerStyle(CPLXMLNode *psStyle, layerObj *layer, free(pszStyle); /* LegendURL */ - pszStyle = (char*) malloc(strlen(pszStyleName) + 25); + pszStyle = (char *)malloc(strlen(pszStyleName) + 25); - sprintf( pszStyle, "wms_style_%s_legendurl", - pszStyleName); - msLoadMapContextURLELements( CPLGetXMLNode(psStyle, "LegendURL"), - &(layer->metadata), pszStyle ); + sprintf(pszStyle, "wms_style_%s_legendurl", pszStyleName); + msLoadMapContextURLELements(CPLGetXMLNode(psStyle, "LegendURL"), + &(layer->metadata), pszStyle); free(pszStyle); @@ -540,20 +512,18 @@ int msLoadMapContextLayerStyle(CPLXMLNode *psStyle, layerObj *layer, /* */ /* Add the stylelist to the layer connection */ /* */ - if(msLookupHashTable(&(layer->metadata), - "wms_stylelist") == NULL) { - if(layer->connection) + if (msLookupHashTable(&(layer->metadata), "wms_stylelist") == NULL) { + if (layer->connection) pszValue = msStrdup(layer->connection); else - pszValue = msStrdup( "" ); + pszValue = msStrdup(""); pszValue1 = strstr(pszValue, "STYLELIST="); - if(pszValue1 != NULL) { + if (pszValue1 != NULL) { pszValue1 += 10; pszValue2 = strchr(pszValue, '&'); - if(pszValue2 != NULL) - pszValue1[pszValue2-pszValue1] = '\0'; - msInsertHashTable(&(layer->metadata), "wms_stylelist", - pszValue1); + if (pszValue2 != NULL) + pszValue1[pszValue2 - pszValue1] = '\0'; + msInsertHashTable(&(layer->metadata), "wms_stylelist", pszValue1); } free(pszValue); } @@ -561,19 +531,18 @@ int msLoadMapContextLayerStyle(CPLXMLNode *psStyle, layerObj *layer, /* */ /* Add the style to the layer connection */ /* */ - if(msLookupHashTable(&(layer->metadata), "wms_style") == NULL) { - if(layer->connection) + if (msLookupHashTable(&(layer->metadata), "wms_style") == NULL) { + if (layer->connection) pszValue = msStrdup(layer->connection); else - pszValue = msStrdup( "" ); + pszValue = msStrdup(""); pszValue1 = strstr(pszValue, "STYLE="); - if(pszValue1 != NULL) { + if (pszValue1 != NULL) { pszValue1 += 6; pszValue2 = strchr(pszValue, '&'); - if(pszValue2 != NULL) - pszValue1[pszValue2-pszValue1] = '\0'; - msInsertHashTable(&(layer->metadata), "wms_style", - pszValue1); + if (pszValue2 != NULL) + pszValue1[pszValue2 - pszValue1] = '\0'; + msInsertHashTable(&(layer->metadata), "wms_style", pszValue1); } free(pszValue); } @@ -581,39 +550,34 @@ int msLoadMapContextLayerStyle(CPLXMLNode *psStyle, layerObj *layer, return MS_SUCCESS; } -int msLoadMapContextLayerDimension(CPLXMLNode *psDimension, layerObj *layer) -{ +int msLoadMapContextLayerDimension(CPLXMLNode *psDimension, layerObj *layer) { char *pszValue; const char *pszHash; - char *pszDimension=NULL, *pszDimensionName=NULL; + char *pszDimension = NULL, *pszDimensionName = NULL; - pszDimensionName =(char*)CPLGetXMLValue(psDimension,"name",NULL); - if(pszDimensionName == NULL) { + pszDimensionName = (char *)CPLGetXMLValue(psDimension, "name", NULL); + if (pszDimensionName == NULL) { return MS_FALSE; } else pszDimensionName = msStrdup(pszDimensionName); - pszDimension = (char*)malloc(strlen(pszDimensionName)+50); + pszDimension = (char *)malloc(strlen(pszDimensionName) + 50); /* wms_dimension: This is the current dimension */ - pszValue = (char*)CPLGetXMLValue(psDimension, "current", NULL); - if(pszValue != NULL && (strcasecmp(pszValue, "1") == 0 || - strcasecmp(pszValue, "true") == 0)) - msInsertHashTable(&(layer->metadata), - "wms_dimension", pszDimensionName); + pszValue = (char *)CPLGetXMLValue(psDimension, "current", NULL); + if (pszValue != NULL && + (strcasecmp(pszValue, "1") == 0 || strcasecmp(pszValue, "true") == 0)) + msInsertHashTable(&(layer->metadata), "wms_dimension", pszDimensionName); /* wms_dimensionlist */ - pszHash = msLookupHashTable(&(layer->metadata), - "wms_dimensionlist"); - if(pszHash != NULL) { - pszValue = (char*)malloc(strlen(pszHash)+ - strlen(pszDimensionName)+2); + pszHash = msLookupHashTable(&(layer->metadata), "wms_dimensionlist"); + if (pszHash != NULL) { + pszValue = (char *)malloc(strlen(pszHash) + strlen(pszDimensionName) + 2); sprintf(pszValue, "%s,%s", pszHash, pszDimensionName); - msInsertHashTable(&(layer->metadata), - "wms_dimensionlist", pszValue); + msInsertHashTable(&(layer->metadata), "wms_dimensionlist", pszValue); free(pszValue); } else - msInsertHashTable(&(layer->metadata), - "wms_dimensionlist", pszDimensionName); + msInsertHashTable(&(layer->metadata), "wms_dimensionlist", + pszDimensionName); /* Units */ sprintf(pszDimension, "wms_dimension_%s_units", pszDimensionName); @@ -629,7 +593,7 @@ int msLoadMapContextLayerDimension(CPLXMLNode *psDimension, layerObj *layer) sprintf(pszDimension, "wms_dimension_%s_uservalue", pszDimensionName); msGetMapContextXMLHashValue(psDimension, "userValue", &(layer->metadata), pszDimension); - if(strcasecmp(pszDimensionName, "time") == 0) + if (strcasecmp(pszDimensionName, "time") == 0) msGetMapContextXMLHashValue(psDimension, "userValue", &(layer->metadata), "wms_time"); @@ -640,7 +604,7 @@ int msLoadMapContextLayerDimension(CPLXMLNode *psDimension, layerObj *layer) /* multipleValues */ sprintf(pszDimension, "wms_dimension_%s_multiplevalues", pszDimensionName); - msGetMapContextXMLHashValue(psDimension, "multipleValues",&(layer->metadata), + msGetMapContextXMLHashValue(psDimension, "multipleValues", &(layer->metadata), pszDimension); /* nearestValue */ @@ -655,8 +619,6 @@ int msLoadMapContextLayerDimension(CPLXMLNode *psDimension, layerObj *layer) return MS_SUCCESS; } - - /* ** msLoadMapContextGeneral ** @@ -664,119 +626,116 @@ int msLoadMapContextLayerDimension(CPLXMLNode *psDimension, layerObj *layer) */ int msLoadMapContextGeneral(mapObj *map, CPLXMLNode *psGeneral, CPLXMLNode *psMapContext, int nVersion, - char *filename) -{ + const char *filename) { - char *pszProj=NULL; + char *pszProj = NULL; char *pszValue, *pszValue1, *pszValue2; int nTmp; /* Projection */ - pszValue = (char*)CPLGetXMLValue(psGeneral, - "BoundingBox.SRS", NULL); - if(pszValue != NULL && !EQUAL(pszValue, "(null)")) { - if(strncasecmp(pszValue, "AUTO:", 5) == 0) { + pszValue = (char *)CPLGetXMLValue(psGeneral, "BoundingBox.SRS", NULL); + if (pszValue != NULL && !EQUAL(pszValue, "(null)")) { + if (strncasecmp(pszValue, "AUTO:", 5) == 0) { pszProj = msStrdup(pszValue); } else { - pszProj = (char*) malloc(sizeof(char)*(strlen(pszValue)+10)); - sprintf(pszProj, "init=epsg:%s", pszValue+5); + pszProj = (char *)malloc(sizeof(char) * (strlen(pszValue) + 10)); + sprintf(pszProj, "init=epsg:%s", pszValue + 5); } + msFreeProjection(&map->projection); msInitProjection(&map->projection); map->projection.args[map->projection.numargs] = msStrdup(pszProj); map->projection.numargs++; msProcessProjection(&map->projection); - if( (nTmp = GetMapserverUnitUsingProj(&(map->projection))) == -1) { + if ((nTmp = GetMapserverUnitUsingProj(&(map->projection))) == -1) { + msSetError(MS_MAPCONTEXTERR, "Unable to set units for projection '%s'", + "msLoadMapContext()", pszProj); free(pszProj); - msSetError( MS_MAPCONTEXTERR, - "Unable to set units for projection '%s'", - "msLoadMapContext()", pszProj ); return MS_FAILURE; } else { map->units = nTmp; } free(pszProj); } else { - msDebug("Mandatory data General.BoundingBox.SRS missing in %s.", - filename); + msDebug("Mandatory data General.BoundingBox.SRS missing in %s.", filename); } /* Extent */ - if( msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.minx", + if (msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.minx", &(map->extent.minx)) == MS_FAILURE) { - msDebug("Mandatory data General.BoundingBox.minx missing in %s.", - filename); + msDebug("Mandatory data General.BoundingBox.minx missing in %s.", filename); } - if( msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.miny", + if (msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.miny", &(map->extent.miny)) == MS_FAILURE) { - msDebug("Mandatory data General.BoundingBox.miny missing in %s.", - filename); + msDebug("Mandatory data General.BoundingBox.miny missing in %s.", filename); } - if( msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.maxx", + if (msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.maxx", &(map->extent.maxx)) == MS_FAILURE) { - msDebug("Mandatory data General.BoundingBox.maxx missing in %s.", - filename); + msDebug("Mandatory data General.BoundingBox.maxx missing in %s.", filename); } - if( msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.maxy", + if (msGetMapContextXMLFloatValue(psGeneral, "BoundingBox.maxy", &(map->extent.maxy)) == MS_FAILURE) { - msDebug("Mandatory data General.BoundingBox.maxy missing in %s.", - filename); + msDebug("Mandatory data General.BoundingBox.maxy missing in %s.", filename); } /* Title */ - if( msGetMapContextXMLHashValue(psGeneral, "Title", - &(map->web.metadata), "wms_title") == MS_FAILURE) { - if ( nVersion >= OWS_1_0_0 ) + if (msGetMapContextXMLHashValue(psGeneral, "Title", &(map->web.metadata), + "wms_title") == MS_FAILURE) { + if (nVersion >= OWS_1_0_0) msDebug("Mandatory data General.Title missing in %s.", filename); else { - if( msGetMapContextXMLHashValue(psGeneral, "gml:name", - &(map->web.metadata), "wms_title") == MS_FAILURE ) { - if( nVersion < OWS_0_1_7 ) + if (msGetMapContextXMLHashValue(psGeneral, "gml:name", + &(map->web.metadata), + "wms_title") == MS_FAILURE) { + if (nVersion < OWS_0_1_7) msDebug("Mandatory data General.Title missing in %s.", filename); else - msDebug("Mandatory data General.gml:name missing in %s.", - filename); + msDebug("Mandatory data General.gml:name missing in %s.", filename); } } } /* Name */ - if( nVersion >= OWS_1_0_0 ) { - pszValue = (char*)CPLGetXMLValue(psMapContext, - "id", NULL); - if (pszValue) + if (nVersion >= OWS_1_0_0) { + pszValue = (char *)CPLGetXMLValue(psMapContext, "id", NULL); + if (pszValue) { + msFree(map->name); map->name = msStrdup(pszValue); + } } else { - if(msGetMapContextXMLStringValue(psGeneral, "Name", - &(map->name)) == MS_FAILURE) { - msGetMapContextXMLStringValue(psGeneral, "gml:name", - &(map->name)); + char *pszMapName = NULL; + if (msGetMapContextXMLStringValue(psGeneral, "Name", &pszMapName) == + MS_FAILURE) { + msGetMapContextXMLStringValue(psGeneral, "gml:name", &pszMapName); + } + if (pszMapName) { + msFree(map->name); + map->name = pszMapName; } } /* Keyword */ - if( nVersion >= OWS_1_0_0 ) { - msLoadMapContextListInMetadata( - CPLGetXMLNode(psGeneral, "KeywordList"), - &(map->web.metadata), "KEYWORD", "wms_keywordlist", "," ); + if (nVersion >= OWS_1_0_0) { + msLoadMapContextListInMetadata(CPLGetXMLNode(psGeneral, "KeywordList"), + &(map->web.metadata), "KEYWORD", + "wms_keywordlist", ","); } else - msGetMapContextXMLHashValue(psGeneral, "Keywords", - &(map->web.metadata), "wms_keywordlist"); + msGetMapContextXMLHashValue(psGeneral, "Keywords", &(map->web.metadata), + "wms_keywordlist"); /* Window */ - pszValue1 = (char*)CPLGetXMLValue(psGeneral,"Window.width",NULL); - pszValue2 = (char*)CPLGetXMLValue(psGeneral,"Window.height",NULL); - if(pszValue1 != NULL && pszValue2 != NULL) { + pszValue1 = (char *)CPLGetXMLValue(psGeneral, "Window.width", NULL); + pszValue2 = (char *)CPLGetXMLValue(psGeneral, "Window.height", NULL); + if (pszValue1 != NULL && pszValue2 != NULL) { map->width = atoi(pszValue1); map->height = atoi(pszValue2); } /* Abstract */ - if( msGetMapContextXMLHashValue( psGeneral, - "Abstract", &(map->web.metadata), - "wms_abstract") == MS_FAILURE ) { - msGetMapContextXMLHashValue( psGeneral, "gml:description", - &(map->web.metadata), "wms_abstract"); + if (msGetMapContextXMLHashValue(psGeneral, "Abstract", &(map->web.metadata), + "wms_abstract") == MS_FAILURE) { + msGetMapContextXMLHashValue(psGeneral, "gml:description", + &(map->web.metadata), "wms_abstract"); } /* DataURL */ @@ -786,19 +745,17 @@ int msLoadMapContextGeneral(mapObj *map, CPLXMLNode *psGeneral, /* LogoURL */ /* The logourl have a width, height, format and an URL */ - msLoadMapContextURLELements( CPLGetXMLNode(psGeneral, "LogoURL"), - &(map->web.metadata), "wms_logourl" ); + msLoadMapContextURLELements(CPLGetXMLNode(psGeneral, "LogoURL"), + &(map->web.metadata), "wms_logourl"); /* DescriptionURL */ /* The descriptionurl have a width, height, format and an URL */ - msLoadMapContextURLELements( CPLGetXMLNode(psGeneral, - "DescriptionURL"), - &(map->web.metadata), "wms_descriptionurl" ); + msLoadMapContextURLELements(CPLGetXMLNode(psGeneral, "DescriptionURL"), + &(map->web.metadata), "wms_descriptionurl"); /* Contact Info */ - msLoadMapContextContactInfo( - CPLGetXMLNode(psGeneral, "ContactInformation"), - &(map->web.metadata) ); + msLoadMapContextContactInfo(CPLGetXMLNode(psGeneral, "ContactInformation"), + &(map->web.metadata)); return MS_SUCCESS; } @@ -809,18 +766,17 @@ int msLoadMapContextGeneral(mapObj *map, CPLXMLNode *psGeneral, ** Load a Layer block from a MapContext document */ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion, - char *filename, int unique_layer_names) -{ + const char *filename, int unique_layer_names) { char *pszValue; const char *pszHash; - char *pszName=NULL; + char *pszName = NULL; CPLXMLNode *psFormatList, *psFormat, *psStyleList, *psStyle, *psExtension; CPLXMLNode *psDimensionList, *psDimension; int nStyle; layerObj *layer; /* Init new layer */ - if(msGrowMapLayers(map) == NULL) + if (msGrowMapLayers(map) == NULL) return MS_FAILURE; layer = (GET_LAYER(map, map->numlayers)); @@ -832,57 +788,57 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion, map->layerorder[map->numlayers] = map->numlayers; map->numlayers++; - /* Status */ - pszValue = (char*)CPLGetXMLValue(psLayer, "hidden", "1"); - if((pszValue != NULL) && (atoi(pszValue) == 0 && - strcasecmp(pszValue, "true") != 0)) + pszValue = (char *)CPLGetXMLValue(psLayer, "hidden", "1"); + if ((pszValue != NULL) && + (atoi(pszValue) == 0 && strcasecmp(pszValue, "true") != 0)) layer->status = MS_ON; else layer->status = MS_OFF; /* Queryable */ - pszValue = (char*)CPLGetXMLValue(psLayer, "queryable", "0"); - if(pszValue !=NULL && (atoi(pszValue) == 1 || - strcasecmp(pszValue, "true") == 0)) + pszValue = (char *)CPLGetXMLValue(psLayer, "queryable", "0"); + if (pszValue != NULL && + (atoi(pszValue) == 1 || strcasecmp(pszValue, "true") == 0)) layer->template = msStrdup("ttt"); /* Name and Title */ - pszValue = (char*)CPLGetXMLValue(psLayer, "Name", NULL); - if(pszValue != NULL) { - msInsertHashTable( &(layer->metadata), "wms_name", pszValue ); + pszValue = (char *)CPLGetXMLValue(psLayer, "Name", NULL); + if (pszValue != NULL) { + msInsertHashTable(&(layer->metadata), "wms_name", pszValue); if (unique_layer_names) { - pszName = (char*)malloc(sizeof(char)*(strlen(pszValue)+15)); + pszName = (char *)malloc(sizeof(char) * (strlen(pszValue) + 15)); sprintf(pszName, "l%d:%s", layer->index, pszValue); layer->name = msStrdup(pszName); free(pszName); } else - layer->name = msStrdup(pszValue); + layer->name = msStrdup(pszValue); } else { - pszName = (char*)malloc(sizeof(char)*15); + pszName = (char *)malloc(sizeof(char) * 15); sprintf(pszName, "l%d:", layer->index); layer->name = msStrdup(pszName); free(pszName); } - if(msGetMapContextXMLHashValue(psLayer, "Title", &(layer->metadata), - "wms_title") == MS_FAILURE) { - if(msGetMapContextXMLHashValue(psLayer, "Server.title", - &(layer->metadata), "wms_title") == MS_FAILURE) { + if (msGetMapContextXMLHashValue(psLayer, "Title", &(layer->metadata), + "wms_title") == MS_FAILURE) { + if (msGetMapContextXMLHashValue(psLayer, "Server.title", &(layer->metadata), + "wms_title") == MS_FAILURE) { msDebug("Mandatory data Layer.Title missing in %s.", filename); } } /* Server Title */ - msGetMapContextXMLHashValue(psLayer, "Server.title", &(layer->metadata), "wms_server_title"); + msGetMapContextXMLHashValue(psLayer, "Server.title", &(layer->metadata), + "wms_server_title"); /* Abstract */ msGetMapContextXMLHashValue(psLayer, "Abstract", &(layer->metadata), "wms_abstract"); /* DataURL */ - if(nVersion <= OWS_0_1_4) { + if (nVersion <= OWS_0_1_4) { msGetMapContextXMLHashValueDecode(psLayer, "DataURL.OnlineResource.xlink:href", &(layer->metadata), "wms_dataurl"); @@ -890,71 +846,74 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion, /* The DataURL have a width, height, format and an URL */ /* Width and height are not used, but they are included to */ /* be consistent with the spec. */ - msLoadMapContextURLELements( CPLGetXMLNode(psLayer, "DataURL"), - &(layer->metadata), "wms_dataurl" ); + msLoadMapContextURLELements(CPLGetXMLNode(psLayer, "DataURL"), + &(layer->metadata), "wms_dataurl"); } /* The MetadataURL have a width, height, format and an URL */ /* Width and height are not used, but they are included to */ /* be consistent with the spec. */ - msLoadMapContextURLELements( CPLGetXMLNode(psLayer, "MetadataURL"), - &(layer->metadata), "wms_metadataurl" ); - + msLoadMapContextURLELements(CPLGetXMLNode(psLayer, "MetadataURL"), + &(layer->metadata), "wms_metadataurl"); /* MinScale && MaxScale */ - pszValue = (char*)CPLGetXMLValue(psLayer, "sld:MinScaleDenominator", NULL); - if(pszValue != NULL) { + pszValue = (char *)CPLGetXMLValue(psLayer, "sld:MinScaleDenominator", NULL); + if (pszValue != NULL) { layer->minscaledenom = atof(pszValue); } - pszValue = (char*)CPLGetXMLValue(psLayer, "sld:MaxScaleDenominator", NULL); - if(pszValue != NULL) { + pszValue = (char *)CPLGetXMLValue(psLayer, "sld:MaxScaleDenominator", NULL); + if (pszValue != NULL) { layer->maxscaledenom = atof(pszValue); } /* */ /* Server */ /* */ - if(nVersion >= OWS_0_1_4) { - if(msGetMapContextXMLStringValueDecode(psLayer, - "Server.OnlineResource.xlink:href", - &(layer->connection)) == MS_FAILURE) { - msSetError(MS_MAPCONTEXTERR, - "Mandatory data Server.OnlineResource.xlink:href missing in %s.", - "msLoadMapContext()", filename); + if (nVersion >= OWS_0_1_4) { + if (msGetMapContextXMLStringValueDecode( + psLayer, "Server.OnlineResource.xlink:href", + &(layer->connection)) == MS_FAILURE) { + msSetError( + MS_MAPCONTEXTERR, + "Mandatory data Server.OnlineResource.xlink:href missing in %s.", + "msLoadMapContext()", filename); return MS_FAILURE; } else { - msGetMapContextXMLHashValueDecode(psLayer, - "Server.OnlineResource.xlink:href", - &(layer->metadata), "wms_onlineresource"); + msGetMapContextXMLHashValueDecode( + psLayer, "Server.OnlineResource.xlink:href", &(layer->metadata), + "wms_onlineresource"); layer->connectiontype = MS_WMS; } } else { - if(msGetMapContextXMLStringValueDecode(psLayer, - "Server.onlineResource", - &(layer->connection)) == MS_FAILURE) { + if (msGetMapContextXMLStringValueDecode(psLayer, "Server.onlineResource", + &(layer->connection)) == + MS_FAILURE) { msSetError(MS_MAPCONTEXTERR, "Mandatory data Server.onlineResource missing in %s.", "msLoadMapContext()", filename); return MS_FAILURE; } else { msGetMapContextXMLHashValueDecode(psLayer, "Server.onlineResource", - &(layer->metadata), "wms_onlineresource"); + &(layer->metadata), + "wms_onlineresource"); layer->connectiontype = MS_WMS; } } - if(nVersion >= OWS_0_1_4) { - if(msGetMapContextXMLHashValue(psLayer, "Server.version", - &(layer->metadata), "wms_server_version") == MS_FAILURE) { + if (nVersion >= OWS_0_1_4) { + if (msGetMapContextXMLHashValue(psLayer, "Server.version", + &(layer->metadata), + "wms_server_version") == MS_FAILURE) { msSetError(MS_MAPCONTEXTERR, "Mandatory data Server.version missing in %s.", "msLoadMapContext()", filename); return MS_FAILURE; } } else { - if(msGetMapContextXMLHashValue(psLayer, "Server.wmtver", - &(layer->metadata), "wms_server_version") == MS_FAILURE) { + if (msGetMapContextXMLHashValue(psLayer, "Server.wmtver", + &(layer->metadata), + "wms_server_version") == MS_FAILURE) { msSetError(MS_MAPCONTEXTERR, "Mandatory data Server.wmtver missing in %s.", "msLoadMapContext()", filename); @@ -963,23 +922,23 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion, } /* Projection */ - msLoadMapContextListInMetadata( psLayer, &(layer->metadata), - "SRS", "wms_srs", " " ); + msLoadMapContextListInMetadata(psLayer, &(layer->metadata), "SRS", "wms_srs", + " "); pszHash = msLookupHashTable(&(layer->metadata), "wms_srs"); - if(((pszHash == NULL) || (strcasecmp(pszHash, "") == 0)) && + if (((pszHash == NULL) || (strcasecmp(pszHash, "") == 0)) && map->projection.numargs != 0) { - char* pszProj = map->projection.args[map->projection.numargs-1]; + char *pszProj = map->projection.args[map->projection.numargs - 1]; - if(pszProj != NULL) { - if(strncasecmp(pszProj, "AUTO:", 5) == 0) { - msInsertHashTable(&(layer->metadata),"wms_srs", pszProj); + if (pszProj != NULL) { + if (strncasecmp(pszProj, "AUTO:", 5) == 0) { + msInsertHashTable(&(layer->metadata), "wms_srs", pszProj); } else { - if(strlen(pszProj) > 10) { - pszProj = (char*) malloc(sizeof(char) * (strlen(pszProj))); - sprintf( pszProj, "EPSG:%s", - map->projection.args[map->projection.numargs-1]+10); - msInsertHashTable(&(layer->metadata),"wms_srs", pszProj); + if (strlen(pszProj) > 10) { + pszProj = (char *)malloc(sizeof(char) * (strlen(pszProj))); + sprintf(pszProj, "EPSG:%s", + map->projection.args[map->projection.numargs - 1] + 10); + msInsertHashTable(&(layer->metadata), "wms_srs", pszProj); } else { msDebug("Unable to set data for layer wms_srs from this" " value %s.", @@ -993,34 +952,32 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion, /* */ /* Format */ /* */ - if( nVersion >= OWS_0_1_4 ) { + if (nVersion >= OWS_0_1_4) { psFormatList = CPLGetXMLNode(psLayer, "FormatList"); } else { psFormatList = psLayer; } - if(psFormatList != NULL) { - for(psFormat = psFormatList->psChild; - psFormat != NULL; - psFormat = psFormat->psNext) { + if (psFormatList != NULL) { + for (psFormat = psFormatList->psChild; psFormat != NULL; + psFormat = psFormat->psNext) { msLoadMapContextLayerFormat(psFormat, layer); } } /* end FormatList parsing */ /* Style */ - if( nVersion >= OWS_0_1_4 ) { + if (nVersion >= OWS_0_1_4) { psStyleList = CPLGetXMLNode(psLayer, "StyleList"); } else { psStyleList = psLayer; } - if(psStyleList != NULL) { + if (psStyleList != NULL) { nStyle = 0; - for(psStyle = psStyleList->psChild; - psStyle != NULL; - psStyle = psStyle->psNext) { - if(strcasecmp(psStyle->pszValue, "Style") == 0) { + for (psStyle = psStyleList->psChild; psStyle != NULL; + psStyle = psStyle->psNext) { + if (strcasecmp(psStyle->pszValue, "Style") == 0) { nStyle++; msLoadMapContextLayerStyle(psStyle, layer, nStyle); } @@ -1029,11 +986,10 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion, /* Dimension */ psDimensionList = CPLGetXMLNode(psLayer, "DimensionList"); - if(psDimensionList != NULL) { - for(psDimension = psDimensionList->psChild; - psDimension != NULL; - psDimension = psDimension->psNext) { - if(strcasecmp(psDimension->pszValue, "Dimension") == 0) { + if (psDimensionList != NULL) { + for (psDimension = psDimensionList->psChild; psDimension != NULL; + psDimension = psDimension->psNext) { + if (strcasecmp(psDimension->pszValue, "Dimension") == 0) { msLoadMapContextLayerDimension(psDimension, layer); } } @@ -1042,13 +998,13 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion, /* Extension */ psExtension = CPLGetXMLNode(psLayer, "Extension"); if (psExtension != NULL) { - pszValue = (char*)CPLGetXMLValue(psExtension, "ol:opacity", NULL); - if(pszValue != NULL) { - if(!layer->compositer) { + pszValue = (char *)CPLGetXMLValue(psExtension, "ol:opacity", NULL); + if (pszValue != NULL) { + if (!layer->compositer) { layer->compositer = msSmallMalloc(sizeof(LayerCompositer)); initLayerCompositer(layer->compositer); } - layer->compositer->opacity = atof(pszValue)*100; + layer->compositer->opacity = atof(pszValue) * 100; } } @@ -1057,8 +1013,6 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion, #endif - - /* msLoadMapContextURL() ** ** load an OGC Web Map Context format from an URL @@ -1066,25 +1020,24 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion, ** Take a map object and a URL to a conect file in arguments */ -int msLoadMapContextURL(mapObj *map, char *urlfilename, int unique_layer_names) -{ +int msLoadMapContextURL(mapObj *map, char *urlfilename, + int unique_layer_names) { #if defined(USE_WMS_LYR) char *pszTmpFile = NULL; int status = 0; if (!map || !urlfilename) { - msSetError(MS_MAPCONTEXTERR, - "Invalid map or url given.", + msSetError(MS_MAPCONTEXTERR, "Invalid map or url given.", "msGetMapContextURL()"); return MS_FAILURE; } pszTmpFile = msTmpFile(map, map->mappath, NULL, "context.xml"); - if (msHTTPGetFile(urlfilename, pszTmpFile, &status,-1, 0, 0, 0) == MS_SUCCESS) { + if (msHTTPGetFile(urlfilename, pszTmpFile, &status, -1, 0, 0, 0) == + MS_SUCCESS) { return msLoadMapContext(map, pszTmpFile, unique_layer_names); } else { - msSetError(MS_MAPCONTEXTERR, - "Could not open context file %s.", + msSetError(MS_MAPCONTEXTERR, "Could not open context file %s.", "msGetMapContextURL()", urlfilename); return MS_FAILURE; } @@ -1102,52 +1055,61 @@ int msLoadMapContextURL(mapObj *map, char *urlfilename, int unique_layer_names) ** ** Take as first map object and a file in arguments ** If The 2nd aregument unique_layer_names is set to MS_TRUE, the layer -** name created would be unique and be prefixed with an l plus the layers's index +** name created would be unique and be prefixed with an l plus the layers's +*index ** (eg l:1:park. l:2:road ...). If It is set to MS_FALSE, the layer name ** would be the same name as the layer name in the context */ -int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names) -{ +int msLoadMapContext(mapObj *map, const char *filename, + int unique_layer_names) { #if defined(USE_WMS_LYR) char *pszWholeText, *pszValue; CPLXMLNode *psRoot, *psMapContext, *psLayer, *psLayerList, *psChild; char szPath[MS_MAXPATHLEN]; - int nVersion=-1; + int nVersion = -1; char szVersionBuf[OWS_VERSION_MAXLEN]; + const char *ms_contextfile_pattern = CPLGetConfigOption( + "MS_CONTEXTFILE_PATTERN", MS_DEFAULT_CONTEXTFILE_PATTERN); + if (msEvalRegex(ms_contextfile_pattern, filename) != MS_TRUE) { + msSetError(MS_REGEXERR, "Filename validation failed.", + "msLoadMapContext()"); + return MS_FAILURE; + } + /* */ /* Load the raw XML file */ /* */ - pszWholeText = msGetMapContextFileText( - msBuildPath(szPath, map->mappath, filename)); - if(pszWholeText == NULL) { - msSetError( MS_MAPCONTEXTERR, "Unable to read %s", - "msLoadMapContext()", filename ); + pszWholeText = + msGetMapContextFileText(msBuildPath(szPath, map->mappath, filename)); + if (pszWholeText == NULL) { + msSetError(MS_MAPCONTEXTERR, "Unable to read %s", "msLoadMapContext()", + filename); return MS_FAILURE; } - if( ( strstr( pszWholeText, "eType == CXT_Element && - (EQUAL(psChild->pszValue,"WMS_Viewer_Context") || - EQUAL(psChild->pszValue,"View_Context") || - EQUAL(psChild->pszValue,"ViewContext")) ) { + while (psChild != NULL) { + if (psChild->eType == CXT_Element && + (EQUAL(psChild->pszValue, "WMS_Viewer_Context") || + EQUAL(psChild->pszValue, "View_Context") || + EQUAL(psChild->pszValue, "ViewContext"))) { psMapContext = psChild; break; } else { @@ -1168,19 +1130,19 @@ int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names) } } - if( psMapContext == NULL ) { + if (psMapContext == NULL) { CPLDestroyXMLNode(psRoot); - msSetError( MS_MAPCONTEXTERR, "Invalid Map Context File (%s)", - "msLoadMapContext()", filename ); + msSetError(MS_MAPCONTEXTERR, "Invalid Map Context File (%s)", + "msLoadMapContext()", filename); return MS_FAILURE; } /* Fetch document version number */ - pszValue = (char*)CPLGetXMLValue(psMapContext, - "version", NULL); - if( !pszValue ) { - msDebug( "msLoadMapContext(): Mandatory data version missing in %s, assuming 0.1.4.", - filename ); + pszValue = (char *)CPLGetXMLValue(psMapContext, "version", NULL); + if (!pszValue) { + msDebug("msLoadMapContext(): Mandatory data version missing in %s, " + "assuming 0.1.4.", + filename); pszValue = "0.1.4"; } @@ -1188,29 +1150,29 @@ int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names) /* Make sure this is a supported version */ switch (nVersion) { - case OWS_0_1_2: - case OWS_0_1_4: - case OWS_0_1_7: - case OWS_1_0_0: - case OWS_1_1_0: - /* All is good, this is a supported version. */ - break; - default: - /* Not a supported version */ - msSetError(MS_MAPCONTEXTERR, - "This version of Map Context is not supported (%s).", - "msLoadMapContext()", pszValue); - CPLDestroyXMLNode(psRoot); - return MS_FAILURE; + case OWS_0_1_2: + case OWS_0_1_4: + case OWS_0_1_7: + case OWS_1_0_0: + case OWS_1_1_0: + /* All is good, this is a supported version. */ + break; + default: + /* Not a supported version */ + msSetError(MS_MAPCONTEXTERR, + "This version of Map Context is not supported (%s).", + "msLoadMapContext()", pszValue); + CPLDestroyXMLNode(psRoot); + return MS_FAILURE; } /* Reformat and save Version in metadata */ - msInsertHashTable( &(map->web.metadata), "wms_context_version", - msOWSGetVersionString(nVersion, szVersionBuf)); + msInsertHashTable(&(map->web.metadata), "wms_context_version", + msOWSGetVersionString(nVersion, szVersionBuf)); - if( nVersion >= OWS_0_1_7 && nVersion < OWS_1_0_0) { - if( msGetMapContextXMLHashValue(psMapContext, "fid", - &(map->web.metadata), "wms_context_fid") == MS_FAILURE ) { + if (nVersion >= OWS_0_1_7 && nVersion < OWS_1_0_0) { + if (msGetMapContextXMLHashValue(psMapContext, "fid", &(map->web.metadata), + "wms_context_fid") == MS_FAILURE) { msDebug("Mandatory data fid missing in %s.", filename); } } @@ -1218,8 +1180,8 @@ int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names) /* */ /* Load the General bloc */ /* */ - psChild = CPLGetXMLNode( psMapContext, "General" ); - if( psChild == NULL ) { + psChild = CPLGetXMLNode(psMapContext, "General"); + if (psChild == NULL) { CPLDestroyXMLNode(psRoot); msSetError(MS_MAPCONTEXTERR, "The Map Context document provided (%s) does not contain any " @@ -1228,8 +1190,8 @@ int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names) return MS_FAILURE; } - if( msLoadMapContextGeneral(map, psChild, psMapContext, - nVersion, filename) == MS_FAILURE ) { + if (msLoadMapContextGeneral(map, psChild, psMapContext, nVersion, filename) == + MS_FAILURE) { CPLDestroyXMLNode(psRoot); return MS_FAILURE; } @@ -1238,18 +1200,17 @@ int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names) /* Load the bloc LayerList */ /* */ psLayerList = CPLGetXMLNode(psMapContext, "LayerList"); - if( psLayerList != NULL ) { - for(psLayer = psLayerList->psChild; - psLayer != NULL; - psLayer = psLayer->psNext) { - if(EQUAL(psLayer->pszValue, "Layer")) { - if( msLoadMapContextLayer(map, psLayer, nVersion, - filename, unique_layer_names) == MS_FAILURE ) { + if (psLayerList != NULL) { + for (psLayer = psLayerList->psChild; psLayer != NULL; + psLayer = psLayer->psNext) { + if (EQUAL(psLayer->pszValue, "Layer")) { + if (msLoadMapContextLayer(map, psLayer, nVersion, filename, + unique_layer_names) == MS_FAILURE) { CPLDestroyXMLNode(psRoot); return MS_FAILURE; } - }/* end Layer parsing */ - }/* for */ + } /* end Layer parsing */ + } /* for */ } CPLDestroyXMLNode(psRoot); @@ -1264,26 +1225,24 @@ int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names) #endif } - /* msSaveMapContext() ** ** Save a mapfile into the OGC Web Map Context format ** ** Take a map object and a file in arguments */ -int msSaveMapContext(mapObj *map, char *filename) -{ +int msSaveMapContext(mapObj *map, char *filename) { #if defined(USE_WMS_LYR) - VSILFILE *stream; + FILE *stream; char szPath[MS_MAXPATHLEN]; int nStatus; /* open file */ - if(filename != NULL && strlen(filename) > 0) { + if (filename != NULL && strlen(filename) > 0) { stream = fopen(msBuildPath(szPath, map->mappath, filename), "wb"); - if(!stream) { + if (!stream) { msSetError(MS_IOERR, "(%s)", "msSaveMapContext()", filename); - return(MS_FAILURE); + return (MS_FAILURE); } } else { msSetError(MS_IOERR, "Filename is undefined.", "msSaveMapContext()"); @@ -1303,133 +1262,139 @@ int msSaveMapContext(mapObj *map, char *filename) #endif } - - -int msWriteMapContext(mapObj *map, FILE *stream) -{ +int msWriteMapContext(mapObj *map, FILE *stream) { #if defined(USE_WMS_LYR) - const char * version; + const char *version; char *pszEPSG; - char * tabspace=NULL, *pszChar,*pszSLD=NULL,*pszSLD2=NULL; - char *pszStyle, *pszStyleItem, *pszSLDBody; + char *tabspace = NULL, *pszChar, *pszSLD = NULL, *pszSLD2 = NULL; + char *pszStyleItem, *pszSLDBody; char *pszEncodedVal; - int i, nValue, nVersion=OWS_VERSION_NOTSET; + int i, nValue, nVersion = OWS_VERSION_NOTSET; /* Dimension element */ char *pszDimension; - const char *pszDimUserValue=NULL, *pszDimUnits=NULL, *pszDimDefault=NULL; - const char *pszDimNearValue=NULL, *pszDimUnitSymbol=NULL; - const char *pszDimMultiValue=NULL; + const char *pszDimUserValue = NULL, *pszDimUnits = NULL, + *pszDimDefault = NULL; + const char *pszDimNearValue = NULL, *pszDimUnitSymbol = NULL; + const char *pszDimMultiValue = NULL; int bDimensionList = 0; /* Decide which version we're going to return... */ version = msLookupHashTable(&(map->web.metadata), "wms_context_version"); - if(version == NULL) + if (version == NULL) version = "1.1.0"; nVersion = msOWSParseVersionString(version); if (nVersion == OWS_VERSION_BADFORMAT) - return MS_FAILURE; /* msSetError() already called. */ + return MS_FAILURE; /* msSetError() already called. */ /* Make sure this is a supported version */ /* Note that we don't write 0.1.2 even if we read it. */ switch (nVersion) { - case OWS_0_1_4: - case OWS_0_1_7: - case OWS_1_0_0: - case OWS_1_1_0: - /* All is good, this is a supported version. */ - break; - default: - /* Not a supported version */ - msSetError(MS_MAPCONTEXTERR, - "This version of Map Context is not supported (%s).", - "msSaveMapContext()", version); - return MS_FAILURE; + case OWS_0_1_4: + case OWS_0_1_7: + case OWS_1_0_0: + case OWS_1_1_0: + /* All is good, this is a supported version. */ + break; + default: + /* Not a supported version */ + msSetError(MS_MAPCONTEXTERR, + "This version of Map Context is not supported (%s).", + "msSaveMapContext()", version); + return MS_FAILURE; } /* file header */ - msIO_fprintf( stream, "\n"); + msIO_fprintf(stream, + "\n"); /* set the WMS_Viewer_Context information */ pszEncodedVal = msEncodeHTMLEntities(version); - if(nVersion >= OWS_1_0_0) { - msIO_fprintf( stream, "= OWS_0_1_7) { - msIO_fprintf( stream, "= OWS_1_0_0) { + msIO_fprintf(stream, "= OWS_0_1_7) { + msIO_fprintf(stream, "= OWS_0_1_7 && nVersion < OWS_1_0_0 ) { + if (nVersion >= OWS_0_1_7 && nVersion < OWS_1_0_0) { msOWSPrintEncodeMetadata(stream, &(map->web.metadata), NULL, - "wms_context_fid", OWS_NOERR," fid=\"%s\"","0"); + "wms_context_fid", OWS_NOERR, " fid=\"%s\"", "0"); } - if ( nVersion >= OWS_1_0_0 ) + if (nVersion >= OWS_1_0_0) msOWSPrintEncodeParam(stream, "MAP.NAME", map->name, OWS_NOERR, " id=\"%s\"", NULL); - msIO_fprintf( stream, " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); - msIO_fprintf( stream, " xmlns:ogc=\"http://www.opengis.net/ogc\""); + msIO_fprintf(stream, + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); + msIO_fprintf(stream, " xmlns:ogc=\"http://www.opengis.net/ogc\""); - if( nVersion >= OWS_0_1_7 && nVersion < OWS_1_0_0 ) { - msIO_fprintf( stream, " xmlns:gml=\"http://www.opengis.net/gml\""); + if (nVersion >= OWS_0_1_7 && nVersion < OWS_1_0_0) { + msIO_fprintf(stream, " xmlns:gml=\"http://www.opengis.net/gml\""); } - if( nVersion >= OWS_1_0_0 ) { - msIO_fprintf( stream, " xmlns:xlink=\"http://www.w3.org/1999/xlink\""); - msIO_fprintf( stream, " xmlns=\"http://www.opengis.net/context\""); - msIO_fprintf( stream, " xmlns:sld=\"http://www.opengis.net/sld\""); + if (nVersion >= OWS_1_0_0) { + msIO_fprintf(stream, " xmlns:xlink=\"http://www.w3.org/1999/xlink\""); + msIO_fprintf(stream, " xmlns=\"http://www.opengis.net/context\""); + msIO_fprintf(stream, " xmlns:sld=\"http://www.opengis.net/sld\""); pszEncodedVal = msEncodeHTMLEntities(msOWSGetSchemasLocation(map)); - if( nVersion >= OWS_1_1_0 ) - msIO_fprintf( stream, - " xsi:schemaLocation=\"http://www.opengis.net/context %s/context/1.1.0/context.xsd\">\n", - pszEncodedVal); + if (nVersion >= OWS_1_1_0) + msIO_fprintf(stream, + " xsi:schemaLocation=\"http://www.opengis.net/context " + "%s/context/1.1.0/context.xsd\">\n", + pszEncodedVal); else - msIO_fprintf( stream, - " xsi:schemaLocation=\"http://www.opengis.net/context %s/context/1.0.0/context.xsd\">\n", - pszEncodedVal); + msIO_fprintf(stream, + " xsi:schemaLocation=\"http://www.opengis.net/context " + "%s/context/1.0.0/context.xsd\">\n", + pszEncodedVal); msFree(pszEncodedVal); } else { - msIO_fprintf( stream, " xmlns:xlink=\"http://www.w3.org/TR/xlink\""); + msIO_fprintf(stream, " xmlns:xlink=\"http://www.w3.org/TR/xlink\""); pszEncodedVal = msEncodeHTMLEntities(msOWSGetSchemasLocation(map)); - msIO_fprintf( stream, " xsi:noNamespaceSchemaLocation=\"%s/contexts/", - pszEncodedVal ); + msIO_fprintf(stream, " xsi:noNamespaceSchemaLocation=\"%s/contexts/", + pszEncodedVal); msFree(pszEncodedVal); pszEncodedVal = msEncodeHTMLEntities(msOWSGetSchemasLocation(map)); - msIO_fprintf( stream, "%s/context.xsd\">\n", pszEncodedVal); + msIO_fprintf(stream, "%s/context.xsd\">\n", pszEncodedVal); msFree(pszEncodedVal); } /* set the General information */ - msIO_fprintf( stream, " \n" ); + msIO_fprintf(stream, " \n"); /* Window */ - if( map->width != -1 || map->height != -1 ) - msIO_fprintf( stream, " \n", - map->width, map->height ); + if (map->width != -1 || map->height != -1) + msIO_fprintf(stream, " \n", + map->width, map->height); /* Bounding box corners and spatial reference system */ - if(tabspace) + if (tabspace) free(tabspace); tabspace = msStrdup(" "); - msOWSGetEPSGProj(&(map->projection), &(map->web.metadata), "MO", MS_TRUE, &pszEPSG); - msIO_fprintf( stream, - "%s\n", - tabspace ); - if(!pszEPSG || (strcasecmp(pszEPSG, "(null)") == 0)) - msIO_fprintf(stream, "\n"); + msOWSGetEPSGProj(&(map->projection), &(map->web.metadata), "MO", MS_TRUE, + &pszEPSG); + msIO_fprintf(stream, + "%s\n", + tabspace); + if (!pszEPSG || (strcasecmp(pszEPSG, "(null)") == 0)) + msIO_fprintf(stream, "\n"); pszEncodedVal = msEncodeHTMLEntities(pszEPSG); - msIO_fprintf( stream, "%s\n", - tabspace, pszEncodedVal, map->extent.minx, map->extent.miny, - map->extent.maxx, map->extent.maxy ); + msIO_fprintf(stream, + "%s\n", + tabspace, pszEncodedVal, map->extent.minx, map->extent.miny, + map->extent.maxx, map->extent.maxy); msFree(pszEncodedVal); msFree(pszEPSG); /* Title, name */ - if( nVersion >= OWS_0_1_7 && nVersion < OWS_1_0_0 ) { + if (nVersion >= OWS_0_1_7 && nVersion < OWS_1_0_0) { msOWSPrintEncodeParam(stream, "MAP.NAME", map->name, OWS_NOERR, " %s\n", NULL); } else { @@ -1437,90 +1402,91 @@ int msWriteMapContext(mapObj *map, FILE *stream) msOWSPrintEncodeParam(stream, "MAP.NAME", map->name, OWS_NOERR, " %s\n", NULL); - msIO_fprintf( stream, "%s\n", tabspace ); - msOWSPrintEncodeMetadata(stream, &(map->web.metadata), - NULL, "wms_title", OWS_WARN, - " %s\n", map->name); + msIO_fprintf(stream, "%s\n", tabspace); + msOWSPrintEncodeMetadata(stream, &(map->web.metadata), NULL, "wms_title", + OWS_WARN, " %s\n", map->name); } /* keyword */ if (nVersion >= OWS_1_0_0) { - if (msLookupHashTable(&(map->web.metadata),"wms_keywordlist")!=NULL) { + if (msLookupHashTable(&(map->web.metadata), "wms_keywordlist") != NULL) { char **papszKeywords; int nKeywords, iKey; - const char* pszValue = msLookupHashTable(&(map->web.metadata), - "wms_keywordlist"); + const char *pszValue = + msLookupHashTable(&(map->web.metadata), "wms_keywordlist"); papszKeywords = msStringSplit(pszValue, ',', &nKeywords); - if(nKeywords > 0 && papszKeywords) { - msIO_fprintf( stream, " \n"); - for(iKey=0; iKey 0 && papszKeywords) { + msIO_fprintf(stream, " \n"); + for (iKey = 0; iKey < nKeywords; iKey++) { pszEncodedVal = msEncodeHTMLEntities(papszKeywords[iKey]); - msIO_fprintf( stream, " %s\n", - pszEncodedVal); + msIO_fprintf(stream, " %s\n", pszEncodedVal); msFree(pszEncodedVal); } - msIO_fprintf( stream, " \n"); + msIO_fprintf(stream, " \n"); } } } else msOWSPrintEncodeMetadataList(stream, &(map->web.metadata), NULL, - "wms_keywordlist", - " \n", " \n", - " %s\n", NULL); + "wms_keywordlist", " \n", + " \n", " %s\n", NULL); /* abstract */ - if( nVersion >= OWS_0_1_7 && nVersion < OWS_1_0_0 ) { - msOWSPrintEncodeMetadata(stream, &(map->web.metadata), - NULL, "wms_abstract", OWS_NOERR, - " %s\n", NULL); + if (nVersion >= OWS_0_1_7 && nVersion < OWS_1_0_0) { + msOWSPrintEncodeMetadata( + stream, &(map->web.metadata), NULL, "wms_abstract", OWS_NOERR, + " %s\n", NULL); } else { - msOWSPrintEncodeMetadata(stream, &(map->web.metadata), - NULL, "wms_abstract", OWS_NOERR, - " %s\n", NULL); + msOWSPrintEncodeMetadata(stream, &(map->web.metadata), NULL, "wms_abstract", + OWS_NOERR, " %s\n", NULL); } /* LogoURL */ /* The LogoURL have a width, height, format and an URL */ - msOWSPrintURLType(stream, &(map->web.metadata), "MO", "logourl", - OWS_NOERR, NULL, "LogoURL", NULL, " width=\"%s\"", - " height=\"%s\""," format=\"%s\"", - " \n", - MS_FALSE, MS_FALSE, MS_FALSE, MS_FALSE, MS_TRUE, - NULL, NULL, NULL, NULL, NULL, " "); + msOWSPrintURLType( + stream, &(map->web.metadata), "MO", "logourl", OWS_NOERR, NULL, "LogoURL", + NULL, " width=\"%s\"", " height=\"%s\"", " format=\"%s\"", + " \n", + MS_FALSE, MS_FALSE, MS_FALSE, MS_FALSE, MS_TRUE, NULL, NULL, NULL, NULL, + NULL, " "); /* DataURL */ - msOWSPrintEncodeMetadata(stream, &(map->web.metadata), - NULL, "wms_dataurl", OWS_NOERR, - " \n \n \n", NULL); + msOWSPrintEncodeMetadata( + stream, &(map->web.metadata), NULL, "wms_dataurl", OWS_NOERR, + " \n \n \n", + NULL); /* DescriptionURL */ /* The DescriptionURL have a width, height, format and an URL */ /* The metadata is structured like this: "width height format url" */ - msOWSPrintURLType(stream, &(map->web.metadata), "MO", "descriptionurl", - OWS_NOERR, NULL, "DescriptionURL", NULL, " width=\"%s\"", - " height=\"%s\""," format=\"%s\"", - " \n", - MS_FALSE, MS_FALSE, MS_FALSE, MS_FALSE, MS_TRUE, - NULL, NULL, NULL, NULL, NULL, " "); + msOWSPrintURLType( + stream, &(map->web.metadata), "MO", "descriptionurl", OWS_NOERR, NULL, + "DescriptionURL", NULL, " width=\"%s\"", " height=\"%s\"", + " format=\"%s\"", + " \n", + MS_FALSE, MS_FALSE, MS_FALSE, MS_FALSE, MS_TRUE, NULL, NULL, NULL, NULL, + NULL, " "); /* Contact Info */ - msOWSPrintContactInfo( stream, tabspace, OWS_1_1_0, &(map->web.metadata), "MO" ); + msOWSPrintContactInfo(stream, tabspace, OWS_1_1_0, &(map->web.metadata), + "MO"); /* Close General */ - msIO_fprintf( stream, " \n" ); + msIO_fprintf(stream, " \n"); free(tabspace); /* Set the layer list */ msIO_fprintf(stream, " \n"); /* Loop on all layer */ - for(i=0; inumlayers; i++) { - if(GET_LAYER(map, i)->status != MS_DELETE && GET_LAYER(map, i)->connectiontype == MS_WMS) { - const char* pszValue; - char* pszValueMod; - const char* pszCurrent; - if(GET_LAYER(map, i)->status == MS_OFF) + for (i = 0; i < map->numlayers; i++) { + if (GET_LAYER(map, i)->status != MS_DELETE && + GET_LAYER(map, i)->connectiontype == MS_WMS) { + const char *pszValue; + char *pszValueMod; + const char *pszCurrent; + if (GET_LAYER(map, i)->status == MS_OFF) nValue = 1; else nValue = 0; @@ -1530,72 +1496,69 @@ int msWriteMapContext(mapObj *map, FILE *stream) /* */ /* Server definition */ /* */ - if(nVersion < OWS_1_0_0 ) - msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), - NULL, "wms_server_version", OWS_WARN, - " metadata), NULL, "wms_server_version", + OWS_WARN, " metadata), - NULL, "wms_server_version", OWS_WARN, - " metadata), "MO", "server_title")) - msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), - NULL, "wms_server_title", OWS_NOERR, + msOWSPrintEncodeMetadata( + stream, &(GET_LAYER(map, i)->metadata), NULL, "wms_server_version", + OWS_WARN, " metadata), "MO", + "server_title")) + msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), NULL, + "wms_server_title", OWS_NOERR, "title=\"%s\">\n", ""); - else if(GET_LAYER(map, i)->name) - msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), - NULL, "wms_title", OWS_NOERR, - "title=\"%s\">\n", GET_LAYER(map, i)->name); + else if (GET_LAYER(map, i)->name) + msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), NULL, + "wms_title", OWS_NOERR, "title=\"%s\">\n", + GET_LAYER(map, i)->name); else { - msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), - NULL, "wms_title", OWS_NOERR, - "title=\"%s\">\n", ""); + msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), NULL, + "wms_title", OWS_NOERR, "title=\"%s\">\n", ""); } /* Get base url of the online resource to be the default value */ - if(GET_LAYER(map, i)->connection) - pszValueMod = msStrdup( GET_LAYER(map, i)->connection ); + if (GET_LAYER(map, i)->connection) + pszValueMod = msStrdup(GET_LAYER(map, i)->connection); else - pszValueMod = msStrdup( "" ); + pszValueMod = msStrdup(""); pszChar = strchr(pszValueMod, '?'); - if( pszChar ) + if (pszChar) pszValueMod[pszChar - pszValueMod] = '\0'; - if(msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), - NULL, "wms_onlineresource", OWS_WARN, - " \n", - pszValueMod) == OWS_WARN) + if (msOWSPrintEncodeMetadata( + stream, &(GET_LAYER(map, i)->metadata), NULL, + "wms_onlineresource", OWS_WARN, + " \n", + pszValueMod) == OWS_WARN) msIO_fprintf(stream, "\n"); + " , but probably not what you want -->\n"); msIO_fprintf(stream, " \n"); - if(pszValueMod) + if (pszValueMod) free(pszValueMod); /* */ /* Layer information */ /* */ - msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), - NULL, "wms_name", OWS_WARN, - " %s\n", - GET_LAYER(map, i)->name); - msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), - NULL, "wms_title", OWS_WARN, - " %s\n", + msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), NULL, + "wms_name", OWS_WARN, " %s\n", GET_LAYER(map, i)->name); - msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), - NULL, "wms_abstract", OWS_NOERR, - " %s\n", - NULL); + msOWSPrintEncodeMetadata( + stream, &(GET_LAYER(map, i)->metadata), NULL, "wms_title", OWS_WARN, + " %s\n", GET_LAYER(map, i)->name); + msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), NULL, + "wms_abstract", OWS_NOERR, + " %s\n", NULL); /* DataURL */ - if(nVersion <= OWS_0_1_4) { - msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), - NULL, "wms_dataurl", OWS_NOERR, - " %s\n", - NULL); + if (nVersion <= OWS_0_1_4) { + msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata), NULL, + "wms_dataurl", OWS_NOERR, + " %s\n", NULL); } else { /* The DataURL have a width, height, format and an URL */ /* The metadata will be structured like this: */ @@ -1605,12 +1568,11 @@ int msWriteMapContext(mapObj *map, FILE *stream) /* for consistency with the URLType. */ msOWSPrintURLType(stream, &(GET_LAYER(map, i)->metadata), "MO", "dataurl", OWS_NOERR, NULL, "DataURL", NULL, - " width=\"%s\"", " height=\"%s\"", - " format=\"%s\"", + " width=\"%s\"", " height=\"%s\"", " format=\"%s\"", " \n", - MS_FALSE, MS_FALSE, MS_FALSE, MS_FALSE, - MS_TRUE, NULL, NULL, NULL,NULL,NULL, " "); + MS_FALSE, MS_FALSE, MS_FALSE, MS_FALSE, MS_TRUE, NULL, + NULL, NULL, NULL, NULL, " "); } /* MetadataURL */ @@ -1618,28 +1580,30 @@ int msWriteMapContext(mapObj *map, FILE *stream) /* The metadata will be structured like this: */ /* "width height format url" */ msOWSPrintURLType(stream, &(GET_LAYER(map, i)->metadata), "MO", - "metadataurl", OWS_NOERR, NULL, "MetadataURL",NULL, - " width=\"%s\"", " height=\"%s\""," format=\"%s\"", + "metadataurl", OWS_NOERR, NULL, "MetadataURL", NULL, + " width=\"%s\"", " height=\"%s\"", " format=\"%s\"", " \n", - MS_FALSE, MS_FALSE, MS_FALSE, MS_FALSE, - MS_TRUE, NULL, NULL, NULL, NULL, NULL, " "); + MS_FALSE, MS_FALSE, MS_FALSE, MS_FALSE, MS_TRUE, NULL, + NULL, NULL, NULL, NULL, " "); /* MinScale && MaxScale */ - if(nVersion >= OWS_1_1_0 && GET_LAYER(map, i)->minscaledenom > 0) - msIO_fprintf(stream, - " %g\n", - GET_LAYER(map, i)->minscaledenom); - if(nVersion >= OWS_1_1_0 && GET_LAYER(map, i)->maxscaledenom > 0) - msIO_fprintf(stream, - " %g\n", - GET_LAYER(map, i)->maxscaledenom); + if (nVersion >= OWS_1_1_0 && GET_LAYER(map, i)->minscaledenom > 0) + msIO_fprintf( + stream, + " %g\n", + GET_LAYER(map, i)->minscaledenom); + if (nVersion >= OWS_1_1_0 && GET_LAYER(map, i)->maxscaledenom > 0) + msIO_fprintf( + stream, + " %g\n", + GET_LAYER(map, i)->maxscaledenom); /* Layer SRS */ msOWSGetEPSGProj(&(GET_LAYER(map, i)->projection), - &(GET_LAYER(map, i)->metadata), - "MO", MS_FALSE, &pszEPSG); - if(pszEPSG && (strcasecmp(pszEPSG, "(null)") != 0)) { + &(GET_LAYER(map, i)->metadata), "MO", MS_FALSE, + &pszEPSG); + if (pszEPSG && (strcasecmp(pszEPSG, "(null)") != 0)) { pszEncodedVal = msEncodeHTMLEntities(pszEPSG); msIO_fprintf(stream, " %s\n", pszEncodedVal); msFree(pszEncodedVal); @@ -1647,25 +1611,27 @@ int msWriteMapContext(mapObj *map, FILE *stream) msFree(pszEPSG); /* Format */ - if(msLookupHashTable(&(GET_LAYER(map, i)->metadata),"wms_formatlist")==NULL && - msLookupHashTable(&(GET_LAYER(map, i)->metadata),"wms_format")==NULL) { - char* pszURL; - if(GET_LAYER(map, i)->connection) - pszURL = msStrdup( GET_LAYER(map, i)->connection ); + if (msLookupHashTable(&(GET_LAYER(map, i)->metadata), "wms_formatlist") == + NULL && + msLookupHashTable(&(GET_LAYER(map, i)->metadata), "wms_format") == + NULL) { + char *pszURL; + if (GET_LAYER(map, i)->connection) + pszURL = msStrdup(GET_LAYER(map, i)->connection); else - pszURL = msStrdup( "" ); + pszURL = msStrdup(""); - pszValueMod = strstr( pszURL, "FORMAT=" ); - if( pszValueMod ) { + pszValueMod = strstr(pszURL, "FORMAT="); + if (pszValueMod) { pszValueMod += 7; pszChar = strchr(pszValueMod, '&'); - if( pszChar ) + if (pszChar) pszValueMod[pszChar - pszValueMod] = '\0'; - if(strcasecmp(pszValueMod, "") != 0) { + if (strcasecmp(pszValueMod, "") != 0) { pszEncodedVal = msEncodeHTMLEntities(pszValueMod); - msIO_fprintf( stream, " \n"); - msIO_fprintf(stream," %s\n",pszValueMod); - msIO_fprintf( stream, " \n"); + msIO_fprintf(stream, " \n"); + msIO_fprintf(stream, " %s\n", pszValueMod); + msIO_fprintf(stream, " \n"); msFree(pszEncodedVal); } } @@ -1674,62 +1640,62 @@ int msWriteMapContext(mapObj *map, FILE *stream) char **papszFormats; int numFormats, nForm; - pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata), - "wms_formatlist"); - if(!pszValue) - pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata), - "wms_format"); - pszCurrent = msLookupHashTable(&(GET_LAYER(map, i)->metadata), - "wms_format"); + pszValue = + msLookupHashTable(&(GET_LAYER(map, i)->metadata), "wms_formatlist"); + if (!pszValue) + pszValue = + msLookupHashTable(&(GET_LAYER(map, i)->metadata), "wms_format"); + pszCurrent = + msLookupHashTable(&(GET_LAYER(map, i)->metadata), "wms_format"); papszFormats = msStringSplit(pszValue, ',', &numFormats); - if(numFormats > 0 && papszFormats) { - msIO_fprintf( stream, " \n"); - for(nForm=0; nForm%s\n", - pszEncodedVal); + if (numFormats > 0 && papszFormats) { + msIO_fprintf(stream, " \n"); + for (nForm = 0; nForm < numFormats; nForm++) { + pszEncodedVal = msEncodeHTMLEntities(papszFormats[nForm]); + if (pszCurrent && + (strcasecmp(papszFormats[nForm], pszCurrent) == 0)) + msIO_fprintf(stream, + " %s\n", + pszEncodedVal); else - msIO_fprintf( stream, " %s\n", - pszEncodedVal); + msIO_fprintf(stream, " %s\n", + pszEncodedVal); msFree(pszEncodedVal); } - msIO_fprintf( stream, " \n"); + msIO_fprintf(stream, " \n"); } - if(papszFormats) + if (papszFormats) msFreeCharArray(papszFormats, numFormats); } /* Style */ /* First check the stylelist */ - pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata), - "wms_stylelist"); - while( pszValue && *pszValue == ' ' ) - pszValue ++; - if(pszValue == NULL || strlen(pszValue) < 1) { + pszValue = + msLookupHashTable(&(GET_LAYER(map, i)->metadata), "wms_stylelist"); + while (pszValue && *pszValue == ' ') + pszValue++; + if (pszValue == NULL || strlen(pszValue) < 1) { /* Check if the style is in the connection URL */ - char* pszURL; - if(GET_LAYER(map, i)->connection) - pszURL = msStrdup( GET_LAYER(map, i)->connection ); + char *pszURL; + if (GET_LAYER(map, i)->connection) + pszURL = msStrdup(GET_LAYER(map, i)->connection); else - pszURL = msStrdup( "" ); + pszURL = msStrdup(""); /* Grab the STYLES in the URL */ - pszValueMod = strstr( pszURL, "STYLES=" ); - if( pszValueMod ) { + pszValueMod = strstr(pszURL, "STYLES="); + if (pszValueMod) { pszValueMod += 7; pszChar = strchr(pszValueMod, '&'); - if( pszChar ) + if (pszChar) pszValueMod[pszChar - pszValueMod] = '\0'; /* Check the SLD string from the URL */ - if(GET_LAYER(map, i)->connection) + if (GET_LAYER(map, i)->connection) pszSLD2 = msStrdup(GET_LAYER(map, i)->connection); else - pszSLD2 = msStrdup( "" ); - if(pszSLD2) { + pszSLD2 = msStrdup(""); + if (pszSLD2) { pszSLD = strstr(pszSLD2, "SLD="); pszSLDBody = strstr(pszSLD2, "SLD_BODY="); } else { @@ -1737,103 +1703,104 @@ int msWriteMapContext(mapObj *map, FILE *stream) pszSLDBody = NULL; } /* Check SLD */ - if( pszSLD ) { + if (pszSLD) { pszChar = strchr(pszSLD, '&'); - if( pszChar ) + if (pszChar) pszSLD[pszChar - pszSLD] = '\0'; pszSLD += 4; } /* Check SLDBody */ - if( pszSLDBody ) { + if (pszSLDBody) { pszChar = strchr(pszSLDBody, '&'); - if( pszChar ) + if (pszChar) pszSLDBody[pszChar - pszSLDBody] = '\0'; pszSLDBody += 9; } - if( (pszValueMod && (strcasecmp(pszValueMod, "") != 0)) || + if ((pszValueMod && (strcasecmp(pszValueMod, "") != 0)) || (pszSLD && (strcasecmp(pszSLD, "") != 0)) || (pszSLDBody && (strcasecmp(pszSLDBody, "") != 0))) { /* Write Name and Title */ - msIO_fprintf( stream, " \n"); - msIO_fprintf( stream, " \n"); + msIO_fprintf(stream, " \n"); } - if(pszSLD2) { + if (pszSLD2) { free(pszSLD2); pszSLD2 = NULL; } } free(pszURL); } else { - const char* pszCurrent; + const char *pszCurrent; /* If the style information is not in the connection URL, */ /* read the metadata. */ - pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata), - "wms_stylelist"); - pszCurrent = msLookupHashTable(&(GET_LAYER(map, i)->metadata), - "wms_style"); - msIO_fprintf( stream, " \n"); + pszValue = + msLookupHashTable(&(GET_LAYER(map, i)->metadata), "wms_stylelist"); + pszCurrent = + msLookupHashTable(&(GET_LAYER(map, i)->metadata), "wms_style"); + msIO_fprintf(stream, " \n"); /* Loop in each style in the style list */ - while(pszValue != NULL) { - pszStyle = msStrdup(pszValue); + while (pszValue != NULL) { + char *pszStyle = msStrdup(pszValue); pszChar = strchr(pszStyle, ','); - if(pszChar != NULL) + if (pszChar != NULL) pszStyle[pszChar - pszStyle] = '\0'; - if(strcasecmp(pszStyle, "") == 0) + if (pszStyle[0] == '\0') { + msFree(pszStyle); continue; + } - if(pszCurrent && (strcasecmp(pszStyle, pszCurrent) == 0)) - msIO_fprintf( stream," \n"); + msIO_fprintf(stream, " \n"); } /* Dimension element */; @@ -1889,75 +1851,72 @@ int msWriteMapContext(mapObj *map, FILE *stream) pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata), "wms_dimensionlist"); - pszCurrent = msLookupHashTable(&(GET_LAYER(map, i)->metadata), - "wms_dimension"); - while(pszValue != NULL) { + pszCurrent = + msLookupHashTable(&(GET_LAYER(map, i)->metadata), "wms_dimension"); + while (pszValue != NULL) { /* Extract the dimension name from the list */ pszDimension = msStrdup(pszValue); pszChar = strchr(pszDimension, ','); - if(pszChar != NULL) + if (pszChar != NULL) pszDimension[pszChar - pszDimension] = '\0'; - if(strcasecmp(pszDimension, "") == 0) { + if (strcasecmp(pszDimension, "") == 0) { free(pszDimension); pszValue = strchr(pszValue, ','); - if(pszValue) + if (pszValue) pszValue++; continue; } /* From the dimension list, extract the required dimension */ - msOWSGetDimensionInfo(GET_LAYER(map, i), pszDimension, - &pszDimUserValue, &pszDimUnits, - &pszDimDefault, &pszDimNearValue, + msOWSGetDimensionInfo(GET_LAYER(map, i), pszDimension, &pszDimUserValue, + &pszDimUnits, &pszDimDefault, &pszDimNearValue, &pszDimUnitSymbol, &pszDimMultiValue); - if(pszDimUserValue == NULL || pszDimUnits == NULL || + if (pszDimUserValue == NULL || pszDimUnits == NULL || pszDimUnitSymbol == NULL) { free(pszDimension); pszValue = strchr(pszValue, ','); - if(pszValue) + if (pszValue) pszValue++; continue; } - if(!bDimensionList) { + if (!bDimensionList) { bDimensionList = 1; - msIO_fprintf( stream, " \n"); + msIO_fprintf(stream, " \n"); } /* name */ - msIO_fprintf( stream, " \n"); + msIO_fprintf(stream, "/>\n"); free(pszDimension); pszValue = strchr(pszValue, ','); - if(pszValue) + if (pszValue) pszValue++; } - if(bDimensionList) { - msIO_fprintf( stream, " \n"); + if (bDimensionList) { + msIO_fprintf(stream, " \n"); bDimensionList = 0; } @@ -1969,9 +1928,9 @@ int msWriteMapContext(mapObj *map, FILE *stream) msIO_fprintf(stream, " \n"); /* Close Map Context */ - if(nVersion >= OWS_1_0_0) { + if (nVersion >= OWS_1_0_0) { msIO_fprintf(stream, "\n"); - } else if(nVersion >= OWS_0_1_7) { + } else if (nVersion >= OWS_0_1_7) { msIO_fprintf(stream, "\n"); } else { /* 0.1.4 */ msIO_fprintf(stream, "\n"); @@ -1985,5 +1944,3 @@ int msWriteMapContext(mapObj *map, FILE *stream) return MS_FAILURE; #endif } - - diff --git a/mapcontour.c b/mapcontour.c index dd6c752575..edccd3b4c1 100644 --- a/mapcontour.c +++ b/mapcontour.c @@ -42,7 +42,7 @@ #include "mapraster.h" #include "cpl_string.h" -#define GEO_TRANS(tr,x,y) ((tr)[0]+(tr)[1]*(x)+(tr)[2]*(y)) +#define GEO_TRANS(tr, x, y) ((tr)[0] + (tr)[1] * (x) + (tr)[2] * (y)) extern int InvGeoTransform(double *gt_in, double *gt_out); @@ -53,7 +53,7 @@ typedef struct { /* internal use */ GDALDatasetH hOrigDS; - GDALDatasetH hDS; + GDALDatasetH hDS; double *buffer; /* memory dataset buffer */ rectObj extent; /* original dataset extent */ OGRDataSourceH hOGRDS; @@ -61,10 +61,8 @@ typedef struct { } contourLayerInfo; - -static int msContourLayerInitItemInfo(layerObj *layer) -{ - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; +static int msContourLayerInitItemInfo(layerObj *layer) { + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (clinfo == NULL) { msSetError(MS_MISCERR, "Assertion failed: Contour layer not opened!!!", @@ -75,9 +73,8 @@ static int msContourLayerInitItemInfo(layerObj *layer) return msLayerInitItemInfo(&clinfo->ogrLayer); } -static void msContourLayerFreeItemInfo(layerObj *layer) -{ - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; +static void msContourLayerFreeItemInfo(layerObj *layer) { + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (clinfo == NULL) { msSetError(MS_MISCERR, "Assertion failed: Contour layer not opened!!!", @@ -88,28 +85,28 @@ static void msContourLayerFreeItemInfo(layerObj *layer) msLayerFreeItemInfo(&clinfo->ogrLayer); } -static void msContourLayerInfoInitialize(layerObj *layer) -{ - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; +static void msContourLayerInfoInitialize(layerObj *layer) { + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (clinfo != NULL) return; - clinfo = (contourLayerInfo *) msSmallCalloc(1,sizeof(contourLayerInfo)); + clinfo = (contourLayerInfo *)msSmallCalloc(1, sizeof(contourLayerInfo)); layer->layerinfo = clinfo; - clinfo->hOrigDS = NULL; + clinfo->hOrigDS = NULL; clinfo->hDS = NULL; clinfo->extent.minx = -1.0; clinfo->extent.miny = -1.0; clinfo->extent.maxx = -1.0; clinfo->extent.maxy = -1.0; - + initLayer(&clinfo->ogrLayer, layer->map); clinfo->ogrLayer.type = layer->type; clinfo->ogrLayer.debug = layer->debug; clinfo->ogrLayer.connectiontype = MS_OGR; clinfo->ogrLayer.name = msStrdup(layer->name); - clinfo->ogrLayer.connection = (char*)msSmallMalloc(strlen(clinfo->ogrLayer.name)+13); + clinfo->ogrLayer.connection = + (char *)msSmallMalloc(strlen(clinfo->ogrLayer.name) + 13); sprintf(clinfo->ogrLayer.connection, "__%s_CONTOUR__", clinfo->ogrLayer.name); clinfo->ogrLayer.units = layer->units; @@ -117,21 +114,20 @@ static void msContourLayerInfoInitialize(layerObj *layer) msInsertHashTable(&(layer->metadata), "gml_ID_type", "Integer"); } { - const char* elevItem = CSLFetchNameValue(layer->processing,"CONTOUR_ITEM"); + const char *elevItem = CSLFetchNameValue(layer->processing, "CONTOUR_ITEM"); if (elevItem && strlen(elevItem) > 0) { - char szTmp[100]; - snprintf(szTmp, sizeof(szTmp), "%s_type", elevItem); - if (msOWSLookupMetadata(&(layer->metadata), "OFG", szTmp) == NULL) { - snprintf(szTmp, sizeof(szTmp), "gml_%s_type", elevItem); - msInsertHashTable(&(layer->metadata), szTmp, "Real"); - } + char szTmp[100]; + snprintf(szTmp, sizeof(szTmp), "%s_type", elevItem); + if (msOWSLookupMetadata(&(layer->metadata), "OFG", szTmp) == NULL) { + snprintf(szTmp, sizeof(szTmp), "gml_%s_type", elevItem); + msInsertHashTable(&(layer->metadata), szTmp, "Real"); + } } } } -static void msContourLayerInfoFree(layerObj *layer) -{ - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; +static void msContourLayerInfoFree(layerObj *layer) { + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (clinfo == NULL) return; @@ -142,23 +138,22 @@ static void msContourLayerInfoFree(layerObj *layer) layer->layerinfo = NULL; } -static int msContourLayerReadRaster(layerObj *layer, rectObj rect) -{ - mapObj *map = layer->map; +static int msContourLayerReadRaster(layerObj *layer, rectObj rect) { + mapObj *map = layer->map; char **bands; char pointer[64], memDSPointer[128]; int band = 1; double adfGeoTransform[6], adfInvGeoTransform[6]; - double llx, lly, urx, ury; + double llx, lly, urx, ury; rectObj copyRect, mapRect; int dst_xsize, dst_ysize; int virtual_grid_step_x, virtual_grid_step_y; - int src_xoff, src_yoff, src_xsize, src_ysize; + int src_xoff, src_yoff, src_xsize, src_ysize; double map_cellsize_x, map_cellsize_y, dst_cellsize_x, dst_cellsize_y; GDALRasterBandH hBand = NULL; CPLErr eErr; - - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; + + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (layer->debug) msDebug("Entering msContourLayerReadRaster().\n"); @@ -166,18 +161,19 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) if (clinfo == NULL || clinfo->hOrigDS == NULL) { msSetError(MS_MISCERR, "Assertion failed: Contour layer not opened!!!", "msContourLayerReadRaster()"); - return MS_FAILURE; + return MS_FAILURE; } bands = CSLTokenizeStringComplex( - CSLFetchNameValue(layer->processing,"BANDS"), " ,", FALSE, FALSE ); + CSLFetchNameValue(layer->processing, "BANDS"), " ,", FALSE, FALSE); if (CSLCount(bands) > 0) { band = atoi(bands[0]); if (band < 1 || band > GDALGetRasterCount(clinfo->hOrigDS)) { - msSetError( MS_IMGERR, - "BANDS PROCESSING directive includes illegal band '%d', should be from 1 to %d.", - "msContourLayerReadRaster()", - band, GDALGetRasterCount(clinfo->hOrigDS)); + msSetError(MS_IMGERR, + "BANDS PROCESSING directive includes illegal band '%d', " + "should be from 1 to %d.", + "msContourLayerReadRaster()", band, + GDALGetRasterCount(clinfo->hOrigDS)); CSLDestroy(bands); return MS_FAILURE; } @@ -185,10 +181,8 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) CSLDestroy(bands); hBand = GDALGetRasterBand(clinfo->hOrigDS, band); - if (hBand == NULL) - { - msSetError(MS_IMGERR, - "Band %d does not exist on dataset.", + if (hBand == NULL) { + msSetError(MS_IMGERR, "Band %d does not exist on dataset.", "msContourLayerReadRaster()", band); return MS_FAILURE; } @@ -198,49 +192,48 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) const char *wkt; wkt = GDALGetProjectionRef(clinfo->hOrigDS); if (wkt != NULL && strlen(wkt) > 0) { - if (msOGCWKT2ProjectionObj(wkt, &(layer->projection), - layer->debug) != MS_SUCCESS) { - char msg[MESSAGELENGTH*2]; + if (msOGCWKT2ProjectionObj(wkt, &(layer->projection), layer->debug) != + MS_SUCCESS) { + char msg[MESSAGELENGTH * 2]; errorObj *ms_error = msGetErrorObj(); - snprintf( msg, sizeof(msg), - "%s\n" - "PROJECTION AUTO cannot be used for this " - "GDAL raster (`%s').", - ms_error->message, layer->data); - msg[MESSAGELENGTH-1] = '\0'; + snprintf(msg, sizeof(msg), + "%s\n" + "PROJECTION AUTO cannot be used for this " + "GDAL raster (`%s').", + ms_error->message, layer->data); + msg[MESSAGELENGTH - 1] = '\0'; - msSetError(MS_OGRERR, "%s","msDrawRasterLayer()", - msg); + msSetError(MS_OGRERR, "%s", "msDrawRasterLayer()", msg); return MS_FAILURE; } } } - + /* * Compute the georeferenced window of overlap, and read the source data * downsampled to match output resolution, or at full resolution if * output resolution is lower than the source resolution. * - * A large portion of this overlap calculation code was borrowed from - * msDrawRasterLayerGDAL(). + * A large portion of this overlap calculation code was borrowed from + * msDrawRasterLayerGDAL(). * Would be possible to move some of this to a reusable function? * * Note: This code works only if no reprojection is involved. It would * need rework to support cases where output projection differs from source * data file projection. */ - + src_xsize = GDALGetRasterXSize(clinfo->hOrigDS); src_ysize = GDALGetRasterYSize(clinfo->hOrigDS); /* set the Dataset extent */ - msGetGDALGeoTransform(clinfo->hOrigDS, map, layer, adfGeoTransform); + msGetGDALGeoTransform(clinfo->hOrigDS, map, layer, adfGeoTransform); clinfo->extent.minx = adfGeoTransform[0]; clinfo->extent.maxy = adfGeoTransform[3]; clinfo->extent.maxx = adfGeoTransform[0] + src_xsize * adfGeoTransform[1]; clinfo->extent.miny = adfGeoTransform[3] + src_ysize * adfGeoTransform[5]; - + if (layer->transform) { if (layer->debug) msDebug("msContourLayerReadRaster(): Entering transform.\n"); @@ -248,16 +241,17 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) InvGeoTransform(adfGeoTransform, adfInvGeoTransform); mapRect = rect; - if( map->cellsize == 0 ) - { - map->cellsize = msAdjustExtent(&mapRect,map->width,map->height); + if (map->cellsize == 0) { + map->cellsize = msAdjustExtent(&mapRect, map->width, map->height); } map_cellsize_x = map_cellsize_y = map->cellsize; /* if necessary, project the searchrect to source coords */ - if (msProjectionsDiffer( &(map->projection), &(layer->projection))) { - if ( msProjectRect(&map->projection, &layer->projection, &mapRect) - != MS_SUCCESS ) { - msDebug("msContourLayerReadRaster(%s): unable to reproject map request rectangle into layer projection, canceling.\n", layer->name); + if (msProjectionsDiffer(&(map->projection), &(layer->projection))) { + if (msProjectRect(&map->projection, &layer->projection, &mapRect) != + MS_SUCCESS) { + msDebug("msContourLayerReadRaster(%s): unable to reproject map request " + "rectangle into layer projection, canceling.\n", + layer->name); return MS_FAILURE; } @@ -266,24 +260,26 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) /* if the projection failed to project the extent requested, we need to calculate the cellsize to preserve the initial map cellsize ratio */ - if ( (mapRect.minx < GEO_TRANS(adfGeoTransform,0,src_ysize)) || - (mapRect.maxx > GEO_TRANS(adfGeoTransform,src_xsize,0)) || - (mapRect.miny < GEO_TRANS(adfGeoTransform+3,0,src_ysize)) || - (mapRect.maxy > GEO_TRANS(adfGeoTransform+3,src_xsize,0)) ) { + if ((mapRect.minx < GEO_TRANS(adfGeoTransform, 0, src_ysize)) || + (mapRect.maxx > GEO_TRANS(adfGeoTransform, src_xsize, 0)) || + (mapRect.miny < GEO_TRANS(adfGeoTransform + 3, 0, src_ysize)) || + (mapRect.maxy > GEO_TRANS(adfGeoTransform + 3, src_xsize, 0))) { int src_unit, dst_unit; src_unit = GetMapserverUnitUsingProj(&map->projection); dst_unit = GetMapserverUnitUsingProj(&layer->projection); if (src_unit == -1 || dst_unit == -1) { - msDebug("msContourLayerReadRaster(%s): unable to reproject map request rectangle into layer projection, canceling.\n", layer->name); + msDebug("msContourLayerReadRaster(%s): unable to reproject map " + "request rectangle into layer projection, canceling.\n", + layer->name); return MS_FAILURE; } - map_cellsize_x = MS_CONVERT_UNIT(src_unit, dst_unit, - MS_CELLSIZE(rect.minx, rect.maxx, map->width)); - map_cellsize_y = MS_CONVERT_UNIT(src_unit, dst_unit, - MS_CELLSIZE(rect.miny, rect.maxy, map->height)); - } + map_cellsize_x = MS_CONVERT_UNIT( + src_unit, dst_unit, MS_CELLSIZE(rect.minx, rect.maxx, map->width)); + map_cellsize_y = MS_CONVERT_UNIT( + src_unit, dst_unit, MS_CELLSIZE(rect.miny, rect.maxy, map->height)); + } } if (map_cellsize_x == 0 || map_cellsize_y == 0) { @@ -291,36 +287,39 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) msDebug("msContourLayerReadRaster(): Cellsize can't be 0.\n"); return MS_FAILURE; } - - /* Adjust MapServer pixel model to GDAL pixel model */ - mapRect.minx -= map_cellsize_x*0.5; - mapRect.maxx += map_cellsize_x*0.5; - mapRect.miny -= map_cellsize_y*0.5; - mapRect.maxy += map_cellsize_y*0.5; + /* Adjust MapServer pixel model to GDAL pixel model */ + mapRect.minx -= map_cellsize_x * 0.5; + mapRect.maxx += map_cellsize_x * 0.5; + mapRect.miny -= map_cellsize_y * 0.5; + mapRect.maxy += map_cellsize_y * 0.5; /* - * If raw data cellsize (from geotransform) is larger than output map_cellsize - * then we want to extract only enough data to match the output map resolution - * which means that GDAL will automatically sample the data on read. + * If raw data cellsize (from geotransform) is larger than output + * map_cellsize then we want to extract only enough data to match the output + * map resolution which means that GDAL will automatically sample the data + * on read. * - * To prevent bad contour effects on tile edges, we adjust the target cellsize - * to align the extracted window with a virtual grid based on the origin of the - * raw data and a virtual grid step size corresponding to an integer sampling step. + * To prevent bad contour effects on tile edges, we adjust the target + * cellsize to align the extracted window with a virtual grid based on the + * origin of the raw data and a virtual grid step size corresponding to an + * integer sampling step. * - * If source data has a greater cellsize (i.e. lower res) that requested ouptut map - * then we use the raw data cellsize as target cellsize since there is no point in - * interpolating the data for contours in this case. + * If source data has a greater cellsize (i.e. lower res) that requested + * ouptut map then we use the raw data cellsize as target cellsize since + * there is no point in interpolating the data for contours in this case. */ virtual_grid_step_x = (int)floor(map_cellsize_x / ABS(adfGeoTransform[1])); if (virtual_grid_step_x < 1) - virtual_grid_step_x = 1; /* Do not interpolate data if grid sampling step < 1 */ + virtual_grid_step_x = + 1; /* Do not interpolate data if grid sampling step < 1 */ virtual_grid_step_y = (int)floor(map_cellsize_y / ABS(adfGeoTransform[5])); if (virtual_grid_step_y < 1) - virtual_grid_step_y = 1; /* Do not interpolate data if grid sampling step < 1 */ - + virtual_grid_step_y = + 1; /* Do not interpolate data if grid sampling step < 1 */ + /* target cellsize is a multiple of raw data cellsize based on grid step*/ dst_cellsize_x = ABS(adfGeoTransform[1]) * virtual_grid_step_x; dst_cellsize_y = ABS(adfGeoTransform[5]) * virtual_grid_step_y; @@ -329,15 +328,15 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) copyRect = mapRect; - if (copyRect.minx < GEO_TRANS(adfGeoTransform,0,src_ysize)) - copyRect.minx = GEO_TRANS(adfGeoTransform,0,src_ysize); - if (copyRect.maxx > GEO_TRANS(adfGeoTransform,src_xsize,0)) - copyRect.maxx = GEO_TRANS(adfGeoTransform,src_xsize,0); - if (copyRect.miny < GEO_TRANS(adfGeoTransform+3,0,src_ysize)) - copyRect.miny = GEO_TRANS(adfGeoTransform+3,0,src_ysize); - if (copyRect.maxy > GEO_TRANS(adfGeoTransform+3,src_xsize,0)) - copyRect.maxy = GEO_TRANS(adfGeoTransform+3,src_xsize,0); - + if (copyRect.minx < GEO_TRANS(adfGeoTransform, 0, src_ysize)) + copyRect.minx = GEO_TRANS(adfGeoTransform, 0, src_ysize); + if (copyRect.maxx > GEO_TRANS(adfGeoTransform, src_xsize, 0)) + copyRect.maxx = GEO_TRANS(adfGeoTransform, src_xsize, 0); + if (copyRect.miny < GEO_TRANS(adfGeoTransform + 3, 0, src_ysize)) + copyRect.miny = GEO_TRANS(adfGeoTransform + 3, 0, src_ysize); + if (copyRect.maxy > GEO_TRANS(adfGeoTransform + 3, src_xsize, 0)) + copyRect.maxy = GEO_TRANS(adfGeoTransform + 3, src_xsize, 0); + if (copyRect.minx >= copyRect.maxx || copyRect.miny >= copyRect.maxy) { if (layer->debug) msDebug("msContourLayerReadRaster(): No overlap.\n"); @@ -347,42 +346,46 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) /* * Convert extraction window to raster coordinates */ - llx = GEO_TRANS(adfInvGeoTransform+0,copyRect.minx,copyRect.miny); - lly = GEO_TRANS(adfInvGeoTransform+3,copyRect.minx,copyRect.miny); - urx = GEO_TRANS(adfInvGeoTransform+0,copyRect.maxx,copyRect.maxy); - ury = GEO_TRANS(adfInvGeoTransform+3,copyRect.maxx,copyRect.maxy); + llx = GEO_TRANS(adfInvGeoTransform + 0, copyRect.minx, copyRect.miny); + lly = GEO_TRANS(adfInvGeoTransform + 3, copyRect.minx, copyRect.miny); + urx = GEO_TRANS(adfInvGeoTransform + 0, copyRect.maxx, copyRect.maxy); + ury = GEO_TRANS(adfInvGeoTransform + 3, copyRect.maxx, copyRect.maxy); - /* - * Align extraction window with virtual grid + /* + * Align extraction window with virtual grid * (keep in mind raster coordinates origin is at upper-left) * We also add an extra buffer to fix tile boundarie issues when zoomed */ - llx = floor(llx / virtual_grid_step_x) * virtual_grid_step_x - (virtual_grid_step_x*5); - urx = ceil(urx / virtual_grid_step_x) * virtual_grid_step_x + (virtual_grid_step_x*5); - ury = floor(ury / virtual_grid_step_y) * virtual_grid_step_y - (virtual_grid_step_x*5); - lly = ceil(lly / virtual_grid_step_y) * virtual_grid_step_y + (virtual_grid_step_x*5); - - src_xoff = MS_MAX(0,(int) floor(llx+0.5)); - src_yoff = MS_MAX(0,(int) floor(ury+0.5)); - src_xsize = MS_MIN(MS_MAX(0,(int) (urx - llx + 0.5)), - GDALGetRasterXSize(clinfo->hOrigDS) - src_xoff); - src_ysize = MS_MIN(MS_MAX(0,(int) (lly - ury + 0.5)), - GDALGetRasterYSize(clinfo->hOrigDS) - src_yoff); + llx = floor(llx / virtual_grid_step_x) * virtual_grid_step_x - + (virtual_grid_step_x * 5); + urx = ceil(urx / virtual_grid_step_x) * virtual_grid_step_x + + (virtual_grid_step_x * 5); + ury = floor(ury / virtual_grid_step_y) * virtual_grid_step_y - + (virtual_grid_step_x * 5); + lly = ceil(lly / virtual_grid_step_y) * virtual_grid_step_y + + (virtual_grid_step_x * 5); + + src_xoff = MS_MAX(0, (int)floor(llx + 0.5)); + src_yoff = MS_MAX(0, (int)floor(ury + 0.5)); + src_xsize = MS_MIN(MS_MAX(0, (int)(urx - llx + 0.5)), + GDALGetRasterXSize(clinfo->hOrigDS) - src_xoff); + src_ysize = MS_MIN(MS_MAX(0, (int)(lly - ury + 0.5)), + GDALGetRasterYSize(clinfo->hOrigDS) - src_yoff); /* Update the geographic extent (buffer added) */ /* TODO: a better way to go the geo_trans */ - copyRect.minx = GEO_TRANS(adfGeoTransform+0,src_xoff,0); - copyRect.maxx = GEO_TRANS(adfGeoTransform+0,src_xoff+src_xsize,0); - copyRect.miny = GEO_TRANS(adfGeoTransform+3,0,src_yoff+src_ysize); - copyRect.maxy = GEO_TRANS(adfGeoTransform+3,0,src_yoff); - - /* + copyRect.minx = GEO_TRANS(adfGeoTransform + 0, src_xoff, 0); + copyRect.maxx = GEO_TRANS(adfGeoTransform + 0, src_xoff + src_xsize, 0); + copyRect.miny = GEO_TRANS(adfGeoTransform + 3, 0, src_yoff + src_ysize); + copyRect.maxy = GEO_TRANS(adfGeoTransform + 3, 0, src_yoff); + + /* * If input window is to small then stop here */ - if (src_xsize < 2 || src_ysize < 2) - { + if (src_xsize < 2 || src_ysize < 2) { if (layer->debug) - msDebug("msContourLayerReadRaster(): input window too small, or no apparent overlap between map view and this window(1).\n"); + msDebug("msContourLayerReadRaster(): input window too small, or no " + "apparent overlap between map view and this window(1).\n"); return MS_SUCCESS; } @@ -392,19 +395,20 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) if (dst_xsize == 0 || dst_ysize == 0) { if (layer->debug) - msDebug("msContourLayerReadRaster(): no apparent overlap between map view and this window(2).\n"); + msDebug("msContourLayerReadRaster(): no apparent overlap between map " + "view and this window(2).\n"); return MS_SUCCESS; } if (layer->debug) - msDebug( "msContourLayerReadRaster(): src=%d,%d,%d,%d, dst=%d,%d,%d,%d\n", - src_xoff, src_yoff, src_xsize, src_ysize, - 0, 0, dst_xsize, dst_ysize ); + msDebug("msContourLayerReadRaster(): src=%d,%d,%d,%d, dst=%d,%d,%d,%d\n", + src_xoff, src_yoff, src_xsize, src_ysize, 0, 0, dst_xsize, + dst_ysize); } else { src_xoff = 0; src_yoff = 0; - dst_xsize = src_xsize = MS_MIN(map->width,src_xsize); - dst_ysize = src_ysize = MS_MIN(map->height,src_ysize); + dst_xsize = src_xsize = MS_MIN(map->width, src_xsize); + dst_ysize = src_ysize = MS_MIN(map->height, src_ysize); copyRect.minx = 0; copyRect.miny = 0; (void)copyRect.miny; @@ -418,46 +422,44 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) /* Allocate buffer, and read data into it. */ /* -------------------------------------------------------------------- */ - clinfo->buffer = (double *) malloc(sizeof(double) * dst_xsize * dst_ysize); + clinfo->buffer = (double *)malloc(sizeof(double) * dst_xsize * dst_ysize); if (clinfo->buffer == NULL) { - msSetError(MS_MEMERR, "Malloc(): Out of memory.", "msContourLayerReadRaster()"); + msSetError(MS_MEMERR, "Malloc(): Out of memory.", + "msContourLayerReadRaster()"); return MS_FAILURE; } - eErr = GDALRasterIO(hBand, GF_Read, - src_xoff, src_yoff, src_xsize, src_ysize, - clinfo->buffer, dst_xsize, dst_ysize, GDT_Float64, - 0, 0); + eErr = GDALRasterIO(hBand, GF_Read, src_xoff, src_yoff, src_xsize, src_ysize, + clinfo->buffer, dst_xsize, dst_ysize, GDT_Float64, 0, 0); if (eErr != CE_None) { - msSetError( MS_IOERR, "GDALRasterIO() failed: %s", - "msContourLayerReadRaster()", CPLGetLastErrorMsg() ); + msSetError(MS_IOERR, "GDALRasterIO() failed: %s", + "msContourLayerReadRaster()", CPLGetLastErrorMsg()); free(clinfo->buffer); return MS_FAILURE; } memset(pointer, 0, sizeof(pointer)); CPLPrintPointer(pointer, clinfo->buffer, sizeof(pointer)); - sprintf(memDSPointer,"MEM:::DATAPOINTER=%s,PIXELS=%d,LINES=%d,BANDS=1,DATATYPE=Float64", + sprintf(memDSPointer, + "MEM:::DATAPOINTER=%s,PIXELS=%d,LINES=%d,BANDS=1,DATATYPE=Float64", pointer, dst_xsize, dst_ysize); - clinfo->hDS = GDALOpen(memDSPointer, GA_ReadOnly); + clinfo->hDS = GDALOpen(memDSPointer, GA_ReadOnly); if (clinfo->hDS == NULL) { - msSetError(MS_IMGERR, - "Unable to open GDAL Memory dataset.", + msSetError(MS_IMGERR, "Unable to open GDAL Memory dataset.", "msContourLayerReadRaster()"); free(clinfo->buffer); return MS_FAILURE; } { - // Copy nodata value from source dataset to memory dataset - int bHasNoData = FALSE; - double dfNoDataValue = GDALGetRasterNoDataValue(hBand, &bHasNoData); - if( bHasNoData ) - { - GDALSetRasterNoDataValue(GDALGetRasterBand(clinfo->hDS, 1), - dfNoDataValue); - } + // Copy nodata value from source dataset to memory dataset + int bHasNoData = FALSE; + double dfNoDataValue = GDALGetRasterNoDataValue(hBand, &bHasNoData); + if (bHasNoData) { + GDALSetRasterNoDataValue(GDALGetRasterBand(clinfo->hDS, 1), + dfNoDataValue); + } } adfGeoTransform[0] = copyRect.minx; @@ -473,14 +475,13 @@ static int msContourLayerReadRaster(layerObj *layer, rectObj rect) sprintf(buf, "%lf", clinfo->cellsize); msInsertHashTable(&layer->metadata, "__data_cellsize__", buf); } - + GDALSetGeoTransform(clinfo->hDS, adfGeoTransform); return MS_SUCCESS; } -static void msContourOGRCloseConnection(void *conn_handle) -{ - OGRDataSourceH hDS = (OGRDataSourceH) conn_handle; +static void msContourOGRCloseConnection(void *conn_handle) { + OGRDataSourceH hDS = (OGRDataSourceH)conn_handle; msAcquireLock(TLOCK_OGR); OGR_DS_Destroy(hDS); @@ -489,19 +490,18 @@ static void msContourOGRCloseConnection(void *conn_handle) /* Function that parses multiple options in the a list. It also supports min/maxscaledenom checks. ie. "CONTOUR_INTERVAL=0,3842942:10" */ -static char* msContourGetOption(layerObj *layer, const char *name) -{ +static char *msContourGetOption(layerObj *layer, const char *name) { int c, i, found = MS_FALSE; char **values, **tmp, **options; double maxscaledenom, minscaledenom; char *value = NULL; - + options = CSLFetchNameValueMultiple(layer->processing, name); c = CSLCount(options); /* First pass to find the value among options that have min/maxscaledenom */ /* specified */ - for (i=0; imap->scaledenom <= 0 || - (((maxscaledenom <= 0) || (layer->map->scaledenom <= maxscaledenom)) && - ((minscaledenom <= 0) || (layer->map->scaledenom > minscaledenom)))) { + (((maxscaledenom <= 0) || + (layer->map->scaledenom <= maxscaledenom)) && + ((minscaledenom <= 0) || + (layer->map->scaledenom > minscaledenom)))) { value = msStrdup(values[1]); found = MS_TRUE; } @@ -519,10 +521,10 @@ static char* msContourGetOption(layerObj *layer, const char *name) } CSLDestroy(values); } - + /* Second pass to find the value among options that do NOT have */ /* min/maxscaledenom specified */ - for (i=0; ilayerinfo; + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; OGRRegisterAll(); @@ -563,12 +564,10 @@ static int msContourLayerGenerateContour(layerObj *layer) if (!clinfo->hDS) { /* no overlap */ return MS_SUCCESS; } - + hBand = GDALGetRasterBand(clinfo->hDS, 1); - if (hBand == NULL) - { - msSetError(MS_IMGERR, - "Band %d does not exist on dataset.", + if (hBand == NULL) { + msSetError(MS_IMGERR, "Band %d does not exist on dataset.", "msContourLayerGenerateContour()", 1); return MS_FAILURE; } @@ -576,22 +575,20 @@ static int msContourLayerGenerateContour(layerObj *layer) /* Create the OGR DataSource */ hDriver = OGRGetDriverByName("Memory"); if (hDriver == NULL) { - msSetError(MS_OGRERR, - "Unable to get OGR driver 'Memory'.", + msSetError(MS_OGRERR, "Unable to get OGR driver 'Memory'.", "msContourLayerCreateOGRDataSource()"); return MS_FAILURE; } clinfo->hOGRDS = OGR_Dr_CreateDataSource(hDriver, "", NULL); if (clinfo->hOGRDS == NULL) { - msSetError(MS_OGRERR, - "Unable to create OGR DataSource.", + msSetError(MS_OGRERR, "Unable to create OGR DataSource.", "msContourLayerCreateOGRDataSource()"); return MS_FAILURE; } hLayer = OGR_DS_CreateLayer(clinfo->hOGRDS, clinfo->ogrLayer.name, NULL, - wkbLineString, NULL ); + wkbLineString, NULL); hFld = OGR_Fld_Create("ID", OFTInteger); OGR_Fld_SetWidth(hFld, 8); @@ -599,15 +596,14 @@ static int msContourLayerGenerateContour(layerObj *layer) OGR_Fld_Destroy(hFld); /* Check if we have a coutour item specified */ - elevItem = CSLFetchNameValue(layer->processing,"CONTOUR_ITEM"); + elevItem = CSLFetchNameValue(layer->processing, "CONTOUR_ITEM"); if (elevItem && strlen(elevItem) > 0) { hFld = OGR_Fld_Create(elevItem, OFTReal); OGR_Fld_SetWidth(hFld, 12); OGR_Fld_SetPrecision(hFld, 3); OGR_L_CreateField(hLayer, hFld, FALSE); OGR_Fld_Destroy(hFld); - } - else { + } else { elevItem = NULL; } @@ -619,11 +615,11 @@ static int msContourLayerGenerateContour(layerObj *layer) option = msContourGetOption(layer, "CONTOUR_LEVELS"); if (option) { - int i,c; + int i, c; char **levelsTmp; levelsTmp = CSLTokenizeStringComplex(option, ",", FALSE, FALSE); c = CSLCount(levelsTmp); - for (i=0;iogrLayer, clinfo->hOGRDS, msContourOGRCloseConnection); - return MS_SUCCESS; + msConnPoolRegister(&clinfo->ogrLayer, clinfo->hOGRDS, + msContourOGRCloseConnection); + return MS_SUCCESS; } -int msContourLayerOpen(layerObj *layer) -{ +int msContourLayerOpen(layerObj *layer) { char *decrypted_path; char szPath[MS_MAXPATHLEN]; contourLayerInfo *clinfo; @@ -667,69 +660,59 @@ int msContourLayerOpen(layerObj *layer) if (layer->layerinfo == NULL) msContourLayerInfoInitialize(layer); - clinfo = (contourLayerInfo *) layer->layerinfo; - if (layer->data == NULL && layer->tileindex == NULL ) { - msSetError(MS_MISCERR, - "Layer %s has neither DATA nor TILEINDEX defined.", - "msContourLayerOpen()", - layer->name); + clinfo = (contourLayerInfo *)layer->layerinfo; + if (layer->data == NULL && layer->tileindex == NULL) { + msSetError(MS_MISCERR, "Layer %s has neither DATA nor TILEINDEX defined.", + "msContourLayerOpen()", layer->name); return MS_FAILURE; } - if( layer->tileindex != NULL ) - { - char szTilename[MS_MAXPATHLEN]; - int status; - int tilelayerindex, tileitemindex, tilesrsindex; - rectObj searchrect; - layerObj* tlp; - shapeObj tshp; - char tilesrsname[1]; - - msInitShape(&tshp); - searchrect = layer->map->extent; - - status = msDrawRasterSetupTileLayer(layer->map, layer, - &searchrect, MS_FALSE, - &tilelayerindex, - &tileitemindex, - &tilesrsindex, - &tlp); - if( status == MS_FAILURE ) - { - return MS_FAILURE; - } + if (layer->tileindex != NULL) { + char szTilename[MS_MAXPATHLEN]; + int status; + int tilelayerindex, tileitemindex, tilesrsindex; + rectObj searchrect; + layerObj *tlp; + shapeObj tshp; + char tilesrsname[1]; - status = msDrawRasterIterateTileIndex(layer, tlp, &tshp, - tileitemindex, -1, - szTilename, sizeof(szTilename), - tilesrsname, sizeof(tilesrsname)); - if( status == MS_FAILURE || status == MS_DONE ) { - if( status == MS_DONE ) - { - if (layer->debug) - msDebug("No raster matching filter.\n"); - } - msDrawRasterCleanupTileLayer(tlp, tilelayerindex); - return MS_FAILURE; - } + msInitShape(&tshp); + searchrect = layer->map->extent; + status = msDrawRasterSetupTileLayer(layer->map, layer, &searchrect, + MS_FALSE, &tilelayerindex, + &tileitemindex, &tilesrsindex, &tlp); + if (status == MS_FAILURE) { + return MS_FAILURE; + } + + status = msDrawRasterIterateTileIndex(layer, tlp, &tshp, tileitemindex, -1, + szTilename, sizeof(szTilename), + tilesrsname, sizeof(tilesrsname)); + if (status == MS_FAILURE || status == MS_DONE) { + if (status == MS_DONE) { + if (layer->debug) + msDebug("No raster matching filter.\n"); + } msDrawRasterCleanupTileLayer(tlp, tilelayerindex); + return MS_FAILURE; + } - msDrawRasterBuildRasterPath(layer->map, layer, szTilename, szPath); - decrypted_path = msStrdup(szPath); + msDrawRasterCleanupTileLayer(tlp, tilelayerindex); - /* Cancel the time filter that might have been set on ours in case of */ - /* a inline tileindex */ - msFreeExpression(&layer->filter); - msInitExpression(&layer->filter); - } - else - { - msTryBuildPath3(szPath, layer->map->mappath, layer->map->shapepath, layer->data); - decrypted_path = msDecryptStringTokens(layer->map, szPath); + msDrawRasterBuildRasterPath(layer->map, layer, szTilename, szPath); + decrypted_path = msStrdup(szPath); + + /* Cancel the time filter that might have been set on ours in case of */ + /* a inline tileindex */ + msFreeExpression(&layer->filter); + msInitExpression(&layer->filter); + } else { + msTryBuildPath3(szPath, layer->map->mappath, layer->map->shapepath, + layer->data); + decrypted_path = msDecryptStringTokens(layer->map, szPath); } - + GDALAllRegister(); /* Open the original Dataset */ @@ -744,12 +727,11 @@ int msContourLayerOpen(layerObj *layer) msReleaseLock(TLOCK_GDAL); if (clinfo->hOrigDS == NULL) { - msSetError(MS_IMGERR, - "Unable to open GDAL dataset.", + msSetError(MS_IMGERR, "Unable to open GDAL dataset.", "msContourLayerOpen()"); return MS_FAILURE; } - + /* Open the raster source */ if (msContourLayerReadRaster(layer, layer->map->extent) != MS_SUCCESS) return MS_FAILURE; @@ -760,27 +742,25 @@ int msContourLayerOpen(layerObj *layer) if (clinfo->hDS) { GDALClose(clinfo->hDS); - clinfo->hDS = NULL; + clinfo->hDS = NULL; free(clinfo->buffer); } /* Open our virtual ogr layer */ if (clinfo->hOGRDS && (msLayerOpen(&clinfo->ogrLayer) != MS_SUCCESS)) return MS_FAILURE; - + return MS_SUCCESS; } -int msContourLayerIsOpen(layerObj *layer) -{ +int msContourLayerIsOpen(layerObj *layer) { if (layer->layerinfo) return MS_TRUE; return MS_FALSE; } - -int msContourLayerClose(layerObj *layer) -{ - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; + +int msContourLayerClose(layerObj *layer) { + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (layer->debug) msDebug("Entering msContourLayerClose().\n"); @@ -790,29 +770,27 @@ int msContourLayerClose(layerObj *layer) msConnPoolRelease(&clinfo->ogrLayer, clinfo->hOGRDS); msLayerClose(&clinfo->ogrLayer); - + if (clinfo->hDS) { GDALClose(clinfo->hDS); clinfo->hDS = NULL; - free(clinfo->buffer); + free(clinfo->buffer); } if (clinfo->hOrigDS) { GDALClose(clinfo->hOrigDS); - clinfo->hOrigDS = NULL; + clinfo->hOrigDS = NULL; } msContourLayerInfoFree(layer); - } - + return MS_SUCCESS; } -int msContourLayerGetItems(layerObj *layer) -{ - const char* elevItem; - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; +int msContourLayerGetItems(layerObj *layer) { + const char *elevItem; + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (clinfo == NULL) { msSetError(MS_MISCERR, "Assertion failed: Contour layer not opened!!!", @@ -821,10 +799,10 @@ int msContourLayerGetItems(layerObj *layer) } layer->numitems = 0; - layer->items = (char **) msSmallCalloc(sizeof(char *),2); + layer->items = (char **)msSmallCalloc(sizeof(char *), 2); layer->items[layer->numitems++] = msStrdup("ID"); - elevItem = CSLFetchNameValue(layer->processing,"CONTOUR_ITEM"); + elevItem = CSLFetchNameValue(layer->processing, "CONTOUR_ITEM"); if (elevItem && strlen(elevItem) > 0) { layer->items[layer->numitems++] = msStrdup(elevItem); } @@ -832,11 +810,10 @@ int msContourLayerGetItems(layerObj *layer) return msLayerGetItems(&clinfo->ogrLayer); } -int msContourLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) -{ +int msContourLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) { int i; rectObj newRect; - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (layer->debug) msDebug("Entering msContourLayerWhichShapes().\n"); @@ -847,18 +824,17 @@ int msContourLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) return MS_FAILURE; } - if( isQuery ) - { + if (isQuery) { newRect = layer->map->extent; - } - else - { + } else { newRect = rect; /* if necessary, project the searchrect to source coords */ - if (msProjectionsDiffer( &(layer->map->projection), &(layer->projection))) { - if (msProjectRect(&layer->projection, &layer->map->projection, &newRect) - != MS_SUCCESS ) { - msDebug("msContourLayerWhichShapes(%s): unable to reproject map request rectangle into layer projection, canceling.\n", layer->name); + if (msProjectionsDiffer(&(layer->map->projection), &(layer->projection))) { + if (msProjectRect(&layer->projection, &layer->map->projection, + &newRect) != MS_SUCCESS) { + msDebug("msContourLayerWhichShapes(%s): unable to reproject map " + "request rectangle into layer projection, canceling.\n", + layer->name); return MS_FAILURE; } } @@ -867,9 +843,9 @@ int msContourLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) /* regenerate the raster io */ if (clinfo->hOGRDS) msConnPoolRelease(&clinfo->ogrLayer, clinfo->hOGRDS); - + msLayerClose(&clinfo->ogrLayer); - + /* Open the raster source */ if (msContourLayerReadRaster(layer, newRect) != MS_SUCCESS) return MS_FAILURE; @@ -883,26 +859,27 @@ int msContourLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) clinfo->hDS = NULL; free(clinfo->buffer); } - + if (!clinfo->hOGRDS) /* no overlap */ return MS_DONE; - + /* Open our virtual ogr layer */ if (msLayerOpen(&clinfo->ogrLayer) != MS_SUCCESS) return MS_FAILURE; clinfo->ogrLayer.numitems = layer->numitems; - clinfo->ogrLayer.items = (char **) msSmallMalloc(sizeof(char *)*layer->numitems); - for (i=0; inumitems;++i) { + clinfo->ogrLayer.items = + (char **)msSmallMalloc(sizeof(char *) * layer->numitems); + for (i = 0; i < layer->numitems; ++i) { clinfo->ogrLayer.items[i] = msStrdup(layer->items[i]); } return msLayerWhichShapes(&clinfo->ogrLayer, rect, isQuery); } -int msContourLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) -{ - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; +int msContourLayerGetShape(layerObj *layer, shapeObj *shape, + resultObj *record) { + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (layer->debug) msDebug("Entering msContourLayerGetShape().\n"); @@ -916,9 +893,8 @@ int msContourLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) return msLayerGetShape(&clinfo->ogrLayer, shape, record); } -int msContourLayerNextShape(layerObj *layer, shapeObj *shape) -{ - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; +int msContourLayerNextShape(layerObj *layer, shapeObj *shape) { + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (layer->debug) msDebug("Entering msContourLayerNextShape().\n"); @@ -937,9 +913,8 @@ int msContourLayerNextShape(layerObj *layer, shapeObj *shape) /* Simple copy of the maprasterquery.c file. might change in the future */ /************************************************************************/ -int msContourLayerGetExtent(layerObj *layer, rectObj *extent) -{ - contourLayerInfo *clinfo = (contourLayerInfo *) layer->layerinfo; +int msContourLayerGetExtent(layerObj *layer, rectObj *extent) { + contourLayerInfo *clinfo = (contourLayerInfo *)layer->layerinfo; if (layer->debug) msDebug("Entering msContourLayerGetExtent().\n"); @@ -970,8 +945,7 @@ int msContourLayerGetExtent(layerObj *layer, rectObj *extent) /************************************************************************/ int msContourLayerSetTimeFilter(layerObj *layer, const char *timestring, - const char *timefield) -{ + const char *timefield) { int tilelayerindex; if (layer->debug) @@ -980,11 +954,11 @@ int msContourLayerSetTimeFilter(layerObj *layer, const char *timestring, /* -------------------------------------------------------------------- */ /* If we don't have a tileindex the time filter has no effect. */ /* -------------------------------------------------------------------- */ - if( layer->tileindex == NULL ) - { - if (layer->debug) - msDebug("msContourLayerSetTimeFilter(): time filter without effect on layers without tileindex.\n"); - return MS_SUCCESS; + if (layer->tileindex == NULL) { + if (layer->debug) + msDebug("msContourLayerSetTimeFilter(): time filter without effect on " + "layers without tileindex.\n"); + return MS_SUCCESS; } /* -------------------------------------------------------------------- */ @@ -997,25 +971,24 @@ int msContourLayerSetTimeFilter(layerObj *layer, const char *timestring, /* to say, the tileindex name is not of another layer), then we */ /* just install a backtics style filter on the current layer. */ /* -------------------------------------------------------------------- */ - if( tilelayerindex == -1 ) - return msLayerMakeBackticsTimeFilter( layer, timestring, timefield ); + if (tilelayerindex == -1) + return msLayerMakeBackticsTimeFilter(layer, timestring, timefield); /* -------------------------------------------------------------------- */ /* Otherwise we invoke the tileindex layers SetTimeFilter */ /* method. */ /* -------------------------------------------------------------------- */ - if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE ) + if (msCheckParentPointer(layer->map, "map") == MS_FAILURE) return MS_FAILURE; - return msLayerSetTimeFilter( layer->GET_LAYER(map,tilelayerindex), - timestring, timefield ); + return msLayerSetTimeFilter(layer->GET_LAYER(map, tilelayerindex), timestring, + timefield); } /************************************************************************/ /* msRASTERLayerInitializeVirtualTable() */ /************************************************************************/ -int msContourLayerInitializeVirtualTable(layerObj *layer) -{ +int msContourLayerInitializeVirtualTable(layerObj *layer) { assert(layer != NULL); assert(layer->vtable != NULL); diff --git a/mapcopy.c b/mapcopy.c old mode 100755 new mode 100644 index 18a8bb2703..ee61a3f32e --- a/mapcopy.c +++ b/mapcopy.c @@ -53,8 +53,8 @@ * Copy a projectionObj while adding additional arguments * **********************************************************************/ -int msCopyProjectionExtended(projectionObj *dst, const projectionObj *src, char ** args, int num_args) -{ +int msCopyProjectionExtended(projectionObj *dst, const projectionObj *src, + char **args, int num_args) { MS_COPYSTELEM(numargs); MS_COPYSTELEM(gt); MS_COPYSTELEM(automatic); @@ -63,11 +63,10 @@ int msCopyProjectionExtended(projectionObj *dst, const projectionObj *src, char /* Our destination consists of unallocated pointers */ dst->args[i] = msStrdup(src->args[i]); } - if( args ) - { - for(int i=0 ; i< num_args; i++) { - dst->args[dst->numargs++] = msStrdup(args[i]); - } + if (args) { + for (int i = 0; i < num_args; i++) { + dst->args[dst->numargs++] = msStrdup(args[i]); + } } msProjectionInheritContextFrom(dst, src); if (dst->numargs != 0) { @@ -84,9 +83,8 @@ int msCopyProjectionExtended(projectionObj *dst, const projectionObj *src, char * Copy a projectionObj * **********************************************************************/ -int msCopyProjection(projectionObj *dst, const projectionObj *src) -{ - return msCopyProjectionExtended(dst,src,NULL,0); +int msCopyProjection(projectionObj *dst, const projectionObj *src) { + return msCopyProjectionExtended(dst, src, NULL, 0); } /*********************************************************************** @@ -94,8 +92,7 @@ int msCopyProjection(projectionObj *dst, const projectionObj *src) * * * Copy a lineObj, using msCopyPoint() * **********************************************************************/ -int msCopyLine(lineObj *dst, const lineObj *src) -{ +int msCopyLine(lineObj *dst, const lineObj *src) { int i; @@ -141,8 +138,7 @@ int msCopyShapeObj(shapeObj *dst, shapeObj *src) { * Copy an itemObj * **********************************************************************/ -int msCopyItem(itemObj *dst, const itemObj *src) -{ +int msCopyItem(itemObj *dst, const itemObj *src) { MS_COPYSTRING(dst->name, src->name); MS_COPYSTELEM(type); @@ -159,9 +155,8 @@ int msCopyItem(itemObj *dst, const itemObj *src) * Copy a hashTableObj, using msInsertHashTable() * **********************************************************************/ -int msCopyHashTable(hashTableObj *dst, const hashTableObj *src) -{ - const char *key=NULL; +int msCopyHashTable(hashTableObj *dst, const hashTableObj *src) { + const char *key = NULL; while (1) { key = msNextKeyFromHashTable(src, key); if (!key) @@ -178,8 +173,7 @@ int msCopyHashTable(hashTableObj *dst, const hashTableObj *src) * Copy a fontSetObj, using msCreateHashTable() and msCopyHashTable() * **********************************************************************/ -int msCopyFontSet(fontSetObj *dst, const fontSetObj *src, mapObj *map) -{ +int msCopyFontSet(fontSetObj *dst, const fontSetObj *src, mapObj *map) { MS_COPYSTRING(dst->filename, src->filename); MS_COPYSTELEM(numfonts); @@ -201,9 +195,9 @@ int msCopyFontSet(fontSetObj *dst, const fontSetObj *src, mapObj *map) * Copy an expressionObj, but only its string, type and flags * **********************************************************************/ -int msCopyExpression(expressionObj *dst, const expressionObj *src) -{ - if((dst->type == MS_REGEX) && dst->compiled) ms_regfree(&(dst->regex)); +int msCopyExpression(expressionObj *dst, const expressionObj *src) { + if ((dst->type == MS_REGEX) && dst->compiled) + ms_regfree(&(dst->regex)); dst->compiled = MS_FALSE; MS_COPYSTRING(dst->string, src->string); @@ -219,8 +213,7 @@ int msCopyExpression(expressionObj *dst, const expressionObj *src) * Copy a joinObj * **********************************************************************/ -int msCopyJoin(joinObj *dst, const joinObj *src) -{ +int msCopyJoin(joinObj *dst, const joinObj *src) { MS_COPYSTRING(dst->name, src->name); /* makes no sense to copy the items or values @@ -253,8 +246,7 @@ int msCopyJoin(joinObj *dst, const joinObj *src) * Copy a queryMapObj, using msCopyColor() * **********************************************************************/ -int msCopyQueryMap(queryMapObj *dst, const queryMapObj *src) -{ +int msCopyQueryMap(queryMapObj *dst, const queryMapObj *src) { MS_COPYSTELEM(height); MS_COPYSTELEM(width); MS_COPYSTELEM(status); @@ -264,15 +256,13 @@ int msCopyQueryMap(queryMapObj *dst, const queryMapObj *src) return MS_SUCCESS; } - /*********************************************************************** * msCopyLeader() * * * * Copy a labelLeaderObj, using msCopyStyle() * **********************************************************************/ -int msCopyLabelLeader(labelLeaderObj *dst, const labelLeaderObj *src) -{ +int msCopyLabelLeader(labelLeaderObj *dst, const labelLeaderObj *src) { int i; assert(dst && src); MS_COPYSTELEM(gridstep); @@ -282,9 +272,10 @@ int msCopyLabelLeader(labelLeaderObj *dst, const labelLeaderObj *src) */ /* free any previous styles on the dst label */ - for(i=0; inumstyles; i++) { /* each style */ - if (dst->styles[i]!=NULL) { - if( freeStyle(dst->styles[i]) == MS_SUCCESS ) msFree(dst->styles[i]); + for (i = 0; i < dst->numstyles; i++) { /* each style */ + if (dst->styles[i] != NULL) { + if (freeStyle(dst->styles[i]) == MS_SUCCESS) + msFree(dst->styles[i]); } } dst->numstyles = 0; @@ -311,13 +302,13 @@ int msCopyLabelLeader(labelLeaderObj *dst, const labelLeaderObj *src) * Copy a labelObj, using msCopyColor() and msCopyStyle() * **********************************************************************/ -int msCopyLabel(labelObj *dst, const labelObj *src) -{ +int msCopyLabel(labelObj *dst, const labelObj *src) { int i; - for(i=0; ibindings[i].item, src->bindings[i].item); - dst->bindings[i].index = src->bindings[i].index; /* no way to use the macros */ + dst->bindings[i].index = + src->bindings[i].index; /* no way to use the macros */ MS_COPYSTRING(dst->exprBindings[i].string, src->exprBindings[i].string); dst->exprBindings[i].type = src->exprBindings[i].type; } @@ -360,7 +351,6 @@ int msCopyLabel(labelObj *dst, const labelObj *src) MS_COPYSTELEM(repeatdistance); MS_COPYSTELEM(maxoverlapangle); - MS_COPYSTRING(dst->encoding, src->encoding); MS_COPYSTELEM(outlinewidth); @@ -381,9 +371,10 @@ int msCopyLabel(labelObj *dst, const labelObj *src) */ /* free any previous styles on the dst label */ - for(i=0; inumstyles; i++) { /* each style */ - if (dst->styles[i]!=NULL) { - if( freeStyle(dst->styles[i]) == MS_SUCCESS ) msFree(dst->styles[i]); + for (i = 0; i < dst->numstyles; i++) { /* each style */ + if (dst->styles[i] != NULL) { + if (freeStyle(dst->styles[i]) == MS_SUCCESS) + msFree(dst->styles[i]); } } dst->numstyles = 0; @@ -402,12 +393,12 @@ int msCopyLabel(labelObj *dst, const labelObj *src) dst->numstyles++; } - if(src->leader) { + if (src->leader) { dst->leader = msSmallMalloc(sizeof(labelLeaderObj)); initLeader(dst->leader); - msCopyLabelLeader(dst->leader,src->leader); + msCopyLabelLeader(dst->leader, src->leader); } else { - if(dst->leader) { + if (dst->leader) { freeLabelLeader(dst->leader); msFree(dst->leader); } @@ -427,8 +418,7 @@ int msCopyLabel(labelObj *dst, const labelObj *src) * msCopyHashTable() * **********************************************************************/ -int msCopyWeb(webObj *dst, const webObj *src, mapObj *map) -{ +int msCopyWeb(webObj *dst, const webObj *src, mapObj *map) { MS_COPYSTRING(dst->imagepath, src->imagepath); MS_COPYSTRING(dst->imageurl, src->imageurl); @@ -453,13 +443,13 @@ int msCopyWeb(webObj *dst, const webObj *src, mapObj *map) if (msCopyHashTable(&(dst->metadata), &(src->metadata)) != MS_SUCCESS) return MS_FAILURE; } - msCopyHashTable(&dst->validation,&src->validation); + msCopyHashTable(&dst->validation, &src->validation); MS_COPYSTRING(dst->queryformat, src->queryformat); MS_COPYSTRING(dst->legendformat, src->legendformat); MS_COPYSTRING(dst->browseformat, src->browseformat); - return MS_SUCCESS ; + return MS_SUCCESS; } /*********************************************************************** @@ -468,13 +458,13 @@ int msCopyWeb(webObj *dst, const webObj *src, mapObj *map) * Copy a styleObj, using msCopyColor() * **********************************************************************/ -int msCopyStyle(styleObj *dst, const styleObj *src) -{ +int msCopyStyle(styleObj *dst, const styleObj *src) { int i; - for(i=0; ibindings[i].item, src->bindings[i].item); - dst->bindings[i].index = src->bindings[i].index; /* no way to use the macros */ + dst->bindings[i].index = + src->bindings[i].index; /* no way to use the macros */ MS_COPYSTRING(dst->exprBindings[i].string, src->exprBindings[i].string); dst->exprBindings[i].type = src->exprBindings[i].type; } @@ -482,15 +472,15 @@ int msCopyStyle(styleObj *dst, const styleObj *src) MS_COPYSTELEM(nexprbindings); MS_COPYCOLOR(&(dst->color), &(src->color)); - MS_COPYCOLOR(&(dst->outlinecolor),&(src->outlinecolor)); + MS_COPYCOLOR(&(dst->outlinecolor), &(src->outlinecolor)); MS_COPYCOLOR(&(dst->mincolor), &(src->mincolor)); MS_COPYCOLOR(&(dst->maxcolor), &(src->maxcolor)); MS_COPYSTRING(dst->symbolname, src->symbolname); MS_COPYSTELEM(patternlength); - for(i=0; ipatternlength; i++) - dst->pattern[i]=src->pattern[i]; + for (i = 0; i < src->patternlength; i++) + dst->pattern[i] = src->pattern[i]; MS_COPYSTELEM(initialgap); MS_COPYSTELEM(gap); MS_COPYSTELEM(linejoin); @@ -533,12 +523,11 @@ int msCopyStyle(styleObj *dst, const styleObj *src) * msCopyLabel(), msCreateHashTable(), msCopyHashTable() * **********************************************************************/ -int msCopyClass(classObj *dst, const classObj *src, layerObj *layer_unused) -{ +int msCopyClass(classObj *dst, const classObj *src, layerObj *layer_unused) { int i, return_value; (void)layer_unused; - return_value = msCopyExpression(&(dst->expression),&(src->expression)); + return_value = msCopyExpression(&(dst->expression), &(src->expression)); if (return_value != MS_SUCCESS) { msSetError(MS_MEMERR, "Failed to copy expression.", "msCopyClass()"); return MS_FAILURE; @@ -548,9 +537,9 @@ int msCopyClass(classObj *dst, const classObj *src, layerObj *layer_unused) MS_COPYSTELEM(isfallback); /* free any previous styles on the dst layer */ - for(i=0; inumstyles; i++) { /* each style */ - if (dst->styles[i]!=NULL) { - if( freeStyle(dst->styles[i]) == MS_SUCCESS ) { + for (i = 0; i < dst->numstyles; i++) { /* each style */ + if (dst->styles[i] != NULL) { + if (freeStyle(dst->styles[i]) == MS_SUCCESS) { msFree(dst->styles[i]); } } @@ -572,7 +561,7 @@ int msCopyClass(classObj *dst, const classObj *src, layerObj *layer_unused) dst->numstyles++; } - for (i=0; inumlabels; i++) { + for (i = 0; i < src->numlabels; i++) { if (msGrowClassLabels(dst) == NULL) return MS_FAILURE; initLabel(dst->labels[i]); @@ -585,15 +574,15 @@ int msCopyClass(classObj *dst, const classObj *src, layerObj *layer_unused) } MS_COPYSTELEM(numlabels); - if(src->leader) { - if(dst->leader) { + if (src->leader) { + if (dst->leader) { freeLabelLeader(dst->leader); } - if(!dst->leader) { + if (!dst->leader) { dst->leader = msSmallMalloc(sizeof(labelLeaderObj)); initLeader(dst->leader); } - msCopyLabelLeader(dst->leader,src->leader); + msCopyLabelLeader(dst->leader, src->leader); } MS_COPYSTRING(dst->keyimage, src->keyimage); @@ -616,7 +605,7 @@ int msCopyClass(classObj *dst, const classObj *src, layerObj *layer_unused) /* dst->metadata = msCreateHashTable(); */ msCopyHashTable(&(dst->metadata), &(src->metadata)); } - msCopyHashTable(&dst->validation,&src->validation); + msCopyHashTable(&dst->validation, &src->validation); MS_COPYSTELEM(minscaledenom); MS_COPYSTELEM(maxscaledenom); @@ -629,21 +618,20 @@ int msCopyClass(classObj *dst, const classObj *src, layerObj *layer_unused) return MS_SUCCESS; } -int msCopyCluster(clusterObj *dst, const clusterObj *src) -{ +int msCopyCluster(clusterObj *dst, const clusterObj *src) { int return_value; MS_COPYSTELEM(maxdistance); MS_COPYSTELEM(buffer); MS_COPYSTRING(dst->region, src->region); - return_value = msCopyExpression(&(dst->group),&(src->group)); + return_value = msCopyExpression(&(dst->group), &(src->group)); if (return_value != MS_SUCCESS) { msSetError(MS_MEMERR, "Failed to copy cluster group.", "msCopyCluster()"); return MS_FAILURE; } - return_value = msCopyExpression(&(dst->filter),&(src->filter)); + return_value = msCopyExpression(&(dst->filter), &(src->filter)); if (return_value != MS_SUCCESS) { msSetError(MS_MEMERR, "Failed to copy cluster filter.", "msCopyCluster()"); return MS_FAILURE; @@ -656,8 +644,7 @@ int msCopyCluster(clusterObj *dst, const clusterObj *src) * msCopyGrid() * **********************************************************************/ -int msCopyGrid(graticuleObj *dst, const graticuleObj *src) -{ +int msCopyGrid(graticuleObj *dst, const graticuleObj *src) { MS_COPYSTELEM(dwhichlatitude); MS_COPYSTELEM(dwhichlongitude); MS_COPYSTELEM(dstartlatitude); @@ -678,7 +665,7 @@ int msCopyGrid(graticuleObj *dst, const graticuleObj *src) MS_COPYSTELEM(ilabeltype); MS_COPYRECT(&(dst->extent), &(src->extent)); MS_COPYSTRING(dst->labelformat, src->labelformat); - + return MS_SUCCESS; } @@ -693,8 +680,8 @@ int msCopyGrid(graticuleObj *dst, const graticuleObj *src) * make exact copies, this method might not get much use. * **********************************************************************/ -int msCopyLabelCacheMember(labelCacheMemberObj *dst, const labelCacheMemberObj *src) -{ +int msCopyLabelCacheMember(labelCacheMemberObj *dst, + const labelCacheMemberObj *src) { int i; MS_COPYSTELEM(featuresize); @@ -705,7 +692,7 @@ int msCopyLabelCacheMember(labelCacheMemberObj *dst, const labelCacheMemberObj * } MS_COPYSTELEM(numlabels); - dst->labels = (labelObj *) msSmallMalloc(sizeof(labelObj)*dst->numlabels); + dst->labels = (labelObj *)msSmallMalloc(sizeof(labelObj) * dst->numlabels); for (i = 0; i < dst->numlabels; i++) { msCopyLabel(&(dst->labels[i]), &(src->labels[i])); } @@ -728,8 +715,7 @@ int msCopyLabelCacheMember(labelCacheMemberObj *dst, const labelCacheMemberObj * **********************************************************************/ int msCopyMarkerCacheMember(markerCacheMemberObj *dst, - const markerCacheMemberObj *src) -{ + const markerCacheMemberObj *src) { MS_COPYSTELEM(id); /* msCopyShape(&(dst->poly), &(src->poly)); */ @@ -740,8 +726,7 @@ int msCopyMarkerCacheMember(markerCacheMemberObj *dst, * msCopyLabelCacheSlot() * **********************************************************************/ -int msCopyLabelCacheSlot(labelCacheSlotObj *dst, const labelCacheSlotObj *src) -{ +int msCopyLabelCacheSlot(labelCacheSlotObj *dst, const labelCacheSlotObj *src) { int i; for (i = 0; i < dst->numlabels; i++) { @@ -761,12 +746,11 @@ int msCopyLabelCacheSlot(labelCacheSlotObj *dst, const labelCacheSlotObj *src) * msCopyLabelCache() * **********************************************************************/ -int msCopyLabelCache(labelCacheObj *dst, const labelCacheObj *src) -{ +int msCopyLabelCache(labelCacheObj *dst, const labelCacheObj *src) { int p; MS_COPYSTELEM(numlabels); - for (p=0; pslots[p]), &(src->slots[p])); } @@ -779,8 +763,7 @@ int msCopyLabelCache(labelCacheObj *dst, const labelCacheObj *src) * msCopyResult() * **********************************************************************/ -int msCopyResult(resultObj *dst, const resultObj *src) -{ +int msCopyResult(resultObj *dst, const resultObj *src) { MS_COPYSTELEM(shapeindex); MS_COPYSTELEM(tileindex); MS_COPYSTELEM(classindex); @@ -793,8 +776,7 @@ int msCopyResult(resultObj *dst, const resultObj *src) * msCopyResultCache() * **********************************************************************/ -int msCopyResultCache(resultCacheObj *dst, const resultCacheObj *src) -{ +int msCopyResultCache(resultCacheObj *dst, const resultCacheObj *src) { int i; MS_COPYSTELEM(cachesize); MS_COPYSTELEM(numresults); @@ -814,8 +796,7 @@ int msCopyResultCache(resultCacheObj *dst, const resultCacheObj *src) **********************************************************************/ int msCopyReferenceMap(referenceMapObj *dst, const referenceMapObj *src, - mapObj *map) -{ + mapObj *map) { initReferenceMap(dst); @@ -824,9 +805,8 @@ int msCopyReferenceMap(referenceMapObj *dst, const referenceMapObj *src, MS_COPYSTELEM(height); MS_COPYSTELEM(width); - MS_COPYCOLOR(&(dst->color), &(src->color)); - MS_COPYCOLOR(&(dst->outlinecolor),&(src->outlinecolor)); + MS_COPYCOLOR(&(dst->outlinecolor), &(src->outlinecolor)); MS_COPYSTRING(dst->image, src->image); MS_COPYSTELEM(status); @@ -847,8 +827,7 @@ int msCopyReferenceMap(referenceMapObj *dst, const referenceMapObj *src, * and msCopyLabel() * **********************************************************************/ -int msCopyScalebar(scalebarObj *dst, const scalebarObj *src) -{ +int msCopyScalebar(scalebarObj *dst, const scalebarObj *src) { initScalebar(dst); @@ -859,7 +838,7 @@ int msCopyScalebar(scalebarObj *dst, const scalebarObj *src) MS_COPYSTELEM(intervals); if (msCopyLabel(&(dst->label), &(src->label)) != MS_SUCCESS) { - msSetError(MS_MEMERR, "Failed to copy label.","msCopyScalebar()"); + msSetError(MS_MEMERR, "Failed to copy label.", "msCopyScalebar()"); return MS_FAILURE; } @@ -884,16 +863,14 @@ int msCopyScalebar(scalebarObj *dst, const scalebarObj *src) * Copy a legendObj, using msCopyColor() * **********************************************************************/ -int msCopyLegend(legendObj *dst, const legendObj *src, mapObj *map) -{ +int msCopyLegend(legendObj *dst, const legendObj *src, mapObj *map) { int return_value; MS_COPYCOLOR(&(dst->imagecolor), &(src->imagecolor)); return_value = msCopyLabel(&(dst->label), &(src->label)); if (return_value != MS_SUCCESS) { - msSetError(MS_MEMERR, "Failed to copy label.", - "msCopyLegend()"); + msSetError(MS_MEMERR, "Failed to copy label.", "msCopyLegend()"); return MS_FAILURE; } @@ -902,7 +879,7 @@ int msCopyLegend(legendObj *dst, const legendObj *src, mapObj *map) MS_COPYSTELEM(keyspacingx); MS_COPYSTELEM(keyspacingy); - MS_COPYCOLOR(&(dst->outlinecolor),&(src->outlinecolor)); + MS_COPYCOLOR(&(dst->outlinecolor), &(src->outlinecolor)); MS_COPYSTELEM(status); MS_COPYSTELEM(height); @@ -921,8 +898,9 @@ int msCopyLegend(legendObj *dst, const legendObj *src, mapObj *map) return MS_SUCCESS; } -int msCopyScaleTokenEntry(const scaleTokenEntryObj *src, scaleTokenEntryObj *dst) { - MS_COPYSTRING(dst->value,src->value); +int msCopyScaleTokenEntry(const scaleTokenEntryObj *src, + scaleTokenEntryObj *dst) { + MS_COPYSTRING(dst->value, src->value); MS_COPYSTELEM(minscale); MS_COPYSTELEM(maxscale); return MS_SUCCESS; @@ -930,23 +908,25 @@ int msCopyScaleTokenEntry(const scaleTokenEntryObj *src, scaleTokenEntryObj *dst int msCopyScaleToken(const scaleTokenObj *src, scaleTokenObj *dst) { int i; - MS_COPYSTRING(dst->name,src->name); + MS_COPYSTRING(dst->name, src->name); MS_COPYSTELEM(n_entries); - dst->tokens = (scaleTokenEntryObj*)msSmallCalloc(src->n_entries,sizeof(scaleTokenEntryObj)); - for(i=0;in_entries;i++) { - msCopyScaleTokenEntry(&src->tokens[i],&dst->tokens[i]); + dst->tokens = (scaleTokenEntryObj *)msSmallCalloc(src->n_entries, + sizeof(scaleTokenEntryObj)); + for (i = 0; i < src->n_entries; i++) { + msCopyScaleTokenEntry(&src->tokens[i], &dst->tokens[i]); } return MS_SUCCESS; } -int msCopyCompositingFilter(CompositingFilter **pdst, const CompositingFilter *src) { +int msCopyCompositingFilter(CompositingFilter **pdst, + const CompositingFilter *src) { CompositingFilter *dst = NULL; - if(!src) { + if (!src) { *pdst = NULL; return MS_SUCCESS; } - while(src) { - if(!dst) { + while (src) { + if (!dst) { dst = *pdst = msSmallMalloc(sizeof(CompositingFilter)); } else { dst->next = msSmallMalloc(sizeof(CompositingFilter)); @@ -961,13 +941,13 @@ int msCopyCompositingFilter(CompositingFilter **pdst, const CompositingFilter *s int msCopyCompositer(LayerCompositer **ldst, const LayerCompositer *src) { LayerCompositer *dst = NULL; - if(!src) { + if (!src) { *ldst = NULL; return MS_SUCCESS; } - while(src) { - if(!dst) { + while (src) { + if (!dst) { dst = *ldst = msSmallMalloc(sizeof(LayerCompositer)); } else { dst->next = msSmallMalloc(sizeof(LayerCompositer)); @@ -992,8 +972,7 @@ int msCopyCompositer(LayerCompositer **ldst, const LayerCompositer *src) { * As it stands, we are not copying a layer's resultcache * **********************************************************************/ -int msCopyLayer(layerObj *dst, const layerObj *src) -{ +int msCopyLayer(layerObj *dst, const layerObj *src) { int i, return_value; featureListNodeObjPtr current; @@ -1002,11 +981,11 @@ int msCopyLayer(layerObj *dst, const layerObj *src) MS_COPYSTELEM(classitemindex); - for(i = 0; i < src->numscaletokens; i++) { - if(msGrowLayerScaletokens(dst) == NULL) + for (i = 0; i < src->numscaletokens; i++) { + if (msGrowLayerScaletokens(dst) == NULL) return MS_FAILURE; initScaleToken(&dst->scaletokens[i]); - msCopyScaleToken(&src->scaletokens[i],&dst->scaletokens[i]); + msCopyScaleToken(&src->scaletokens[i], &dst->scaletokens[i]); dst->numscaletokens++; } @@ -1015,7 +994,7 @@ int msCopyLayer(layerObj *dst, const layerObj *src) return MS_FAILURE; #ifndef __cplusplus initClass(dst->class[i]); - return_value = msCopyClass(dst->class[i], src->class[i], dst); + return_value = msCopyClass(dst->class[i], src -> class[i], dst); #else initClass(dst->_class[i]); return_value = msCopyClass(dst->_class[i], src->_class[i], dst); @@ -1073,13 +1052,13 @@ int msCopyLayer(layerObj *dst, const layerObj *src) MS_COPYSTRING(dst->tileindex, src->tileindex); - return_value = msCopyProjection(&(dst->projection),&(src->projection)); + return_value = msCopyProjection(&(dst->projection), &(src->projection)); if (return_value != MS_SUCCESS) { msSetError(MS_MEMERR, "Failed to copy projection.", "msCopyLayer()"); return MS_FAILURE; } - return_value = msCopyCluster(&(dst->cluster),&(src->cluster)); + return_value = msCopyCluster(&(dst->cluster), &(src->cluster)); if (return_value != MS_SUCCESS) { return MS_FAILURE; } @@ -1088,7 +1067,7 @@ int msCopyLayer(layerObj *dst, const layerObj *src) MS_COPYSTELEM(units); current = src->features; - while(current != NULL) { + while (current != NULL) { insertFeatureList(&(dst->features), &(current->shape)); current = current->next; } @@ -1120,7 +1099,8 @@ int msCopyLayer(layerObj *dst, const layerObj *src) if (&(src->metadata)) { msCopyHashTable(&(dst->metadata), &(src->metadata)); } - msCopyHashTable(&dst->validation,&src->validation); + msCopyHashTable(&dst->validation, &src->validation); + msCopyHashTable(&dst->connectionoptions, &src->connectionoptions); MS_COPYSTELEM(debug); @@ -1149,13 +1129,13 @@ int msCopyLayer(layerObj *dst, const layerObj *src) freeGrid(dst->grid); msFree(dst->grid); } - dst->grid = (void *) malloc(sizeof(graticuleObj)); + dst->grid = (void *)malloc(sizeof(graticuleObj)); MS_CHECK_ALLOC(dst->grid, sizeof(graticuleObj), -1); initGrid(dst->grid); msCopyGrid(dst->grid, src->grid); } - if(src->compositer) { + if (src->compositer) { msCopyCompositer(&dst->compositer, src->compositer); } @@ -1171,8 +1151,7 @@ int msCopyLayer(layerObj *dst, const layerObj *src) * msCopyOutputFormat(), msCopyWeb(), msCopyReferenceMap() * **********************************************************************/ -int msCopyMap(mapObj *dst, const mapObj *src) -{ +int msCopyMap(mapObj *dst, const mapObj *src) { int i, return_value; outputFormatObj *format; @@ -1202,7 +1181,7 @@ int msCopyMap(mapObj *dst, const mapObj *src) } return_value = msCopySymbolSet(&(dst->symbolset), &(src->symbolset), dst); - if(return_value != MS_SUCCESS) { + if (return_value != MS_SUCCESS) { msSetError(MS_MEMERR, "Failed to copy symbolset.", "msCopyMap()"); return MS_FAILURE; } @@ -1222,31 +1201,30 @@ int msCopyMap(mapObj *dst, const mapObj *src) MS_COPYCOLOR(&(dst->imagecolor), &(src->imagecolor)); /* clear existing destination format list */ - if( dst->outputformat && --dst->outputformat->refcount < 1 ) { - msFreeOutputFormat( dst->outputformat ); + if (dst->outputformat && --dst->outputformat->refcount < 1) { + msFreeOutputFormat(dst->outputformat); dst->outputformat = NULL; } - for(i=0; i < dst->numoutputformats; i++ ) { - if( --dst->outputformatlist[i]->refcount < 1 ) - msFreeOutputFormat( dst->outputformatlist[i] ); + for (i = 0; i < dst->numoutputformats; i++) { + if (--dst->outputformatlist[i]->refcount < 1) + msFreeOutputFormat(dst->outputformatlist[i]); } - if( dst->outputformatlist != NULL ) - msFree( dst->outputformatlist ); + if (dst->outputformatlist != NULL) + msFree(dst->outputformatlist); dst->outputformatlist = NULL; dst->outputformat = NULL; dst->numoutputformats = 0; for (i = 0; i < src->numoutputformats; i++) - msAppendOutputFormat( dst, - msCloneOutputFormat( src->outputformatlist[i]) ); + msAppendOutputFormat(dst, msCloneOutputFormat(src->outputformatlist[i])); /* set the active output format */ MS_COPYSTRING(dst->imagetype, src->imagetype); - format = msSelectOutputFormat( dst, dst->imagetype ); + format = msSelectOutputFormat(dst, dst->imagetype); msApplyOutputFormat(&(dst->outputformat), format, MS_NOOVERRIDE); - return_value = msCopyProjection(&(dst->projection),&(src->projection)); + return_value = msCopyProjection(&(dst->projection), &(src->projection)); if (return_value != MS_SUCCESS) { msSetError(MS_MEMERR, "Failed to copy projection.", "msCopyMap()"); return MS_FAILURE; @@ -1254,8 +1232,7 @@ int msCopyMap(mapObj *dst, const mapObj *src) /* No need to copy latlon projection */ - return_value = msCopyReferenceMap(&(dst->reference),&(src->reference), - dst); + return_value = msCopyReferenceMap(&(dst->reference), &(src->reference), dst); if (return_value != MS_SUCCESS) { msSetError(MS_MEMERR, "Failed to copy reference.", "msCopyMap()"); return MS_FAILURE; @@ -1267,7 +1244,7 @@ int msCopyMap(mapObj *dst, const mapObj *src) return MS_FAILURE; } - return_value = msCopyLegend(&(dst->legend), &(src->legend),dst); + return_value = msCopyLegend(&(dst->legend), &(src->legend), dst); if (return_value != MS_SUCCESS) { msSetError(MS_MEMERR, "Failed to copy legend.", "msCopyMap()"); return MS_FAILURE; @@ -1285,16 +1262,17 @@ int msCopyMap(mapObj *dst, const mapObj *src) return MS_FAILURE; } - if( src->layerorder ) { + if (src->layerorder) { for (i = 0; i < dst->numlayers; i++) { - MS_COPYSTELEM(layerorder[i]); + MS_COPYSTELEM(layerorder[i]); } } MS_COPYSTELEM(debug); MS_COPYSTRING(dst->datapattern, src->datapattern); MS_COPYSTRING(dst->templatepattern, src->templatepattern); - if( msCopyHashTable( &(dst->configoptions), &(src->configoptions) ) != MS_SUCCESS ) + if (msCopyHashTable(&(dst->configoptions), &(src->configoptions)) != + MS_SUCCESS) return MS_FAILURE; return MS_SUCCESS; @@ -1302,19 +1280,24 @@ int msCopyMap(mapObj *dst, const mapObj *src) int msCopyRasterBuffer(rasterBufferObj *dst, const rasterBufferObj *src) { *dst = *src; - if(src->type == MS_BUFFER_BYTE_RGBA) { + if (src->type == MS_BUFFER_BYTE_RGBA) { dst->data.rgba = src->data.rgba; - dst->data.rgba.pixels = msSmallMalloc(src->height * src->data.rgba.row_step); - memcpy(dst->data.rgba.pixels, src->data.rgba.pixels, src->data.rgba.row_step*src->height); - dst->data.rgba.r = dst->data.rgba.pixels + (src->data.rgba.r - src->data.rgba.pixels); - dst->data.rgba.g = dst->data.rgba.pixels + (src->data.rgba.g - src->data.rgba.pixels); - dst->data.rgba.b = dst->data.rgba.pixels + (src->data.rgba.b - src->data.rgba.pixels); - if(src->data.rgba.a) { - dst->data.rgba.a = dst->data.rgba.pixels + (src->data.rgba.a - src->data.rgba.pixels); + dst->data.rgba.pixels = + msSmallMalloc(src->height * src->data.rgba.row_step); + memcpy(dst->data.rgba.pixels, src->data.rgba.pixels, + src->data.rgba.row_step * src->height); + dst->data.rgba.r = + dst->data.rgba.pixels + (src->data.rgba.r - src->data.rgba.pixels); + dst->data.rgba.g = + dst->data.rgba.pixels + (src->data.rgba.g - src->data.rgba.pixels); + dst->data.rgba.b = + dst->data.rgba.pixels + (src->data.rgba.b - src->data.rgba.pixels); + if (src->data.rgba.a) { + dst->data.rgba.a = + dst->data.rgba.pixels + (src->data.rgba.a - src->data.rgba.pixels); } else { dst->data.rgba.a = NULL; } } return MS_SUCCESS; } - diff --git a/mapcopy.h b/mapcopy.h index cf91567812..1ed5990eda 100644 --- a/mapcopy.h +++ b/mapcopy.h @@ -32,42 +32,39 @@ /* Following works for GCC and MSVC. That's ~98% of our users, if Tyler * Mitchell's survey is correct */ -#define MS_COPYSTELEM(_name) (dst)->/**/_name = (src)->/**/_name +#define MS_COPYSTELEM(_name) (dst)->/**/ _name = (src)->/**/ _name -#define MS_MACROBEGIN do { -#define MS_MACROEND } while (0) +#define MS_MACROBEGIN do { +#define MS_MACROEND \ + } \ + while (0) -#define MS_COPYRECT(_dst, _src) \ - MS_MACROBEGIN \ - (_dst)->minx = (_src)->minx; \ - (_dst)->miny = (_src)->miny; \ - (_dst)->maxx = (_src)->maxx; \ - (_dst)->maxy = (_src)->maxy; \ - MS_MACROEND +#define MS_COPYRECT(_dst, _src) \ + MS_MACROBEGIN(_dst)->minx = (_src)->minx; \ + (_dst)->miny = (_src)->miny; \ + (_dst)->maxx = (_src)->maxx; \ + (_dst)->maxy = (_src)->maxy; \ + MS_MACROEND -#define MS_COPYPOINT(_dst, _src) \ - MS_MACROBEGIN \ - (_dst)->x = (_src)->x; \ - (_dst)->y = (_src)->y; \ - (_dst)->m = (_src)->m; \ - MS_MACROEND - -#define MS_COPYCOLOR(_dst, _src) \ - MS_MACROBEGIN \ - (_dst)->red = (_src)->red; \ - (_dst)->green = (_src)->green;\ - (_dst)->blue = (_src)->blue; \ - (_dst)->alpha = (_src)->alpha; \ - MS_MACROEND - -#define MS_COPYSTRING(_dst, _src) \ - MS_MACROBEGIN \ - if ((_dst) != NULL) \ - msFree((_dst)); \ - if ((_src)) \ - (_dst) = msStrdup((_src)); \ - else \ - (_dst) = NULL; \ - MS_MACROEND +#define MS_COPYPOINT(_dst, _src) \ + MS_MACROBEGIN(_dst)->x = (_src)->x; \ + (_dst)->y = (_src)->y; \ + (_dst)->m = (_src)->m; \ + MS_MACROEND +#define MS_COPYCOLOR(_dst, _src) \ + MS_MACROBEGIN(_dst)->red = (_src)->red; \ + (_dst)->green = (_src)->green; \ + (_dst)->blue = (_src)->blue; \ + (_dst)->alpha = (_src)->alpha; \ + MS_MACROEND +#define MS_COPYSTRING(_dst, _src) \ + MS_MACROBEGIN \ + if ((_dst) != NULL) \ + msFree((_dst)); \ + if ((_src)) \ + (_dst) = msStrdup((_src)); \ + else \ + (_dst) = NULL; \ + MS_MACROEND diff --git a/mapcpl.c b/mapcpl.c index 9a2854dc35..bad88c940d 100644 --- a/mapcpl.c +++ b/mapcpl.c @@ -41,27 +41,24 @@ #include #include "mapserver.h" - - /* should be size of largest possible filename */ #define MS_PATH_BUF_SIZE 2048 -static char szStaticResult[MS_PATH_BUF_SIZE]; - +static char szStaticResult[MS_PATH_BUF_SIZE]; /************************************************************************/ /* msFindFilenameStart() */ /************************************************************************/ -static int msFindFilenameStart( const char * pszFilename ) +static int msFindFilenameStart(const char *pszFilename) { - int iFileStart; + int iFileStart; - for( iFileStart = strlen(pszFilename); - iFileStart > 0 - && pszFilename[iFileStart-1] != '/' - && pszFilename[iFileStart-1] != '\\'; - iFileStart-- ) {} + for (iFileStart = strlen(pszFilename); + iFileStart > 0 && pszFilename[iFileStart - 1] != '/' && + pszFilename[iFileStart - 1] != '\\'; + iFileStart--) { + } return iFileStart; } @@ -90,24 +87,25 @@ static int msFindFilenameStart( const char * pszFilename ) * may be destroyed by the next ms filename handling call. */ -const char *msGetBasename( const char *pszFullFilename ) +const char *msGetBasename(const char *pszFullFilename) { - int iFileStart = msFindFilenameStart( pszFullFilename ); + int iFileStart = msFindFilenameStart(pszFullFilename); int iExtStart, nLength; - for( iExtStart = strlen(pszFullFilename); + for (iExtStart = strlen(pszFullFilename); iExtStart > iFileStart && pszFullFilename[iExtStart] != '.'; - iExtStart-- ) {} + iExtStart--) { + } - if( iExtStart == iFileStart ) + if (iExtStart == iFileStart) iExtStart = strlen(pszFullFilename); nLength = iExtStart - iFileStart; - assert( nLength < MS_PATH_BUF_SIZE ); + assert(nLength < MS_PATH_BUF_SIZE); - strlcpy( szStaticResult, pszFullFilename + iFileStart, nLength+1 ); + strlcpy(szStaticResult, pszFullFilename + iFileStart, nLength + 1); return szStaticResult; } @@ -159,45 +157,42 @@ const char *msGetBasename( const char *pszFullFilename ) * found, or the shared library can't be loaded. */ -void *msGetSymbol( const char * pszLibrary, const char * pszSymbolName ) -{ - void *pLibrary; - void *pSymbol; +void *msGetSymbol(const char *pszLibrary, const char *pszSymbolName) { + void *pLibrary; + void *pSymbol; pLibrary = dlopen(pszLibrary, RTLD_LAZY); - if( pLibrary == NULL ) { - msSetError(MS_MISCERR, - "Dynamic loading failed: %s", - "msGetSymbol()", dlerror()); + if (pLibrary == NULL) { + msSetError(MS_MISCERR, "Dynamic loading failed: %s", "msGetSymbol()", + dlerror()); return NULL; } - pSymbol = dlsym( pLibrary, pszSymbolName ); + pSymbol = dlsym(pLibrary, pszSymbolName); #if (defined(__APPLE__) && defined(__MACH__)) /* On mach-o systems, C symbols have a leading underscore and depending * on how dlcompat is configured it may or may not add the leading * underscore. So if dlsym() fails add an underscore and try again. */ - if( pSymbol == NULL ) { + if (pSymbol == NULL) { char withUnder[strlen(pszSymbolName) + 2]; withUnder[0] = '_'; withUnder[1] = 0; strcat(withUnder, pszSymbolName); - pSymbol = dlsym( pLibrary, withUnder ); + pSymbol = dlsym(pLibrary, withUnder); } #endif - if( pSymbol == NULL ) { - msSetError(MS_MISCERR, - "Dynamic loading failed: %s", - "msGetSymbol()", dlerror()); + if (pSymbol == NULL) { + msSetError(MS_MISCERR, "Dynamic loading failed: %s", "msGetSymbol()", + dlerror()); return NULL; } /* We accept leakage of pLibrary */ /* coverity[leaked_storage] */ - return( pSymbol ); + return (pSymbol); } #endif /* def __unix__ && defined(HAVE_DLFCN_H) */ @@ -215,29 +210,26 @@ void *msGetSymbol( const char * pszLibrary, const char * pszSymbolName ) /* msGetSymbol() */ /************************************************************************/ -void *msGetSymbol( const char * pszLibrary, const char * pszSymbolName ) -{ - void *pLibrary; - void *pSymbol; +void *msGetSymbol(const char *pszLibrary, const char *pszSymbolName) { + void *pLibrary; + void *pSymbol; pLibrary = LoadLibrary(pszLibrary); - if( pLibrary == NULL ) { - msSetError(MS_MISCERR, - "Can't load requested dynamic library: %s", + if (pLibrary == NULL) { + msSetError(MS_MISCERR, "Can't load requested dynamic library: %s", "msGetSymbol()", pszLibrary); return NULL; } - pSymbol = (void *) GetProcAddress( (HINSTANCE) pLibrary, pszSymbolName ); + pSymbol = (void *)GetProcAddress((HINSTANCE)pLibrary, pszSymbolName); - if( pSymbol == NULL ) { - msSetError(MS_MISCERR, - "Can't find requested entry point: %s in lib %s", + if (pSymbol == NULL) { + msSetError(MS_MISCERR, "Can't find requested entry point: %s in lib %s", "msGetSymbol()", pszSymbolName, pLibrary); return NULL; } - return( pSymbol ); + return (pSymbol); } #endif /* def _WIN32 */ @@ -254,11 +246,11 @@ void *msGetSymbol( const char * pszLibrary, const char * pszSymbolName ) /* Dummy implementation. */ /************************************************************************/ -void *msGetSymbol(const char *pszLibrary, const char *pszEntryPoint) -{ - msSetError(MS_MISCERR, - "msGetSymbol(%s,%s) called. Failed as this is stub implementation.", - "msGetSymbol()", pszLibrary, pszEntryPoint); +void *msGetSymbol(const char *pszLibrary, const char *pszEntryPoint) { + msSetError( + MS_MISCERR, + "msGetSymbol(%s,%s) called. Failed as this is stub implementation.", + "msGetSymbol()", pszLibrary, pszEntryPoint); return NULL; } #endif diff --git a/mapcrypto.c b/mapcrypto.c index 2f72da180e..91c14dfafd 100644 --- a/mapcrypto.c +++ b/mapcrypto.c @@ -28,15 +28,14 @@ ****************************************************************************/ #include -#include /* isxdigit() */ -#include /* rand() */ -#include /* time() */ +#include /* isxdigit() */ +#include /* rand() */ +#include /* time() */ #include "mapserver.h" #include "cpl_conv.h" - /********************************************************************** * encipher() and decipher() from the Tiny Encryption Algorithm (TEA) * website at: @@ -86,35 +85,34 @@ **********************************************************************/ static void encipher(const ms_uint32 *const v, ms_uint32 *const w, - const ms_uint32 *const k) -{ - register ms_uint32 y=v[0],z=v[1],sum=0,delta=0x9E3779B9,n=32; + const ms_uint32 *const k) { + register ms_uint32 y = v[0], z = v[1], sum = 0, delta = 0x9E3779B9, n = 32; - while(n-->0) { - y += ((z << 4 ^ z >> 5) + z) ^ (sum + k[sum&3]); + while (n-- > 0) { + y += ((z << 4 ^ z >> 5) + z) ^ (sum + k[sum & 3]); sum += delta; - z += ((y << 4 ^ y >> 5) + y) ^ (sum + k[sum>>11 & 3]); + z += ((y << 4 ^ y >> 5) + y) ^ (sum + k[sum >> 11 & 3]); } - w[0]=y; - w[1]=z; + w[0] = y; + w[1] = z; } static void decipher(const ms_uint32 *const v, ms_uint32 *const w, - const ms_uint32 *const k) -{ - register ms_uint32 y=v[0],z=v[1],sum=0xC6EF3720, delta=0x9E3779B9,n=32; + const ms_uint32 *const k) { + register ms_uint32 y = v[0], z = v[1], sum = 0xC6EF3720, delta = 0x9E3779B9, + n = 32; /* sum = delta<<5, in general sum = delta * n */ - while(n-->0) { - z -= ((y << 4 ^ y >> 5) + y) ^ (sum + k[sum>>11 & 3]); + while (n-- > 0) { + z -= ((y << 4 ^ y >> 5) + y) ^ (sum + k[sum >> 11 & 3]); sum -= delta; - y -= ((z << 4 ^ z >> 5) + z) ^ (sum + k[sum&3]); + y -= ((z << 4 ^ z >> 5) + z) ^ (sum + k[sum & 3]); } - w[0]=y; - w[1]=z; + w[0] = y; + w[1] = z; } /********************************************************************** @@ -125,13 +123,12 @@ static void decipher(const ms_uint32 *const v, ms_uint32 *const w, * out[] should be preallocated by the caller to be at least 2*numbytes+1 * (+1 for the terminating '\0') **********************************************************************/ -void msHexEncode(const unsigned char *in, char *out, int numbytes) -{ +void msHexEncode(const unsigned char *in, char *out, int numbytes) { char *hex = "0123456789ABCDEF"; while (numbytes-- > 0) { - *out++ = hex[*in/16]; - *out++ = hex[*in%16]; + *out++ = hex[*in / 16]; + *out++ = hex[*in % 16]; in++; } *out = '\0'; @@ -151,20 +148,19 @@ void msHexEncode(const unsigned char *in, char *out, int numbytes) * Returns the number of bytes written to out[] which may be different from * numchars/2 if an error or a '\0' is encountered. **********************************************************************/ -int msHexDecode(const char *in, unsigned char *out, int numchars) -{ +int msHexDecode(const char *in, unsigned char *out, int numchars) { int numbytes_out = 0; /* Make sure numchars is even */ - numchars = (numchars/2) * 2; + numchars = (numchars / 2) * 2; if (numchars < 2) numchars = -1; /* Will result in this value being ignored in the loop*/ - while (*in != '\0' && *(in+1) != '\0' && numchars != 0) { - *out = 0x10 * (*in >= 'A' ? ((*in & 0xdf) - 'A')+10 : (*in - '0')); + while (*in != '\0' && *(in + 1) != '\0' && numchars != 0) { + *out = 0x10 * (*in >= 'A' ? ((*in & 0xdf) - 'A') + 10 : (*in - '0')); in++; - *out += (*in >= 'A' ? ((*in & 0xdf) - 'A')+10 : (*in - '0')); + *out += (*in >= 'A' ? ((*in & 0xdf) - 'A') + 10 : (*in - '0')); in++; out++; @@ -176,7 +172,6 @@ int msHexDecode(const char *in, unsigned char *out, int numchars) return numbytes_out; } - /********************************************************************** * msGenerateEncryptionKey() * @@ -185,15 +180,13 @@ int msHexDecode(const char *in, unsigned char *out, int numchars) * The output buffer should be at least MS_ENCRYPTION_KEY_SIZE bytes. **********************************************************************/ -int msGenerateEncryptionKey(unsigned char *k) -{ +int msGenerateEncryptionKey(unsigned char *k) { int i; /* Use current time as seed for rand() */ - srand( (unsigned int) time( NULL )); + srand((unsigned int)time(NULL)); - for(i=0; iencryption_key_loaded) - return MS_SUCCESS; /* Already loaded */ + return MS_SUCCESS; /* Already loaded */ keyfile = msGetConfigOption(map, "MS_ENCRYPTION_KEY"); - if(!keyfile) keyfile = CPLGetConfigOption("MS_ENCRYPTION_KEY", NULL); + if (!keyfile) + keyfile = CPLGetConfigOption("MS_ENCRYPTION_KEY", NULL); if (keyfile && - msReadEncryptionKeyFromFile(keyfile,map->encryption_key) == MS_SUCCESS) { + msReadEncryptionKeyFromFile(keyfile, map->encryption_key) == MS_SUCCESS) { map->encryption_key_loaded = MS_TRUE; } else { - msSetError(MS_MISCERR, "Failed reading encryption key. Make sure " + msSetError(MS_MISCERR, + "Failed reading encryption key. Make sure " "MS_ENCRYPTION_KEY is set and points to a valid key file.", "msLoadEncryptionKey()"); return MS_FAILURE; @@ -294,8 +288,8 @@ static int msLoadEncryptionKey(mapObj *map) * **********************************************************************/ -void msEncryptStringWithKey(const unsigned char *key, const char *in, char *out) -{ +void msEncryptStringWithKey(const unsigned char *key, const char *in, + char *out) { ms_uint32 v[4], w[4]; const ms_uint32 *k; int last_block = MS_FALSE; @@ -303,9 +297,9 @@ void msEncryptStringWithKey(const unsigned char *key, const char *in, char *out) /* Casting the key this way is safe only as long as longs are 4 bytes * on this platform */ assert(sizeof(ms_uint32) == 4); - k = (const ms_uint32 *) key; + k = (const ms_uint32 *)key; - while(!last_block) { + while (!last_block) { int i, j; /* encipher() takes v[2] (64 bits) as input. * Copy bytes from in[] to the v[2] input array (pair of 4 bytes) @@ -313,14 +307,14 @@ void msEncryptStringWithKey(const unsigned char *key, const char *in, char *out) */ v[0] = 0; v[1] = 0; - for(i=0; !last_block && i<2; i++) { - for(j=0; j<4; j++) { + for (i = 0; !last_block && i < 2; i++) { + for (j = 0; j < 4; j++) { if (*in == '\0') { last_block = MS_TRUE; break; } - v[i] |= *in << (j*8); + v[i] |= *in << (j * 8); in++; } } @@ -334,9 +328,8 @@ void msEncryptStringWithKey(const unsigned char *key, const char *in, char *out) /* Append hex-encoded bytes to output, 4 bytes at a time */ msHexEncode((unsigned char *)w, out, 4); out += 8; - msHexEncode((unsigned char *)(w+1), out, 4); + msHexEncode((unsigned char *)(w + 1), out, 4); out += 8; - } /* Make sure output is 0-terminated */ @@ -352,8 +345,8 @@ void msEncryptStringWithKey(const unsigned char *key, const char *in, char *out) * **********************************************************************/ -void msDecryptStringWithKey(const unsigned char *key, const char *in, char *out) -{ +void msDecryptStringWithKey(const unsigned char *key, const char *in, + char *out) { ms_uint32 v[4], w[4]; const ms_uint32 *k; int last_block = MS_FALSE; @@ -361,9 +354,9 @@ void msDecryptStringWithKey(const unsigned char *key, const char *in, char *out) /* Casting the key this way is safe only as long as longs are 4 bytes * on this platform */ assert(sizeof(ms_uint32) == 4); - k = (const ms_uint32 *) key; + k = (const ms_uint32 *)key; - while(!last_block) { + while (!last_block) { int i; /* decipher() takes v[2] (64 bits) as input. * Copy bytes from in[] to the v[2] input array (pair of 4 bytes) @@ -376,7 +369,7 @@ void msDecryptStringWithKey(const unsigned char *key, const char *in, char *out) last_block = MS_TRUE; else { in += 8; - if (msHexDecode(in, (unsigned char *)(v+1), 8) != 4) + if (msHexDecode(in, (unsigned char *)(v + 1), 8) != 4) last_block = MS_TRUE; else in += 8; @@ -386,7 +379,7 @@ void msDecryptStringWithKey(const unsigned char *key, const char *in, char *out) decipher(v, w, k); /* Copy the results to out[] */ - for(i=0; i<2; i++) { + for (i = 0; i < 2; i++) { *out++ = (w[i] & 0x000000ff); *out++ = (w[i] & 0x0000ff00) >> 8; *out++ = (w[i] & 0x00ff0000) >> 16; @@ -410,8 +403,7 @@ void msDecryptStringWithKey(const unsigned char *key, const char *in, char *out) * **********************************************************************/ -char *msDecryptStringTokens(mapObj *map, const char *in) -{ +char *msDecryptStringTokens(mapObj *map, const char *in) { char *outbuf, *out; if (map == NULL) { @@ -421,13 +413,13 @@ char *msDecryptStringTokens(mapObj *map, const char *in) /* Start with a copy of the string. Decryption can only result in * a string with the same or shorter length */ - if ((outbuf = (char *)malloc((strlen(in)+1)*sizeof(char))) == NULL) { + if ((outbuf = (char *)malloc((strlen(in) + 1) * sizeof(char))) == NULL) { msSetError(MS_MEMERR, NULL, "msDecryptStringTokens()"); return NULL; } out = outbuf; - while(*in != '\0') { + while (*in != '\0') { if (*in == '{') { /* Possibly beginning of a token, look for closing bracket ** and make sure all chars in between are valid hex encoding chars @@ -435,12 +427,11 @@ char *msDecryptStringTokens(mapObj *map, const char *in) const char *pszStart, *pszEnd; int valid_token = MS_FALSE; - pszStart = in+1; - if ( (pszEnd = strchr(pszStart, '}')) != NULL && - pszEnd - pszStart > 1) { + pszStart = in + 1; + if ((pszEnd = strchr(pszStart, '}')) != NULL && pszEnd - pszStart > 1) { const char *pszTmp; valid_token = MS_TRUE; - for(pszTmp = pszStart; pszTmp < pszEnd; pszTmp++) { + for (pszTmp = pszStart; pszTmp < pszEnd; pszTmp++) { if (!isxdigit(*pszTmp)) { valid_token = MS_FALSE; break; @@ -460,13 +451,13 @@ char *msDecryptStringTokens(mapObj *map, const char *in) if (msLoadEncryptionKey(map) != MS_SUCCESS) return NULL; - pszTmp = (char*)malloc( (pszEnd-pszStart+1)*sizeof(char)); - strlcpy(pszTmp, pszStart, (pszEnd-pszStart)+1); + pszTmp = (char *)malloc((pszEnd - pszStart + 1) * sizeof(char)); + strlcpy(pszTmp, pszStart, (pszEnd - pszStart) + 1); msDecryptStringWithKey(map->encryption_key, pszTmp, out); out += strlen(out); - in = pszEnd+1; + in = pszEnd + 1; free(pszTmp); } else { /* Not a valid token, just copy the '{' and keep going */ @@ -482,7 +473,6 @@ char *msDecryptStringTokens(mapObj *map, const char *in) return outbuf; } - #ifdef TEST_MAPCRYPTO /* Test for mapcrypto.c functions. To run these tests, use the following @@ -493,10 +483,9 @@ test_mapcrypto: $(LIBMAP_STATIC) mapcrypto.c ** */ -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { const unsigned char bytes_in[] = {0x12, 0x34, 0xff, 0x00, 0x44, 0x22}; - unsigned char bytes_out[8], encryption_key[MS_ENCRYPTION_KEY_SIZE*2+1]; + unsigned char bytes_out[8], encryption_key[MS_ENCRYPTION_KEY_SIZE * 2 + 1]; char string_buf[256], string_buf2[256]; int numbytes = 0; @@ -511,29 +500,30 @@ int main(int argc, char *argv[]) */ memset(bytes_out, 0, 8); numbytes = msHexDecode(string_buf, bytes_out, -1); - printf("msHexDecode(%s, -1) = %d, bytes_out = %x, %x, %x, %x, %x, %x, %x, %x\n", - string_buf, numbytes, - bytes_out[0], bytes_out[1], bytes_out[2], bytes_out[3], - bytes_out[4], bytes_out[5], bytes_out[6], bytes_out[7]); + printf( + "msHexDecode(%s, -1) = %d, bytes_out = %x, %x, %x, %x, %x, %x, %x, %x\n", + string_buf, numbytes, bytes_out[0], bytes_out[1], bytes_out[2], + bytes_out[3], bytes_out[4], bytes_out[5], bytes_out[6], bytes_out[7]); memset(bytes_out, 0, 8); numbytes = msHexDecode(string_buf, bytes_out, 4); - printf("msHexDecode(%s, 4) = %d, bytes_out = %x, %x, %x, %x, %x, %x, %x, %x\n", - string_buf, numbytes, - bytes_out[0], bytes_out[1], bytes_out[2], bytes_out[3], - bytes_out[4], bytes_out[5], bytes_out[6], bytes_out[7]); + printf( + "msHexDecode(%s, 4) = %d, bytes_out = %x, %x, %x, %x, %x, %x, %x, %x\n", + string_buf, numbytes, bytes_out[0], bytes_out[1], bytes_out[2], + bytes_out[3], bytes_out[4], bytes_out[5], bytes_out[6], bytes_out[7]); memset(bytes_out, 0, 8); numbytes = msHexDecode(string_buf, bytes_out, 20); - printf("msHexDecode(%s, 20) = %d, bytes_out = %x, %x, %x, %x, %x, %x, %x, %x\n", - string_buf, numbytes, - bytes_out[0], bytes_out[1], bytes_out[2], bytes_out[3], - bytes_out[4], bytes_out[5], bytes_out[6], bytes_out[7]); + printf( + "msHexDecode(%s, 20) = %d, bytes_out = %x, %x, %x, %x, %x, %x, %x, %x\n", + string_buf, numbytes, bytes_out[0], bytes_out[1], bytes_out[2], + bytes_out[3], bytes_out[4], bytes_out[5], bytes_out[6], bytes_out[7]); /* ** Test loading encryption key */ - if (msReadEncryptionKeyFromFile("/tmp/test.key", encryption_key) != MS_SUCCESS) { + if (msReadEncryptionKeyFromFile("/tmp/test.key", encryption_key) != + MS_SUCCESS) { printf("msReadEncryptionKeyFromFile() = MS_FAILURE\n"); printf("Aborting tests!\n"); msWriteError(stderr); @@ -552,21 +542,24 @@ int main(int argc, char *argv[]) printf("msEncryptStringWithKey('test1234') returned '%s'\n", string_buf); msDecryptStringWithKey(encryption_key, string_buf, string_buf2); - printf("msDecryptStringWithKey('%s') returned '%s'\n", string_buf, string_buf2); + printf("msDecryptStringWithKey('%s') returned '%s'\n", string_buf, + string_buf2); /* Next with an 1 byte input string */ msEncryptStringWithKey(encryption_key, "t", string_buf); printf("msEncryptStringWithKey('t') returned '%s'\n", string_buf); msDecryptStringWithKey(encryption_key, string_buf, string_buf2); - printf("msDecryptStringWithKey('%s') returned '%s'\n", string_buf, string_buf2); + printf("msDecryptStringWithKey('%s') returned '%s'\n", string_buf, + string_buf2); /* Next with an 12 bytes input string */ msEncryptStringWithKey(encryption_key, "test123456", string_buf); printf("msEncryptStringWithKey('test123456') returned '%s'\n", string_buf); msDecryptStringWithKey(encryption_key, string_buf, string_buf2); - printf("msDecryptStringWithKey('%s') returned '%s'\n", string_buf, string_buf2); + printf("msDecryptStringWithKey('%s') returned '%s'\n", string_buf, + string_buf2); /* ** Test decryption with tokens @@ -586,8 +579,8 @@ int main(int argc, char *argv[]) msWriteError(stderr); return -1; } else { - printf("msDecryptStringTokens('%s') returned '%s'\n", - string_buf2, pszBuf); + printf("msDecryptStringTokens('%s') returned '%s'\n", string_buf2, + pszBuf); } msFree(pszBuf); msFreeMap(map); @@ -596,5 +589,4 @@ int main(int argc, char *argv[]) return 0; } - #endif /* TEST_MAPCRYPTO */ diff --git a/mapdebug.c b/mapdebug.c index 75261808ba..d03cfdea7e 100644 --- a/mapdebug.c +++ b/mapdebug.c @@ -27,7 +27,6 @@ * DEALINGS IN THE SOFTWARE. ****************************************************************************/ - #include "mapserver.h" #include "maperror.h" #include "mapthread.h" @@ -50,16 +49,11 @@ #include /* OutputDebugStringA() */ #endif - - - #ifndef USE_THREAD -debugInfoObj *msGetDebugInfoObj() -{ - static debugInfoObj debuginfo = {MS_DEBUGLEVEL_ERRORSONLY, - MS_DEBUGMODE_OFF, NULL, NULL - }; +debugInfoObj *msGetDebugInfoObj() { + static debugInfoObj debuginfo = {MS_DEBUGLEVEL_ERRORSONLY, MS_DEBUGMODE_OFF, + NULL, NULL}; return &debuginfo; } @@ -67,32 +61,32 @@ debugInfoObj *msGetDebugInfoObj() static debugInfoObj *debuginfo_list = NULL; -debugInfoObj *msGetDebugInfoObj() -{ +debugInfoObj *msGetDebugInfoObj() { debugInfoObj *link; - void* thread_id; + void *thread_id; debugInfoObj *ret_obj; - msAcquireLock( TLOCK_DEBUGOBJ ); + msAcquireLock(TLOCK_DEBUGOBJ); thread_id = msGetThreadId(); /* find link for this thread */ - for( link = debuginfo_list; - link != NULL && link->thread_id != thread_id - && link->next != NULL && link->next->thread_id != thread_id; - link = link->next ) {} + for (link = debuginfo_list; + link != NULL && link->thread_id != thread_id && link->next != NULL && + link->next->thread_id != thread_id; + link = link->next) { + } /* If the target thread link is already at the head of the list were ok */ - if( debuginfo_list != NULL && debuginfo_list->thread_id == thread_id ) { + if (debuginfo_list != NULL && debuginfo_list->thread_id == thread_id) { } /* We don't have one ... initialize one. */ - else if( link == NULL || link->next == NULL ) { + else if (link == NULL || link->next == NULL) { debugInfoObj *new_link; - new_link = (debugInfoObj *) msSmallMalloc(sizeof(debugInfoObj)); + new_link = (debugInfoObj *)msSmallMalloc(sizeof(debugInfoObj)); new_link->next = debuginfo_list; new_link->thread_id = thread_id; new_link->global_debug_level = MS_DEBUGLEVEL_ERRORSONLY; @@ -113,13 +107,12 @@ debugInfoObj *msGetDebugInfoObj() ret_obj = debuginfo_list; - msReleaseLock( TLOCK_DEBUGOBJ ); + msReleaseLock(TLOCK_DEBUGOBJ); return ret_obj; } #endif - /* msSetErrorFile() ** ** Set output target, ready to write to it, open file if necessary @@ -130,8 +123,7 @@ debugInfoObj *msGetDebugInfoObj() ** ** Returns MS_SUCCESS/MS_FAILURE */ -int msSetErrorFile(const char *pszErrorFile, const char *pszRelToPath) -{ +int msSetErrorFile(const char *pszErrorFile, const char *pszRelToPath) { char extended_path[MS_MAXPATHLEN]; debugInfoObj *debuginfo = msGetDebugInfoObj(); @@ -139,7 +131,7 @@ int msSetErrorFile(const char *pszErrorFile, const char *pszRelToPath) strcmp(pszErrorFile, "stdout") != 0 && strcmp(pszErrorFile, "windowsdebug") != 0) { /* Try to make the path relative */ - if(msBuildPath(extended_path, pszRelToPath, pszErrorFile) == NULL) + if (msBuildPath(extended_path, pszRelToPath, pszErrorFile) == NULL) return MS_FAILURE; pszErrorFile = extended_path; } @@ -171,13 +163,17 @@ int msSetErrorFile(const char *pszErrorFile, const char *pszRelToPath) debuginfo->fp = NULL; debuginfo->debug_mode = MS_DEBUGMODE_WINDOWSDEBUG; #else - msSetError(MS_MISCERR, "'MS_ERRORFILE windowsdebug' is available only on Windows platforms.", "msSetErrorFile()"); + msSetError( + MS_MISCERR, + "'MS_ERRORFILE windowsdebug' is available only on Windows platforms.", + "msSetErrorFile()"); return MS_FAILURE; #endif } else { debuginfo->fp = fopen(pszErrorFile, "a"); if (debuginfo->fp == NULL) { - msSetError(MS_MISCERR, "Failed to open MS_ERRORFILE %s", "msSetErrorFile()", pszErrorFile); + msSetError(MS_MISCERR, "Failed to open MS_ERRORFILE %s", + "msSetErrorFile()", pszErrorFile); return MS_FAILURE; } debuginfo->errorfile = msStrdup(pszErrorFile); @@ -191,8 +187,7 @@ int msSetErrorFile(const char *pszErrorFile, const char *pszRelToPath) ** ** Close current output file (if one is open) and reset related members */ -void msCloseErrorFile() -{ +void msCloseErrorFile() { debugInfoObj *debuginfo = msGetDebugInfoObj(); if (debuginfo && debuginfo->debug_mode != MS_DEBUGMODE_OFF) { @@ -212,16 +207,13 @@ void msCloseErrorFile() } } - - /* msGetErrorFile() ** ** Returns name of current error file ** ** Returns NULL if not set. */ -const char *msGetErrorFile() -{ +const char *msGetErrorFile() { debugInfoObj *debuginfo = msGetDebugInfoObj(); if (debuginfo) @@ -235,16 +227,14 @@ const char *msGetErrorFile() ** the context of mapObj or layerObj. ** */ -void msSetGlobalDebugLevel(int level) -{ +void msSetGlobalDebugLevel(int level) { debugInfoObj *debuginfo = msGetDebugInfoObj(); if (debuginfo) debuginfo->global_debug_level = (debugLevel)level; } -debugLevel msGetGlobalDebugLevel() -{ +debugLevel msGetGlobalDebugLevel() { debugInfoObj *debuginfo = msGetDebugInfoObj(); if (debuginfo) @@ -253,67 +243,63 @@ debugLevel msGetGlobalDebugLevel() return MS_DEBUGLEVEL_ERRORSONLY; } - /* msDebugInitFromEnv() ** ** Init debug state from MS_ERRORFILE and MS_DEBUGLEVEL env vars if set ** ** Returns MS_SUCCESS/MS_FAILURE */ -int msDebugInitFromEnv() -{ +int msDebugInitFromEnv() { const char *val; - if( (val=CPLGetConfigOption("MS_ERRORFILE", NULL)) != NULL ) { - if ( msSetErrorFile(val, NULL) != MS_SUCCESS ) + if ((val = CPLGetConfigOption("MS_ERRORFILE", NULL)) != NULL) { + if (msSetErrorFile(val, NULL) != MS_SUCCESS) return MS_FAILURE; } - if( (val=CPLGetConfigOption("MS_DEBUGLEVEL", NULL)) != NULL ) + if ((val = CPLGetConfigOption("MS_DEBUGLEVEL", NULL)) != NULL) msSetGlobalDebugLevel(atoi(val)); return MS_SUCCESS; } - /* msDebugCleanup() ** ** Called by msCleanup to remove info related to this thread. */ -void msDebugCleanup() -{ +void msDebugCleanup() { /* make sure file is closed */ msCloseErrorFile(); #ifdef USE_THREAD { - void* thread_id = msGetThreadId(); + void *thread_id = msGetThreadId(); debugInfoObj *link; - msAcquireLock( TLOCK_DEBUGOBJ ); + msAcquireLock(TLOCK_DEBUGOBJ); /* find link for this thread */ - for( link = debuginfo_list; - link != NULL && link->thread_id != thread_id - && link->next != NULL && link->next->thread_id != thread_id; - link = link->next ) {} + for (link = debuginfo_list; + link != NULL && link->thread_id != thread_id && link->next != NULL && + link->next->thread_id != thread_id; + link = link->next) { + } - if( link->thread_id == thread_id ) { + if (link->thread_id == thread_id) { /* presumably link is at head of list. */ - if( debuginfo_list == link ) + if (debuginfo_list == link) debuginfo_list = link->next; - free( link ); - } else if( link->next != NULL && link->next->thread_id == thread_id ) { + free(link); + } else if (link->next != NULL && link->next->thread_id == thread_id) { debugInfoObj *next_link = link->next; link->next = link->next->next; - free( next_link ); + free(next_link); } - msReleaseLock( TLOCK_DEBUGOBJ ); + msReleaseLock(TLOCK_DEBUGOBJ); } #endif - } /* msDebug() @@ -322,13 +308,20 @@ void msDebugCleanup() ** (see msSetErrorFile()) ** */ -void msDebug( const char * pszFormat, ... ) -{ +void msDebug(const char *pszFormat, ...) { va_list args; debugInfoObj *debuginfo = msGetDebugInfoObj(); + char szMessage[MESSAGELENGTH]; if (debuginfo == NULL || debuginfo->debug_mode == MS_DEBUGMODE_OFF) - return; /* Don't waste time here! */ + return; /* Don't waste time here! */ + + va_start(args, pszFormat); + vsnprintf(szMessage, MESSAGELENGTH, pszFormat, args); + va_end(args); + szMessage[MESSAGELENGTH - 1] = '\0'; + + msRedactCredentials(szMessage); if (debuginfo->fp) { /* Writing to a stdio file handle */ @@ -343,38 +336,23 @@ void msDebug( const char * pszFormat, ... ) time_t t; msGettimeofday(&tv, NULL); t = tv.tv_sec; - msIO_fprintf(debuginfo->fp, "[%s].%ld ", - msStringChop(ctime(&t)), (long)tv.tv_usec); + msIO_fprintf(debuginfo->fp, "[%s].%ld ", msStringChop(ctime(&t)), + (long)tv.tv_usec); } - va_start(args, pszFormat); - msIO_vfprintf(debuginfo->fp, pszFormat, args); - va_end(args); + msIO_fprintf(debuginfo->fp, "%s", szMessage); } #ifdef _WIN32 else if (debuginfo->debug_mode == MS_DEBUGMODE_WINDOWSDEBUG) { /* Writing to Windows Debug Console */ - - char szMessage[MESSAGELENGTH]; - - va_start(args, pszFormat); - vsnprintf( szMessage, MESSAGELENGTH, pszFormat, args ); - va_end(args); - - szMessage[MESSAGELENGTH-1] = '\0'; OutputDebugStringA(szMessage); } #endif - } - /* msDebug2() ** ** Variadic function with no operation ** */ -void msDebug2( int level, ... ) -{ - (void)level; -} +void msDebug2(int level, ...) { (void)level; } diff --git a/mapdraw.c b/mapdraw.c index 60d6c1f2f4..4c66440d5c 100644 --- a/mapdraw.c +++ b/mapdraw.c @@ -35,7 +35,6 @@ #include "mapfile.h" #include "mapows.h" - /* msPrepareImage() * * Returns a new imageObj ready for rendering the current map. @@ -44,69 +43,76 @@ * msMapRestoreRealExtent() once they are done with the image. * This should be set to MS_TRUE only when called from msDrawMap(), see bug 945. */ -imageObj *msPrepareImage(mapObj *map, int allow_nonsquare) -{ +imageObj *msPrepareImage(mapObj *map, int allow_nonsquare) { int i, status; - imageObj *image=NULL; + imageObj *image = NULL; double geo_cellsize; - if(map->width == -1 || map->height == -1) { - msSetError(MS_MISCERR, "Image dimensions not specified.", "msPrepareImage()"); - return(NULL); + if (map->width == -1 || map->height == -1) { + msSetError(MS_MISCERR, "Image dimensions not specified.", + "msPrepareImage()"); + return (NULL); } msFreeLabelCache(&(map->labelcache)); - msInitLabelCache(&(map->labelcache)); /* this clears any previously allocated cache */ + msInitLabelCache( + &(map->labelcache)); /* this clears any previously allocated cache */ /* clear any previously created mask layer images */ - for(i=0; inumlayers; i++) { - if(GET_LAYER(map, i)->maskimage) { + for (i = 0; i < map->numlayers; i++) { + if (GET_LAYER(map, i)->maskimage) { msFreeImage(GET_LAYER(map, i)->maskimage); GET_LAYER(map, i)->maskimage = NULL; } } - status = msValidateContexts(map); /* make sure there are no recursive REQUIRES or LABELREQUIRES expressions */ - if(status != MS_SUCCESS) return NULL; + status = msValidateContexts(map); /* make sure there are no recursive REQUIRES + or LABELREQUIRES expressions */ + if (status != MS_SUCCESS) + return NULL; - if(!map->outputformat) { + if (!map->outputformat) { msSetError(MS_IMGERR, "Map outputformat not set!", "msPrepareImage()"); - return(NULL); + return (NULL); } else if (MS_RENDERER_PLUGIN(map->outputformat)) { rendererVTableObj *renderer = map->outputformat->vtable; colorObj *bg = &map->imagecolor; - map->imagecolor.alpha=255; + map->imagecolor.alpha = 255; - image = renderer->createImage(map->width, map->height, map->outputformat,bg); + image = + renderer->createImage(map->width, map->height, map->outputformat, bg); if (image == NULL) - return(NULL); + return (NULL); image->format = map->outputformat; image->format->refcount++; image->width = map->width; image->height = map->height; - + image->resolution = map->resolution; - image->resolutionfactor = map->resolution/map->defresolution; + image->resolutionfactor = map->resolution / map->defresolution; if (map->web.imagepath) image->imagepath = msStrdup(map->web.imagepath); if (map->web.imageurl) image->imageurl = msStrdup(map->web.imageurl); - } else if( MS_RENDERER_IMAGEMAP(map->outputformat) ) { + } else if (MS_RENDERER_IMAGEMAP(map->outputformat)) { image = msImageCreateIM(map->width, map->height, map->outputformat, - map->web.imagepath, map->web.imageurl, map->resolution, map->defresolution); - } else if( MS_RENDERER_RAWDATA(map->outputformat) ) { - image = msImageCreate(map->width, map->height, map->outputformat, - map->web.imagepath, map->web.imageurl, map->resolution, map->defresolution, &map->imagecolor); + map->web.imagepath, map->web.imageurl, + map->resolution, map->defresolution); + } else if (MS_RENDERER_RAWDATA(map->outputformat)) { + image = + msImageCreate(map->width, map->height, map->outputformat, + map->web.imagepath, map->web.imageurl, map->resolution, + map->defresolution, &map->imagecolor); } else { image = NULL; } - - if(!image) { + + if (!image) { msSetError(MS_IMGERR, "Unable to initialize image.", "msPrepareImage()"); - return(NULL); + return (NULL); } - + image->map = map; /* @@ -115,135 +121,151 @@ imageObj *msPrepareImage(mapObj *map, int allow_nonsquare) * * If allow_nonsquare is set to MS_TRUE then the caller should call * msMapRestoreRealExtent() once they are done with the image. - * This should be set to MS_TRUE only when called from msDrawMap(), see bug 945. + * This should be set to MS_TRUE only when called from msDrawMap(), see bug + * 945. */ - if( allow_nonsquare && msTestConfigOption( map, "MS_NONSQUARE", MS_FALSE ) ) { - double cellsize_x = (map->extent.maxx - map->extent.minx)/map->width; - double cellsize_y = (map->extent.maxy - map->extent.miny)/map->height; + if (allow_nonsquare && msTestConfigOption(map, "MS_NONSQUARE", MS_FALSE)) { + double cellsize_x = (map->extent.maxx - map->extent.minx) / map->width; + double cellsize_y = (map->extent.maxy - map->extent.miny) / map->height; - if( cellsize_y != 0.0 - && (fabs(cellsize_x/cellsize_y) > 1.00001 - || fabs(cellsize_x/cellsize_y) < 0.99999) ) { + if (cellsize_y != 0.0 && (fabs(cellsize_x / cellsize_y) > 1.00001 || + fabs(cellsize_x / cellsize_y) < 0.99999)) { map->gt.need_geotransform = MS_TRUE; if (map->debug) - msDebug( "msDrawMap(): kicking into non-square pixel preserving mode.\n" ); + msDebug( + "msDrawMap(): kicking into non-square pixel preserving mode.\n"); } - map->cellsize = (cellsize_x*0.5 + cellsize_y*0.5); + map->cellsize = (cellsize_x * 0.5 + cellsize_y * 0.5); } else - map->cellsize = msAdjustExtent(&(map->extent),map->width,map->height); + map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height); - status = msCalculateScale(map->extent,map->units,map->width,map->height, map->resolution, &map->scaledenom); - if(status != MS_SUCCESS) { + status = msCalculateScale(map->extent, map->units, map->width, map->height, + map->resolution, &map->scaledenom); + if (status != MS_SUCCESS) { msFreeImage(image); - return(NULL); + return (NULL); } /* update geotransform based on adjusted extent. */ - msMapComputeGeotransform( map ); + msMapComputeGeotransform(map); /* Do we need to fake out stuff for rotated support? */ - if( map->gt.need_geotransform ) - msMapSetFakedExtent( map ); + if (map->gt.need_geotransform) + msMapSetFakedExtent(map); /* We will need a cellsize that represents a real georeferenced */ /* coordinate cellsize here, so compute it from saved extents. */ geo_cellsize = map->cellsize; - if( map->gt.need_geotransform == MS_TRUE ) { - double cellsize_x = (map->saved_extent.maxx - map->saved_extent.minx) - / map->width; - double cellsize_y = (map->saved_extent.maxy - map->saved_extent.miny) - / map->height; - - geo_cellsize = sqrt(cellsize_x*cellsize_x + cellsize_y*cellsize_y) - / sqrt(2.0); + if (map->gt.need_geotransform == MS_TRUE) { + double cellsize_x = + (map->saved_extent.maxx - map->saved_extent.minx) / map->width; + double cellsize_y = + (map->saved_extent.maxy - map->saved_extent.miny) / map->height; + + geo_cellsize = + sqrt(cellsize_x * cellsize_x + cellsize_y * cellsize_y) / sqrt(2.0); } /* compute layer/class/style/label scale factors now */ - for(int lid=0; lidnumlayers; lid++) { - layerObj * layer = GET_LAYER(map, lid); - if(layer->sizeunits != MS_PIXELS) - layer->scalefactor = (msInchesPerUnit(layer->sizeunits,0)/msInchesPerUnit(map->units,0)) / geo_cellsize; - else if(layer->symbolscaledenom > 0 && map->scaledenom > 0) - layer->scalefactor = layer->symbolscaledenom/map->scaledenom*map->resolution/map->defresolution; + for (int lid = 0; lid < map->numlayers; lid++) { + layerObj *layer = GET_LAYER(map, lid); + if (layer->sizeunits != MS_PIXELS) + layer->scalefactor = (msInchesPerUnit(layer->sizeunits, 0) / + msInchesPerUnit(map->units, 0)) / + geo_cellsize; + else if (layer->symbolscaledenom > 0 && map->scaledenom > 0) + layer->scalefactor = layer->symbolscaledenom / map->scaledenom * + map->resolution / map->defresolution; else - layer->scalefactor = map->resolution/map->defresolution; - for (int cid=0 ; cidnumclasses ; cid++) - { - classObj * class = GET_CLASS(map, lid, cid); + layer->scalefactor = map->resolution / map->defresolution; + for (int cid = 0; cid < layer->numclasses; cid++) { + classObj *class = GET_CLASS(map, lid, cid); if (class->sizeunits == MS_INHERIT) class->scalefactor = layer->scalefactor; else if (class->sizeunits != MS_PIXELS) - class->scalefactor = (msInchesPerUnit(class->sizeunits,0)/msInchesPerUnit(map->units,0)) / geo_cellsize; + class->scalefactor = (msInchesPerUnit(class->sizeunits, 0) / + msInchesPerUnit(map->units, 0)) / + geo_cellsize; else if (layer->symbolscaledenom > 0 && map->scaledenom > 0) - class->scalefactor = layer->symbolscaledenom/map->scaledenom*map->resolution/map->defresolution; + class->scalefactor = layer->symbolscaledenom / map->scaledenom * + map->resolution / map->defresolution; else - class->scalefactor = map->resolution/map->defresolution; - for (int sid=0 ; sidnumstyles ; sid++) - { - styleObj * style = class->styles[sid]; + class->scalefactor = map->resolution / map->defresolution; + for (int sid = 0; sid < class->numstyles; sid++) { + styleObj *style = class->styles[sid]; if (style->sizeunits == MS_INHERIT) style->scalefactor = class->scalefactor; else if (style->sizeunits != MS_PIXELS) - style->scalefactor = (msInchesPerUnit(style->sizeunits,0)/msInchesPerUnit(map->units,0)) / geo_cellsize; + style->scalefactor = (msInchesPerUnit(style->sizeunits, 0) / + msInchesPerUnit(map->units, 0)) / + geo_cellsize; else if (layer->symbolscaledenom > 0 && map->scaledenom > 0) - style->scalefactor = layer->symbolscaledenom/map->scaledenom*map->resolution/map->defresolution; + style->scalefactor = layer->symbolscaledenom / map->scaledenom * + map->resolution / map->defresolution; else - style->scalefactor = map->resolution/map->defresolution; + style->scalefactor = map->resolution / map->defresolution; } - for (int sid=0 ; sidnumlabels ; sid++) - { - labelObj * label = class->labels[sid]; + for (int sid = 0; sid < class->numlabels; sid++) { + labelObj *label = class->labels[sid]; if (label->sizeunits == MS_INHERIT) label->scalefactor = class->scalefactor; else if (label->sizeunits != MS_PIXELS) - label->scalefactor = (msInchesPerUnit(label->sizeunits,0)/msInchesPerUnit(map->units,0)) / geo_cellsize; + label->scalefactor = (msInchesPerUnit(label->sizeunits, 0) / + msInchesPerUnit(map->units, 0)) / + geo_cellsize; else if (layer->symbolscaledenom > 0 && map->scaledenom > 0) - label->scalefactor = layer->symbolscaledenom/map->scaledenom*map->resolution/map->defresolution; + label->scalefactor = layer->symbolscaledenom / map->scaledenom * + map->resolution / map->defresolution; else - label->scalefactor = map->resolution/map->defresolution; - for (int lsid=0 ; lsidnumstyles ; lsid++) - { - styleObj * lstyle = label->styles[lsid]; + label->scalefactor = map->resolution / map->defresolution; + for (int lsid = 0; lsid < label->numstyles; lsid++) { + styleObj *lstyle = label->styles[lsid]; if (lstyle->sizeunits == MS_INHERIT) lstyle->scalefactor = label->scalefactor; else if (lstyle->sizeunits != MS_PIXELS) - lstyle->scalefactor = (msInchesPerUnit(lstyle->sizeunits,0)/msInchesPerUnit(map->units,0)) / geo_cellsize; + lstyle->scalefactor = (msInchesPerUnit(lstyle->sizeunits, 0) / + msInchesPerUnit(map->units, 0)) / + geo_cellsize; else if (layer->symbolscaledenom > 0 && map->scaledenom > 0) - lstyle->scalefactor = layer->symbolscaledenom/map->scaledenom*map->resolution/map->defresolution; + lstyle->scalefactor = layer->symbolscaledenom / map->scaledenom * + map->resolution / map->defresolution; else - lstyle->scalefactor = map->resolution/map->defresolution; + lstyle->scalefactor = map->resolution / map->defresolution; } } } } - image->refpt.x = MS_MAP2IMAGE_X_IC_DBL(0, map->extent.minx, 1.0/map->cellsize); - image->refpt.y = MS_MAP2IMAGE_Y_IC_DBL(0, map->extent.maxy, 1.0/map->cellsize); + image->refpt.x = + MS_MAP2IMAGE_X_IC_DBL(0, map->extent.minx, 1.0 / map->cellsize); + image->refpt.y = + MS_MAP2IMAGE_Y_IC_DBL(0, map->extent.maxy, 1.0 / map->cellsize); return image; - } -static int msCompositeRasterBuffer(mapObj *map, imageObj *img, rasterBufferObj *rb, LayerCompositer *comp) { +static int msCompositeRasterBuffer(mapObj *map, imageObj *img, + rasterBufferObj *rb, LayerCompositer *comp) { int ret = MS_SUCCESS; - if(MS_IMAGE_RENDERER(img)->compositeRasterBuffer) { - while(comp && ret == MS_SUCCESS) { + if (MS_IMAGE_RENDERER(img)->compositeRasterBuffer) { + while (comp && ret == MS_SUCCESS) { rasterBufferObj *rb_ptr = rb; CompositingFilter *filter = comp->filter; - if(filter && comp->next) { - /* if we have another compositor to apply, then we need to copy the rasterBufferObj. Otherwise - * we can work on it directly */ - rb_ptr = (rasterBufferObj*)msSmallCalloc(sizeof(rasterBufferObj),1); - msCopyRasterBuffer(rb_ptr,rb); - } - while(filter && ret == MS_SUCCESS) { - ret = msApplyCompositingFilter(map,rb_ptr,filter); + if (filter && comp->next) { + /* if we have another compositor to apply, then we need to copy the + * rasterBufferObj. Otherwise we can work on it directly */ + rb_ptr = (rasterBufferObj *)msSmallCalloc(sizeof(rasterBufferObj), 1); + msCopyRasterBuffer(rb_ptr, rb); + } + while (filter && ret == MS_SUCCESS) { + ret = msApplyCompositingFilter(map, rb_ptr, filter); filter = filter->next; } - if(ret == MS_SUCCESS) - ret = MS_IMAGE_RENDERER(img)->compositeRasterBuffer(img,rb_ptr,comp->comp_op, comp->opacity); - if(rb_ptr != rb) { + if (ret == MS_SUCCESS) + ret = MS_IMAGE_RENDERER(img)->compositeRasterBuffer( + img, rb_ptr, comp->comp_op, comp->opacity); + if (rb_ptr != rb) { msFreeRasterBuffer(rb_ptr); msFree(rb_ptr); } @@ -257,15 +279,15 @@ static int msCompositeRasterBuffer(mapObj *map, imageObj *img, rasterBufferObj * /* * Generic function to render the map file. - * The type of the image created is based on the imagetype parameter in the map file. + * The type of the image created is based on the imagetype parameter in the map + * file. * * mapObj *map - map object loaded in MapScript or via a mapfile to use * int querymap - is this map the result of a query operation, MS_TRUE|MS_FALSE -*/ -imageObj *msDrawMap(mapObj *map, int querymap) -{ + */ +imageObj *msDrawMap(mapObj *map, int querymap) { int i; - layerObj *lp=NULL; + layerObj *lp = NULL; int status = MS_FAILURE; imageObj *image = NULL; struct mstimeval mapstarttime = {0}, mapendtime = {0}; @@ -273,85 +295,92 @@ imageObj *msDrawMap(mapObj *map, int querymap) #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR) enum MS_CONNECTION_TYPE lastconnectiontype; - httpRequestObj *pasOWSReqInfo=NULL; - int numOWSLayers=0; - int numOWSRequests=0; + httpRequestObj *pasOWSReqInfo = NULL; + int numOWSLayers = 0; + int numOWSRequests = 0; wmsParamsObj sLastWMSParams; #endif - if(map->debug >= MS_DEBUGLEVEL_TUNING) msGettimeofday(&mapstarttime, NULL); + if (map->debug >= MS_DEBUGLEVEL_TUNING) + msGettimeofday(&mapstarttime, NULL); - if(querymap) { /* use queryMapObj image dimensions */ - if(map->querymap.width > 0 && map->querymap.width <= map->maxsize) map->width = map->querymap.width; - if(map->querymap.height > 0 && map->querymap.height <= map->maxsize) map->height = map->querymap.height; + if (querymap) { /* use queryMapObj image dimensions */ + if (map->querymap.width > 0 && map->querymap.width <= map->maxsize) + map->width = map->querymap.width; + if (map->querymap.height > 0 && map->querymap.height <= map->maxsize) + map->height = map->querymap.height; } msApplyMapConfigOptions(map); image = msPrepareImage(map, MS_TRUE); - if(!image) { + if (!image) { msSetError(MS_IMGERR, "Unable to initialize image.", "msDrawMap()"); - return(NULL); + return (NULL); } - if( map->debug >= MS_DEBUGLEVEL_DEBUG ) - msDebug( "msDrawMap(): rendering using outputformat named %s (%s).\n", - map->outputformat->name, - map->outputformat->driver ); + if (map->debug >= MS_DEBUGLEVEL_DEBUG) + msDebug("msDrawMap(): rendering using outputformat named %s (%s).\n", + map->outputformat->name, map->outputformat->driver); #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR) /* Time the OWS query phase */ - if(map->debug >= MS_DEBUGLEVEL_TUNING ) msGettimeofday(&starttime, NULL); + if (map->debug >= MS_DEBUGLEVEL_TUNING) + msGettimeofday(&starttime, NULL); /* How many OWS (WMS/WFS) layers do we have to draw? * Note: numOWSLayers is the number of actual layers and numOWSRequests is * the number of HTTP requests which could be lower if multiple layers * are merged into the same request. */ - numOWSLayers=0; - for(i=0; inumlayers; i++) { - if(map->layerorder[i] == -1 ) - continue; + numOWSLayers = 0; + for (i = 0; i < map->numlayers; i++) { + if (map->layerorder[i] == -1) + continue; - lp = GET_LAYER(map,map->layerorder[i]); - if( lp->connectiontype != MS_WMS && - lp->connectiontype != MS_WFS ) { - continue; - } - numOWSLayers++; + lp = GET_LAYER(map, map->layerorder[i]); + if (lp->connectiontype != MS_WMS && lp->connectiontype != MS_WFS) { + continue; + } + numOWSLayers++; } if (numOWSLayers > 0) { /* Alloc and init pasOWSReqInfo... */ - pasOWSReqInfo = (httpRequestObj *)malloc(numOWSLayers*sizeof(httpRequestObj)); + pasOWSReqInfo = + (httpRequestObj *)malloc(numOWSLayers * sizeof(httpRequestObj)); if (pasOWSReqInfo == NULL) { - msSetError(MS_MEMERR, "Allocation of httpRequestObj failed.", "msDrawMap()"); + msSetError(MS_MEMERR, "Allocation of httpRequestObj failed.", + "msDrawMap()"); return NULL; } msHTTPInitRequestObj(pasOWSReqInfo, numOWSLayers); msInitWmsParamsObj(&sLastWMSParams); - /* Pre-download all WMS/WFS layers in parallel before starting to draw map */ + /* Pre-download all WMS/WFS layers in parallel before starting to draw map + */ lastconnectiontype = MS_SHAPEFILE; - for(i=0; inumlayers; i++) { - if(map->layerorder[i] == -1 ) + for (i = 0; i < map->numlayers; i++) { + if (map->layerorder[i] == -1) continue; - lp = GET_LAYER(map,map->layerorder[i]); - if( lp->connectiontype != MS_WMS && - lp->connectiontype != MS_WFS ) { + lp = GET_LAYER(map, map->layerorder[i]); + if (lp->connectiontype != MS_WMS && lp->connectiontype != MS_WFS) { continue; } - if( !msLayerIsVisible(map, lp) ) + if (!msLayerIsVisible(map, lp)) continue; #ifdef USE_WMS_LYR - if(lp->connectiontype == MS_WMS) { - if(msPrepareWMSLayerRequest(map->layerorder[i], map, lp, 1, lastconnectiontype, &sLastWMSParams, 0, 0, 0, NULL, pasOWSReqInfo, &numOWSRequests) == MS_FAILURE) { + if (lp->connectiontype == MS_WMS) { + if (msPrepareWMSLayerRequest(map->layerorder[i], map, lp, 1, + lastconnectiontype, &sLastWMSParams, 0, 0, + 0, NULL, pasOWSReqInfo, + &numOWSRequests) == MS_FAILURE) { msFreeWmsParamsObj(&sLastWMSParams); msFreeImage(image); msFree(pasOWSReqInfo); @@ -361,8 +390,9 @@ imageObj *msDrawMap(mapObj *map, int querymap) #endif #ifdef USE_WFS_LYR - if(lp->connectiontype == MS_WFS) { - if(msPrepareWFSLayerRequest(map->layerorder[i], map, lp, pasOWSReqInfo, &numOWSRequests) == MS_FAILURE) { + if (lp->connectiontype == MS_WFS) { + if (msPrepareWFSLayerRequest(map->layerorder[i], map, lp, pasOWSReqInfo, + &numOWSRequests) == MS_FAILURE) { msFreeWmsParamsObj(&sLastWMSParams); msFreeImage(image); msFree(pasOWSReqInfo); @@ -377,73 +407,86 @@ imageObj *msDrawMap(mapObj *map, int querymap) msFreeWmsParamsObj(&sLastWMSParams); } /* if numOWSLayers > 0 */ - if(numOWSRequests && msOWSExecuteRequests(pasOWSReqInfo, numOWSRequests, map, MS_TRUE) == MS_FAILURE) { + if (numOWSRequests && msOWSExecuteRequests(pasOWSReqInfo, numOWSRequests, map, + MS_TRUE) == MS_FAILURE) { msFreeImage(image); msFree(pasOWSReqInfo); return NULL; } - if(map->debug >= MS_DEBUGLEVEL_TUNING) { + if (map->debug >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&endtime, NULL); msDebug("msDrawMap(): WMS/WFS set-up and query, %.3fs\n", - (endtime.tv_sec+endtime.tv_usec/1.0e6)- - (starttime.tv_sec+starttime.tv_usec/1.0e6) ); + (endtime.tv_sec + endtime.tv_usec / 1.0e6) - + (starttime.tv_sec + starttime.tv_usec / 1.0e6)); } #endif /* USE_WMS_LYR || USE_WFS_LYR */ /* OK, now we can start drawing */ - for(i=0; inumlayers; i++) { + for (i = 0; i < map->numlayers; i++) { - if(map->layerorder[i] != -1) { + if (map->layerorder[i] != -1) { const char *force_draw_label_cache = NULL; - lp = (GET_LAYER(map, map->layerorder[i])); + lp = (GET_LAYER(map, map->layerorder[i])); - if(lp->postlabelcache) /* wait to draw */ + if (lp->postlabelcache) /* wait to draw */ continue; - if(map->debug >= MS_DEBUGLEVEL_TUNING || lp->debug >= MS_DEBUGLEVEL_TUNING ) msGettimeofday(&starttime, NULL); + if (map->debug >= MS_DEBUGLEVEL_TUNING || + lp->debug >= MS_DEBUGLEVEL_TUNING) + msGettimeofday(&starttime, NULL); - if(!msLayerIsVisible(map, lp)) continue; + if (!msLayerIsVisible(map, lp)) + continue; - if(lp->connectiontype == MS_WMS) { + if (lp->connectiontype == MS_WMS) { #ifdef USE_WMS_LYR - if(MS_RENDERER_PLUGIN(image->format) || MS_RENDERER_RAWDATA(image->format)) { + if (MS_RENDERER_PLUGIN(image->format) || + MS_RENDERER_RAWDATA(image->format)) { assert(pasOWSReqInfo); - status = msDrawWMSLayerLow(map->layerorder[i], pasOWSReqInfo, numOWSRequests, map, lp, image); - } - else { - msSetError(MS_WMSCONNERR, "Output format '%s' doesn't support WMS layers.", "msDrawMap()", image->format->name); + status = msDrawWMSLayerLow(map->layerorder[i], pasOWSReqInfo, + numOWSRequests, map, lp, image); + } else { + msSetError(MS_WMSCONNERR, + "Output format '%s' doesn't support WMS layers.", + "msDrawMap()", image->format->name); status = MS_FAILURE; } - if(status == MS_FAILURE) { + if (status == MS_FAILURE) { msSetError(MS_WMSCONNERR, - "Failed to draw WMS layer named '%s'. This most likely happened because " - "the remote WMS server returned an invalid image, and XML exception " - "or another unexpected result in response to the GetMap request. Also check " + "Failed to draw WMS layer named '%s'. This most likely " + "happened because " + "the remote WMS server returned an invalid image, and XML " + "exception " + "or another unexpected result in response to the GetMap " + "request. Also check " "and make sure that the layer's connection URL is valid.", "msDrawMap()", lp->name); msFreeImage(image); msHTTPFreeRequestObj(pasOWSReqInfo, numOWSRequests); msFree(pasOWSReqInfo); - return(NULL); + return (NULL); } - #else /* ndef USE_WMS_LYR */ - msSetError(MS_WMSCONNERR, "MapServer not built with WMS Client support, unable to render layer '%s'.", "msDrawMap()", lp->name); + msSetError(MS_WMSCONNERR, + "MapServer not built with WMS Client support, unable to " + "render layer '%s'.", + "msDrawMap()", lp->name); msFreeImage(image); - return(NULL); + return (NULL); #endif } else { /* Default case: anything but WMS layers */ - if(querymap) + if (querymap) status = msDrawQueryLayer(map, lp, image); else status = msDrawLayer(map, lp, image); - if(status == MS_FAILURE) { - msSetError(MS_IMGERR, "Failed to draw layer named '%s'.", "msDrawMap()", lp->name); + if (status == MS_FAILURE) { + msSetError(MS_IMGERR, "Failed to draw layer named '%s'.", + "msDrawMap()", lp->name); msFreeImage(image); #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR) if (pasOWSReqInfo) { @@ -451,80 +494,81 @@ imageObj *msDrawMap(mapObj *map, int querymap) msFree(pasOWSReqInfo); } #endif /* USE_WMS_LYR || USE_WFS_LYR */ - return(NULL); + return (NULL); } } - if(map->debug >= MS_DEBUGLEVEL_TUNING || lp->debug >= MS_DEBUGLEVEL_TUNING) { + if (map->debug >= MS_DEBUGLEVEL_TUNING || + lp->debug >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&endtime, NULL); - msDebug("msDrawMap(): Layer %d (%s), %.3fs\n", - map->layerorder[i], lp->name?lp->name:"(null)", - (endtime.tv_sec+endtime.tv_usec/1.0e6)- - (starttime.tv_sec+starttime.tv_usec/1.0e6) ); + msDebug("msDrawMap(): Layer %d (%s), %.3fs\n", map->layerorder[i], + lp->name ? lp->name : "(null)", + (endtime.tv_sec + endtime.tv_usec / 1.0e6) - + (starttime.tv_sec + starttime.tv_usec / 1.0e6)); } - /* Flush layer cache in-between layers if requested by PROCESSING directive*/ - force_draw_label_cache = msLayerGetProcessingKey(lp, "FORCE_DRAW_LABEL_CACHE"); + /* Flush layer cache in-between layers if requested by PROCESSING + * directive*/ + force_draw_label_cache = + msLayerGetProcessingKey(lp, "FORCE_DRAW_LABEL_CACHE"); if (force_draw_label_cache && - strncasecmp(force_draw_label_cache,"FLUSH",5)==0) { - if(map->debug >= MS_DEBUGLEVEL_V) - msDebug("msDrawMap(): PROCESSING FORCE_DRAW_LABEL_CACHE=FLUSH found.\n"); - if(msDrawLabelCache(map, image) != MS_SUCCESS) { - msFreeImage(image); + strncasecmp(force_draw_label_cache, "FLUSH", 5) == 0) { + if (map->debug >= MS_DEBUGLEVEL_V) + msDebug( + "msDrawMap(): PROCESSING FORCE_DRAW_LABEL_CACHE=FLUSH found.\n"); + if (msDrawLabelCache(map, image) != MS_SUCCESS) { + msFreeImage(image); #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR) - if (pasOWSReqInfo) { - msHTTPFreeRequestObj(pasOWSReqInfo, numOWSRequests); - msFree(pasOWSReqInfo); - } + if (pasOWSReqInfo) { + msHTTPFreeRequestObj(pasOWSReqInfo, numOWSRequests); + msFree(pasOWSReqInfo); + } #endif /* USE_WMS_LYR || USE_WFS_LYR */ - return(NULL); - } - msFreeLabelCache(&(map->labelcache)); - msInitLabelCache(&(map->labelcache)); + return (NULL); + } + msFreeLabelCache(&(map->labelcache)); + msInitLabelCache(&(map->labelcache)); } /* PROCESSING FORCE_DRAW_LABEL_CACHE */ - } } - if(map->scalebar.status == MS_EMBED && !map->scalebar.postlabelcache) { + if (map->scalebar.status == MS_EMBED && !map->scalebar.postlabelcache) { /* We need to temporarily restore the original extent for drawing */ /* the scalebar as it uses the extent to recompute cellsize. */ - if(map->gt.need_geotransform) + if (map->gt.need_geotransform) msMapRestoreRealExtent(map); - - if(MS_SUCCESS != msEmbedScalebar(map, image)) { - msFreeImage( image ); + if (MS_SUCCESS != msEmbedScalebar(map, image)) { + msFreeImage(image); #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR) /* Cleanup WMS/WFS Request stuff */ if (pasOWSReqInfo) { - msHTTPFreeRequestObj(pasOWSReqInfo, numOWSRequests); - msFree(pasOWSReqInfo); + msHTTPFreeRequestObj(pasOWSReqInfo, numOWSRequests); + msFree(pasOWSReqInfo); } #endif return NULL; } - - if(map->gt.need_geotransform) + if (map->gt.need_geotransform) msMapSetFakedExtent(map); } - if(map->legend.status == MS_EMBED && !map->legend.postlabelcache) { - if( msEmbedLegend(map, image) != MS_SUCCESS ) { - msFreeImage( image ); + if (map->legend.status == MS_EMBED && !map->legend.postlabelcache) { + if (msEmbedLegend(map, image) != MS_SUCCESS) { + msFreeImage(image); #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR) /* Cleanup WMS/WFS Request stuff */ if (pasOWSReqInfo) { - msHTTPFreeRequestObj(pasOWSReqInfo, numOWSRequests); - msFree(pasOWSReqInfo); + msHTTPFreeRequestObj(pasOWSReqInfo, numOWSRequests); + msFree(pasOWSReqInfo); } #endif return NULL; } } - if(msDrawLabelCache(map, image) != MS_SUCCESS) { + if (msDrawLabelCache(map, image) != MS_SUCCESS) { msFreeImage(image); #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR) if (pasOWSReqInfo) { @@ -532,38 +576,42 @@ imageObj *msDrawMap(mapObj *map, int querymap) msFree(pasOWSReqInfo); } #endif /* USE_WMS_LYR || USE_WFS_LYR */ - return(NULL); + return (NULL); } - - for(i=0; inumlayers; i++) { /* for each layer, check for postlabelcache layers */ + for (i = 0; i < map->numlayers; + i++) { /* for each layer, check for postlabelcache layers */ lp = (GET_LAYER(map, map->layerorder[i])); - if(!lp->postlabelcache) continue; - if(!msLayerIsVisible(map, lp)) continue; + if (!lp->postlabelcache) + continue; + if (!msLayerIsVisible(map, lp)) + continue; - if(map->debug >= MS_DEBUGLEVEL_TUNING || lp->debug >= MS_DEBUGLEVEL_TUNING) msGettimeofday(&starttime, NULL); + if (map->debug >= MS_DEBUGLEVEL_TUNING || lp->debug >= MS_DEBUGLEVEL_TUNING) + msGettimeofday(&starttime, NULL); - if(lp->connectiontype == MS_WMS) { + if (lp->connectiontype == MS_WMS) { #ifdef USE_WMS_LYR - if(MS_RENDERER_PLUGIN(image->format) || MS_RENDERER_RAWDATA(image->format)) - { + if (MS_RENDERER_PLUGIN(image->format) || + MS_RENDERER_RAWDATA(image->format)) { assert(pasOWSReqInfo); - status = msDrawWMSLayerLow(map->layerorder[i], pasOWSReqInfo, numOWSRequests, map, lp, image); + status = msDrawWMSLayerLow(map->layerorder[i], pasOWSReqInfo, + numOWSRequests, map, lp, image); } #else status = MS_FAILURE; #endif } else { - if(querymap) + if (querymap) status = msDrawQueryLayer(map, lp, image); else status = msDrawLayer(map, lp, image); } - if(status == MS_FAILURE) { + if (status == MS_FAILURE) { msFreeImage(image); #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR) if (pasOWSReqInfo) { @@ -571,27 +619,27 @@ imageObj *msDrawMap(mapObj *map, int querymap) msFree(pasOWSReqInfo); } #endif /* USE_WMS_LYR || USE_WFS_LYR */ - return(NULL); + return (NULL); } - if(map->debug >= MS_DEBUGLEVEL_TUNING || lp->debug >= MS_DEBUGLEVEL_TUNING) { + if (map->debug >= MS_DEBUGLEVEL_TUNING || + lp->debug >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&endtime, NULL); - msDebug("msDrawMap(): Layer %d (%s), %.3fs\n", - map->layerorder[i], lp->name?lp->name:"(null)", - (endtime.tv_sec+endtime.tv_usec/1.0e6)- - (starttime.tv_sec+starttime.tv_usec/1.0e6) ); + msDebug("msDrawMap(): Layer %d (%s), %.3fs\n", map->layerorder[i], + lp->name ? lp->name : "(null)", + (endtime.tv_sec + endtime.tv_usec / 1.0e6) - + (starttime.tv_sec + starttime.tv_usec / 1.0e6)); } - } /* Do we need to fake out stuff for rotated support? */ /* This really needs to be done on every preceeding exit point too... */ - if(map->gt.need_geotransform) + if (map->gt.need_geotransform) msMapRestoreRealExtent(map); - if(map->legend.status == MS_EMBED && map->legend.postlabelcache) - if(MS_UNLIKELY(MS_FAILURE == msEmbedLegend(map, image))) { - msFreeImage( image ); + if (map->legend.status == MS_EMBED && map->legend.postlabelcache) + if (MS_UNLIKELY(MS_FAILURE == msEmbedLegend(map, image))) { + msFreeImage(image); #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR) /* Cleanup WMS/WFS Request stuff */ if (pasOWSReqInfo) { @@ -602,27 +650,26 @@ imageObj *msDrawMap(mapObj *map, int querymap) return NULL; } - if(map->scalebar.status == MS_EMBED && map->scalebar.postlabelcache) { + if (map->scalebar.status == MS_EMBED && map->scalebar.postlabelcache) { /* We need to temporarily restore the original extent for drawing */ /* the scalebar as it uses the extent to recompute cellsize. */ - if(map->gt.need_geotransform) + if (map->gt.need_geotransform) msMapRestoreRealExtent(map); - if(MS_SUCCESS != msEmbedScalebar(map, image)) { - msFreeImage( image ); + if (MS_SUCCESS != msEmbedScalebar(map, image)) { + msFreeImage(image); #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR) /* Cleanup WMS/WFS Request stuff */ if (pasOWSReqInfo) { - msHTTPFreeRequestObj(pasOWSReqInfo, numOWSRequests); - msFree(pasOWSReqInfo); + msHTTPFreeRequestObj(pasOWSReqInfo, numOWSRequests); + msFree(pasOWSReqInfo); } #endif return NULL; } - - if(map->gt.need_geotransform) + if (map->gt.need_geotransform) msMapSetFakedExtent(map); } @@ -634,162 +681,195 @@ imageObj *msDrawMap(mapObj *map, int querymap) } #endif - if(map->debug >= MS_DEBUGLEVEL_TUNING) { + if (map->debug >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&mapendtime, NULL); msDebug("msDrawMap() total time: %.3fs\n", - (mapendtime.tv_sec+mapendtime.tv_usec/1.0e6)- - (mapstarttime.tv_sec+mapstarttime.tv_usec/1.0e6) ); + (mapendtime.tv_sec + mapendtime.tv_usec / 1.0e6) - + (mapstarttime.tv_sec + mapstarttime.tv_usec / 1.0e6)); } - return(image); + return (image); } /* * Test whether a layer should be drawn or not in the current map view and * at the current scale. * Returns TRUE if layer is visible, FALSE if not. -*/ -int msLayerIsVisible(mapObj *map, layerObj *layer) -{ + */ +int msLayerIsVisible(mapObj *map, layerObj *layer) { int i; - if(!layer->data && !layer->tileindex && !layer->connection && !layer->features && !layer->grid) - return(MS_FALSE); /* no data associated with this layer, not an error since layer may be used as a template from MapScript */ + if (!layer->data && !layer->tileindex && !layer->connection && + !layer->features && !layer->grid) + return (MS_FALSE); /* no data associated with this layer, not an error since + layer may be used as a template from MapScript */ - if(layer->type == MS_LAYER_QUERY || layer->type == MS_LAYER_TILEINDEX) return(MS_FALSE); - if((layer->status != MS_ON) && (layer->status != MS_DEFAULT)) return(MS_FALSE); + if (layer->type == MS_LAYER_QUERY || layer->type == MS_LAYER_TILEINDEX) + return (MS_FALSE); + if ((layer->status != MS_ON) && (layer->status != MS_DEFAULT)) + return (MS_FALSE); /* Do comparisons of layer scale vs map scale now, since msExtentsOverlap() */ /* can be slow */ - if(map->scaledenom > 0) { + if (map->scaledenom > 0) { /* layer scale boundaries should be checked first */ - if((layer->maxscaledenom > 0) && (map->scaledenom > layer->maxscaledenom)) { - if( layer->debug >= MS_DEBUGLEVEL_V ) { - msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER.MAXSCALE is too small for this MAP scale\n", layer->name); + if ((layer->maxscaledenom > 0) && + (map->scaledenom > layer->maxscaledenom)) { + if (layer->debug >= MS_DEBUGLEVEL_V) { + msDebug("msLayerIsVisible(): Skipping layer (%s) because " + "LAYER.MAXSCALE is too small for this MAP scale\n", + layer->name); } - return(MS_FALSE); + return (MS_FALSE); } - if(/*(layer->minscaledenom > 0) &&*/ (map->scaledenom <= layer->minscaledenom)) { - if( layer->debug >= MS_DEBUGLEVEL_V ) { - msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER.MINSCALE is too large for this MAP scale\n", layer->name); + if (/*(layer->minscaledenom > 0) &&*/ (map->scaledenom <= + layer->minscaledenom)) { + if (layer->debug >= MS_DEBUGLEVEL_V) { + msDebug("msLayerIsVisible(): Skipping layer (%s) because " + "LAYER.MINSCALE is too large for this MAP scale\n", + layer->name); } - return(MS_FALSE); + return (MS_FALSE); } } - /* Only return MS_FALSE if it is definitely false. Sometimes it will return MS_UNKNOWN, which we - ** consider true, for this use case (it might be visible, try and draw it, see what happens). */ - if ( msExtentsOverlap(map, layer) == MS_FALSE ) { - if( layer->debug >= MS_DEBUGLEVEL_V ) { - msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER.EXTENT does not intersect MAP.EXTENT\n", layer->name); + /* Only return MS_FALSE if it is definitely false. Sometimes it will return + *MS_UNKNOWN, which we + ** consider true, for this use case (it might be visible, try and draw it, + *see what happens). */ + if (msExtentsOverlap(map, layer) == MS_FALSE) { + if (layer->debug >= MS_DEBUGLEVEL_V) { + msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER.EXTENT " + "does not intersect MAP.EXTENT\n", + layer->name); } - return(MS_FALSE); + return (MS_FALSE); } - if(msEvalContext(map, layer, layer->requires) == MS_FALSE) return(MS_FALSE); + if (msEvalContext(map, layer, layer->requires) == MS_FALSE) + return (MS_FALSE); - if(map->scaledenom > 0) { + if (map->scaledenom > 0) { /* now check class scale boundaries (all layers *must* pass these tests) */ - if(layer->numclasses > 0) { - for(i=0; inumclasses; i++) { - if((layer->class[i]->maxscaledenom > 0) && (map->scaledenom > layer->class[i]->maxscaledenom)) + if (layer->numclasses > 0) { + for (i = 0; i < layer->numclasses; i++) { + if ((layer->class[i] -> maxscaledenom > 0) && + (map->scaledenom > layer->class[i] -> maxscaledenom)) continue; /* can skip this one, next class */ - if((layer->class[i]->minscaledenom > 0) && (map->scaledenom <= layer->class[i]->minscaledenom)) + if ((layer->class[i] -> minscaledenom > 0) && + (map->scaledenom <= layer->class[i] -> minscaledenom)) continue; /* can skip this one, next class */ break; /* can't skip this class (or layer for that matter) */ } - if(i == layer->numclasses) { - if( layer->debug >= MS_DEBUGLEVEL_V ) { - msDebug("msLayerIsVisible(): Skipping layer (%s) because no CLASS in the layer is in-scale for this MAP scale\n", layer->name); + if (i == layer->numclasses) { + if (layer->debug >= MS_DEBUGLEVEL_V) { + msDebug("msLayerIsVisible(): Skipping layer (%s) because no CLASS in " + "the layer is in-scale for this MAP scale\n", + layer->name); } - return(MS_FALSE); + return (MS_FALSE); } } - } if (layer->maxscaledenom <= 0 && layer->minscaledenom <= 0) { - if((layer->maxgeowidth > 0) && ((map->extent.maxx - map->extent.minx) > layer->maxgeowidth)) { - if( layer->debug >= MS_DEBUGLEVEL_V ) { - msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER width is much smaller than map width\n", layer->name); + if ((layer->maxgeowidth > 0) && + ((map->extent.maxx - map->extent.minx) > layer->maxgeowidth)) { + if (layer->debug >= MS_DEBUGLEVEL_V) { + msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER width " + "is much smaller than map width\n", + layer->name); } - return(MS_FALSE); + return (MS_FALSE); } - if((layer->mingeowidth > 0) && ((map->extent.maxx - map->extent.minx) < layer->mingeowidth)) { - if( layer->debug >= MS_DEBUGLEVEL_V ) { - msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER width is much larger than map width\n", layer->name); + if ((layer->mingeowidth > 0) && + ((map->extent.maxx - map->extent.minx) < layer->mingeowidth)) { + if (layer->debug >= MS_DEBUGLEVEL_V) { + msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER width " + "is much larger than map width\n", + layer->name); } - return(MS_FALSE); + return (MS_FALSE); } } - return MS_TRUE; /* All tests passed. Layer is visible. */ + return MS_TRUE; /* All tests passed. Layer is visible. */ } - -#define LAYER_NEEDS_COMPOSITING(layer) (((layer)->compositer != NULL) && ((layer)->compositer->next || (layer)->compositor->opacity < 100 || (layer)->compositor->compop != MS_COMPOP_SRC_OVER || (layer)->compositer->filter )) +#define LAYER_NEEDS_COMPOSITING(layer) \ + (((layer)->compositer != NULL) && \ + ((layer)->compositer->next || (layer)->compositor->opacity < 100 || \ + (layer)->compositor->compop != MS_COMPOP_SRC_OVER || \ + (layer)->compositer->filter)) /* * Generic function to render a layer object. -*/ -int msDrawLayer(mapObj *map, layerObj *layer, imageObj *image) -{ + */ +int msDrawLayer(mapObj *map, layerObj *layer, imageObj *image) { imageObj *image_draw = image; - outputFormatObj *altFormat=NULL; - int retcode=MS_SUCCESS; + outputFormatObj *altFormat = NULL; + int retcode = MS_SUCCESS; const char *alternativeFomatString = NULL; layerObj *maskLayer = NULL; - if(!msLayerIsVisible(map, layer)) + if (!msLayerIsVisible(map, layer)) return MS_SUCCESS; - if(layer->compositer && !layer->compositer->next && layer->compositer->opacity == 0) return MS_SUCCESS; /* layer is completely transparent, skip it */ - + if (layer->compositer && !layer->compositer->next && + layer->compositer->opacity == 0) + return MS_SUCCESS; /* layer is completely transparent, skip it */ /* conditions may have changed since this layer last drawn, so retest layer->project (Bug #673) */ - layer->project = msProjectionsDiffer(&(layer->projection),&(map->projection)); + layer->project = + msProjectionsDiffer(&(layer->projection), &(map->projection)); - /* make sure labelcache setting is set correctly if postlabelcache is set. This is done by the parser but - may have been altered by a mapscript. see #5142 */ - if(layer->postlabelcache) { + /* make sure labelcache setting is set correctly if postlabelcache is set. + This is done by the parser but may have been altered by a mapscript. see + #5142 */ + if (layer->postlabelcache) { layer->labelcache = MS_FALSE; } - if(layer->mask) { + if (layer->mask) { int maskLayerIdx; /* render the mask layer in its own imageObj */ - if(!MS_IMAGE_RENDERER(image)->supports_pixel_buffer) { - msSetError(MS_MISCERR, "Layer (%s) references references a mask layer, but the selected renderer does not support them", "msDrawLayer()", - layer->name); + if (!MS_IMAGE_RENDERER(image)->supports_pixel_buffer) { + msSetError(MS_MISCERR, + "Layer (%s) references references a mask layer, but the " + "selected renderer does not support them", + "msDrawLayer()", layer->name); return (MS_FAILURE); } - maskLayerIdx = msGetLayerIndex(map,layer->mask); - if(maskLayerIdx == -1) { - msSetError(MS_MISCERR, "Layer (%s) references unknown mask layer (%s)", "msDrawLayer()", - layer->name,layer->mask); + maskLayerIdx = msGetLayerIndex(map, layer->mask); + if (maskLayerIdx == -1) { + msSetError(MS_MISCERR, "Layer (%s) references unknown mask layer (%s)", + "msDrawLayer()", layer->name, layer->mask); return (MS_FAILURE); } maskLayer = GET_LAYER(map, maskLayerIdx); - if(!maskLayer->maskimage) { + if (!maskLayer->maskimage) { int i; int origstatus, origlabelcache; - altFormat = msSelectOutputFormat(map, "png24"); + altFormat = msSelectOutputFormat(map, "png24"); msInitializeRendererVTable(altFormat); - /* TODO: check the png24 format hasn't been tampered with, i.e. it's agg */ - maskLayer->maskimage= msImageCreate(image->width, image->height,altFormat, - image->imagepath, image->imageurl, map->resolution, map->defresolution, NULL); + /* TODO: check the png24 format hasn't been tampered with, i.e. it's agg + */ + maskLayer->maskimage = msImageCreate( + image->width, image->height, altFormat, image->imagepath, + image->imageurl, map->resolution, map->defresolution, NULL); if (!maskLayer->maskimage) { - msSetError(MS_MISCERR, "Unable to initialize mask image.", "msDrawLayer()"); + msSetError(MS_MISCERR, "Unable to initialize mask image.", + "msDrawLayer()"); return (MS_FAILURE); } /* - * force the masked layer to status on, and turn off the labelcache so that - * eventual labels are added to the temporary image instead of being added - * to the labelcache + * force the masked layer to status on, and turn off the labelcache so + * that eventual labels are added to the temporary image instead of being + * added to the labelcache */ origstatus = maskLayer->status; origlabelcache = maskLayer->labelcache; @@ -800,79 +880,85 @@ int msDrawLayer(mapObj *map, layerObj *layer, imageObj *image) retcode = msDrawLayer(map, maskLayer, maskLayer->maskimage); maskLayer->status = origstatus; maskLayer->labelcache = origlabelcache; - if(retcode != MS_SUCCESS) { + if (retcode != MS_SUCCESS) { return MS_FAILURE; } /* - * hack to work around bug #3834: if we have use an alternate renderer, the symbolset may contain - * symbols that reference it. We want to remove those references before the altFormat is destroyed - * to avoid a segfault and/or a leak, and so the the main renderer doesn't pick the cache up thinking - * it's for him. + * hack to work around bug #3834: if we have use an alternate renderer, + * the symbolset may contain symbols that reference it. We want to remove + * those references before the altFormat is destroyed to avoid a segfault + * and/or a leak, and so the the main renderer doesn't pick the cache up + * thinking it's for him. */ - for(i=0; isymbolset.numsymbols; i++) { - if (map->symbolset.symbol[i]!=NULL) { + for (i = 0; i < map->symbolset.numsymbols; i++) { + if (map->symbolset.symbol[i] != NULL) { symbolObj *s = map->symbolset.symbol[i]; - if(s->renderer == MS_IMAGE_RENDERER(maskLayer->maskimage)) { + if (s->renderer == MS_IMAGE_RENDERER(maskLayer->maskimage)) { MS_IMAGE_RENDERER(maskLayer->maskimage)->freeSymbol(s); s->renderer = NULL; } } } - /* set the imagetype from the original outputformat back (it was removed by msSelectOutputFormat() */ + /* set the imagetype from the original outputformat back (it was removed + * by msSelectOutputFormat() */ msFree(map->imagetype); map->imagetype = msStrdup(image->format->name); } - } altFormat = NULL; /* inform the rendering device that layer draw is starting. */ msImageStartLayer(map, layer, image); - /*check if an alternative renderer should be used for this layer*/ - alternativeFomatString = msLayerGetProcessingKey( layer, "RENDERER"); - if (MS_RENDERER_PLUGIN(image_draw->format) && alternativeFomatString!=NULL && - (altFormat= msSelectOutputFormat(map, alternativeFomatString))) { - rendererVTableObj *renderer=NULL; + alternativeFomatString = msLayerGetProcessingKey(layer, "RENDERER"); + if (MS_RENDERER_PLUGIN(image_draw->format) && + alternativeFomatString != NULL && + (altFormat = msSelectOutputFormat(map, alternativeFomatString))) { + rendererVTableObj *renderer = NULL; msInitializeRendererVTable(altFormat); - image_draw = msImageCreate(image->width, image->height, - altFormat, image->imagepath, image->imageurl, map->resolution, map->defresolution, &map->imagecolor); + image_draw = msImageCreate( + image->width, image->height, altFormat, image->imagepath, + image->imageurl, map->resolution, map->defresolution, &map->imagecolor); renderer = MS_IMAGE_RENDERER(image_draw); - renderer->startLayer(image_draw,map,layer); + renderer->startLayer(image_draw, map, layer); } else if (MS_RENDERER_PLUGIN(image_draw->format)) { rendererVTableObj *renderer = MS_IMAGE_RENDERER(image_draw); - if ((layer->mask && layer->connectiontype!=MS_WMS && layer->type != MS_LAYER_RASTER) || layer->compositer) { - /* masking occurs at the pixel/layer level for raster images, so we don't need to create a temporary image - in these cases + if ((layer->mask && layer->connectiontype != MS_WMS && + layer->type != MS_LAYER_RASTER) || + layer->compositer) { + /* masking occurs at the pixel/layer level for raster images, so we don't + need to create a temporary image in these cases */ if (layer->mask || renderer->compositeRasterBuffer) { - image_draw = msImageCreate(image->width, image->height, - image->format, image->imagepath, image->imageurl, map->resolution, map->defresolution, NULL); + image_draw = msImageCreate(image->width, image->height, image->format, + image->imagepath, image->imageurl, + map->resolution, map->defresolution, NULL); if (!image_draw) { - msSetError(MS_MISCERR, "Unable to initialize temporary transparent image.", + msSetError(MS_MISCERR, + "Unable to initialize temporary transparent image.", "msDrawLayer()"); return (MS_FAILURE); } image_draw->map = map; - renderer->startLayer(image_draw,map,layer); + renderer->startLayer(image_draw, map, layer); } } } /* ** redirect procesing of some layer types. */ - if(layer->connectiontype == MS_WMS) { + if (layer->connectiontype == MS_WMS) { #ifdef USE_WMS_LYR retcode = msDrawWMSLayer(map, layer, image_draw); #else retcode = MS_FAILURE; #endif - } else if(layer->type == MS_LAYER_RASTER) { + } else if (layer->type == MS_LAYER_RASTER) { retcode = msDrawRasterLayer(map, layer, image_draw); - } else if(layer->type == MS_LAYER_CHART) { + } else if (layer->type == MS_LAYER_CHART) { retcode = msDrawChartLayer(map, layer, image_draw); - } else { /* must be a Vector layer */ + } else { /* must be a Vector layer */ retcode = msDrawVectorLayer(map, layer, image_draw); } @@ -881,226 +967,230 @@ int msDrawLayer(mapObj *map, layerObj *layer, imageObj *image) rendererVTableObj *altrenderer = MS_IMAGE_RENDERER(image_draw); rasterBufferObj rb; int i; - memset(&rb,0,sizeof(rasterBufferObj)); + memset(&rb, 0, sizeof(rasterBufferObj)); - altrenderer->endLayer(image_draw,map,layer); + altrenderer->endLayer(image_draw, map, layer); - retcode = altrenderer->getRasterBufferHandle(image_draw,&rb); - if(MS_UNLIKELY(retcode == MS_FAILURE)) { + retcode = altrenderer->getRasterBufferHandle(image_draw, &rb); + if (MS_UNLIKELY(retcode == MS_FAILURE)) { goto altformat_cleanup; } - retcode = renderer->mergeRasterBuffer(image,&rb,((layer->compositer)?(layer->compositer->opacity*0.01):(1.0)),0,0,0,0,rb.width,rb.height); - if(MS_UNLIKELY(retcode == MS_FAILURE)) { + retcode = renderer->mergeRasterBuffer( + image, &rb, + ((layer->compositer) ? (layer->compositer->opacity * 0.01) : (1.0)), 0, + 0, 0, 0, rb.width, rb.height); + if (MS_UNLIKELY(retcode == MS_FAILURE)) { goto altformat_cleanup; } -altformat_cleanup: + altformat_cleanup: /* - * hack to work around bug #3834: if we have use an alternate renderer, the symbolset may contain - * symbols that reference it. We want to remove those references before the altFormat is destroyed - * to avoid a segfault and/or a leak, and so the the main renderer doesn't pick the cache up thinking + * hack to work around bug #3834: if we have use an alternate renderer, the + * symbolset may contain symbols that reference it. We want to remove those + * references before the altFormat is destroyed to avoid a segfault and/or a + * leak, and so the the main renderer doesn't pick the cache up thinking * it's for him. */ - for(i=0; isymbolset.numsymbols; i++) { - if (map->symbolset.symbol[i]!=NULL) { + for (i = 0; i < map->symbolset.numsymbols; i++) { + if (map->symbolset.symbol[i] != NULL) { symbolObj *s = map->symbolset.symbol[i]; - if(s->renderer == altrenderer) { + if (s->renderer == altrenderer) { altrenderer->freeSymbol(s); s->renderer = NULL; } } } msFreeImage(image_draw); - /* set the imagetype from the original outputformat back (it was removed by msSelectOutputFormat() */ + /* set the imagetype from the original outputformat back (it was removed by + * msSelectOutputFormat() */ msFree(map->imagetype); map->imagetype = msStrdup(image->format->name); - } else if( image != image_draw) { + } else if (image != image_draw) { rendererVTableObj *renderer = MS_IMAGE_RENDERER(image_draw); rasterBufferObj rb; - memset(&rb,0,sizeof(rasterBufferObj)); + memset(&rb, 0, sizeof(rasterBufferObj)); - renderer->endLayer(image_draw,map,layer); + renderer->endLayer(image_draw, map, layer); - retcode = renderer->getRasterBufferHandle(image_draw,&rb); - if(MS_UNLIKELY(retcode == MS_FAILURE)) { + retcode = renderer->getRasterBufferHandle(image_draw, &rb); + if (MS_UNLIKELY(retcode == MS_FAILURE)) { goto imagedraw_cleanup; } - if(maskLayer && maskLayer->maskimage) { + if (maskLayer && maskLayer->maskimage) { rasterBufferObj mask; - unsigned int row,col; - memset(&mask,0,sizeof(rasterBufferObj)); - retcode = MS_IMAGE_RENDERER(maskLayer->maskimage)->getRasterBufferHandle(maskLayer->maskimage,&mask); - if(MS_UNLIKELY(retcode == MS_FAILURE)) { + unsigned int row, col; + memset(&mask, 0, sizeof(rasterBufferObj)); + retcode = MS_IMAGE_RENDERER(maskLayer->maskimage) + ->getRasterBufferHandle(maskLayer->maskimage, &mask); + if (MS_UNLIKELY(retcode == MS_FAILURE)) { goto imagedraw_cleanup; } /* modify the pixels of the overlay */ - if(rb.type == MS_BUFFER_BYTE_RGBA) { - for(row=0; rowcompositer) { - /*we have a mask layer with no composition configured, do a nomral blend */ - retcode = renderer->mergeRasterBuffer(image,&rb,1.0,0,0,0,0,rb.width,rb.height); + if (!layer->compositer) { + /*we have a mask layer with no composition configured, do a nomral blend + */ + retcode = renderer->mergeRasterBuffer(image, &rb, 1.0, 0, 0, 0, 0, + rb.width, rb.height); } else { - retcode = msCompositeRasterBuffer(map,image,&rb,layer->compositer); + retcode = msCompositeRasterBuffer(map, image, &rb, layer->compositer); } - if(MS_UNLIKELY(retcode == MS_FAILURE)) { + if (MS_UNLIKELY(retcode == MS_FAILURE)) { goto imagedraw_cleanup; } -imagedraw_cleanup: + imagedraw_cleanup: msFreeImage(image_draw); } - msImageEndLayer(map,layer,image); - return(retcode); + msImageEndLayer(map, layer, image); + return (retcode); } -int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image) -{ - int status, retcode=MS_SUCCESS; - int drawmode=MS_DRAWMODE_FEATURES; - char annotate=MS_TRUE; - shapeObj shape; - shapeObj savedShape; - rectObj searchrect; - char cache=MS_FALSE; - int maxnumstyles=1; - featureListNodeObjPtr shpcache=NULL, current=NULL; +int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image) { + int status, retcode = MS_SUCCESS; + int drawmode = MS_DRAWMODE_FEATURES; + char annotate = MS_TRUE; + shapeObj shape; + shapeObj savedShape; + rectObj searchrect; + char cache = MS_FALSE; + int maxnumstyles = 1; + featureListNodeObjPtr shpcache = NULL, current = NULL; int nclasses = 0; int *classgroup = NULL; double minfeaturesize = -1; - int maxfeatures=-1; - int featuresdrawn=0; + int maxfeatures = -1; + int featuresdrawn = 0; if (image) - maxfeatures=msLayerGetMaxFeaturesToDraw(layer, image->format); + maxfeatures = msLayerGetMaxFeaturesToDraw(layer, image->format); /* TODO TBT: draw as raster layer in vector renderers */ annotate = msEvalContext(map, layer, layer->labelrequires); - if(map->scaledenom > 0) { - if((layer->labelmaxscaledenom != -1) && (map->scaledenom >= layer->labelmaxscaledenom)) annotate = MS_FALSE; - if((layer->labelminscaledenom != -1) && (map->scaledenom < layer->labelminscaledenom)) annotate = MS_FALSE; + if (map->scaledenom > 0) { + if ((layer->labelmaxscaledenom != -1) && + (map->scaledenom >= layer->labelmaxscaledenom)) + annotate = MS_FALSE; + if ((layer->labelminscaledenom != -1) && + (map->scaledenom < layer->labelminscaledenom)) + annotate = MS_FALSE; } /* open this layer */ status = msLayerOpen(layer); - if(status != MS_SUCCESS) return MS_FAILURE; + if (status != MS_SUCCESS) + return MS_FAILURE; /* build item list. STYLEITEM javascript needs the shape attributes */ - if (layer->styleitem && (strncasecmp(layer->styleitem, "javascript://", 13) == 0)) { + if (layer->styleitem && + (strncasecmp(layer->styleitem, "javascript://", 13) == 0)) { status = msLayerWhichItems(layer, MS_TRUE, NULL); } else { status = msLayerWhichItems(layer, MS_FALSE, NULL); } - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { msLayerClose(layer); return MS_FAILURE; } /* identify target shapes */ - if(layer->transform == MS_TRUE) { + if (layer->transform == MS_TRUE) { searchrect = map->extent; - if((map->projection.numargs > 0) && (layer->projection.numargs > 0)) { + if ((map->projection.numargs > 0) && (layer->projection.numargs > 0)) { int bDone = MS_FALSE; - if( layer->connectiontype == MS_UVRASTER ) - { - /* Nasty hack to make msUVRASTERLayerWhichShapes() aware that the */ - /* original area of interest is (map->extent, map->projection)... */ - /* Useful when dealin with UVRASTER that extend beyond 180 deg */ - msUVRASTERLayerUseMapExtentAndProjectionForNextWhichShapes( layer, map ); + if (layer->connectiontype == MS_UVRASTER) { + /* Nasty hack to make msUVRASTERLayerWhichShapes() aware that the */ + /* original area of interest is (map->extent, map->projection)... */ + /* Useful when dealin with UVRASTER that extend beyond 180 deg */ + msUVRASTERLayerUseMapExtentAndProjectionForNextWhichShapes(layer, map); - searchrect = msUVRASTERGetSearchRect( layer, map ); - bDone = MS_TRUE; + searchrect = msUVRASTERGetSearchRect(layer, map); + bDone = MS_TRUE; } - if( !bDone ) - msProjectRect(&map->projection, &layer->projection, &searchrect); /* project the searchrect to source coords */ + if (!bDone) + msProjectRect( + &map->projection, &layer->projection, + &searchrect); /* project the searchrect to source coords */ } } else { searchrect.minx = searchrect.miny = 0; - searchrect.maxx = map->width-1; - searchrect.maxy = map->height-1; + searchrect.maxx = map->width - 1; + searchrect.maxy = map->height - 1; } status = msLayerWhichShapes(layer, searchrect, MS_FALSE); - if( layer->connectiontype == MS_UVRASTER ) - { - msUVRASTERLayerUseMapExtentAndProjectionForNextWhichShapes( layer, NULL ); + if (layer->connectiontype == MS_UVRASTER) { + msUVRASTERLayerUseMapExtentAndProjectionForNextWhichShapes(layer, NULL); } - if(status == MS_DONE) { /* no overlap */ + if (status == MS_DONE) { /* no overlap */ msLayerClose(layer); return MS_SUCCESS; - } else if(status != MS_SUCCESS) { + } else if (status != MS_SUCCESS) { msLayerClose(layer); return MS_FAILURE; } nclasses = 0; classgroup = NULL; - if(layer->classgroup && layer->numclasses > 0) + if (layer->classgroup && layer->numclasses > 0) classgroup = msAllocateValidClassGroups(layer, &nclasses); - if(layer->minfeaturesize > 0) + if (layer->minfeaturesize > 0) minfeaturesize = Pix2LayerGeoref(map, layer, layer->minfeaturesize); // Select how to render classes // MS_FIRST_MATCHING_CLASS: Default and historic MapServer behavior // MS_ALL_MATCHING_CLASSES: SLD behavior int ref_rendermode; - const char * rendermodestr = msLayerGetProcessingKey(layer, "RENDERMODE"); - if (layer->rendermode == MS_ALL_MATCHING_CLASSES) - { + const char *rendermodestr = msLayerGetProcessingKey(layer, "RENDERMODE"); + if (layer->rendermode == MS_ALL_MATCHING_CLASSES) { // SLD takes precedence ref_rendermode = MS_ALL_MATCHING_CLASSES; - } - else if (!rendermodestr) - { + } else if (!rendermodestr) { // Default Mapfile ref_rendermode = MS_FIRST_MATCHING_CLASS; - } - else if (!strcmp(rendermodestr,"FIRST_MATCHING_CLASS")) - { + } else if (!strcmp(rendermodestr, "FIRST_MATCHING_CLASS")) { // Explicit default Mapfile ref_rendermode = MS_FIRST_MATCHING_CLASS; - } - else if (!strcmp(rendermodestr,"ALL_MATCHING_CLASSES")) - { + } else if (!strcmp(rendermodestr, "ALL_MATCHING_CLASSES")) { // SLD-like Mapfile ref_rendermode = MS_ALL_MATCHING_CLASSES; - } - else - { + } else { msLayerClose(layer); msSetError(MS_MISCERR, - "Unknown RENDERMODE: %s, should be one of: FIRST_MATCHING_CLASS, ALL_MATCHING_CLASSES.", - "msDrawVectorLayer()", - rendermodestr); + "Unknown RENDERMODE: %s, should be one of: " + "FIRST_MATCHING_CLASS, ALL_MATCHING_CLASSES.", + "msDrawVectorLayer()", rendermodestr); return MS_FAILURE; } @@ -1118,63 +1208,78 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image) } /* Check if the shape size is ok to be drawn */ - if((shape.type == MS_SHAPE_LINE || shape.type == MS_SHAPE_POLYGON) && (minfeaturesize > 0) && (msShapeCheckSize(&shape, minfeaturesize) == MS_FALSE)) { - if(layer->debug >= MS_DEBUGLEVEL_V) - msDebug("msDrawVectorLayer(): Skipping shape (%ld) because LAYER::MINFEATURESIZE is bigger than shape size\n", shape.index); + if ((shape.type == MS_SHAPE_LINE || shape.type == MS_SHAPE_POLYGON) && + (minfeaturesize > 0) && + (msShapeCheckSize(&shape, minfeaturesize) == MS_FALSE)) { + if (layer->debug >= MS_DEBUGLEVEL_V) + msDebug("msDrawVectorLayer(): Skipping shape (%ld) because " + "LAYER::MINFEATURESIZE is bigger than shape size\n", + shape.index); continue; } classcount = 0; } - classindex = msShapeGetNextClass(classindex, layer, map, &shape, classgroup, nclasses); - if((classindex == -1) || (layer->class[classindex]->status == MS_OFF)) { + classindex = msShapeGetNextClass(classindex, layer, map, &shape, classgroup, + nclasses); + if ((classindex == -1) || (layer->class[classindex] -> status == MS_OFF)) { continue; } shape.classindex = classindex; - // When only one class is applicable, rendering mode is forced to its default, - // i.e. only the first applicable class is actually applied. As a consequence, - // cache can be enabled when relevant. + // When only one class is applicable, rendering mode is forced to its + // default, i.e. only the first applicable class is actually applied. As a + // consequence, cache can be enabled when relevant. classcount++; rendermode = ref_rendermode; - if ((classcount == 1) && (msShapeGetNextClass(classindex, layer, map, &shape, classgroup, nclasses) == -1)) - { + if ((classcount == 1) && + (msShapeGetNextClass(classindex, layer, map, &shape, classgroup, + nclasses) == -1)) { rendermode = MS_FIRST_MATCHING_CLASS; } - if (rendermode == MS_FIRST_MATCHING_CLASS) - { + if (rendermode == MS_FIRST_MATCHING_CLASS) { classindex = -1; } - if(maxfeatures >=0 && featuresdrawn >= maxfeatures) { + if (maxfeatures >= 0 && featuresdrawn >= maxfeatures) { status = MS_DONE; break; } featuresdrawn++; cache = MS_FALSE; - if(layer->type == MS_LAYER_LINE && (layer->class[shape.classindex]->numstyles > 1 || (layer->class[shape.classindex]->numstyles == 1 && layer->class[shape.classindex]->styles[0]->outlinewidth > 0))) { + if (layer->type == MS_LAYER_LINE && + (layer->class[shape.classindex] + -> numstyles > 1 || + (layer->class[shape.classindex] -> numstyles == 1 && layer + -> class[shape.classindex] -> styles[0] -> outlinewidth > + 0))) { int i; - cache = MS_TRUE; /* only line layers with multiple styles need be cached (I don't think POLYLINE layers need caching - SDL) */ - - /* we can't handle caching with attribute binding other than for the first style (#3976) */ - for(i=1; iclass[shape.classindex]->numstyles; i++) { - if(layer->class[shape.classindex]->styles[i]->numbindings > 0) cache = MS_FALSE; + cache = MS_TRUE; /* only line layers with multiple styles need be cached + (I don't think POLYLINE layers need caching - SDL) */ + + /* we can't handle caching with attribute binding other than for the first + * style (#3976) */ + for (i = 1; i < layer->class[shape.classindex] -> numstyles; i++) { + if (layer->class[shape.classindex] -> styles[i] -> numbindings > 0) + cache = MS_FALSE; } } /* With 'STYLEITEM AUTO', we will have the datasource fill the class' */ /* style parameters for this shape. */ - if(layer->styleitem) { - if(strcasecmp(layer->styleitem, "AUTO") == 0) { - if(msLayerGetAutoStyle(map, layer, layer->class[shape.classindex], &shape) != MS_SUCCESS) { + if (layer->styleitem) { + if (strcasecmp(layer->styleitem, "AUTO") == 0) { + if (msLayerGetAutoStyle(map, layer, layer->class[shape.classindex], + &shape) != MS_SUCCESS) { retcode = MS_FAILURE; break; } } else { /* Generic feature style handling as per RFC-61 */ - if(msLayerGetFeatureStyle(map, layer, layer->class[shape.classindex], &shape) != MS_SUCCESS) { + if (msLayerGetFeatureStyle(map, layer, layer->class[shape.classindex], + &shape) != MS_SUCCESS) { retcode = MS_FAILURE; break; } @@ -1184,31 +1289,31 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image) cache = MS_FALSE; } - if (rendermode == MS_ALL_MATCHING_CLASSES) - { + if (rendermode == MS_ALL_MATCHING_CLASSES) { // Cache is designed to handle only one class. Therefore it is // disabled when using SLD "painters model" rendering mode. cache = MS_FALSE; } - /* RFC77 TODO: check return value, may need a more sophisticated if-then test. */ - if(annotate && layer->class[shape.classindex]->numlabels > 0) { + /* RFC77 TODO: check return value, may need a more sophisticated if-then + * test. */ + if (annotate && layer->class[shape.classindex] -> numlabels > 0) { drawmode |= MS_DRAWMODE_LABELS; if (msLayerGetProcessingKey(layer, "LABEL_NO_CLIP")) { drawmode |= MS_DRAWMODE_UNCLIPPEDLABELS; } } - if (layer->type == MS_LAYER_LINE && msLayerGetProcessingKey(layer, "POLYLINE_NO_CLIP")) { + if (layer->type == MS_LAYER_LINE && + msLayerGetProcessingKey(layer, "POLYLINE_NO_CLIP")) { drawmode |= MS_DRAWMODE_UNCLIPPEDLINES; } - if (rendermode == MS_ALL_MATCHING_CLASSES) - { - // In SLD "painters model" rendering mode, all applicable classes are actually applied. - // Coordinates stored in the shape must keep their original values for - // the shape to be drawn multiple times. - // Here the original shape is saved. + if (rendermode == MS_ALL_MATCHING_CLASSES) { + // In SLD "painters model" rendering mode, all applicable classes are + // actually applied. Coordinates stored in the shape must keep their + // original values for the shape to be drawn multiple times. Here the + // original shape is saved. msInitShape(&savedShape); msCopyShape(&shape, &savedShape); } @@ -1224,86 +1329,95 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image) * - draw the shape (the outline) in the first pass of the * caching mechanism */ - msOutlineRenderingPrepareStyle(pStyle, map, layer, image); + msOutlineRenderingPrepareStyle(pStyle, map, layer, image); } - status = msDrawShape(map, layer, &shape, image, 0, drawmode|MS_DRAWMODE_SINGLESTYLE); /* draw a single style */ + status = msDrawShape( + map, layer, &shape, image, 0, + drawmode | MS_DRAWMODE_SINGLESTYLE); /* draw a single style */ if (pStyle->outlinewidth > 0) { /* * RFC 49 implementation: switch back the styleobj to its * original state, so the line fill will be drawn in the * second pass of the caching mechanism */ - msOutlineRenderingRestoreStyle(pStyle, map, layer, image); + msOutlineRenderingRestoreStyle(pStyle, map, layer, image); } } else - status = msDrawShape(map, layer, &shape, image, -1, drawmode); /* all styles */ - - if (rendermode == MS_ALL_MATCHING_CLASSES) - { - // In SLD "painters model" rendering mode, all applicable classes are actually applied. - // Coordinates stored in the shape must keep their original values for - // the shape to be drawn multiple times. - // Here the original shape is restored. + status = + msDrawShape(map, layer, &shape, image, -1, drawmode); /* all styles */ + + if (rendermode == MS_ALL_MATCHING_CLASSES) { + // In SLD "painters model" rendering mode, all applicable classes are + // actually applied. Coordinates stored in the shape must keep their + // original values for the shape to be drawn multiple times. Here the + // original shape is restored. msFreeShape(&shape); msCopyShape(&savedShape, &shape); msFreeShape(&savedShape); } - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { retcode = MS_FAILURE; break; } - - if(shape.numlines == 0) { /* once clipped the shape didn't need to be drawn */ + + if (shape.numlines == + 0) { /* once clipped the shape didn't need to be drawn */ continue; } - if(cache) { - if(insertFeatureList(&shpcache, &shape) == NULL) { + if (cache) { + if (insertFeatureList(&shpcache, &shape) == NULL) { retcode = MS_FAILURE; /* problem adding to the cache */ break; } } - maxnumstyles = MS_MAX(maxnumstyles, layer->class[shape.classindex]->numstyles); - + maxnumstyles = + MS_MAX(maxnumstyles, layer->class[shape.classindex] -> numstyles); } msFreeShape(&shape); if (classgroup) msFree(classgroup); - if(status != MS_DONE || retcode == MS_FAILURE) { + if (status != MS_DONE || retcode == MS_FAILURE) { msLayerClose(layer); - if(shpcache) { + if (shpcache) { freeFeatureList(shpcache); shpcache = NULL; } return MS_FAILURE; } - if(shpcache && MS_DRAW_FEATURES(drawmode)) { + if (shpcache && MS_DRAW_FEATURES(drawmode)) { int s; - for(s=0; snext) { - if(layer->class[current->shape.classindex]->numstyles > s) { + for (s = 0; s < maxnumstyles; s++) { + for (current = shpcache; current; current = current->next) { + if (layer->class[current->shape.classindex] -> numstyles > s) { styleObj *pStyle = layer->class[current->shape.classindex]->styles[s]; - if(pStyle->_geomtransform.type != MS_GEOMTRANSFORM_NONE) + if (pStyle->_geomtransform.type != MS_GEOMTRANSFORM_NONE) continue; /*skip this as it has already been rendered*/ - if(map->scaledenom > 0) { - if((pStyle->maxscaledenom != -1) && (map->scaledenom >= pStyle->maxscaledenom)) + if (map->scaledenom > 0) { + if ((pStyle->maxscaledenom != -1) && + (map->scaledenom >= pStyle->maxscaledenom)) continue; - if((pStyle->minscaledenom != -1) && (map->scaledenom < pStyle->minscaledenom)) + if ((pStyle->minscaledenom != -1) && + (map->scaledenom < pStyle->minscaledenom)) continue; } - if(s==0 && pStyle->outlinewidth>0 && MS_VALID_COLOR(pStyle->color)) { - if(MS_UNLIKELY(MS_FAILURE == msDrawLineSymbol(map, image, ¤t->shape, pStyle, pStyle->scalefactor))) { + if (s == 0 && pStyle->outlinewidth > 0 && + MS_VALID_COLOR(pStyle->color)) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawLineSymbol(map, image, ¤t->shape, + pStyle, pStyle->scalefactor))) { return MS_FAILURE; } - } else if(s>0) { - if (pStyle->outlinewidth > 0 && MS_VALID_COLOR(pStyle->outlinecolor)) { + } else if (s > 0) { + if (pStyle->outlinewidth > 0 && + MS_VALID_COLOR(pStyle->outlinecolor)) { /* * RFC 49 implementation * if an outlinewidth is used: @@ -1312,8 +1426,10 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image) * - draw the shape (the outline) in the first pass of the * caching mechanism */ - msOutlineRenderingPrepareStyle(pStyle, map, layer, image); - if(MS_UNLIKELY(MS_FAILURE == msDrawLineSymbol(map, image, ¤t->shape, pStyle, pStyle->scalefactor))) { + msOutlineRenderingPrepareStyle(pStyle, map, layer, image); + if (MS_UNLIKELY(MS_FAILURE == + msDrawLineSymbol(map, image, ¤t->shape, + pStyle, pStyle->scalefactor))) { return MS_FAILURE; } /* @@ -1321,19 +1437,19 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image) * original state, so the line fill will be drawn in the * second pass of the caching mechanism */ - msOutlineRenderingRestoreStyle(pStyle, map, layer, image); + msOutlineRenderingRestoreStyle(pStyle, map, layer, image); } - /* draw a valid line, i.e. one with a color defined or of type pixmap*/ - if(MS_VALID_COLOR(pStyle->color) || - ( - pStyle->symbolsymbolset.numsymbols && - ( - map->symbolset.symbol[pStyle->symbol]->type == MS_SYMBOL_PIXMAP || - map->symbolset.symbol[pStyle->symbol]->type == MS_SYMBOL_SVG - ) - ) - ) { - if(MS_UNLIKELY(MS_FAILURE == msDrawLineSymbol(map, image, ¤t->shape, pStyle, pStyle->scalefactor))) + /* draw a valid line, i.e. one with a color defined or of type + * pixmap*/ + if (MS_VALID_COLOR(pStyle->color) || + (pStyle->symbol < map->symbolset.numsymbols && + (map->symbolset.symbol[pStyle->symbol]->type == + MS_SYMBOL_PIXMAP || + map->symbolset.symbol[pStyle->symbol]->type == + MS_SYMBOL_SVG))) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawLineSymbol(map, image, ¤t->shape, + pStyle, pStyle->scalefactor))) return MS_FAILURE; } } @@ -1347,52 +1463,60 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image) msLayerClose(layer); return MS_SUCCESS; - } /* -** Function to draw a layer IF it already has a result cache associated with it. Called by msDrawMap and via MapScript. +** Function to draw a layer IF it already has a result cache associated with it. +*Called by msDrawMap and via MapScript. */ -int msDrawQueryLayer(mapObj *map, layerObj *layer, imageObj *image) -{ +int msDrawQueryLayer(mapObj *map, layerObj *layer, imageObj *image) { int i, status; - char annotate=MS_TRUE, cache=MS_FALSE; + char annotate = MS_TRUE, cache = MS_FALSE; int drawmode = MS_DRAWMODE_FEATURES; shapeObj shape; - int maxnumstyles=1; + int maxnumstyles = 1; - featureListNodeObjPtr shpcache=NULL, current=NULL; + featureListNodeObjPtr shpcache = NULL, current = NULL; colorObj *colorbuffer = NULL; int *mindistancebuffer = NULL; - if(!layer->resultcache) return(msDrawLayer(map, layer, image)); + if (!layer->resultcache) + return (msDrawLayer(map, layer, image)); - if(!msLayerIsVisible(map, layer)) return(MS_SUCCESS); /* not an error, just nothing to do */ + if (!msLayerIsVisible(map, layer)) + return (MS_SUCCESS); /* not an error, just nothing to do */ /* conditions may have changed since this layer last drawn, so reset layer->project to recheck projection needs (Bug #673) */ - layer->project = msProjectionsDiffer(&(layer->projection),&(map->projection)); + layer->project = + msProjectionsDiffer(&(layer->projection), &(map->projection)); /* set annotation status */ annotate = msEvalContext(map, layer, layer->labelrequires); - if(map->scaledenom > 0) { - if((layer->labelmaxscaledenom != -1) && (map->scaledenom >= layer->labelmaxscaledenom)) annotate = MS_FALSE; - if((layer->labelminscaledenom != -1) && (map->scaledenom < layer->labelminscaledenom)) annotate = MS_FALSE; + if (map->scaledenom > 0) { + if ((layer->labelmaxscaledenom != -1) && + (map->scaledenom >= layer->labelmaxscaledenom)) + annotate = MS_FALSE; + if ((layer->labelminscaledenom != -1) && + (map->scaledenom < layer->labelminscaledenom)) + annotate = MS_FALSE; } /* - ** Certain query map styles require us to render all features only (MS_NORMAL) or first (MS_HILITE). With - ** single-pass queries we have to make a copy of the layer and work from it instead. + ** Certain query map styles require us to render all features only (MS_NORMAL) + *or first (MS_HILITE). With + ** single-pass queries we have to make a copy of the layer and work from it + *instead. */ - if(map->querymap.style == MS_NORMAL || map->querymap.style == MS_HILITE) { + if (map->querymap.style == MS_NORMAL || map->querymap.style == MS_HILITE) { layerObj tmp_layer; - if(initLayer(&tmp_layer, map) == -1) - return(MS_FAILURE); + if (initLayer(&tmp_layer, map) == -1) + return (MS_FAILURE); if (msCopyLayer(&tmp_layer, layer) != MS_SUCCESS) - return(MS_FAILURE); + return (MS_FAILURE); /* disable the connection pool for this layer */ msLayerSetProcessingKey(&tmp_layer, "CLOSE_CONNECTION", "ALWAYS"); @@ -1401,72 +1525,113 @@ int msDrawQueryLayer(mapObj *map, layerObj *layer, imageObj *image) freeLayer(&tmp_layer); - if(map->querymap.style == MS_NORMAL || status != MS_SUCCESS) return(status); + if (map->querymap.style == MS_NORMAL || status != MS_SUCCESS) + return (status); } - /* if MS_HILITE, alter the one style (always at least 1 style), and set a MINDISTANCE for the labelObj to avoid duplicates */ - if(map->querymap.style == MS_HILITE) { + /* if MS_HILITE, alter the one style (always at least 1 style), and set a + * MINDISTANCE for the labelObj to avoid duplicates */ + if (map->querymap.style == MS_HILITE) { drawmode |= MS_DRAWMODE_QUERY; if (layer->numclasses > 0) { - colorbuffer = (colorObj*)msSmallMalloc(layer->numclasses*sizeof(colorObj)); - mindistancebuffer = (int*)msSmallMalloc(layer->numclasses*sizeof(int)); + colorbuffer = + (colorObj *)msSmallMalloc(layer->numclasses * sizeof(colorObj)); + mindistancebuffer = (int *)msSmallMalloc(layer->numclasses * sizeof(int)); } - for(i=0; inumclasses; i++) { - if(layer->type == MS_LAYER_POLYGON && layer->class[i]->numstyles > 0) { /* alter BOTTOM style since that's almost always the fill */ - if (layer->class[i]->styles == NULL) { - msSetError(MS_MISCERR, "Don't know how to draw class %s of layer %s without a style definition.", "msDrawQueryLayer()", layer->class[i]->name, layer->name); + for (i = 0; i < layer->numclasses; i++) { + if (layer->type == MS_LAYER_POLYGON && + layer->class[i] -> numstyles > + 0) { /* alter BOTTOM style since that's + almost always the fill */ + if (layer->class[i] -> styles == NULL) { + msSetError(MS_MISCERR, + "Don't know how to draw class %s of layer %s without a " + "style definition.", + "msDrawQueryLayer()", layer->class[i] -> name, + layer -> name); msFree(colorbuffer); msFree(mindistancebuffer); - return(MS_FAILURE); + return (MS_FAILURE); } - if(MS_VALID_COLOR(layer->class[i]->styles[0]->color)) { - colorbuffer[i] = layer->class[i]->styles[0]->color; /* save the color from the BOTTOM style */ + if (MS_VALID_COLOR(layer->class[i] -> styles[0] -> color)) { + colorbuffer[i] = + layer->class[i] + ->styles[0] + ->color; /* save the color from the BOTTOM style */ layer->class[i]->styles[0]->color = map->querymap.color; - } else if(MS_VALID_COLOR(layer->class[i]->styles[0]->outlinecolor)) { - colorbuffer[i] = layer->class[i]->styles[0]->outlinecolor; /* if no color, save the outlinecolor from the BOTTOM style */ + } else if (MS_VALID_COLOR( + layer->class[i] -> styles[0] -> outlinecolor)) { + colorbuffer[i] = + layer->class[i] + ->styles[0] + ->outlinecolor; /* if no color, save the outlinecolor from the + BOTTOM style */ layer->class[i]->styles[0]->outlinecolor = map->querymap.color; } - } else if (layer->type == MS_LAYER_LINE && layer->class[i]->numstyles > 0 && layer->class[i]->styles[0]->outlinewidth > 0) { /* alter BOTTOM style for lines with outlines */ - if(MS_VALID_COLOR(layer->class[i]->styles[0]->color)) { - colorbuffer[i] = layer->class[i]->styles[0]->color; /* save the color from the BOTTOM style */ + } else if (layer->type == MS_LAYER_LINE && + layer->class[i] -> numstyles > 0 && + layer -> class[i] -> styles[0] + -> outlinewidth > + 0) { /* alter BOTTOM style for lines with outlines */ + if (MS_VALID_COLOR(layer->class[i] -> styles[0] -> color)) { + colorbuffer[i] = + layer->class[i] + ->styles[0] + ->color; /* save the color from the BOTTOM style */ layer->class[i]->styles[0]->color = map->querymap.color; } /* else ??? */ - } else if (layer->class[i]->numstyles > 0) { - if(MS_VALID_COLOR(layer->class[i]->styles[layer->class[i]->numstyles-1]->color)) { - colorbuffer[i] = layer->class[i]->styles[layer->class[i]->numstyles-1]->color; /* save the color from the TOP style */ - layer->class[i]->styles[layer->class[i]->numstyles-1]->color = map->querymap.color; - } else if(MS_VALID_COLOR(layer->class[i]->styles[layer->class[i]->numstyles-1]->outlinecolor)) { - colorbuffer[i] = layer->class[i]->styles[layer->class[i]->numstyles-1]->outlinecolor; /* if no color, save the outlinecolor from the TOP style */ - layer->class[i]->styles[layer->class[i]->numstyles-1]->outlinecolor = map->querymap.color; + } else if (layer->class[i] -> numstyles > 0) { + if (MS_VALID_COLOR( + layer->class[i] -> styles[layer->class[i] -> numstyles - 1] + -> color)) { + colorbuffer[i] = layer->class[i] + ->styles[layer->class[i] -> numstyles - 1] + ->color; /* save the color from the TOP style */ + layer->class[i]->styles[layer->class[i] -> numstyles - 1]->color = + map->querymap.color; + } else if (MS_VALID_COLOR(layer->class[i] + -> styles[layer->class[i] -> numstyles - 1] + -> outlinecolor)) { + colorbuffer[i] = + layer->class[i] + ->styles[layer->class[i] -> numstyles - 1] + ->outlinecolor; /* if no color, save the outlinecolor from the + TOP style */ + layer->class[i] + ->styles[layer->class[i] -> numstyles - 1] + ->outlinecolor = map->querymap.color; } - } else if (layer->class[i]->numlabels > 0) { - colorbuffer[i] = layer->class[i]->labels[0]->color; - layer->class[i]->labels[0]->color = map->querymap.color; + } else if (layer->class[i] -> numlabels > 0) { + colorbuffer[i] = layer->class[i]->labels[0]->color; + layer->class[i]->labels[0]->color = map->querymap.color; } /* else ??? */ - mindistancebuffer[i] = -1; /* RFC77 TODO: only using the first label, is that cool? */ - if(layer->class[i]->numlabels > 0) { + mindistancebuffer[i] = + -1; /* RFC77 TODO: only using the first label, is that cool? */ + if (layer->class[i] -> numlabels > 0) { mindistancebuffer[i] = layer->class[i]->labels[0]->mindistance; - layer->class[i]->labels[0]->mindistance = MS_MAX(0, layer->class[i]->labels[0]->mindistance); + layer->class[i]->labels[0]->mindistance = + MS_MAX(0, layer->class[i] -> labels[0] -> mindistance); } } } /* - ** Layer was opened as part of the query process, msLayerWhichItems() has also been run, shapes have been classified - start processing! + ** Layer was opened as part of the query process, msLayerWhichItems() has also + *been run, shapes have been classified - start processing! */ msInitShape(&shape); - for(i=0; iresultcache->numresults; i++) { + for (i = 0; i < layer->resultcache->numresults; i++) { status = msLayerGetShape(layer, &shape, &(layer->resultcache->results[i])); - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { msFree(colorbuffer); msFree(mindistancebuffer); - return(MS_FAILURE); + return (MS_FAILURE); } shape.classindex = layer->resultcache->results[i].classindex; @@ -1477,89 +1642,119 @@ int msDrawQueryLayer(mapObj *map, layerObj *layer, imageObj *image) * FrankW: classindex is also sometimes 0 even if there are no classes, so * we are careful not to use out of range class values as an index. */ - if(shape.classindex==-1 - || shape.classindex >= layer->numclasses - || layer->class[shape.classindex]->status == MS_OFF) { + if (shape.classindex == -1 || shape.classindex >= layer->numclasses || + layer->class[shape.classindex] -> status == MS_OFF) { msFreeShape(&shape); continue; } cache = MS_FALSE; - if(layer->type == MS_LAYER_LINE && (layer->class[shape.classindex]->numstyles > 1 || (layer->class[shape.classindex]->numstyles == 1 && layer->class[shape.classindex]->styles[0]->outlinewidth > 0))) { + if (layer->type == MS_LAYER_LINE && + (layer->class[shape.classindex] + -> numstyles > 1 || + (layer->class[shape.classindex] -> numstyles == 1 && layer + -> class[shape.classindex] -> styles[0] -> outlinewidth > + 0))) { int i; - cache = MS_TRUE; /* only line layers with multiple styles need be cached (I don't think POLYLINE layers need caching - SDL) */ - - /* we can't handle caching with attribute binding other than for the first style (#3976) */ - for(i=1; iclass[shape.classindex]->numstyles; i++) { - if(layer->class[shape.classindex]->styles[i]->numbindings > 0) cache = MS_FALSE; + cache = MS_TRUE; /* only line layers with multiple styles need be cached + (I don't think POLYLINE layers need caching - SDL) */ + + /* we can't handle caching with attribute binding other than for the first + * style (#3976) */ + for (i = 1; i < layer->class[shape.classindex] -> numstyles; i++) { + if (layer->class[shape.classindex] -> styles[i] -> numbindings > 0) + cache = MS_FALSE; } } - if(annotate && layer->class[shape.classindex]->numlabels > 0) { + if (annotate && layer->class[shape.classindex] -> numlabels > 0) { drawmode |= MS_DRAWMODE_LABELS; } - if(cache) { + if (cache) { styleObj *pStyle = layer->class[shape.classindex]->styles[0]; - if (pStyle->outlinewidth > 0) msOutlineRenderingPrepareStyle(pStyle, map, layer, image); - status = msDrawShape(map, layer, &shape, image, 0, drawmode|MS_DRAWMODE_SINGLESTYLE); /* draw only the first style */ - if (pStyle->outlinewidth > 0) msOutlineRenderingRestoreStyle(pStyle, map, layer, image); + if (pStyle->outlinewidth > 0) + msOutlineRenderingPrepareStyle(pStyle, map, layer, image); + status = msDrawShape( + map, layer, &shape, image, 0, + drawmode | MS_DRAWMODE_SINGLESTYLE); /* draw only the first style */ + if (pStyle->outlinewidth > 0) + msOutlineRenderingRestoreStyle(pStyle, map, layer, image); } else { - status = msDrawShape(map, layer, &shape, image, -1, drawmode); /* all styles */ + status = + msDrawShape(map, layer, &shape, image, -1, drawmode); /* all styles */ } - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { msLayerClose(layer); msFree(colorbuffer); msFree(mindistancebuffer); - return(MS_FAILURE); + return (MS_FAILURE); } - if(shape.numlines == 0) { /* once clipped the shape didn't need to be drawn */ + if (shape.numlines == + 0) { /* once clipped the shape didn't need to be drawn */ msFreeShape(&shape); continue; } - if(cache) { - if(insertFeatureList(&shpcache, &shape) == NULL) { + if (cache) { + if (insertFeatureList(&shpcache, &shape) == NULL) { msFree(colorbuffer); msFree(mindistancebuffer); - return(MS_FAILURE); /* problem adding to the cache */ + return (MS_FAILURE); /* problem adding to the cache */ } } - maxnumstyles = MS_MAX(maxnumstyles, layer->class[shape.classindex]->numstyles); + maxnumstyles = + MS_MAX(maxnumstyles, layer->class[shape.classindex] -> numstyles); msFreeShape(&shape); } - if(shpcache) { + if (shpcache) { int s; - for(s=0; snext) { - if(layer->class[current->shape.classindex]->numstyles > s) { + for (s = 0; s < maxnumstyles; s++) { + for (current = shpcache; current; current = current->next) { + if (layer->class[current->shape.classindex] -> numstyles > s) { styleObj *pStyle = layer->class[current->shape.classindex]->styles[s]; - if(pStyle->_geomtransform.type != MS_GEOMTRANSFORM_NONE) + if (pStyle->_geomtransform.type != MS_GEOMTRANSFORM_NONE) continue; /* skip this as it has already been rendered */ - if(map->scaledenom > 0) { - if((pStyle->maxscaledenom != -1) && (map->scaledenom >= pStyle->maxscaledenom)) + if (map->scaledenom > 0) { + if ((pStyle->maxscaledenom != -1) && + (map->scaledenom >= pStyle->maxscaledenom)) continue; - if((pStyle->minscaledenom != -1) && (map->scaledenom < pStyle->minscaledenom)) + if ((pStyle->minscaledenom != -1) && + (map->scaledenom < pStyle->minscaledenom)) continue; } - if(s==0 && pStyle->outlinewidth>0 && MS_VALID_COLOR(pStyle->color)) { - if(MS_UNLIKELY(MS_FAILURE == msDrawLineSymbol(map, image, ¤t->shape, pStyle, pStyle->scalefactor))) { + if (s == 0 && pStyle->outlinewidth > 0 && + MS_VALID_COLOR(pStyle->color)) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawLineSymbol(map, image, ¤t->shape, + pStyle, pStyle->scalefactor))) { return MS_FAILURE; } - } else if(s>0) { - if (pStyle->outlinewidth > 0 && MS_VALID_COLOR(pStyle->outlinecolor)) { + } else if (s > 0) { + if (pStyle->outlinewidth > 0 && + MS_VALID_COLOR(pStyle->outlinecolor)) { msOutlineRenderingPrepareStyle(pStyle, map, layer, image); - if(MS_UNLIKELY(MS_FAILURE == msDrawLineSymbol(map, image, ¤t->shape, pStyle, pStyle->scalefactor))) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawLineSymbol(map, image, ¤t->shape, + pStyle, pStyle->scalefactor))) { return MS_FAILURE; } msOutlineRenderingRestoreStyle(pStyle, map, layer, image); } - /* draw a valid line, i.e. one with a color defined or of type pixmap */ - if(MS_VALID_COLOR(pStyle->color) || (pStyle->symbolsymbolset.numsymbols && (map->symbolset.symbol[pStyle->symbol]->type == MS_SYMBOL_PIXMAP || map->symbolset.symbol[pStyle->symbol]->type == MS_SYMBOL_SVG))) { - if(MS_UNLIKELY(MS_FAILURE == msDrawLineSymbol(map, image, ¤t->shape, pStyle, pStyle->scalefactor))) + /* draw a valid line, i.e. one with a color defined or of type + * pixmap */ + if (MS_VALID_COLOR(pStyle->color) || + (pStyle->symbol < map->symbolset.numsymbols && + (map->symbolset.symbol[pStyle->symbol]->type == + MS_SYMBOL_PIXMAP || + map->symbolset.symbol[pStyle->symbol]->type == + MS_SYMBOL_SVG))) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawLineSymbol(map, image, ¤t->shape, + pStyle, pStyle->scalefactor))) return MS_FAILURE; } } @@ -1572,72 +1767,99 @@ int msDrawQueryLayer(mapObj *map, layerObj *layer, imageObj *image) } /* if MS_HILITE, restore color and mindistance values */ - if(map->querymap.style == MS_HILITE) { - for(i=0; inumclasses; i++) { - if(layer->type == MS_LAYER_POLYGON && layer->class[i]->numstyles > 0) { - if(MS_VALID_COLOR(layer->class[i]->styles[0]->color)) + if (map->querymap.style == MS_HILITE) { + for (i = 0; i < layer->numclasses; i++) { + if (layer->type == MS_LAYER_POLYGON && layer->class[i] -> numstyles > 0) { + if (MS_VALID_COLOR(layer->class[i] -> styles[0] -> color)) + layer->class[i]->styles[0]->color = colorbuffer[i]; + else if (MS_VALID_COLOR(layer->class[i] -> styles[0] -> outlinecolor)) + layer->class[i]->styles[0]->outlinecolor = + colorbuffer[i]; /* if no color, restore outlinecolor for the + BOTTOM style */ + } else if (layer->type == MS_LAYER_LINE && + layer->class[i] -> numstyles > 0 && layer -> class[i] + -> styles[0] -> outlinewidth > 0) { + if (MS_VALID_COLOR(layer->class[i] -> styles[0] -> color)) layer->class[i]->styles[0]->color = colorbuffer[i]; - else if(MS_VALID_COLOR(layer->class[i]->styles[0]->outlinecolor)) - layer->class[i]->styles[0]->outlinecolor = colorbuffer[i]; /* if no color, restore outlinecolor for the BOTTOM style */ - } else if (layer->type == MS_LAYER_LINE && layer->class[i]->numstyles > 0 && layer->class[i]->styles[0]->outlinewidth > 0) { - if(MS_VALID_COLOR(layer->class[i]->styles[0]->color)) - layer->class[i]->styles[0]->color = colorbuffer[i]; - } else if (layer->class[i]->numstyles > 0) { - if(MS_VALID_COLOR(layer->class[i]->styles[layer->class[i]->numstyles-1]->color)) - layer->class[i]->styles[layer->class[i]->numstyles-1]->color = colorbuffer[i]; - else if(MS_VALID_COLOR(layer->class[i]->styles[layer->class[i]->numstyles-1]->outlinecolor)) - layer->class[i]->styles[layer->class[i]->numstyles-1]->outlinecolor = colorbuffer[i]; /* if no color, restore outlinecolor for the TOP style */ - } else if (layer->class[i]->numlabels > 0) { - if(MS_VALID_COLOR(layer->class[i]->labels[0]->color)) + } else if (layer->class[i] -> numstyles > 0) { + if (MS_VALID_COLOR( + layer->class[i] -> styles[layer->class[i] -> numstyles - 1] + -> color)) + layer->class[i]->styles[layer->class[i] -> numstyles - 1]->color = + colorbuffer[i]; + else if (MS_VALID_COLOR( + layer->class[i] -> styles[layer->class[i] -> numstyles - 1] + -> outlinecolor)) + layer->class[i] + ->styles[layer->class[i] -> numstyles - 1] + ->outlinecolor = + colorbuffer[i]; /* if no color, restore outlinecolor for the TOP + style */ + } else if (layer->class[i] -> numlabels > 0) { + if (MS_VALID_COLOR(layer->class[i] -> labels[0] -> color)) layer->class[i]->labels[0]->color = colorbuffer[i]; } - if(layer->class[i]->numlabels > 0) - layer->class[i]->labels[0]->mindistance = mindistancebuffer[i]; /* RFC77 TODO: again, only using the first label, is that cool? */ + if (layer->class[i] -> numlabels > 0) + layer->class[i]->labels[0]->mindistance = + mindistancebuffer[i]; /* RFC77 TODO: again, only using the first + label, is that cool? */ } msFree(colorbuffer); msFree(mindistancebuffer); } - return(MS_SUCCESS); + return (MS_SUCCESS); } /** * msDrawRasterLayerPlugin() */ -static int -msDrawRasterLayerPlugin( mapObj *map, layerObj *layer, imageObj *image) +static int msDrawRasterLayerPlugin(mapObj *map, layerObj *layer, + imageObj *image) { rendererVTableObj *renderer = MS_IMAGE_RENDERER(image); - rasterBufferObj *rb = msSmallCalloc(1,sizeof(rasterBufferObj)); + rasterBufferObj *rb = msSmallCalloc(1, sizeof(rasterBufferObj)); int ret; - if( renderer->supports_pixel_buffer ) { - if (MS_SUCCESS != renderer->getRasterBufferHandle( image, rb )) { - msSetError(MS_MISCERR,"renderer failed to extract raster buffer","msDrawRasterLayer()"); + if (renderer->supports_pixel_buffer) { + if (MS_SUCCESS != renderer->getRasterBufferHandle(image, rb)) { + msSetError(MS_MISCERR, "renderer failed to extract raster buffer", + "msDrawRasterLayer()"); return MS_FAILURE; } - ret = msDrawRasterLayerLow( map, layer, image, rb ); + ret = msDrawRasterLayerLow(map, layer, image, rb); } else { - if (MS_SUCCESS != renderer->initializeRasterBuffer( rb, image->width, image->height, MS_IMAGEMODE_RGBA )) { - msSetError(MS_MISCERR,"renderer failed to create raster buffer","msDrawRasterLayer()"); + if (MS_SUCCESS != renderer->initializeRasterBuffer( + rb, image->width, image->height, MS_IMAGEMODE_RGBA)) { + msSetError(MS_MISCERR, "renderer failed to create raster buffer", + "msDrawRasterLayer()"); return MS_FAILURE; } - ret = msDrawRasterLayerLow( map, layer, image, rb ); + ret = msDrawRasterLayerLow(map, layer, image, rb); - if( ret == 0 ) { - ret = renderer->mergeRasterBuffer( image, rb, 1.0, 0, 0, 0, 0, rb->width, rb->height ); + if (ret == 0) { + ret = renderer->mergeRasterBuffer(image, rb, 1.0, 0, 0, 0, 0, rb->width, + rb->height); } msFreeRasterBuffer(rb); } -#define RB_GET_R(rb,x,y) *((rb)->data.rgba.r + (x) * (rb)->data.rgba.pixel_step + (y) * (rb)->data.rgba.row_step) -#define RB_GET_G(rb,x,y) *((rb)->data.rgba.g + (x) * (rb)->data.rgba.pixel_step + (y) * (rb)->data.rgba.row_step) -#define RB_GET_B(rb,x,y) *((rb)->data.rgba.b + (x) * (rb)->data.rgba.pixel_step + (y) * (rb)->data.rgba.row_step) -#define RB_GET_A(rb,x,y) *((rb)->data.rgba.a + (x) * (rb)->data.rgba.pixel_step + (y) * (rb)->data.rgba.row_step) +#define RB_GET_R(rb, x, y) \ + *((rb)->data.rgba.r + (x) * (rb)->data.rgba.pixel_step + \ + (y) * (rb)->data.rgba.row_step) +#define RB_GET_G(rb, x, y) \ + *((rb)->data.rgba.g + (x) * (rb)->data.rgba.pixel_step + \ + (y) * (rb)->data.rgba.row_step) +#define RB_GET_B(rb, x, y) \ + *((rb)->data.rgba.b + (x) * (rb)->data.rgba.pixel_step + \ + (y) * (rb)->data.rgba.row_step) +#define RB_GET_A(rb, x, y) \ + *((rb)->data.rgba.a + (x) * (rb)->data.rgba.pixel_step + \ + (y) * (rb)->data.rgba.row_step) free(rb); @@ -1647,20 +1869,21 @@ msDrawRasterLayerPlugin( mapObj *map, layerObj *layer, imageObj *image) /** * Generic function to render raster layers. */ -int msDrawRasterLayer(mapObj *map, layerObj *layer, imageObj *image) -{ - +int msDrawRasterLayer(mapObj *map, layerObj *layer, imageObj *image) { + int rv = MS_FAILURE; if (!image || !map || !layer) { return rv; } /* RFC-86 Scale dependant token replacements*/ - rv = msLayerApplyScaletokens(layer,(layer->map)?layer->map->scaledenom:-1); - if (rv != MS_SUCCESS) return rv; - if( MS_RENDERER_PLUGIN(image->format) ) + rv = msLayerApplyScaletokens(layer, + (layer->map) ? layer->map->scaledenom : -1); + if (rv != MS_SUCCESS) + return rv; + if (MS_RENDERER_PLUGIN(image->format)) rv = msDrawRasterLayerPlugin(map, layer, image); - else if( MS_RENDERER_RAWDATA(image->format) ) + else if (MS_RENDERER_RAWDATA(image->format)) rv = msDrawRasterLayerLow(map, layer, image, NULL); msLayerRestoreFromScaletokens(layer); return rv; @@ -1675,8 +1898,7 @@ int msDrawRasterLayer(mapObj *map, layerObj *layer, imageObj *image) */ #ifdef USE_WMS_LYR -int msDrawWMSLayer(mapObj *map, layerObj *layer, imageObj *image) -{ +int msDrawWMSLayer(mapObj *map, layerObj *layer, imageObj *image) { int nStatus = MS_FAILURE; if (image && map && layer) { @@ -1688,22 +1910,19 @@ int msDrawWMSLayer(mapObj *map, layerObj *layer, imageObj *image) msHTTPInitRequestObj(asReqInfo, 2); - if ( msPrepareWMSLayerRequest(1, map, layer, 1, - 0, NULL, 0, 0, 0, NULL, - asReqInfo, &numReq) == MS_FAILURE || - msOWSExecuteRequests(asReqInfo, numReq, map, MS_TRUE) == MS_FAILURE ) { + if (msPrepareWMSLayerRequest(1, map, layer, 1, 0, NULL, 0, 0, 0, NULL, + asReqInfo, &numReq) == MS_FAILURE || + msOWSExecuteRequests(asReqInfo, numReq, map, MS_TRUE) == MS_FAILURE) { return MS_FAILURE; } /* ------------------------------------------------------------------ * Then draw layer based on output format * ------------------------------------------------------------------ */ - if( MS_RENDERER_PLUGIN(image->format) ) - nStatus = msDrawWMSLayerLow(1, asReqInfo, numReq, - map, layer, image) ; - else if( MS_RENDERER_RAWDATA(image->format) ) - nStatus = msDrawWMSLayerLow(1, asReqInfo, numReq, - map, layer, image) ; + if (MS_RENDERER_PLUGIN(image->format)) + nStatus = msDrawWMSLayerLow(1, asReqInfo, numReq, map, layer, image); + else if (MS_RENDERER_RAWDATA(image->format)) + nStatus = msDrawWMSLayerLow(1, asReqInfo, numReq, map, layer, image); else { msSetError(MS_WMSCONNERR, @@ -1719,15 +1938,17 @@ int msDrawWMSLayer(mapObj *map, layerObj *layer, imageObj *image) } #endif -int circleLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj *shape) -{ +int circleLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, + shapeObj *shape) { pointObj center; double r; int s; int c = shape->classindex; - if (shape->numlines != 1) return (MS_SUCCESS); /* invalid shape */ - if (shape->line[0].numpoints != 2) return (MS_SUCCESS); /* invalid shape */ + if (shape->numlines != 1) + return (MS_SUCCESS); /* invalid shape */ + if (shape->line[0].numpoints != 2) + return (MS_SUCCESS); /* invalid shape */ center.x = (shape->line[0].point[0].x + shape->line[0].point[1].x) / 2.0; center.y = (shape->line[0].point[0].y + shape->line[0].point[1].y) / 2.0; @@ -1748,12 +1969,14 @@ int circleLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj } else msOffsetPointRelativeTo(¢er, layer); - for (s = 0; s < layer->class[c]->numstyles; s++) { + for (s = 0; s < layer->class[c] -> numstyles; s++) { if (msScaleInBounds(map->scaledenom, - layer->class[c]->styles[s]->minscaledenom, - layer->class[c]->styles[s]->maxscaledenom)) - if(MS_UNLIKELY(MS_FAILURE == msCircleDrawShadeSymbol(map, image, ¢er, r, - layer->class[c]->styles[s], layer->class[c]->styles[s]->scalefactor))) { + layer->class[c] -> styles[s] -> minscaledenom, + layer -> class[c] -> styles[s] -> maxscaledenom)) + if (MS_UNLIKELY(MS_FAILURE == + msCircleDrawShadeSymbol( + map, image, ¢er, r, layer->class[c] -> styles[s], + layer -> class[c] -> styles[s] -> scalefactor))) { return MS_FAILURE; } } @@ -1761,41 +1984,31 @@ int circleLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj /* TODO: need to handle circle annotation */ } -static -int pointLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj *shape, int drawmode) -{ +static int pointLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, + shapeObj *shape, int drawmode) { int l, c = shape->classindex, j, i, s; pointObj *point; int ret = MS_FAILURE; - if (layer->project && layer->transform == MS_TRUE) - { - if( layer->reprojectorLayerToMap == NULL ) - { - layer->reprojectorLayerToMap = msProjectCreateReprojector( - &layer->projection, &map->projection); - if( layer->reprojectorLayerToMap == NULL ) - { - return MS_FAILURE; - } - } - msProjectShapeEx(layer->reprojectorLayerToMap, shape); + if (layer->project && layer->transform == MS_TRUE) { + reprojectionObj *reprojector = msLayerGetReprojectorToMap(layer, map); + if (reprojector == NULL) { + return MS_FAILURE; + } + msProjectShapeEx(reprojector, shape); } // Only take into account map rotation if the label and style angles are // non-zero. - if( map->gt.rotation_angle ) - { - for (l = 0; l < layer->class[c]->numlabels; l++) - { - if( layer->class[c]->labels[l]->angle != 0 ) - layer->class[c]->labels[l]->angle -= map->gt.rotation_angle; + if (map->gt.rotation_angle) { + for (l = 0; l < layer->class[c] -> numlabels; l++) { + if (layer->class[c] -> labels[l] -> angle != 0) + layer->class[c]->labels[l]->angle -= map->gt.rotation_angle; } - for (s = 0; s < layer->class[c]->numstyles; s++) - { - if( layer->class[c]->styles[s]->angle != 0 ) - layer->class[c]->styles[s]->angle -= map->gt.rotation_angle; + for (s = 0; s < layer->class[c] -> numstyles; s++) { + if (layer->class[c] -> styles[s] -> angle != 0) + layer->class[c]->styles[s]->angle -= map->gt.rotation_angle; } } @@ -1803,29 +2016,42 @@ int pointLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj for (i = 0; i < shape->line[j].numpoints; i++) { point = &(shape->line[j].point[i]); if (layer->transform == MS_TRUE) { - if (!msPointInRect(point, &map->extent)) continue; /* next point */ + if (!msPointInRect(point, &map->extent)) + continue; /* next point */ msTransformPoint(point, &map->extent, map->cellsize, image); } else msOffsetPointRelativeTo(point, layer); - if(MS_DRAW_FEATURES(drawmode)) { - for (s = 0; s < layer->class[c]->numstyles; s++) { + if (MS_DRAW_FEATURES(drawmode)) { + for (s = 0; s < layer->class[c] -> numstyles; s++) { if (msScaleInBounds(map->scaledenom, - layer->class[c]->styles[s]->minscaledenom, - layer->class[c]->styles[s]->maxscaledenom)) - if(MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, image, point, layer->class[c]->styles[s], layer->class[c]->styles[s]->scalefactor))) { + layer->class[c] -> styles[s] -> minscaledenom, + layer -> class[c] -> styles[s] -> maxscaledenom)) + if (MS_UNLIKELY( + MS_FAILURE == + msDrawMarkerSymbol( + map, image, point, layer->class[c] -> styles[s], + layer -> class[c] -> styles[s] -> scalefactor))) { goto end; } } } - if(MS_DRAW_LABELS(drawmode)) { + if (MS_DRAW_LABELS(drawmode)) { if (layer->labelcache) { - if (msAddLabelGroup(map, image, layer, c, shape, point, -1) != MS_SUCCESS) goto end; + if (msAddLabelGroup(map, image, layer, c, shape, point, -1) != + MS_SUCCESS) + goto end; } else { - for (l = 0; l < layer->class[c]->numlabels; l++) - if(msGetLabelStatus(map,layer,shape,layer->class[c]->labels[l]) == MS_ON) { - char *annotext = msShapeGetLabelAnnotation(layer,shape,layer->class[c]->labels[l]); - if(MS_UNLIKELY(MS_FAILURE == msDrawLabel(map, image, *point, annotext, layer->class[c]->labels[l], layer->class[c]->labels[l]->scalefactor))) { + for (l = 0; l < layer->class[c] -> numlabels; l++) + if (msGetLabelStatus(map, layer, shape, + layer->class[c] -> labels[l]) == MS_ON) { + char *annotext = msShapeGetLabelAnnotation( + layer, shape, layer->class[c] -> labels[l]); + if (MS_UNLIKELY(MS_FAILURE == + msDrawLabel(map, image, *point, annotext, + layer->class[c] -> labels[l], + layer -> class[c] -> labels[l] + -> scalefactor))) { goto end; } } @@ -1836,92 +2062,103 @@ int pointLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj ret = MS_SUCCESS; end: - if( map->gt.rotation_angle ) - { - for (l = 0; l < layer->class[c]->numlabels; l++) - { - if( layer->class[c]->labels[l]->angle != 0 ) - layer->class[c]->labels[l]->angle += map->gt.rotation_angle; + if (map->gt.rotation_angle) { + for (l = 0; l < layer->class[c] -> numlabels; l++) { + if (layer->class[c] -> labels[l] -> angle != 0) + layer->class[c]->labels[l]->angle += map->gt.rotation_angle; } - for (s = 0; s < layer->class[c]->numstyles; s++) - { - if( layer->class[c]->styles[s]->angle != 0 ) - layer->class[c]->styles[s]->angle += map->gt.rotation_angle; + for (s = 0; s < layer->class[c] -> numstyles; s++) { + if (layer->class[c] -> styles[s] -> angle != 0) + layer->class[c]->styles[s]->angle += map->gt.rotation_angle; } } return ret; } -int lineLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj *shape, - shapeObj *anno_shape, shapeObj *unclipped_shape, int style, int drawmode) -{ +int lineLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, + shapeObj *shape, shapeObj *anno_shape, + shapeObj *unclipped_shape, int style, int drawmode) { int c = shape->classindex; int ret = MS_SUCCESS; /* RFC48: loop through the styles, and pass off to the type-specific function if the style has an appropriate type */ - if(MS_DRAW_FEATURES(drawmode)) { - for (int s = 0; s < layer->class[c]->numstyles; s++) { + if (MS_DRAW_FEATURES(drawmode)) { + for (int s = 0; s < layer->class[c] -> numstyles; s++) { if (msScaleInBounds(map->scaledenom, - layer->class[c]->styles[s]->minscaledenom, - layer->class[c]->styles[s]->maxscaledenom)) { - if (layer->class[c]->styles[s]->_geomtransform.type != MS_GEOMTRANSFORM_NONE) { - if(MS_UNLIKELY(MS_FAILURE == msDrawTransformedShape(map, image, unclipped_shape, layer->class[c]->styles[s], layer->class[c]->styles[s]->scalefactor))) { + layer->class[c] -> styles[s] -> minscaledenom, + layer -> class[c] -> styles[s] -> maxscaledenom)) { + if (layer->class[c] -> styles[s] -> _geomtransform.type != + MS_GEOMTRANSFORM_NONE) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawTransformedShape( + map, image, unclipped_shape, + layer->class[c] -> styles[s], + layer -> class[c] -> styles[s] -> scalefactor))) { return MS_FAILURE; } - } - else if (!MS_DRAW_SINGLESTYLE(drawmode) || s == style) { - if(MS_UNLIKELY(MS_FAILURE == msDrawLineSymbol(map, image, shape, layer->class[c]->styles[s], layer->class[c]->styles[s]->scalefactor))) { + } else if (!MS_DRAW_SINGLESTYLE(drawmode) || s == style) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawLineSymbol( + map, image, shape, layer->class[c] -> styles[s], + layer -> class[c] -> styles[s] -> scalefactor))) { return MS_FAILURE; } } } } } - - if(MS_DRAW_LABELS(drawmode)) { - for (int l = 0; l < layer->class[c]->numlabels; l++) { + + if (MS_DRAW_LABELS(drawmode)) { + for (int l = 0; l < layer->class[c] -> numlabels; l++) { labelObj *label = layer->class[c]->labels[l]; textSymbolObj ts; char *annotext; - if(!msGetLabelStatus(map,layer,shape,label)) { + if (!msGetLabelStatus(map, layer, shape, label)) { continue; } - annotext = msShapeGetLabelAnnotation(layer,anno_shape,label); - if(!annotext) continue; + annotext = msShapeGetLabelAnnotation(layer, anno_shape, label); + if (!annotext) + continue; initTextSymbol(&ts); - msPopulateTextSymbolForLabelAndString(&ts,label,annotext,label->scalefactor,image->resolutionfactor, layer->labelcache); - - + msPopulateTextSymbolForLabelAndString( + &ts, label, annotext, label->scalefactor, image->resolutionfactor, + layer->labelcache); + if (label->anglemode == MS_FOLLOW) { /* bug #1620 implementation */ struct label_follow_result lfr; - + if (!layer->labelcache) { - msSetError(MS_MISCERR, "Angle mode 'FOLLOW' is supported only with labelcache on", "msDrawShape()"); + msSetError(MS_MISCERR, + "Angle mode 'FOLLOW' is supported only with labelcache on", + "msDrawShape()"); ret = MS_FAILURE; goto line_cleanup; } - - memset(&lfr,0,sizeof(lfr)); + + memset(&lfr, 0, sizeof(lfr)); msPolylineLabelPath(map, image, anno_shape, &ts, label, &lfr); for (int i = 0; i < lfr.num_follow_labels; i++) { - if (msAddLabel(map, image, label, layer->index, c, anno_shape, NULL, -1, lfr.follow_labels[i]) != MS_SUCCESS) { + if (msAddLabel(map, image, label, layer->index, c, anno_shape, NULL, + -1, lfr.follow_labels[i]) != MS_SUCCESS) { ret = MS_FAILURE; goto line_cleanup; } } free(lfr.follow_labels); - for(int i=0; irotation = lfr.lar.angles[i]; { - if (msAddLabel(map, image, label, layer->index, c, anno_shape, &lfr.lar.label_points[i], -1, ts_auto) != MS_SUCCESS) { + if (msAddLabel(map, image, label, layer->index, c, anno_shape, + &lfr.lar.label_points[i], -1, + ts_auto) != MS_SUCCESS) { ret = MS_FAILURE; free(lfr.lar.angles); free(lfr.lar.label_points); @@ -1933,20 +2170,23 @@ int lineLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj * free(lfr.lar.label_points); } else { struct label_auto_result lar; - memset(&lar,0,sizeof(struct label_auto_result)); - ret = msPolylineLabelPoint(map, anno_shape, &ts, label, &lar, image->resolutionfactor); - if(MS_UNLIKELY(MS_FAILURE == ret)) goto line_cleanup; + memset(&lar, 0, sizeof(struct label_auto_result)); + ret = msPolylineLabelPoint(map, anno_shape, &ts, label, &lar, + image->resolutionfactor); + if (MS_UNLIKELY(MS_FAILURE == ret)) + goto line_cleanup; if (label->angle != 0) label->angle -= map->gt.rotation_angle; /* apply rotation angle */ - for(int i=0; irotation = lar.angles[i]; if (layer->labelcache) { - if (msAddLabel(map, image, label, layer->index, c, anno_shape, &lar.label_points[i], -1, ts_auto) != MS_SUCCESS) { + if (msAddLabel(map, image, label, layer->index, c, anno_shape, + &lar.label_points[i], -1, ts_auto) != MS_SUCCESS) { ret = MS_FAILURE; free(lar.angles); free(lar.label_points); @@ -1955,8 +2195,8 @@ int lineLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj * goto line_cleanup; } } else { - if(!ts_auto->textpath) { - if(MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map,ts_auto))) { + if (!ts_auto->textpath) { + if (MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map, ts_auto))) { ret = MS_FAILURE; free(lar.angles); free(lar.label_points); @@ -1965,21 +2205,23 @@ int lineLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj * goto line_cleanup; } } - ret = msDrawTextSymbol(map,image,lar.label_points[i],ts_auto); + ret = msDrawTextSymbol(map, image, lar.label_points[i], ts_auto); freeTextSymbol(ts_auto); - free(ts_auto); /* TODO RFC98: could we not re-use the original ts instead of duplicating into ts_auto ? - * we cannot for now, as the rendering code will modify the glyph positions to apply - * the labelpoint and rotation offsets */ + free(ts_auto); /* TODO RFC98: could we not re-use the original ts + * instead of duplicating into ts_auto ? we cannot + * for now, as the rendering code will modify the + * glyph positions to apply the labelpoint and + * rotation offsets */ ts_auto = NULL; - if(MS_UNLIKELY(MS_FAILURE == ret)) goto line_cleanup; + if (MS_UNLIKELY(MS_FAILURE == ret)) + goto line_cleanup; } - } free(lar.angles); free(lar.label_points); } -line_cleanup: + line_cleanup: /* clean up and reset */ if (ret == MS_FAILURE) { break; /* from the label looping */ @@ -1989,29 +2231,35 @@ int lineLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj * } return ret; - } int polygonLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, - shapeObj *shape, shapeObj *anno_shape, shapeObj *unclipped_shape, int drawmode) -{ + shapeObj *shape, shapeObj *anno_shape, + shapeObj *unclipped_shape, int drawmode) { int c = shape->classindex; pointObj annopnt = {0}; // initialize int i; - if(MS_DRAW_FEATURES(drawmode)) { - for (i = 0; i < layer->class[c]->numstyles; i++) { - if (msScaleInBounds(map->scaledenom, layer->class[c]->styles[i]->minscaledenom, - layer->class[c]->styles[i]->maxscaledenom)) { - if (layer->class[c]->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE) { - if(MS_UNLIKELY(MS_FAILURE == msDrawShadeSymbol(map, image, shape, layer->class[c]->styles[i], layer->class[c]->styles[i]->scalefactor))) { + if (MS_DRAW_FEATURES(drawmode)) { + for (i = 0; i < layer->class[c] -> numstyles; i++) { + if (msScaleInBounds(map->scaledenom, + layer->class[c] -> styles[i] -> minscaledenom, + layer -> class[c] -> styles[i] -> maxscaledenom)) { + if (layer->class[c] -> styles[i] -> _geomtransform.type == + MS_GEOMTRANSFORM_NONE) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawShadeSymbol( + map, image, shape, layer->class[c] -> styles[i], + layer -> class[c] -> styles[i] -> scalefactor))) { return MS_FAILURE; } - } - else { - if(MS_UNLIKELY(MS_FAILURE == msDrawTransformedShape(map, image, unclipped_shape, - layer->class[c]->styles[i], layer->class[c]->styles[i]->scalefactor))) { + } else { + if (MS_UNLIKELY(MS_FAILURE == + msDrawTransformedShape( + map, image, unclipped_shape, + layer->class[c] -> styles[i], + layer -> class[c] -> styles[i] -> scalefactor))) { return MS_FAILURE; } } @@ -2019,22 +2267,37 @@ int polygonLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, } } - if(MS_DRAW_LABELS(drawmode)) { - if (layer->class[c]->numlabels > 0) { - double minfeaturesize = layer->class[c]->labels[0]->minfeaturesize * image->resolutionfactor; - if (msPolygonLabelPoint(anno_shape, &annopnt, minfeaturesize) == MS_SUCCESS) { - for (i = 0; i < layer->class[c]->numlabels; i++) - if (layer->class[c]->labels[i]->angle != 0) layer->class[c]->labels[i]->angle -= map->gt.rotation_angle; /* TODO: is this correct ??? */ + if (MS_DRAW_LABELS(drawmode)) { + if (layer->class[c] -> numlabels > 0) { + double minfeaturesize = + layer->class[c]->labels[0]->minfeaturesize * image->resolutionfactor; + if (msPolygonLabelPoint(anno_shape, &annopnt, minfeaturesize) == + MS_SUCCESS) { + for (i = 0; i < layer->class[c] -> numlabels; i++) + if (layer->class[c] -> labels[i] -> angle != 0) + layer->class[c]->labels[i]->angle -= + map->gt.rotation_angle; /* TODO: is this correct ??? */ if (layer->labelcache) { if (msAddLabelGroup(map, image, layer, c, anno_shape, &annopnt, - MS_MIN(shape->bounds.maxx - shape->bounds.minx, shape->bounds.maxy - shape->bounds.miny)) != MS_SUCCESS) { + MS_MIN(shape->bounds.maxx - shape->bounds.minx, + shape->bounds.maxy - + shape->bounds.miny)) != MS_SUCCESS) { return MS_FAILURE; } } else { - for (i = 0; i < layer->class[c]->numlabels; i++) - if(msGetLabelStatus(map,layer,shape,layer->class[c]->labels[i]) == MS_ON) { - char *annotext = msShapeGetLabelAnnotation(layer,shape,layer->class[c]->labels[i]); /*ownership taken by msDrawLabel, no need to free */ - if(MS_UNLIKELY(MS_FAILURE == msDrawLabel(map, image, annopnt, annotext, layer->class[c]->labels[i], layer->class[c]->labels[i]->scalefactor))) { + for (i = 0; i < layer->class[c] -> numlabels; i++) + if (msGetLabelStatus(map, layer, shape, + layer->class[c] -> labels[i]) == MS_ON) { + char *annotext = msShapeGetLabelAnnotation( + layer, shape, + layer->class[c] + -> labels[i]); /*ownership taken by msDrawLabel, no need to + free */ + if (MS_UNLIKELY(MS_FAILURE == + msDrawLabel(map, image, annopnt, annotext, + layer->class[c] -> labels[i], + layer -> class[c] -> labels[i] + -> scalefactor))) { return MS_FAILURE; } } @@ -2046,74 +2309,81 @@ int polygonLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, } /* -** Function to render an individual shape, the style variable enables/disables the drawing of a single style -** versus a single style. This is necessary when drawing entire layers as proper overlay can only be achived -** through caching. "querymapMode" parameter is used to tell msBindLayerToShape to not override the +** Function to render an individual shape, the style variable enables/disables +*the drawing of a single style +** versus a single style. This is necessary when drawing entire layers as proper +*overlay can only be achived +** through caching. "querymapMode" parameter is used to tell msBindLayerToShape +*to not override the ** QUERYMAP HILITE color. */ -int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image, int style, int drawmode) -{ - int c,s,ret=MS_SUCCESS; +int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image, + int style, int drawmode) { + int c, s, ret = MS_SUCCESS; shapeObj *anno_shape, *unclipped_shape = shape; int bNeedUnclippedShape = MS_FALSE; int bNeedUnclippedAnnoShape = MS_FALSE; int bShapeNeedsClipping = MS_TRUE; - if(shape->numlines == 0 || shape->type == MS_SHAPE_NULL) return MS_SUCCESS; + if (shape->numlines == 0 || shape->type == MS_SHAPE_NULL) + return MS_SUCCESS; c = shape->classindex; /* Before we do anything else, we will check for a rangeitem. If its there, we need to change the style's color to map the range to the shape */ - for(s=0; sclass[c]->numstyles; s++) { + for (s = 0; s < layer->class[c] -> numstyles; s++) { styleObj *style = layer->class[c]->styles[s]; - if(style->rangeitem != NULL) - msShapeToRange((layer->class[c]->styles[s]), shape); + if (style->rangeitem != NULL) + msShapeToRange((layer->class[c] -> styles[s]), shape); } /* circle and point layers go through their own treatment */ - if(layer->type == MS_LAYER_CIRCLE) { - if(msBindLayerToShape(layer, shape, drawmode) != MS_SUCCESS) return MS_FAILURE; + if (layer->type == MS_LAYER_CIRCLE) { + if (msBindLayerToShape(layer, shape, drawmode) != MS_SUCCESS) + return MS_FAILURE; msDrawStartShape(map, layer, image, shape); - ret = circleLayerDrawShape(map,image,layer,shape); - msDrawEndShape(map,layer,image,shape); + ret = circleLayerDrawShape(map, image, layer, shape); + msDrawEndShape(map, layer, image, shape); return ret; - } else if(layer->type == MS_LAYER_POINT || layer->type == MS_LAYER_RASTER) { - if(msBindLayerToShape(layer, shape, drawmode) != MS_SUCCESS) return MS_FAILURE; + } else if (layer->type == MS_LAYER_POINT || layer->type == MS_LAYER_RASTER) { + if (msBindLayerToShape(layer, shape, drawmode) != MS_SUCCESS) + return MS_FAILURE; msDrawStartShape(map, layer, image, shape); - ret = pointLayerDrawShape(map,image,layer,shape,drawmode); - msDrawEndShape(map,layer,image,shape); + ret = pointLayerDrawShape(map, image, layer, shape, drawmode); + msDrawEndShape(map, layer, image, shape); return ret; } if (layer->type == MS_LAYER_POLYGON && shape->type != MS_SHAPE_POLYGON) { - msSetError(MS_MISCERR, "Only polygon shapes can be drawn using a polygon layer definition.", "polygonLayerDrawShape()"); + msSetError( + MS_MISCERR, + "Only polygon shapes can be drawn using a polygon layer definition.", + "polygonLayerDrawShape()"); return (MS_FAILURE); } - if (layer->type == MS_LAYER_LINE && shape->type != MS_SHAPE_POLYGON && shape->type != MS_SHAPE_LINE) { - msSetError(MS_MISCERR, "Only polygon or line shapes can be drawn using a line layer definition.", "msDrawShape()"); + if (layer->type == MS_LAYER_LINE && shape->type != MS_SHAPE_POLYGON && + shape->type != MS_SHAPE_LINE) { + msSetError(MS_MISCERR, + "Only polygon or line shapes can be drawn using a line layer " + "definition.", + "msDrawShape()"); return (MS_FAILURE); } - if (layer->project && layer->transform == MS_TRUE) - { - if( layer->reprojectorLayerToMap == NULL ) - { - layer->reprojectorLayerToMap = msProjectCreateReprojector( - &layer->projection, &map->projection); - if( layer->reprojectorLayerToMap == NULL ) - { - return MS_FAILURE; - } - } - msProjectShapeEx(layer->reprojectorLayerToMap, shape); + if (layer->project && layer->transform == MS_TRUE) { + reprojectionObj *reprojector = msLayerGetReprojectorToMap(layer, map); + if (reprojector == NULL) { + return MS_FAILURE; + } + msProjectShapeEx(reprojector, shape); } /* check if we'll need the unclipped shape */ if (shape->type != MS_SHAPE_POINT) { - if(MS_DRAW_FEATURES(drawmode)) { - for (s = 0; s < layer->class[c]->numstyles; s++) { + if (MS_DRAW_FEATURES(drawmode)) { + for (s = 0; s < layer->class[c] -> numstyles; s++) { styleObj *style = layer->class[c]->styles[s]; if (style->_geomtransform.type != MS_GEOMTRANSFORM_NONE) bNeedUnclippedShape = MS_TRUE; @@ -2126,31 +2396,33 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image, shape->bounds.maxy > map->extent.maxy) { bShapeNeedsClipping = MS_TRUE; } - - if(MS_DRAW_LABELS(drawmode) && MS_DRAW_UNCLIPPED_LABELS(drawmode)) { + + if (MS_DRAW_LABELS(drawmode) && MS_DRAW_UNCLIPPED_LABELS(drawmode)) { bNeedUnclippedAnnoShape = MS_TRUE; bNeedUnclippedShape = MS_TRUE; } - if(MS_DRAW_UNCLIPPED_LINES(drawmode)) { + if (MS_DRAW_UNCLIPPED_LINES(drawmode)) { bShapeNeedsClipping = MS_FALSE; } } else { bShapeNeedsClipping = MS_FALSE; } - if(layer->transform == MS_TRUE && bShapeNeedsClipping) { - /* compute the size of the clipping buffer, in pixels. This buffer must account - for the size of symbols drawn to avoid artifacts around the image edges */ + if (layer->transform == MS_TRUE && bShapeNeedsClipping) { + /* compute the size of the clipping buffer, in pixels. This buffer must + account for the size of symbols drawn to avoid artifacts around the image + edges */ int clip_buf = 0; int s; rectObj cliprect; - for (s=0;sclass[c]->numstyles;s++) { + for (s = 0; s < layer->class[c] -> numstyles; s++) { double maxsize, maxunscaledsize; symbolObj *symbol; styleObj *style = layer->class[c]->styles[s]; if (!MS_IS_VALID_ARRAY_INDEX(style->symbol, map->symbolset.numsymbols)) { - msSetError(MS_SYMERR, "Invalid symbol index: %d", "msDrawShape()", style->symbol); + msSetError(MS_SYMERR, "Invalid symbol index: %d", "msDrawShape()", + style->symbol); return MS_FAILURE; } symbol = map->symbolset.symbol[style->symbol]; @@ -2162,68 +2434,77 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image, if (MS_SUCCESS != msPreloadSVGSymbol(symbol)) return MS_FAILURE; #else - msSetError(MS_SYMERR, "SVG symbol support is not enabled.", "msDrawShape()"); + msSetError(MS_SYMERR, "SVG symbol support is not enabled.", + "msDrawShape()"); return MS_FAILURE; #endif } - maxsize = MS_MAX(msSymbolGetDefaultSize(symbol), MS_MAX(style->size, style->width)); - maxunscaledsize = MS_MAX(style->minsize*image->resolutionfactor, style->minwidth*image->resolutionfactor); - if(shape->type == MS_SHAPE_POLYGON && !IS_PARALLEL_OFFSET(style->offsety)) { - maxsize += MS_MAX(fabs(style->offsety),fabs(style->offsetx)); + maxsize = MS_MAX(msSymbolGetDefaultSize(symbol), + MS_MAX(style->size, style->width)); + maxunscaledsize = MS_MAX(style->minsize * image->resolutionfactor, + style->minwidth * image->resolutionfactor); + if (shape->type == MS_SHAPE_POLYGON && + !IS_PARALLEL_OFFSET(style->offsety)) { + maxsize += MS_MAX(fabs(style->offsety), fabs(style->offsetx)); } - clip_buf = MS_MAX(clip_buf,MS_NINT(MS_MAX(maxsize * style->scalefactor, maxunscaledsize) + 1)); + clip_buf = MS_MAX( + clip_buf, + MS_NINT(MS_MAX(maxsize * style->scalefactor, maxunscaledsize) + 1)); } - - /* if we need a copy of the unclipped shape, transform first, then clip to avoid transforming twice */ - if(bNeedUnclippedShape) { + /* if we need a copy of the unclipped shape, transform first, then clip to + * avoid transforming twice */ + if (bNeedUnclippedShape) { msTransformShape(shape, map->extent, map->cellsize, image); - if(shape->numlines == 0) return MS_SUCCESS; + if (shape->numlines == 0) + return MS_SUCCESS; msComputeBounds(shape); /* TODO: there's an optimization here that can be implemented: - no need to allocate unclipped_shape for each call to this function - - the calls to msClipXXXRect will discard the original lineObjs, whereas - we have just copied them because they where needed. These two functions - could be changed so they are instructed not to free the original lineObjs. */ - unclipped_shape = (shapeObj *) msSmallMalloc(sizeof (shapeObj)); + - the calls to msClipXXXRect will discard the original lineObjs, + whereas we have just copied them because they where needed. These two + functions could be changed so they are instructed not to free the + original lineObjs. */ + unclipped_shape = (shapeObj *)msSmallMalloc(sizeof(shapeObj)); msInitShape(unclipped_shape); msCopyShape(shape, unclipped_shape); - if(shape->type == MS_SHAPE_POLYGON) { - /* #179: additional buffer for polygons */ - clip_buf += 2; + if (shape->type == MS_SHAPE_POLYGON) { + /* #179: additional buffer for polygons */ + clip_buf += 2; } cliprect.minx = cliprect.miny = -clip_buf; cliprect.maxx = image->width + clip_buf; cliprect.maxy = image->height + clip_buf; - if(shape->type == MS_SHAPE_POLYGON) { + if (shape->type == MS_SHAPE_POLYGON) { msClipPolygonRect(shape, cliprect); } else { assert(shape->type == MS_SHAPE_LINE); msClipPolylineRect(shape, cliprect); } - if(bNeedUnclippedAnnoShape) { + if (bNeedUnclippedAnnoShape) { anno_shape = unclipped_shape; } else { anno_shape = shape; } } else { - /* clip first, then transform. This means we are clipping in geographical space */ + /* clip first, then transform. This means we are clipping in geographical + * space */ double clip_buf_d; - if(shape->type == MS_SHAPE_POLYGON) { - /* - * add a small buffer around the cliping rectangle to - * avoid lines around the edges : #179 - */ - clip_buf += 2; + if (shape->type == MS_SHAPE_POLYGON) { + /* + * add a small buffer around the cliping rectangle to + * avoid lines around the edges : #179 + */ + clip_buf += 2; } clip_buf_d = clip_buf * map->cellsize; cliprect.minx = map->extent.minx - clip_buf_d; cliprect.miny = map->extent.miny - clip_buf_d; cliprect.maxx = map->extent.maxx + clip_buf_d; cliprect.maxy = map->extent.maxy + clip_buf_d; - if(shape->type == MS_SHAPE_POLYGON) { + if (shape->type == MS_SHAPE_POLYGON) { msClipPolygonRect(shape, cliprect); } else { assert(shape->type == MS_SHAPE_LINE); @@ -2236,7 +2517,8 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image, } else { /* the shape is fully in the map extent, - * or is a point type layer where out of bounds points are treated differently*/ + * or is a point type layer where out of bounds points are treated + * differently*/ if (layer->transform == MS_TRUE) { msTransformShape(shape, map->extent, map->cellsize, image); msComputeBounds(shape); @@ -2245,36 +2527,38 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image, } anno_shape = shape; } - if(shape->numlines == 0) { + if (shape->numlines == 0) { ret = MS_SUCCESS; /* error message is set in msBindLayerToShape() */ goto draw_shape_cleanup; } - if(msBindLayerToShape(layer, shape, drawmode) != MS_SUCCESS) { + if (msBindLayerToShape(layer, shape, drawmode) != MS_SUCCESS) { ret = MS_FAILURE; /* error message is set in msBindLayerToShape() */ goto draw_shape_cleanup; } - switch(layer->type) { - case MS_LAYER_LINE: - msDrawStartShape(map, layer, image, shape); - ret = lineLayerDrawShape(map, image, layer, shape, anno_shape, unclipped_shape, style, drawmode); - break; - case MS_LAYER_POLYGON: - msDrawStartShape(map, layer, image, shape); - ret = polygonLayerDrawShape(map, image, layer, shape, anno_shape, unclipped_shape, drawmode); - break; - case MS_LAYER_POINT: - case MS_LAYER_RASTER: - assert(0); //bug ! - default: - msSetError(MS_MISCERR, "Unknown layer type.", "msDrawShape()"); - ret = MS_FAILURE; + switch (layer->type) { + case MS_LAYER_LINE: + msDrawStartShape(map, layer, image, shape); + ret = lineLayerDrawShape(map, image, layer, shape, anno_shape, + unclipped_shape, style, drawmode); + break; + case MS_LAYER_POLYGON: + msDrawStartShape(map, layer, image, shape); + ret = polygonLayerDrawShape(map, image, layer, shape, anno_shape, + unclipped_shape, drawmode); + break; + case MS_LAYER_POINT: + case MS_LAYER_RASTER: + assert(0); // bug ! + default: + msSetError(MS_MISCERR, "Unknown layer type.", "msDrawShape()"); + ret = MS_FAILURE; } draw_shape_cleanup: - msDrawEndShape(map,layer,image,shape); - if(unclipped_shape != shape) { + msDrawEndShape(map, layer, image, shape); + if (unclipped_shape != shape) { msFreeShape(unclipped_shape); msFree(unclipped_shape); } @@ -2282,93 +2566,107 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image, } /* -** Function to render an individual point, used as a helper function for mapscript only. Since a point +** Function to render an individual point, used as a helper function for +*mapscript only. Since a point ** can't carry attributes you can't do attribute based font size or angle. */ -int msDrawPoint(mapObj *map, layerObj *layer, pointObj *point, imageObj *image, int classindex, char *labeltext) -{ - int s,ret; - classObj *theclass=NULL; - labelObj *label=NULL; - - if(layer->transform == MS_TRUE && layer->project && msProjectionsDiffer(&(layer->projection), &(map->projection))) { +int msDrawPoint(mapObj *map, layerObj *layer, pointObj *point, imageObj *image, + int classindex, char *labeltext) { + int s, ret; + classObj *theclass = NULL; + labelObj *label = NULL; + + if (layer->transform == MS_TRUE && layer->project && + msProjectionsDiffer(&(layer->projection), &(map->projection))) { msProjectPoint(&(layer->projection), &(map->projection), point); } - - if(classindex > layer->numclasses) { - msSetError(MS_MISCERR, "Invalid classindex (%d)", "msDrawPoint()", classindex); - return MS_FAILURE; + + if (classindex > layer->numclasses) { + msSetError(MS_MISCERR, "Invalid classindex (%d)", "msDrawPoint()", + classindex); + return MS_FAILURE; } theclass = layer->class[classindex]; - - if(labeltext && theclass->numlabels > 0) { + + if (labeltext && theclass->numlabels > 0) { label = theclass->labels[0]; } - - switch(layer->type) { - case MS_LAYER_POINT: - if(layer->transform == MS_TRUE) { - if(!msPointInRect(point, &map->extent)) return(0); - point->x = MS_MAP2IMAGE_X(point->x, map->extent.minx, map->cellsize); - point->y = MS_MAP2IMAGE_Y(point->y, map->extent.maxy, map->cellsize); - } else - msOffsetPointRelativeTo(point, layer); - for(s=0; snumstyles; s++) { - if(msScaleInBounds(map->scaledenom, theclass->styles[s]->minscaledenom, theclass->styles[s]->maxscaledenom)) - if(MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, image, point, theclass->styles[s], theclass->styles[s]->scalefactor))) { - return MS_FAILURE; - } - } - if(label && labeltext && *labeltext) { - textSymbolObj *ts = msSmallMalloc(sizeof(textSymbolObj)); - initTextSymbol(ts); - msPopulateTextSymbolForLabelAndString(ts, label, msStrdup(labeltext), label->scalefactor, image->resolutionfactor, layer->labelcache); - if(layer->labelcache) { - if(msAddLabel(map, image, label, layer->index, classindex, NULL, point, -1, ts) != MS_SUCCESS) { - return(MS_FAILURE); - } - } else { - if(MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map,ts))) { - freeTextSymbol(ts); - free(ts); - return MS_FAILURE; - } - ret = msDrawTextSymbol(map,image,*point,ts); + switch (layer->type) { + case MS_LAYER_POINT: + if (layer->transform == MS_TRUE) { + if (!msPointInRect(point, &map->extent)) + return (0); + point->x = MS_MAP2IMAGE_X(point->x, map->extent.minx, map->cellsize); + point->y = MS_MAP2IMAGE_Y(point->y, map->extent.maxy, map->cellsize); + } else + msOffsetPointRelativeTo(point, layer); + + for (s = 0; s < theclass->numstyles; s++) { + if (msScaleInBounds(map->scaledenom, theclass->styles[s]->minscaledenom, + theclass->styles[s]->maxscaledenom)) + if (MS_UNLIKELY(MS_FAILURE == + msDrawMarkerSymbol(map, image, point, + theclass->styles[s], + theclass->styles[s]->scalefactor))) { + return MS_FAILURE; + } + } + if (label && labeltext && *labeltext) { + textSymbolObj *ts = msSmallMalloc(sizeof(textSymbolObj)); + initTextSymbol(ts); + msPopulateTextSymbolForLabelAndString( + ts, label, msStrdup(labeltext), label->scalefactor, + image->resolutionfactor, layer->labelcache); + if (layer->labelcache) { + if (msAddLabel(map, image, label, layer->index, classindex, NULL, point, + -1, ts) != MS_SUCCESS) { + return (MS_FAILURE); + } + } else { + if (MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map, ts))) { freeTextSymbol(ts); - free(ts); - if(MS_UNLIKELY(ret == MS_FAILURE)) return MS_FAILURE; + free(ts); + return MS_FAILURE; } + ret = msDrawTextSymbol(map, image, *point, ts); + freeTextSymbol(ts); + free(ts); + if (MS_UNLIKELY(ret == MS_FAILURE)) + return MS_FAILURE; } - break; - default: - break; /* don't do anything with layer of other types */ + } + break; + default: + break; /* don't do anything with layer of other types */ } - return(MS_SUCCESS); /* all done, no cleanup */ + return (MS_SUCCESS); /* all done, no cleanup */ } /* -** Draws a single label independently of the label cache. No collision avoidance is performed. +** Draws a single label independently of the label cache. No collision avoidance +*is performed. */ -int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, labelObj *label, double scalefactor) -{ +int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, + labelObj *label, double scalefactor) { shapeObj labelPoly; label_bounds lbounds = {0}; lineObj labelPolyLine; pointObj labelPolyPoints[5]; textSymbolObj ts = {0}; - int needLabelPoly=MS_TRUE; - int needLabelPoint=MS_TRUE; - int haveLabelText=MS_TRUE; + int needLabelPoly = MS_TRUE; + int needLabelPoint = MS_TRUE; + int haveLabelText = MS_TRUE; - if(!string || !*string) + if (!string || !*string) haveLabelText = MS_FALSE; - if(haveLabelText) { + if (haveLabelText) { initTextSymbol(&ts); - msPopulateTextSymbolForLabelAndString(&ts, label, string, scalefactor, image->resolutionfactor, 0); - if(MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map,&ts))) { + msPopulateTextSymbolForLabelAndString(&ts, label, string, scalefactor, + image->resolutionfactor, 0); + if (MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map, &ts))) { freeTextSymbol(&ts); return MS_FAILURE; } @@ -2380,24 +2678,33 @@ int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, l labelPoly.line->point = labelPolyPoints; labelPoly.line->numpoints = 5; - if(label->position != MS_XY) { + if (label->position != MS_XY) { pointObj p = {0}; - if(label->numstyles > 0) { + if (label->numstyles > 0) { int i; - for(i=0; inumstyles; i++) { - if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT || label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE) { - if(MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, image, &labelPnt, label->styles[i], scalefactor))) { - if(haveLabelText) + for (i = 0; i < label->numstyles; i++) { + if (label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT || + label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawMarkerSymbol(map, image, &labelPnt, + label->styles[i], scalefactor))) { + if (haveLabelText) freeTextSymbol(&ts); return MS_FAILURE; } - } else if(haveLabelText && (label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY || label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELCENTER)) { - if(needLabelPoly) { - p = get_metrics(&labelPnt, label->position, ts.textpath, label->offsetx * ts.scalefactor, - label->offsety * ts.scalefactor, ts.rotation, 1, &lbounds); - if(!lbounds.poly) { + } else if (haveLabelText && (label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOLY || + label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELCENTER)) { + if (needLabelPoly) { + p = get_metrics(&labelPnt, label->position, ts.textpath, + label->offsetx * ts.scalefactor, + label->offsety * ts.scalefactor, ts.rotation, 1, + &lbounds); + if (!lbounds.poly) { /* we need the full shape to draw the label background */ labelPolyPoints[0].x = labelPolyPoints[4].x = lbounds.bbox.minx; labelPolyPoints[0].y = labelPolyPoints[4].y = lbounds.bbox.miny; @@ -2411,36 +2718,45 @@ int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, l needLabelPoint = MS_FALSE; /* don't re-compute */ needLabelPoly = MS_FALSE; } - if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) { - if(MS_UNLIKELY(MS_FAILURE == msDrawShadeSymbol(map, image, &labelPoly, label->styles[i], ts.scalefactor))) { + if (label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOLY) { + if (MS_UNLIKELY(MS_FAILURE == msDrawShadeSymbol(map, image, + &labelPoly, + label->styles[i], + ts.scalefactor))) { freeTextSymbol(&ts); return MS_FAILURE; } } else { pointObj labelCenter; - labelCenter.x = (lbounds.bbox.maxx + lbounds.bbox.minx)/2; - labelCenter.y = (lbounds.bbox.maxy + lbounds.bbox.miny)/2; - if(MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, image, &labelCenter, label->styles[i], scalefactor))) { + labelCenter.x = (lbounds.bbox.maxx + lbounds.bbox.minx) / 2; + labelCenter.y = (lbounds.bbox.maxy + lbounds.bbox.miny) / 2; + if (MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol( + map, image, &labelCenter, + label->styles[i], scalefactor))) { freeTextSymbol(&ts); return MS_FAILURE; } } } else { - msSetError(MS_MISCERR,"Unknown label geomtransform %s", "msDrawLabel()",label->styles[i]->_geomtransform.string); - if(haveLabelText) + msSetError(MS_MISCERR, "Unknown label geomtransform %s", + "msDrawLabel()", label->styles[i]->_geomtransform.string); + if (haveLabelText) freeTextSymbol(&ts); return MS_FAILURE; } } } - if(haveLabelText) { - if(needLabelPoint) - p = get_metrics(&labelPnt, label->position, ts.textpath, label->offsetx * ts.scalefactor, - label->offsety * ts.scalefactor, ts.rotation, 0, &lbounds); + if (haveLabelText) { + if (needLabelPoint) + p = get_metrics(&labelPnt, label->position, ts.textpath, + label->offsetx * ts.scalefactor, + label->offsety * ts.scalefactor, ts.rotation, 0, + &lbounds); /* draw the label text */ - if(MS_UNLIKELY(MS_FAILURE == msDrawTextSymbol(map,image,p,&ts))) { + if (MS_UNLIKELY(MS_FAILURE == msDrawTextSymbol(map, image, p, &ts))) { freeTextSymbol(&ts); return MS_FAILURE; } @@ -2449,22 +2765,30 @@ int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, l labelPnt.x += label->offsetx * ts.scalefactor; labelPnt.y += label->offsety * ts.scalefactor; - if(label->numstyles > 0) { + if (label->numstyles > 0) { int i; - for(i=0; inumstyles; i++) { - if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT || - label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE) { - if(MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, image, &labelPnt, label->styles[i], scalefactor))) { + for (i = 0; i < label->numstyles; i++) { + if (label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT || + label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawMarkerSymbol(map, image, &labelPnt, + label->styles[i], scalefactor))) { freeTextSymbol(&ts); return MS_FAILURE; } - } else if(haveLabelText && (label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY || label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELCENTER)) { - if(needLabelPoly) { - get_metrics(&labelPnt, label->position, ts.textpath, label->offsetx * ts.scalefactor, - label->offsety * ts.scalefactor, ts.rotation, 1, &lbounds); + } else if (haveLabelText && (label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOLY || + label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELCENTER)) { + if (needLabelPoly) { + get_metrics(&labelPnt, label->position, ts.textpath, + label->offsetx * ts.scalefactor, + label->offsety * ts.scalefactor, ts.rotation, 1, + &lbounds); needLabelPoly = MS_FALSE; /* don't re-compute */ - if(!lbounds.poly) { + if (!lbounds.poly) { /* we need the full shape to draw the label background */ labelPolyPoints[0].x = labelPolyPoints[4].x = lbounds.bbox.minx; labelPolyPoints[0].y = labelPolyPoints[4].y = lbounds.bbox.miny; @@ -2476,54 +2800,63 @@ int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, l labelPolyPoints[3].y = lbounds.bbox.miny; } } - if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) { - if(MS_UNLIKELY(MS_FAILURE == msDrawShadeSymbol(map, image, &labelPoly, label->styles[i], scalefactor))) { + if (label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOLY) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawShadeSymbol(map, image, &labelPoly, + label->styles[i], scalefactor))) { freeTextSymbol(&ts); return MS_FAILURE; } } else { - pointObj labelCenter; - labelCenter.x = (lbounds.bbox.maxx + lbounds.bbox.minx)/2; - labelCenter.y = (lbounds.bbox.maxy + lbounds.bbox.miny)/2; - if(MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, image, &labelCenter, label->styles[i], scalefactor))) { + pointObj labelCenter; + labelCenter.x = (lbounds.bbox.maxx + lbounds.bbox.minx) / 2; + labelCenter.y = (lbounds.bbox.maxy + lbounds.bbox.miny) / 2; + if (MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol( + map, image, &labelCenter, + label->styles[i], scalefactor))) { freeTextSymbol(&ts); return MS_FAILURE; } } } else { - msSetError(MS_MISCERR,"Unknown label geomtransform %s", "msDrawLabel()",label->styles[i]->_geomtransform.string); - if(haveLabelText) + msSetError(MS_MISCERR, "Unknown label geomtransform %s", + "msDrawLabel()", label->styles[i]->_geomtransform.string); + if (haveLabelText) freeTextSymbol(&ts); return MS_FAILURE; } } } - if(haveLabelText) { + if (haveLabelText) { /* draw the label text */ - if(MS_UNLIKELY(MS_FAILURE == msDrawTextSymbol(map,image,labelPnt,&ts))) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawTextSymbol(map, image, labelPnt, &ts))) { freeTextSymbol(&ts); return MS_FAILURE; } } } - if(haveLabelText) + if (haveLabelText) freeTextSymbol(&ts); return MS_SUCCESS; } -static inline void offset_bbox(const rectObj *from, rectObj *to, double ox, double oy) { +static inline void offset_bbox(const rectObj *from, rectObj *to, double ox, + double oy) { to->minx = from->minx + ox; to->miny = from->miny + oy; to->maxx = from->maxx + ox; to->maxy = from->maxy + oy; } -static inline void offset_label_bounds(const label_bounds *from, label_bounds *to, double ox, double oy) { - if(from->poly) { +static inline void offset_label_bounds(const label_bounds *from, + label_bounds *to, double ox, double oy) { + if (from->poly) { int i; - for(i=0; ipoly->numpoints; i++) { + for (i = 0; i < from->poly->numpoints; i++) { to->poly->point[i].x = from->poly->point[i].x + ox; to->poly->point[i].y = from->poly->point[i].y + oy; } @@ -2535,30 +2868,33 @@ static inline void offset_label_bounds(const label_bounds *from, label_bounds *t } /* private shortcut function to try a leader offsetted label - * the caller must ensure that scratch->poly->points has been sufficiently allocated - * to hold the points from the cachePtr's label_bounds */ -void offsetAndTest(mapObj *map, labelCacheMemberObj *cachePtr, double ox, double oy, - int priority, int label_idx, label_bounds *scratch) -{ - int i,j,status; + * the caller must ensure that scratch->poly->points has been sufficiently + * allocated to hold the points from the cachePtr's label_bounds */ +void offsetAndTest(mapObj *map, labelCacheMemberObj *cachePtr, double ox, + double oy, int priority, int label_idx, + label_bounds *scratch) { + int i, j, status; pointObj leaderpt; lineObj *scratch_line = scratch->poly; - for(i=0; inumtextsymbols; i++) { + for (i = 0; i < cachePtr->numtextsymbols; i++) { textSymbolObj *ts = cachePtr->textsymbols[i]; - if(ts->textpath) { + if (ts->textpath) { offset_label_bounds(&ts->textpath->bounds, scratch, ox, oy); - status = msTestLabelCacheCollisions(map, cachePtr, scratch, priority, label_idx); - if(!status) { + status = msTestLabelCacheCollisions(map, cachePtr, scratch, priority, + label_idx); + if (!status) { return; } } - for(j=0; jlabel->numstyles; j++) { - if(ts->label->styles[j]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { + for (j = 0; j < ts->label->numstyles; j++) { + if (ts->label->styles[j]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT) { scratch->poly = scratch_line; offset_label_bounds(ts->style_bounds[j], scratch, ox, oy); - status = msTestLabelCacheCollisions(map, cachePtr, scratch, priority, label_idx); - if(!status) { + status = msTestLabelCacheCollisions(map, cachePtr, scratch, priority, + label_idx); + if (!status) { return; } } @@ -2569,11 +2905,10 @@ void offsetAndTest(mapObj *map, labelCacheMemberObj *cachePtr, double ox, double leaderpt.y = cachePtr->point.y + oy; status = msTestLabelCacheLeaderCollision(map, &cachePtr->point, &leaderpt); - if(!status) { + if (!status) { return; } - /* the current offset is ok */ cachePtr->leaderbbox = msSmallMalloc(sizeof(rectObj)); cachePtr->leaderline = msSmallMalloc(sizeof(lineObj)); @@ -2581,32 +2916,31 @@ void offsetAndTest(mapObj *map, labelCacheMemberObj *cachePtr, double ox, double cachePtr->leaderline->numpoints = 2; cachePtr->leaderline->point[0] = cachePtr->point; cachePtr->leaderline->point[1] = leaderpt; - cachePtr->leaderbbox->minx = MS_MIN(leaderpt.x,cachePtr->point.x); - cachePtr->leaderbbox->maxx = MS_MAX(leaderpt.x,cachePtr->point.x); - cachePtr->leaderbbox->miny = MS_MIN(leaderpt.y,cachePtr->point.y); - cachePtr->leaderbbox->maxy = MS_MAX(leaderpt.y,cachePtr->point.y); + cachePtr->leaderbbox->minx = MS_MIN(leaderpt.x, cachePtr->point.x); + cachePtr->leaderbbox->maxx = MS_MAX(leaderpt.x, cachePtr->point.x); + cachePtr->leaderbbox->miny = MS_MIN(leaderpt.y, cachePtr->point.y); + cachePtr->leaderbbox->maxy = MS_MAX(leaderpt.y, cachePtr->point.y); cachePtr->status = MS_ON; - offset_bbox(&cachePtr->bbox,&cachePtr->bbox,ox,oy); + offset_bbox(&cachePtr->bbox, &cachePtr->bbox, ox, oy); - for(i=0; inumtextsymbols; i++) { + for (i = 0; i < cachePtr->numtextsymbols; i++) { textSymbolObj *ts = cachePtr->textsymbols[i]; - if(ts->textpath) { + if (ts->textpath) { offset_label_bounds(&ts->textpath->bounds, &ts->textpath->bounds, ox, oy); ts->annopoint.x += ox; ts->annopoint.y += oy; } - if(ts->style_bounds) { - for(j=0; jlabel->numstyles; j++) { - if(ts->label->styles[j]->_geomtransform.type != MS_GEOMTRANSFORM_NONE) + if (ts->style_bounds) { + for (j = 0; j < ts->label->numstyles; j++) { + if (ts->label->styles[j]->_geomtransform.type != MS_GEOMTRANSFORM_NONE) offset_label_bounds(ts->style_bounds[j], ts->style_bounds[j], ox, oy); } } } } -int msDrawOffsettedLabels(imageObj *image, mapObj *map, int priority) -{ +int msDrawOffsettedLabels(imageObj *image, mapObj *map, int priority) { int retval = MS_SUCCESS; int l; labelCacheObj *labelcache = &(map->labelcache); @@ -2620,68 +2954,75 @@ int msDrawOffsettedLabels(imageObj *image, mapObj *map, int priority) cacheslot = &(labelcache->slots[priority]); scratch.poly = &scratch_line; - for(l=cacheslot->numlabels-1; l>=0; l--) { - cachePtr = &(cacheslot->labels[l]); /* point to right spot in the label cache */ - if(cachePtr->status == MS_OFF) { + for (l = cacheslot->numlabels - 1; l >= 0; l--) { + cachePtr = + &(cacheslot->labels[l]); /* point to right spot in the label cache */ + if (cachePtr->status == MS_OFF) { /* only test regular labels that have had their bounding box computed and that haven't been rendered */ - classObj *classPtr = (GET_CLASS(map,cachePtr->layerindex,cachePtr->classindex)); - layerObj *layerPtr = (GET_LAYER(map,cachePtr->layerindex)); - int steps,i,num_scratch_points_to_allocate = 0; + classObj *classPtr = + (GET_CLASS(map, cachePtr->layerindex, cachePtr->classindex)); + layerObj *layerPtr = (GET_LAYER(map, cachePtr->layerindex)); + int steps, i, num_scratch_points_to_allocate = 0; - assert(classPtr->leader); /* cachePtrs that don't need to be tested have been marked as status on or delete */ + assert(classPtr->leader); /* cachePtrs that don't need to be tested have + been marked as status on or delete */ - if(cachePtr->point.x < labelcache->gutter || + if (cachePtr->point.x < labelcache->gutter || cachePtr->point.y < labelcache->gutter || cachePtr->point.x >= image->width - labelcache->gutter || cachePtr->point.y >= image->height - labelcache->gutter) { - /* don't look for leaders if point is in edge buffer as the leader line would end up chopped off */ + /* don't look for leaders if point is in edge buffer as the leader line + * would end up chopped off */ continue; } - for(i=0; inumtextsymbols; i++) { + for (i = 0; i < cachePtr->numtextsymbols; i++) { int j; textSymbolObj *ts = cachePtr->textsymbols[i]; - if(ts->textpath && ts->textpath->bounds.poly) { - num_scratch_points_to_allocate = MS_MAX(num_scratch_points_to_allocate, ts->textpath->bounds.poly->numpoints); + if (ts->textpath && ts->textpath->bounds.poly) { + num_scratch_points_to_allocate = + MS_MAX(num_scratch_points_to_allocate, + ts->textpath->bounds.poly->numpoints); } - if(ts->style_bounds) { - for(j=0;jlabel->numstyles; j++) { - if(ts->label->styles[j]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT && + if (ts->style_bounds) { + for (j = 0; j < ts->label->numstyles; j++) { + if (ts->label->styles[j]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT && ts->style_bounds[j]->poly) { - num_scratch_points_to_allocate = MS_MAX(num_scratch_points_to_allocate, ts->style_bounds[j]->poly->numpoints); + num_scratch_points_to_allocate = + MS_MAX(num_scratch_points_to_allocate, + ts->style_bounds[j]->poly->numpoints); } } } } - if(num_scratch_points_to_allocate > num_allocated_scratch_points) { - scratch_points = msSmallRealloc(scratch_points, num_scratch_points_to_allocate * sizeof(pointObj)); + if (num_scratch_points_to_allocate > num_allocated_scratch_points) { + scratch_points = msSmallRealloc( + scratch_points, num_scratch_points_to_allocate * sizeof(pointObj)); num_allocated_scratch_points = num_scratch_points_to_allocate; } - steps = classPtr->leader->maxdistance / classPtr->leader->gridstep; #define x0 (cachePtr->point.x) #define y0 (cachePtr->point.y) #define gridstepsc (classPtr->leader->gridstep) - -#define otest(ox,oy) if((x0+(ox)) >= labelcache->gutter &&\ - (y0+(oy)) >= labelcache->gutter &&\ - (x0+(ox)) < image->width - labelcache->gutter &&\ - (y0+(oy)) < image->height - labelcache->gutter) {\ - scratch_line.point = scratch_points;\ - scratch.poly = &scratch_line; \ - offsetAndTest(map,cachePtr,(ox),(oy),priority,l,&scratch); \ - if(cachePtr->status == MS_ON) break;\ - } +#define otest(ox, oy) \ + if ((x0 + (ox)) >= labelcache->gutter && \ + (y0 + (oy)) >= labelcache->gutter && \ + (x0 + (ox)) < image->width - labelcache->gutter && \ + (y0 + (oy)) < image->height - labelcache->gutter) { \ + scratch_line.point = scratch_points; \ + scratch.poly = &scratch_line; \ + offsetAndTest(map, cachePtr, (ox), (oy), priority, l, &scratch); \ + if (cachePtr->status == MS_ON) \ + break; \ + } /* loop through possible offsetted positions */ - for(i=1; i<=steps; i++) { - - - + for (i = 1; i <= steps; i++) { /* test the intermediate points on the ring */ @@ -2696,27 +3037,27 @@ int msDrawOffsettedLabels(imageObj *image, mapObj *map, int priority) X00X00X */ int j; - for(j=1; jstatus == MS_ON) { + if (cachePtr->status == MS_ON) { int ll; - shapeObj labelLeader; /* label polygon (bounding box, possibly rotated) */ - labelLeader.line = cachePtr->leaderline; /* setup the label polygon structure */ + shapeObj + labelLeader; /* label polygon (bounding box, possibly rotated) */ + labelLeader.line = + cachePtr->leaderline; /* setup the label polygon structure */ labelLeader.numlines = 1; insertRenderedLabelMember(map, cachePtr); - for(ll=0; llleader->numstyles; ll++) { - retval = msDrawLineSymbol(map, image,&labelLeader , classPtr->leader->styles[ll], layerPtr->scalefactor); - if(MS_UNLIKELY(retval == MS_FAILURE)) { + for (ll = 0; ll < classPtr->leader->numstyles; ll++) { + retval = msDrawLineSymbol(map, image, &labelLeader, + classPtr->leader->styles[ll], + layerPtr->scalefactor); + if (MS_UNLIKELY(retval == MS_FAILURE)) { goto offset_cleanup; } } - for(ll=0; llnumtextsymbols; ll++) { + for (ll = 0; ll < cachePtr->numtextsymbols; ll++) { textSymbolObj *ts = cachePtr->textsymbols[ll]; - if(ts->style_bounds) { + if (ts->style_bounds) { /* here's where we draw the label styles */ - for(i=0; ilabel->numstyles; i++) { - if(ts->label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { - retval = msDrawMarkerSymbol(map, image, &(labelLeader.line->point[1]), ts->label->styles[i], layerPtr->scalefactor); - if(MS_UNLIKELY(retval == MS_FAILURE)) { + for (i = 0; i < ts->label->numstyles; i++) { + if (ts->label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT) { + retval = msDrawMarkerSymbol( + map, image, &(labelLeader.line->point[1]), + ts->label->styles[i], layerPtr->scalefactor); + if (MS_UNLIKELY(retval == MS_FAILURE)) { goto offset_cleanup; } - } else if(ts->label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) { - retval = msDrawLabelBounds(map,image,ts->style_bounds[i],ts->label->styles[i], ts->scalefactor); - if(MS_UNLIKELY(retval == MS_FAILURE)) { + } else if (ts->label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOLY) { + retval = + msDrawLabelBounds(map, image, ts->style_bounds[i], + ts->label->styles[i], ts->scalefactor); + if (MS_UNLIKELY(retval == MS_FAILURE)) { goto offset_cleanup; } - } else if(ts->label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELCENTER) { + } else if (ts->label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELCENTER) { pointObj labelCenter; - labelCenter.x = (ts->style_bounds[i]->bbox.maxx + ts->style_bounds[i]->bbox.minx)/2; - labelCenter.y = (ts->style_bounds[i]->bbox.maxy + ts->style_bounds[i]->bbox.miny)/2; - retval = msDrawMarkerSymbol(map, image, &labelCenter, ts->label->styles[i], layerPtr->scalefactor); - if(MS_UNLIKELY(retval == MS_FAILURE)) { + labelCenter.x = (ts->style_bounds[i]->bbox.maxx + + ts->style_bounds[i]->bbox.minx) / + 2; + labelCenter.y = (ts->style_bounds[i]->bbox.maxy + + ts->style_bounds[i]->bbox.miny) / + 2; + retval = msDrawMarkerSymbol(map, image, &labelCenter, + ts->label->styles[i], + layerPtr->scalefactor); + if (MS_UNLIKELY(retval == MS_FAILURE)) { goto offset_cleanup; } } else { - msSetError(MS_MISCERR,"Labels only support LABELPNT, LABELPOLY and LABELCENTER GEOMTRANSFORMS", "msDrawOffsettedLabels()"); + msSetError(MS_MISCERR, + "Labels only support LABELPNT, LABELPOLY and " + "LABELCENTER GEOMTRANSFORMS", + "msDrawOffsettedLabels()"); retval = MS_FAILURE; } } } - if(ts->annotext) { - retval = msDrawTextSymbol(map,image,ts->annopoint,ts); - if(MS_UNLIKELY(retval == MS_FAILURE)) { + if (ts->annotext) { + retval = msDrawTextSymbol(map, image, ts->annopoint, ts); + if (MS_UNLIKELY(retval == MS_FAILURE)) { goto offset_cleanup; } } @@ -2839,9 +3200,9 @@ int msDrawOffsettedLabels(imageObj *image, mapObj *map, int priority) tstyle.color.red = random()%255; tstyle.color.green = random()%255; tstyle.color.blue =random()%255; - msDrawLineSymbol(&map->symbolset, image, cachePtr->poly, &tstyle, layerPtr->scalefactor); + msDrawLineSymbol(&map->symbolset, image, cachePtr->poly, &tstyle, + layerPtr->scalefactor); */ - } } } @@ -2850,18 +3211,15 @@ int msDrawOffsettedLabels(imageObj *image, mapObj *map, int priority) free(scratch_points); - return retval; } -void fastComputeBounds(lineObj *line, rectObj *bounds) -{ +void fastComputeBounds(lineObj *line, rectObj *bounds) { int j; bounds->minx = bounds->maxx = line->point[0].x; bounds->miny = bounds->maxy = line->point[0].y; - - for( j=0; jnumpoints; j++ ) { + for (j = 0; j < line->numpoints; j++) { bounds->minx = MS_MIN(bounds->minx, line->point[j].x); bounds->maxx = MS_MAX(bounds->maxx, line->point[j].x); bounds->miny = MS_MIN(bounds->miny, line->point[j].y); @@ -2869,35 +3227,36 @@ void fastComputeBounds(lineObj *line, rectObj *bounds) } } -int computeMarkerBounds(mapObj *map, pointObj *annopoint, textSymbolObj *ts, label_bounds *poly) -{ +int computeMarkerBounds(mapObj *map, pointObj *annopoint, textSymbolObj *ts, + label_bounds *poly) { int i; - for (i=0; ilabel->numstyles; i++) { + for (i = 0; i < ts->label->numstyles; i++) { styleObj *style = ts->label->styles[i]; - if(style->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT && + if (style->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT && style->symbol < map->symbolset.numsymbols && style->symbol >= 0) { - double sx,sy; + double sx, sy; int p; - double aox,aoy; + double aox, aoy; symbolObj *symbol = map->symbolset.symbol[style->symbol]; - if(msGetMarkerSize(map, style, &sx, &sy, ts->scalefactor) != MS_SUCCESS) - return -1; /* real error, different from MS_FALSE, return -1 so we can trap it */ - if(style->angle) { + if (msGetMarkerSize(map, style, &sx, &sy, ts->scalefactor) != MS_SUCCESS) + return -1; /* real error, different from MS_FALSE, return -1 so we can + trap it */ + if (style->angle) { pointObj *point = poly->poly->point; point[0].x = sx / 2.0; point[0].y = sy / 2.0; - point[1].x = point[0].x; + point[1].x = point[0].x; point[1].y = -point[0].y; point[2].x = -point[0].x; point[2].y = -point[0].y; point[3].x = -point[0].x; - point[3].y = point[0].y; - point[4].x = point[0].x; - point[4].y = point[0].y; - if(symbol->anchorpoint_x != 0.5 || symbol->anchorpoint_y != 0.5) { + point[3].y = point[0].y; + point[4].x = point[0].x; + point[4].y = point[0].y; + if (symbol->anchorpoint_x != 0.5 || symbol->anchorpoint_y != 0.5) { aox = (0.5 - symbol->anchorpoint_x) * sx; aoy = (0.5 - symbol->anchorpoint_y) * sy; - for(p=0; p<5; p++) { + for (p = 0; p < 5; p++) { point[p].x += aox; point[p].y += aoy; } @@ -2906,7 +3265,7 @@ int computeMarkerBounds(mapObj *map, pointObj *annopoint, textSymbolObj *ts, lab double rot = -style->angle * MS_DEG_TO_RAD; double sina = sin(rot); double cosa = cos(rot); - for(p=0; p<5; p++) { + for (p = 0; p < 5; p++) { double tmpx = point[p].x; point[p].x = point[p].x * cosa - point[p].y * sina; point[p].y = tmpx * sina + point[p].y * cosa; @@ -2914,35 +3273,35 @@ int computeMarkerBounds(mapObj *map, pointObj *annopoint, textSymbolObj *ts, lab } aox = annopoint->x + style->offsetx * ts->scalefactor; aoy = annopoint->y + style->offsety * ts->scalefactor; - for(p=0; p<5; p++) { + for (p = 0; p < 5; p++) { point[p].x += aox; point[p].y += aoy; } - fastComputeBounds(poly->poly,&poly->bbox); + fastComputeBounds(poly->poly, &poly->bbox); } else { - double aox = (0.5 - symbol->anchorpoint_x)*sx + annopoint->x + style->offsetx * ts->scalefactor; - double aoy = (0.5 - symbol->anchorpoint_y)*sy + annopoint->y + style->offsety * ts->scalefactor; + double aox = (0.5 - symbol->anchorpoint_x) * sx + annopoint->x + + style->offsetx * ts->scalefactor; + double aoy = (0.5 - symbol->anchorpoint_y) * sy + annopoint->y + + style->offsety * ts->scalefactor; poly->poly = NULL; - poly->bbox.maxx = sx/2.0 + aox; - poly->bbox.minx = -sx/2.0 + aox; - poly->bbox.maxy = sy/2.0 + aoy; - poly->bbox.miny = -sy/2.0 + aoy; + poly->bbox.maxx = sx / 2.0 + aox; + poly->bbox.minx = -sx / 2.0 + aox; + poly->bbox.maxy = sy / 2.0 + aoy; + poly->bbox.miny = -sy / 2.0 + aoy; } break; } } - if(i == ts->label->numstyles) + if (i == ts->label->numstyles) return MS_FALSE; /* the label has no marker styles */ else return MS_TRUE; } +/* check that the current entry does not fall close to a label with identical + * text, if configured so. Currently only checks the first label/text */ -/* check that the current entry does not fall close to a label with identical text, if configured so. - * Currently only checks the first label/text */ - -int msCheckLabelMinDistance(mapObj *map, labelCacheMemberObj *lc) -{ +int msCheckLabelMinDistance(mapObj *map, labelCacheMemberObj *lc) { int i; textSymbolObj *s; /* shortcut */ textSymbolObj *ts; @@ -2951,13 +3310,14 @@ int msCheckLabelMinDistance(mapObj *map, labelCacheMemberObj *lc) return MS_FALSE; /* no label with text */ s = lc->textsymbols[0]; - if (!s->annotext || s->label->mindistance <= 0.0 || s->label->force == MS_TRUE) + if (!s->annotext || s->label->mindistance <= 0.0 || + s->label->force == MS_TRUE) return MS_FALSE; /* min distance is not checked */ /* we buffer the label and check for intersection instead of calculating - the distance of two textpaths. we also buffer only the bbox of lc for + the distance of two textpaths. we also buffer only the bbox of lc for faster computation (it is still compared to the full textpath - of the label cache members). + of the label cache members). */ buffered = lc->bbox; buffered.minx -= s->label->mindistance * s->resolutionfactor; @@ -2968,7 +3328,7 @@ int msCheckLabelMinDistance(mapObj *map, labelCacheMemberObj *lc) for (i = 0; i < map->labelcache.num_rendered_members; i++) { labelCacheMemberObj *ilc = map->labelcache.rendered_text_symbols[i]; if (ilc->numtextsymbols == 0 || !ilc->textsymbols[0]->annotext) - continue; + continue; ts = ilc->textsymbols[0]; if (strcmp(s->annotext, ts->annotext) != 0) { @@ -2980,66 +3340,74 @@ int msCheckLabelMinDistance(mapObj *map, labelCacheMemberObj *lc) return MS_TRUE; } - if(ts->textpath && ts->textpath->absolute) { - if (intersectLabelPolygons(ts->textpath->bounds.poly, &ilc->bbox, NULL, &buffered) == MS_TRUE) { + if (ts->textpath && ts->textpath->absolute) { + if (intersectLabelPolygons(ts->textpath->bounds.poly, &ilc->bbox, NULL, + &buffered) == MS_TRUE) { return MS_TRUE; } continue; } - if (intersectLabelPolygons(NULL, &ilc->bbox, NULL, &buffered) == MS_TRUE) { - return MS_TRUE; + return MS_TRUE; } - } return MS_FALSE; } void copyLabelBounds(label_bounds *dst, label_bounds *src) { *dst = *src; - if(src->poly) { + if (src->poly) { int i; dst->poly = msSmallMalloc(sizeof(lineObj)); dst->poly->numpoints = src->poly->numpoints; dst->poly->point = msSmallMalloc(dst->poly->numpoints * sizeof(pointObj)); - for(i=0; ipoly->numpoints; i++) { + for (i = 0; i < dst->poly->numpoints; i++) { dst->poly->point[i] = src->poly->point[i]; } } } static int getLabelPositionFromString(char *pszString) { - if (strcasecmp(pszString, "UL")==0) return MS_UL; - else if (strcasecmp(pszString, "LR")==0) return MS_LR; - else if (strcasecmp(pszString, "UR")==0) return MS_UR; - else if (strcasecmp(pszString, "LL")==0) return MS_LL; - else if (strcasecmp(pszString, "CR")==0) return MS_CR; - else if (strcasecmp(pszString, "CL")==0) return MS_CL; - else if (strcasecmp(pszString, "UC")==0) return MS_UC; - else if (strcasecmp(pszString, "LC")==0) return MS_LC; - else return MS_CC; + if (strcasecmp(pszString, "UL") == 0) + return MS_UL; + else if (strcasecmp(pszString, "LR") == 0) + return MS_LR; + else if (strcasecmp(pszString, "UR") == 0) + return MS_UR; + else if (strcasecmp(pszString, "LL") == 0) + return MS_LL; + else if (strcasecmp(pszString, "CR") == 0) + return MS_CR; + else if (strcasecmp(pszString, "CL") == 0) + return MS_CL; + else if (strcasecmp(pszString, "UC") == 0) + return MS_UC; + else if (strcasecmp(pszString, "LC") == 0) + return MS_LC; + else + return MS_CC; } -int msDrawLabelCache(mapObj *map, imageObj *image) -{ +int msDrawLabelCache(mapObj *map, imageObj *image) { int nReturnVal = MS_SUCCESS; - struct mstimeval starttime={0}, endtime={0}; + struct mstimeval starttime = {0}, endtime = {0}; - if(map->debug >= MS_DEBUGLEVEL_TUNING) msGettimeofday(&starttime, NULL); + if (map->debug >= MS_DEBUGLEVEL_TUNING) + msGettimeofday(&starttime, NULL); - if(image) { - if(MS_RENDERER_PLUGIN(image->format)) { + if (image) { + if (MS_RENDERER_PLUGIN(image->format)) { int i, l, ll, priority, its; double marker_offset_x, marker_offset_y; int label_offset_x, label_offset_y; const char *value; - labelCacheMemberObj *cachePtr=NULL; - layerObj *layerPtr=NULL; - classObj *classPtr=NULL; - textSymbolObj *textSymbolPtr=NULL; + labelCacheMemberObj *cachePtr = NULL; + layerObj *layerPtr = NULL; + classObj *classPtr = NULL; + textSymbolObj *textSymbolPtr = NULL; /* * some statically allocated containers for storing label bounds before @@ -3049,7 +3417,7 @@ int msDrawLabelCache(mapObj *map, imageObj *image) lineObj labelpoly_line; pointObj labelpoly_points[5]; label_bounds labelpoly_bounds = {0}; - lineObj label_marker_line; + lineObj label_marker_line; pointObj label_marker_points[5]; label_bounds label_marker_bounds; lineObj metrics_line; @@ -3064,365 +3432,545 @@ int msDrawLabelCache(mapObj *map, imageObj *image) labelpoly_line.numpoints = 5; /* Look for labelcache_map_edge_buffer map metadata - * If set then the value defines a buffer (in pixels) along the edge of the - * map image where labels can't fall + * If set then the value defines a buffer (in pixels) along the edge of + * the map image where labels can't fall */ - if((value = msLookupHashTable(&(map->web.metadata), "labelcache_map_edge_buffer")) != NULL) { + if ((value = msLookupHashTable(&(map->web.metadata), + "labelcache_map_edge_buffer")) != NULL) { map->labelcache.gutter = MS_ABS(atoi(value)); - if(map->debug) msDebug("msDrawLabelCache(): labelcache_map_edge_buffer = %d\n", map->labelcache.gutter); + if (map->debug) + msDebug("msDrawLabelCache(): labelcache_map_edge_buffer = %d\n", + map->labelcache.gutter); } - for(priority=MS_MAX_LABEL_PRIORITY-1; priority>=0; priority--) { + for (priority = MS_MAX_LABEL_PRIORITY - 1; priority >= 0; priority--) { labelCacheSlotObj *cacheslot; cacheslot = &(map->labelcache.slots[priority]); - for(l=cacheslot->numlabels-1; l>=0; l--) { - cachePtr = &(cacheslot->labels[l]); /* point to right spot in the label cache */ + for (l = cacheslot->numlabels - 1; l >= 0; l--) { + cachePtr = + &(cacheslot + ->labels[l]); /* point to right spot in the label cache */ - layerPtr = (GET_LAYER(map, cachePtr->layerindex)); /* set a couple of other pointers, avoids nasty references */ - classPtr = (GET_CLASS(map, cachePtr->layerindex, cachePtr->classindex)); + layerPtr = (GET_LAYER( + map, cachePtr->layerindex)); /* set a couple of other pointers, + avoids nasty references */ + classPtr = + (GET_CLASS(map, cachePtr->layerindex, cachePtr->classindex)); - if(cachePtr->textsymbols[0]->textpath && cachePtr->textsymbols[0]->textpath->absolute) { + if (cachePtr->textsymbols[0]->textpath && + cachePtr->textsymbols[0]->textpath->absolute) { /* we have an angle follow label */ cachePtr->bbox = cachePtr->textsymbols[0]->textpath->bounds.bbox; /* before going any futher, check that mindistance is respected */ - if (cachePtr->numtextsymbols && cachePtr->textsymbols[0]->label->mindistance > 0.0 && cachePtr->textsymbols[0]->annotext) { + if (cachePtr->numtextsymbols && + cachePtr->textsymbols[0]->label->mindistance > 0.0 && + cachePtr->textsymbols[0]->annotext) { if (msCheckLabelMinDistance(map, cachePtr) == MS_TRUE) { cachePtr->status = MS_DELETE; MS_DEBUG(MS_DEBUGLEVEL_DEVDEBUG, map, - "Skipping labelgroup %d \"%s\" in layer \"%s\": too close to an identical label (mindistance)\n", - l, cachePtr->textsymbols[0]->annotext, layerPtr->name); - continue; /* move on to next entry, this one is too close to an already placed one */ + "Skipping labelgroup %d \"%s\" in layer \"%s\": too " + "close to an identical label (mindistance)\n", + l, cachePtr->textsymbols[0]->annotext, layerPtr->name); + continue; /* move on to next entry, this one is too close to an + already placed one */ } } - if(!cachePtr->textsymbols[0]->label->force) - cachePtr->status = msTestLabelCacheCollisions(map,cachePtr,&cachePtr->textsymbols[0]->textpath->bounds, priority, l); + if (!cachePtr->textsymbols[0]->label->force) + cachePtr->status = msTestLabelCacheCollisions( + map, cachePtr, &cachePtr->textsymbols[0]->textpath->bounds, + priority, l); else cachePtr->status = MS_ON; - if(cachePtr->status) { - - - if (MS_UNLIKELY(MS_FAILURE == msDrawTextSymbol(map, image, cachePtr->textsymbols[0]->annopoint /*not used*/, cachePtr->textsymbols[0]))) - { + if (cachePtr->status) { + + if (MS_UNLIKELY( + MS_FAILURE == + msDrawTextSymbol( + map, image, + cachePtr->textsymbols[0]->annopoint /*not used*/, + cachePtr->textsymbols[0]))) { return MS_FAILURE; } insertRenderedLabelMember(map, cachePtr); } else { - MS_DEBUG(MS_DEBUGLEVEL_DEVDEBUG,map, - "Skipping follow labelgroup %d \"%s\" in layer \"%s\": text collided\n", - l, cachePtr->textsymbols[0]->annotext, layerPtr->name); + MS_DEBUG(MS_DEBUGLEVEL_DEVDEBUG, map, + "Skipping follow labelgroup %d \"%s\" in layer \"%s\": " + "text collided\n", + l, cachePtr->textsymbols[0]->annotext, layerPtr->name); } - cachePtr->status = MS_DELETE; /* we're done with this label, it won't even have a second chance in the leader phase */ + cachePtr->status = + MS_DELETE; /* we're done with this label, it won't even have a + second chance in the leader phase */ } else { marker_offset_x = marker_offset_y = 0; /* assume no marker */ - - if (layerPtr->type == MS_LAYER_POINT && cachePtr->markerid!=-1) { /* there is a marker already in the image that we need to account for */ - markerCacheMemberObj *markerPtr = &(cacheslot->markers[cachePtr->markerid]); /* point to the right spot in the marker cache*/ - marker_offset_x = (markerPtr->bounds.maxx-markerPtr->bounds.minx)/2.0; - marker_offset_y = (markerPtr->bounds.maxy-markerPtr->bounds.miny)/2.0; - } + if (layerPtr->type == MS_LAYER_POINT && + cachePtr->markerid != + -1) { /* there is a marker already in the image that we need + to account for */ + markerCacheMemberObj *markerPtr = &( + cacheslot + ->markers[cachePtr->markerid]); /* point to the right spot + in the marker cache*/ + marker_offset_x = + (markerPtr->bounds.maxx - markerPtr->bounds.minx) / 2.0; + marker_offset_y = + (markerPtr->bounds.maxy - markerPtr->bounds.miny) / 2.0; + } /* ** all other cases *could* have multiple labels defined */ - cachePtr->status = MS_ON; /* assume this cache element can be placed */ - for(ll=0; llnumtextsymbols; ll++) { /* RFC 77 TODO: Still may want to step through backwards... */ - int label_marker_status = MS_ON, have_label_marker, metrics_status = MS_ON; + cachePtr->status = + MS_ON; /* assume this cache element can be placed */ + for (ll = 0; ll < cachePtr->numtextsymbols; + ll++) { /* RFC 77 TODO: Still may want to step through + backwards... */ + int label_marker_status = MS_ON, have_label_marker, + metrics_status = MS_ON; int need_labelpoly = 0; - - /* reset the lineObj which may have been unset by a previous call to get_metrics() */ + + /* reset the lineObj which may have been unset by a previous call + * to get_metrics() */ label_marker_bounds.poly = &label_marker_line; labelpoly_bounds.poly = &labelpoly_line; textSymbolPtr = cachePtr->textsymbols[ll]; - for(i=0; ilabel->numstyles; i++) { - if(textSymbolPtr->label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY || - textSymbolPtr->label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELCENTER) { + for (i = 0; i < textSymbolPtr->label->numstyles; i++) { + if (textSymbolPtr->label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOLY || + textSymbolPtr->label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELCENTER) { need_labelpoly = 1; break; } } /* compute the poly of the label styles */ - if((have_label_marker = computeMarkerBounds(map,&cachePtr->point,textSymbolPtr, &label_marker_bounds)) == MS_TRUE) { - if(cachePtr->numtextsymbols > 1) { /* FIXME this test doesn't seem right, should probably check if we have an annotation layer with a regular style defined */ - marker_offset_x = (label_marker_bounds.bbox.maxx-label_marker_bounds.bbox.minx)/2.0; - marker_offset_y = (label_marker_bounds.bbox.maxy-label_marker_bounds.bbox.miny)/2.0; + if ((have_label_marker = + computeMarkerBounds(map, &cachePtr->point, textSymbolPtr, + &label_marker_bounds)) == MS_TRUE) { + if (cachePtr->numtextsymbols > + 1) { /* FIXME this test doesn't seem right, should probably + check if we have an annotation layer with a regular + style defined */ + marker_offset_x = (label_marker_bounds.bbox.maxx - + label_marker_bounds.bbox.minx) / + 2.0; + marker_offset_y = (label_marker_bounds.bbox.maxy - + label_marker_bounds.bbox.miny) / + 2.0; } else { /* we might be using an old style behavior with a markerPtr */ - marker_offset_x = MS_MAX(marker_offset_x,(label_marker_bounds.bbox.maxx-label_marker_bounds.bbox.minx)/2.0); - marker_offset_y = MS_MAX(marker_offset_y,(label_marker_bounds.bbox.maxy-label_marker_bounds.bbox.miny)/2.0); + marker_offset_x = + MS_MAX(marker_offset_x, (label_marker_bounds.bbox.maxx - + label_marker_bounds.bbox.minx) / + 2.0); + marker_offset_y = + MS_MAX(marker_offset_y, (label_marker_bounds.bbox.maxy - + label_marker_bounds.bbox.miny) / + 2.0); } /* add marker to cachePtr->poly */ - if(textSymbolPtr->label->force != MS_TRUE) { - label_marker_status = msTestLabelCacheCollisions(map, cachePtr, &label_marker_bounds ,priority, l); + if (textSymbolPtr->label->force != MS_TRUE) { + label_marker_status = msTestLabelCacheCollisions( + map, cachePtr, &label_marker_bounds, priority, l); } - if(label_marker_status == MS_OFF && - !(textSymbolPtr->label->force==MS_ON || classPtr->leader)) { + if (label_marker_status == MS_OFF && + !(textSymbolPtr->label->force == MS_ON || + classPtr->leader)) { cachePtr->status = MS_DELETE; MS_DEBUG(MS_DEBUGLEVEL_DEVDEBUG, map, - "Skipping label %d of labelgroup %d of class %d in layer \"%s\": marker collided\n", - ll, l, cachePtr->classindex, layerPtr->name); + "Skipping label %d of labelgroup %d of class %d in " + "layer \"%s\": marker collided\n", + ll, l, cachePtr->classindex, layerPtr->name); break; /* the marker collided, break from multi-label loop */ } } - if(have_label_marker == -1) return MS_FAILURE; /* error occured (symbol not found, etc...) */ + if (have_label_marker == -1) + return MS_FAILURE; /* error occured (symbol not found, etc...) + */ - if(textSymbolPtr->annotext) { + if (textSymbolPtr->annotext) { /* - * if we don't have an offset defined, first check that the labelpoint itself does not collide - * this helps speed things up in dense labelling, as if the labelpoint collides there's - * no use in computing the labeltext bounds (i.e. going into shaping+freetype). - * We do however skip collision testing against the marker cache, as we want to allow rendering - * a label for points that overlap each other: this is done by setting priority to MAX_PRIORITY - * in the call to msTestLabelCacheCollisions (which is a hack!!) + * if we don't have an offset defined, first check that the + * labelpoint itself does not collide this helps speed things up + * in dense labelling, as if the labelpoint collides there's no + * use in computing the labeltext bounds (i.e. going into + * shaping+freetype). We do however skip collision testing + * against the marker cache, as we want to allow rendering a + * label for points that overlap each other: this is done by + * setting priority to MAX_PRIORITY in the call to + * msTestLabelCacheCollisions (which is a hack!!) */ - if(!have_label_marker && textSymbolPtr->label->force != MS_TRUE && !classPtr->leader && - !textSymbolPtr->label->offsetx && !textSymbolPtr->label->offsety) { + if (!have_label_marker && + textSymbolPtr->label->force != MS_TRUE && + !classPtr->leader && !textSymbolPtr->label->offsetx && + !textSymbolPtr->label->offsety) { label_bounds labelpoint_bounds; labelpoint_bounds.poly = NULL; labelpoint_bounds.bbox.minx = cachePtr->point.x - 0.1; labelpoint_bounds.bbox.maxx = cachePtr->point.x + 0.1; labelpoint_bounds.bbox.miny = cachePtr->point.y - 0.1; labelpoint_bounds.bbox.maxy = cachePtr->point.y + 0.1; - if(MS_OFF == msTestLabelCacheCollisions(map, cachePtr, &labelpoint_bounds, MS_MAX_LABEL_PRIORITY, l)) { - cachePtr->status = MS_DELETE; /* we won't check for leader offseted positions, as the anchor point colided */ + if (MS_OFF == msTestLabelCacheCollisions( + map, cachePtr, &labelpoint_bounds, + MS_MAX_LABEL_PRIORITY, l)) { + cachePtr->status = + MS_DELETE; /* we won't check for leader offseted + positions, as the anchor point colided */ MS_DEBUG(MS_DEBUGLEVEL_DEVDEBUG, map, - "Skipping label %d \"%s\" of labelgroup %d of class %d in layer \"%s\": labelpoint collided\n", - ll, textSymbolPtr->annotext, l, cachePtr->classindex, layerPtr->name); + "Skipping label %d \"%s\" of labelgroup %d of " + "class %d in layer \"%s\": labelpoint collided\n", + ll, textSymbolPtr->annotext, l, + cachePtr->classindex, layerPtr->name); break; } } /* compute label size */ - if(!textSymbolPtr->textpath) { - if(MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map,textSymbolPtr))) { + if (!textSymbolPtr->textpath) { + if (MS_UNLIKELY(MS_FAILURE == + msComputeTextPath(map, textSymbolPtr))) { return MS_FAILURE; } } - /* if our label has an outline, adjust the marker offset so the outlinecolor does - * not bleed into the marker */ - if(marker_offset_x && MS_VALID_COLOR(textSymbolPtr->label->outlinecolor)) { - marker_offset_x += textSymbolPtr->label->outlinewidth/2.0 * textSymbolPtr->scalefactor; - marker_offset_y += textSymbolPtr->label->outlinewidth/2.0 * textSymbolPtr->scalefactor; + /* if our label has an outline, adjust the marker offset so the + * outlinecolor does not bleed into the marker */ + if (marker_offset_x && + MS_VALID_COLOR(textSymbolPtr->label->outlinecolor)) { + marker_offset_x += textSymbolPtr->label->outlinewidth / 2.0 * + textSymbolPtr->scalefactor; + marker_offset_y += textSymbolPtr->label->outlinewidth / 2.0 * + textSymbolPtr->scalefactor; } - + /* apply offset and buffer settings */ - if(textSymbolPtr->label->anglemode != MS_FOLLOW) { - label_offset_x = textSymbolPtr->label->offsetx * textSymbolPtr->scalefactor; - label_offset_y = textSymbolPtr->label->offsety * textSymbolPtr-> scalefactor; + if (textSymbolPtr->label->anglemode != MS_FOLLOW) { + label_offset_x = textSymbolPtr->label->offsetx * + textSymbolPtr->scalefactor; + label_offset_y = textSymbolPtr->label->offsety * + textSymbolPtr->scalefactor; } else { label_offset_x = 0; label_offset_y = 0; } - if(textSymbolPtr->label->position == MS_AUTO) { - /* no point in using auto positionning if the marker cannot be placed */ - int positions[MS_POSITIONS_LENGTH], npositions=0; - + if (textSymbolPtr->label->position == MS_AUTO) { + /* no point in using auto positionning if the marker cannot be + * placed */ + int positions[MS_POSITIONS_LENGTH], npositions = 0; + /* ** (Note: might be able to re-order this for more speed.) */ - if(msLayerGetProcessingKey(layerPtr, "LABEL_POSITIONS")) { - int p, ncustom_positions=0; - char **custom_positions = msStringSplitComplex(msLayerGetProcessingKey(layerPtr, "LABEL_POSITIONS"), ",", &ncustom_positions, MS_STRIPLEADSPACES|MS_STRIPENDSPACES); - for(p=0; ptype == MS_LAYER_POLYGON && marker_offset_x==0 ) { - positions[0]=MS_CC; - positions[1]=MS_UC; - positions[2]=MS_LC; - positions[3]=MS_CL; - positions[4]=MS_CR; + } else if (layerPtr->type == MS_LAYER_POLYGON && + marker_offset_x == 0) { + positions[0] = MS_CC; + positions[1] = MS_UC; + positions[2] = MS_LC; + positions[3] = MS_CL; + positions[4] = MS_CR; npositions = 5; - } else if(layerPtr->type == MS_LAYER_LINE && marker_offset_x == 0) { - positions[0]=MS_UC; - positions[1]=MS_LC; - positions[2]=MS_CC; + } else if (layerPtr->type == MS_LAYER_LINE && + marker_offset_x == 0) { + positions[0] = MS_UC; + positions[1] = MS_LC; + positions[2] = MS_CC; npositions = 3; } else { - positions[0]=MS_UL; - positions[1]=MS_LR; - positions[2]=MS_UR; - positions[3]=MS_LL; - positions[4]=MS_CR; - positions[5]=MS_CL; - positions[6]=MS_UC; - positions[7]=MS_LC; + positions[0] = MS_UL; + positions[1] = MS_LR; + positions[2] = MS_UR; + positions[3] = MS_LL; + positions[4] = MS_CR; + positions[5] = MS_CL; + positions[6] = MS_UC; + positions[7] = MS_LC; npositions = 8; } - for(i=0; iannopoint = get_metrics(&(cachePtr->point), positions[i], textSymbolPtr->textpath, - marker_offset_x + label_offset_x, marker_offset_y + label_offset_y, - textSymbolPtr->rotation, textSymbolPtr->label->buffer * textSymbolPtr->scalefactor, &metrics_bounds); - if(textSymbolPtr->label->force == MS_OFF) { - for(its=0;itsannopoint = + get_metrics(&(cachePtr->point), positions[i], + textSymbolPtr->textpath, + marker_offset_x + label_offset_x, + marker_offset_y + label_offset_y, + textSymbolPtr->rotation, + textSymbolPtr->label->buffer * + textSymbolPtr->scalefactor, + &metrics_bounds); + if (textSymbolPtr->label->force == MS_OFF) { + for (its = 0; its < ll; its++) { /* check for collisions inside the label group */ - if(intersectTextSymbol(cachePtr->textsymbols[its],&metrics_bounds) == MS_TRUE) { + if (intersectTextSymbol(cachePtr->textsymbols[its], + &metrics_bounds) == MS_TRUE) { /* there was a self intersection */ - break; /* next position, will break out to next position in containing loop*/ + break; /* next position, will break out to next + position in containing loop*/ } - if(its != ll) - continue; /* goto next position, this one had an intersection with our own label group */ + if (its != ll) + continue; /* goto next position, this one had an + intersection with our own label group */ } } - metrics_status = msTestLabelCacheCollisions(map, cachePtr,&metrics_bounds, priority, l); + metrics_status = msTestLabelCacheCollisions( + map, cachePtr, &metrics_bounds, priority, l); /* found a suitable place for this label */ - if(metrics_status == MS_TRUE || (i==(npositions-1) && textSymbolPtr->label->force == MS_ON)) { - metrics_status = MS_TRUE; /* set to true in case we are forcing it */ + if (metrics_status == MS_TRUE || + (i == (npositions - 1) && + textSymbolPtr->label->force == MS_ON)) { + metrics_status = + MS_TRUE; /* set to true in case we are forcing it */ /* compute anno poly for label background if needed */ - if(need_labelpoly) get_metrics(&(cachePtr->point), positions[i], textSymbolPtr->textpath, - marker_offset_x + label_offset_x, marker_offset_y + label_offset_y, - textSymbolPtr->rotation, 1, &labelpoly_bounds); + if (need_labelpoly) + get_metrics(&(cachePtr->point), positions[i], + textSymbolPtr->textpath, + marker_offset_x + label_offset_x, + marker_offset_y + label_offset_y, + textSymbolPtr->rotation, 1, + &labelpoly_bounds); break; /* ...out of position loop */ } } /* next position */ - /* if position auto didn't manage to find a position, but we have leader configured - * for the class, then we want to compute the label poly anyway, placed as MS_CC */ - if(classPtr->leader && metrics_status == MS_FALSE) { + /* if position auto didn't manage to find a position, but we + * have leader configured for the class, then we want to + * compute the label poly anyway, placed as MS_CC */ + if (classPtr->leader && metrics_status == MS_FALSE) { metrics_bounds.poly = &metrics_line; - textSymbolPtr->annopoint = get_metrics(&(cachePtr->point), MS_CC, textSymbolPtr->textpath, label_offset_x, label_offset_y, - textSymbolPtr->rotation, textSymbolPtr->label->buffer * textSymbolPtr->scalefactor, - &metrics_bounds); - if(need_labelpoly) get_metrics(&(cachePtr->point), MS_CC, textSymbolPtr->textpath, - label_offset_x, label_offset_y, - textSymbolPtr->rotation, 1, &labelpoly_bounds); + textSymbolPtr->annopoint = get_metrics( + &(cachePtr->point), MS_CC, textSymbolPtr->textpath, + label_offset_x, label_offset_y, textSymbolPtr->rotation, + textSymbolPtr->label->buffer * + textSymbolPtr->scalefactor, + &metrics_bounds); + if (need_labelpoly) + get_metrics(&(cachePtr->point), MS_CC, + textSymbolPtr->textpath, label_offset_x, + label_offset_y, textSymbolPtr->rotation, 1, + &labelpoly_bounds); } } else { /* explicit position */ - if(textSymbolPtr->label->position == MS_CC) { /* don't need the marker_offset */ + if (textSymbolPtr->label->position == + MS_CC) { /* don't need the marker_offset */ metrics_bounds.poly = &metrics_line; - textSymbolPtr->annopoint = get_metrics(&(cachePtr->point), MS_CC, textSymbolPtr->textpath, label_offset_x, label_offset_y, - textSymbolPtr->rotation, textSymbolPtr->label->buffer * textSymbolPtr->scalefactor, &metrics_bounds); - if(need_labelpoly) get_metrics(&(cachePtr->point), MS_CC, textSymbolPtr->textpath, - label_offset_x, label_offset_y, textSymbolPtr->rotation, 1, &labelpoly_bounds); + textSymbolPtr->annopoint = get_metrics( + &(cachePtr->point), MS_CC, textSymbolPtr->textpath, + label_offset_x, label_offset_y, textSymbolPtr->rotation, + textSymbolPtr->label->buffer * + textSymbolPtr->scalefactor, + &metrics_bounds); + if (need_labelpoly) + get_metrics(&(cachePtr->point), MS_CC, + textSymbolPtr->textpath, label_offset_x, + label_offset_y, textSymbolPtr->rotation, 1, + &labelpoly_bounds); } else { metrics_bounds.poly = &metrics_line; - textSymbolPtr->annopoint = get_metrics(&(cachePtr->point), textSymbolPtr->label->position, textSymbolPtr->textpath, - marker_offset_x + label_offset_x, marker_offset_y + label_offset_y, - textSymbolPtr->rotation, textSymbolPtr->label->buffer * textSymbolPtr->scalefactor, - &metrics_bounds); - if(need_labelpoly) get_metrics(&(cachePtr->point), textSymbolPtr->label->position, textSymbolPtr->textpath, - marker_offset_x + label_offset_x, marker_offset_y + label_offset_y, textSymbolPtr->rotation, 1, &labelpoly_bounds); + textSymbolPtr->annopoint = get_metrics( + &(cachePtr->point), textSymbolPtr->label->position, + textSymbolPtr->textpath, + marker_offset_x + label_offset_x, + marker_offset_y + label_offset_y, + textSymbolPtr->rotation, + textSymbolPtr->label->buffer * + textSymbolPtr->scalefactor, + &metrics_bounds); + if (need_labelpoly) + get_metrics( + &(cachePtr->point), textSymbolPtr->label->position, + textSymbolPtr->textpath, + marker_offset_x + label_offset_x, + marker_offset_y + label_offset_y, + textSymbolPtr->rotation, 1, &labelpoly_bounds); } - if(textSymbolPtr->label->force == MS_ON) { + if (textSymbolPtr->label->force == MS_ON) { metrics_status = MS_ON; } else { - if(textSymbolPtr->label->force == MS_OFF) { - /* check for collisions inside the label group unless the label is FORCE GROUP */ - for(its=0;itslabel->force == MS_OFF) { + /* check for collisions inside the label group unless the + * label is FORCE GROUP */ + for (its = 0; its < ll; its++) { /* check for collisions inside the label group */ - if(intersectTextSymbol(cachePtr->textsymbols[its],&metrics_bounds) == MS_TRUE) { + if (intersectTextSymbol(cachePtr->textsymbols[its], + &metrics_bounds) == MS_TRUE) { /* there was a self intersection */ - break; /* will break out to next position in containing loop*/ + break; /* will break out to next position in + containing loop*/ } - if(its != ll) { - cachePtr->status = MS_DELETE; /* TODO RFC98: check if this is correct */ - MS_DEBUG(MS_DEBUGLEVEL_DEVDEBUG,map, - "Skipping label %d (\"%s\") of labelgroup %d of class %d in layer \"%s\": intercollision with label text inside labelgroup\n", - ll, textSymbolPtr->annotext, l,cachePtr->classindex, layerPtr->name); - break; /* collision within the group, break out of textSymbol loop */ + if (its != ll) { + cachePtr->status = MS_DELETE; /* TODO RFC98: check if + this is correct */ + MS_DEBUG( + MS_DEBUGLEVEL_DEVDEBUG, map, + "Skipping label %d (\"%s\") of labelgroup %d of " + "class %d in layer \"%s\": intercollision with " + "label text inside labelgroup\n", + ll, textSymbolPtr->annotext, l, + cachePtr->classindex, layerPtr->name); + break; /* collision within the group, break out of + textSymbol loop */ } } } - /* TODO: in case we have leader lines and multiple labels, there's no use in testing for labelcache collisions - * once a first collision has been found. we only need to know that the label group has collided, and the - * poly of the whole label group: if(label_group) testLabelCacheCollisions */ - metrics_status = msTestLabelCacheCollisions(map, cachePtr,&metrics_bounds, priority, l); + /* TODO: in case we have leader lines and multiple labels, + * there's no use in testing for labelcache collisions once + * a first collision has been found. we only need to know + * that the label group has collided, and the poly of the + * whole label group: if(label_group) + * testLabelCacheCollisions */ + metrics_status = msTestLabelCacheCollisions( + map, cachePtr, &metrics_bounds, priority, l); } } /* end POSITION AUTO vs Fixed POSITION */ - if(!metrics_status && classPtr->leader == 0) { + if (!metrics_status && classPtr->leader == 0) { cachePtr->status = MS_DELETE; - MS_DEBUG(MS_DEBUGLEVEL_DEVDEBUG,map, - "Skipping label %d \"%s\" of labelgroup %d of class %d in layer \"%s\": text collided\n", - ll, textSymbolPtr->annotext, l, cachePtr->classindex, layerPtr->name); - break; /* no point looking at more labels, unless their is a leader defined */ + MS_DEBUG(MS_DEBUGLEVEL_DEVDEBUG, map, + "Skipping label %d \"%s\" of labelgroup %d of class " + "%d in layer \"%s\": text collided\n", + ll, textSymbolPtr->annotext, l, cachePtr->classindex, + layerPtr->name); + break; /* no point looking at more labels, unless their is a + leader defined */ } } - /* if we're here, we can either fit the label directly, or we need to put it in the leader queue */ - assert((metrics_status && label_marker_status) || classPtr->leader); + /* if we're here, we can either fit the label directly, or we need + * to put it in the leader queue */ + assert((metrics_status && label_marker_status) || + classPtr->leader); - if(textSymbolPtr->annotext) { - copyLabelBounds(&textSymbolPtr->textpath->bounds, &metrics_bounds); + if (textSymbolPtr->annotext) { + copyLabelBounds(&textSymbolPtr->textpath->bounds, + &metrics_bounds); } - if(have_label_marker) { - if(!textSymbolPtr->style_bounds) - textSymbolPtr->style_bounds = msSmallCalloc(textSymbolPtr->label->numstyles, sizeof(label_bounds*)); - for(its=0;itslabel->numstyles; its++) { - if(textSymbolPtr->label->styles[its]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { - textSymbolPtr->style_bounds[its] = msSmallMalloc(sizeof(label_bounds)); - copyLabelBounds(textSymbolPtr->style_bounds[its], &label_marker_bounds); + if (have_label_marker) { + if (!textSymbolPtr->style_bounds) + textSymbolPtr->style_bounds = msSmallCalloc( + textSymbolPtr->label->numstyles, sizeof(label_bounds *)); + for (its = 0; its < textSymbolPtr->label->numstyles; its++) { + if (textSymbolPtr->label->styles[its]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT) { + textSymbolPtr->style_bounds[its] = + msSmallMalloc(sizeof(label_bounds)); + copyLabelBounds(textSymbolPtr->style_bounds[its], + &label_marker_bounds); } } } - if(!label_marker_status || ! metrics_status) { + if (!label_marker_status || !metrics_status) { MS_DEBUG(MS_DEBUGLEVEL_DEVDEBUG, map, - "Putting label %d of labelgroup %d of class %d , layer \"%s\" in leader queue\n", - ll, l, cachePtr->classindex, layerPtr->name); - cachePtr->status = MS_OFF; /* we have a collision, but this entry is a candidate for leader testing */ + "Putting label %d of labelgroup %d of class %d , " + "layer \"%s\" in leader queue\n", + ll, l, cachePtr->classindex, layerPtr->name); + cachePtr->status = + MS_OFF; /* we have a collision, but this entry is a + candidate for leader testing */ } - /* do we need to copy the labelpoly, or can we use the static one ?*/ - if(cachePtr->numtextsymbols > 1 || (cachePtr->status == MS_OFF && classPtr->leader)) { + /* do we need to copy the labelpoly, or can we use the static one + * ?*/ + if (cachePtr->numtextsymbols > 1 || + (cachePtr->status == MS_OFF && classPtr->leader)) { /* - * if we have more than one label, or if we have a single one which didn't fit but needs - * to go through leader offset testing + * if we have more than one label, or if we have a single one + * which didn't fit but needs to go through leader offset + * testing */ - if(!textSymbolPtr->style_bounds) - textSymbolPtr->style_bounds = msSmallCalloc(textSymbolPtr->label->numstyles, sizeof(label_bounds*)); - for(its=0;itslabel->numstyles; its++) { - if(textSymbolPtr->label->styles[its]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY || - textSymbolPtr->label->styles[its]->_geomtransform.type == MS_GEOMTRANSFORM_LABELCENTER) { - textSymbolPtr->style_bounds[its] = msSmallMalloc(sizeof(label_bounds)); - copyLabelBounds(textSymbolPtr->style_bounds[its], &labelpoly_bounds); + if (!textSymbolPtr->style_bounds) + textSymbolPtr->style_bounds = msSmallCalloc( + textSymbolPtr->label->numstyles, sizeof(label_bounds *)); + for (its = 0; its < textSymbolPtr->label->numstyles; its++) { + if (textSymbolPtr->label->styles[its]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOLY || + textSymbolPtr->label->styles[its]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELCENTER) { + textSymbolPtr->style_bounds[its] = + msSmallMalloc(sizeof(label_bounds)); + copyLabelBounds(textSymbolPtr->style_bounds[its], + &labelpoly_bounds); } } } /* else: we'll use labelpoly_bounds directly below */ - } /* next label in the group */ + } /* next label in the group */ - if(cachePtr->status != MS_DELETE) { + if (cachePtr->status != MS_DELETE) { /* compute the global label bbox */ - int inited = 0,s; - for(its=0;itsnumtextsymbols;its++) { - if(cachePtr->textsymbols[its]->annotext) { - if(inited == 0) { - cachePtr->bbox = cachePtr->textsymbols[its]->textpath->bounds.bbox; + int inited = 0, s; + for (its = 0; its < cachePtr->numtextsymbols; its++) { + if (cachePtr->textsymbols[its]->annotext) { + if (inited == 0) { + cachePtr->bbox = + cachePtr->textsymbols[its]->textpath->bounds.bbox; inited = 1; } else { - cachePtr->bbox.minx = MS_MIN(cachePtr->bbox.minx, cachePtr->textsymbols[its]->textpath->bounds.bbox.minx); - cachePtr->bbox.miny = MS_MIN(cachePtr->bbox.miny, cachePtr->textsymbols[its]->textpath->bounds.bbox.miny); - cachePtr->bbox.maxx = MS_MAX(cachePtr->bbox.maxx, cachePtr->textsymbols[its]->textpath->bounds.bbox.maxx); - cachePtr->bbox.maxy = MS_MAX(cachePtr->bbox.maxy, cachePtr->textsymbols[its]->textpath->bounds.bbox.maxy); + cachePtr->bbox.minx = MS_MIN( + cachePtr->bbox.minx, + cachePtr->textsymbols[its]->textpath->bounds.bbox.minx); + cachePtr->bbox.miny = MS_MIN( + cachePtr->bbox.miny, + cachePtr->textsymbols[its]->textpath->bounds.bbox.miny); + cachePtr->bbox.maxx = MS_MAX( + cachePtr->bbox.maxx, + cachePtr->textsymbols[its]->textpath->bounds.bbox.maxx); + cachePtr->bbox.maxy = MS_MAX( + cachePtr->bbox.maxy, + cachePtr->textsymbols[its]->textpath->bounds.bbox.maxy); } } - for(s=0; stextsymbols[its]->label->numstyles; s++) { - if(cachePtr->textsymbols[its]->label->styles[s]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { - if(inited == 0) { - cachePtr->bbox = cachePtr->textsymbols[its]->style_bounds[s]->bbox; + for (s = 0; s < cachePtr->textsymbols[its]->label->numstyles; + s++) { + if (cachePtr->textsymbols[its] + ->label->styles[s] + ->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT) { + if (inited == 0) { + cachePtr->bbox = + cachePtr->textsymbols[its]->style_bounds[s]->bbox; inited = 1; break; } else { - cachePtr->bbox.minx = MS_MIN(cachePtr->bbox.minx, cachePtr->textsymbols[its]->style_bounds[s]->bbox.minx); - cachePtr->bbox.miny = MS_MIN(cachePtr->bbox.miny, cachePtr->textsymbols[its]->style_bounds[s]->bbox.miny); - cachePtr->bbox.maxx = MS_MAX(cachePtr->bbox.maxx, cachePtr->textsymbols[its]->style_bounds[s]->bbox.maxx); - cachePtr->bbox.maxy = MS_MAX(cachePtr->bbox.maxy, cachePtr->textsymbols[its]->style_bounds[s]->bbox.maxy); - break; + cachePtr->bbox.minx = + MS_MIN(cachePtr->bbox.minx, cachePtr->textsymbols[its] + ->style_bounds[s] + ->bbox.minx); + cachePtr->bbox.miny = + MS_MIN(cachePtr->bbox.miny, cachePtr->textsymbols[its] + ->style_bounds[s] + ->bbox.miny); + cachePtr->bbox.maxx = + MS_MAX(cachePtr->bbox.maxx, cachePtr->textsymbols[its] + ->style_bounds[s] + ->bbox.maxx); + cachePtr->bbox.maxy = + MS_MAX(cachePtr->bbox.maxy, cachePtr->textsymbols[its] + ->style_bounds[s] + ->bbox.maxy); + break; } } } @@ -3430,72 +3978,122 @@ int msDrawLabelCache(mapObj *map, imageObj *image) } /* check that mindistance is respected */ - if (cachePtr->numtextsymbols && cachePtr->textsymbols[0]->label->mindistance > 0.0 && cachePtr->textsymbols[0]->annotext) { + if (cachePtr->numtextsymbols && + cachePtr->textsymbols[0]->label->mindistance > 0.0 && + cachePtr->textsymbols[0]->annotext) { if (msCheckLabelMinDistance(map, cachePtr) == MS_TRUE) { cachePtr->status = MS_DELETE; MS_DEBUG(MS_DEBUGLEVEL_DEVDEBUG, map, - "Skipping labelgroup %d \"%s\" in layer \"%s\": too close to an identical label (mindistance)\n", + "Skipping labelgroup %d \"%s\" in layer \"%s\": too " + "close to an identical label (mindistance)\n", l, cachePtr->textsymbols[0]->annotext, layerPtr->name); } } - if(cachePtr->status == MS_OFF || cachePtr->status == MS_DELETE) + if (cachePtr->status == MS_OFF || cachePtr->status == MS_DELETE) continue; /* next labelCacheMemberObj, as we had a collision */ /* insert the rendered label */ insertRenderedLabelMember(map, cachePtr); - for(ll=0; llnumtextsymbols; ll++) { + for (ll = 0; ll < cachePtr->numtextsymbols; ll++) { textSymbolPtr = cachePtr->textsymbols[ll]; /* here's where we draw the label styles */ - for(i=0; ilabel->numstyles; i++) { - if(textSymbolPtr->label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { - if(MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, image, &(cachePtr->point), textSymbolPtr->label->styles[i], textSymbolPtr->scalefactor))) { + for (i = 0; i < textSymbolPtr->label->numstyles; i++) { + if (textSymbolPtr->label->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT) { + if (MS_UNLIKELY( + MS_FAILURE == + msDrawMarkerSymbol(map, image, &(cachePtr->point), + textSymbolPtr->label->styles[i], + textSymbolPtr->scalefactor))) { + return MS_FAILURE; + } + } else if (textSymbolPtr->annotext && + textSymbolPtr->label->styles[i] + ->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOLY) { + if (textSymbolPtr->style_bounds && + textSymbolPtr->style_bounds[i]) { + if (MS_UNLIKELY( + MS_FAILURE == + msDrawLabelBounds(map, image, + textSymbolPtr->style_bounds[i], + textSymbolPtr->label->styles[i], + textSymbolPtr->scalefactor))) { return MS_FAILURE; } - } else if(textSymbolPtr->annotext && textSymbolPtr->label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) { - if(textSymbolPtr->style_bounds && textSymbolPtr->style_bounds[i]) { - if(MS_UNLIKELY(MS_FAILURE == msDrawLabelBounds(map,image,textSymbolPtr->style_bounds[i],textSymbolPtr->label->styles[i], textSymbolPtr->scalefactor))) { - return MS_FAILURE; - } - } else { - if(MS_UNLIKELY(MS_FAILURE == msDrawLabelBounds(map,image,&labelpoly_bounds,textSymbolPtr->label->styles[i], textSymbolPtr->scalefactor))) { - return MS_FAILURE; - } + } else { + if (MS_UNLIKELY( + MS_FAILURE == + msDrawLabelBounds(map, image, &labelpoly_bounds, + textSymbolPtr->label->styles[i], + textSymbolPtr->scalefactor))) { + return MS_FAILURE; } - } else if(textSymbolPtr->annotext && textSymbolPtr->label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELCENTER) { - pointObj labelCenter; - - if(textSymbolPtr->style_bounds && textSymbolPtr->style_bounds[i]) { - labelCenter.x = (textSymbolPtr->style_bounds[i]->bbox.maxx + textSymbolPtr->style_bounds[i]->bbox.minx)/2; - labelCenter.y = (textSymbolPtr->style_bounds[i]->bbox.maxy + textSymbolPtr->style_bounds[i]->bbox.miny)/2; - if(MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map,image,&labelCenter,textSymbolPtr->label->styles[i], textSymbolPtr->scalefactor))) { - return MS_FAILURE; - } - } else { - labelCenter.x = (labelpoly_bounds.bbox.maxx + labelpoly_bounds.bbox.minx)/2; - labelCenter.y = (labelpoly_bounds.bbox.maxy + labelpoly_bounds.bbox.miny)/2; - if(MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map,image,&labelCenter,textSymbolPtr->label->styles[i], textSymbolPtr->scalefactor))) { - return MS_FAILURE; - } + } + } else if (textSymbolPtr->annotext && + textSymbolPtr->label->styles[i] + ->_geomtransform.type == + MS_GEOMTRANSFORM_LABELCENTER) { + pointObj labelCenter; + + if (textSymbolPtr->style_bounds && + textSymbolPtr->style_bounds[i]) { + labelCenter.x = + (textSymbolPtr->style_bounds[i]->bbox.maxx + + textSymbolPtr->style_bounds[i]->bbox.minx) / + 2; + labelCenter.y = + (textSymbolPtr->style_bounds[i]->bbox.maxy + + textSymbolPtr->style_bounds[i]->bbox.miny) / + 2; + if (MS_UNLIKELY( + MS_FAILURE == + msDrawMarkerSymbol(map, image, &labelCenter, + textSymbolPtr->label->styles[i], + textSymbolPtr->scalefactor))) { + return MS_FAILURE; } - } else { - msSetError(MS_MISCERR,"Labels only support LABELPNT, LABELPOLY and LABELCENTER GEOMTRANSFORMS", "msDrawLabelCache()"); - return MS_FAILURE; + labelCenter.x = (labelpoly_bounds.bbox.maxx + + labelpoly_bounds.bbox.minx) / + 2; + labelCenter.y = (labelpoly_bounds.bbox.maxy + + labelpoly_bounds.bbox.miny) / + 2; + if (MS_UNLIKELY( + MS_FAILURE == + msDrawMarkerSymbol(map, image, &labelCenter, + textSymbolPtr->label->styles[i], + textSymbolPtr->scalefactor))) { + return MS_FAILURE; + } } + + } else { + msSetError(MS_MISCERR, + "Labels only support LABELPNT, LABELPOLY and " + "LABELCENTER GEOMTRANSFORMS", + "msDrawLabelCache()"); + return MS_FAILURE; } - - if(textSymbolPtr->annotext) { - if(MS_UNLIKELY(MS_FAILURE == msDrawTextSymbol(map,image,textSymbolPtr->annopoint,textSymbolPtr))) { + } + + if (textSymbolPtr->annotext) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawTextSymbol(map, image, + textSymbolPtr->annopoint, + textSymbolPtr))) { return MS_FAILURE; } } } } } /* next label(group) from cacheslot */ - if(MS_UNLIKELY(MS_FAILURE == msDrawOffsettedLabels(image, map, priority))) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawOffsettedLabels(image, map, priority))) { return MS_FAILURE; } } /* next priority */ @@ -3507,18 +4105,21 @@ int msDrawLabelCache(mapObj *map, imageObj *image) tstyle.color.red = 255; tstyle.color.green = 0; tstyle.color.blue = 0; - for(priority=MS_MAX_LABEL_PRIORITY-1; priority>=0; priority--) { + for (priority = MS_MAX_LABEL_PRIORITY - 1; priority >= 0; priority--) { labelCacheSlotObj *cacheslot; cacheslot = &(map->labelcache.slots[priority]); - for(l=cacheslot->numlabels-1; l>=0; l--) { - cachePtr = &(cacheslot->labels[l]); /* point to right spot in the label cache */ + for (l = cacheslot->numlabels - 1; l >= 0; l--) { + cachePtr = + &(cacheslot + ->labels[l]); /* point to right spot in the label cache */ /* assert((cachePtr->poly == NULL && cachePtr->status == MS_OFF) || (cachePtr->poly && (cachePtr->status == MS_ON)); */ - if(cachePtr->status) { - msDrawLineSymbol(map, image, cachePtr->poly, &tstyle, layerPtr->scalefactor); + if (cachePtr->status) { + msDrawLineSymbol(map, image, cachePtr->poly, &tstyle, + layerPtr->scalefactor); } } } @@ -3528,60 +4129,60 @@ int msDrawLabelCache(mapObj *map, imageObj *image) } } - if(map->debug >= MS_DEBUGLEVEL_TUNING) { + if (map->debug >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&endtime, NULL); msDebug("msDrawMap(): Drawing Label Cache, %.3fs\n", - (endtime.tv_sec+endtime.tv_usec/1.0e6)- - (starttime.tv_sec+starttime.tv_usec/1.0e6) ); + (endtime.tv_sec + endtime.tv_usec / 1.0e6) - + (starttime.tv_sec + starttime.tv_usec / 1.0e6)); } return nReturnVal; } - /** * Generic function to tell the underline device that layer * drawing is stating */ -void msImageStartLayer(mapObj *map, layerObj *layer, imageObj *image) -{ +void msImageStartLayer(mapObj *map, layerObj *layer, imageObj *image) { if (image) { - if( MS_RENDERER_PLUGIN(image->format) ) { - const char *approximation_scale = msLayerGetProcessingKey( layer, "APPROXIMATION_SCALE" ); - if(approximation_scale) { - if(!strncasecmp(approximation_scale,"ROUND",5)) { + if (MS_RENDERER_PLUGIN(image->format)) { + const char *approximation_scale = + msLayerGetProcessingKey(layer, "APPROXIMATION_SCALE"); + if (approximation_scale) { + if (!strncasecmp(approximation_scale, "ROUND", 5)) { MS_IMAGE_RENDERER(image)->transform_mode = MS_TRANSFORM_ROUND; - } else if(!strncasecmp(approximation_scale,"FULL",4)) { - MS_IMAGE_RENDERER(image)->transform_mode = MS_TRANSFORM_FULLRESOLUTION; - } else if(!strncasecmp(approximation_scale,"SIMPLIFY",8)) { + } else if (!strncasecmp(approximation_scale, "FULL", 4)) { + MS_IMAGE_RENDERER(image)->transform_mode = + MS_TRANSFORM_FULLRESOLUTION; + } else if (!strncasecmp(approximation_scale, "SIMPLIFY", 8)) { MS_IMAGE_RENDERER(image)->transform_mode = MS_TRANSFORM_SIMPLIFY; } else { MS_IMAGE_RENDERER(image)->transform_mode = MS_TRANSFORM_SNAPTOGRID; - MS_IMAGE_RENDERER(image)->approximation_scale = atof(approximation_scale); + MS_IMAGE_RENDERER(image)->approximation_scale = + atof(approximation_scale); } } else { - MS_IMAGE_RENDERER(image)->transform_mode = MS_IMAGE_RENDERER(image)->default_transform_mode; - MS_IMAGE_RENDERER(image)->approximation_scale = MS_IMAGE_RENDERER(image)->default_approximation_scale; + MS_IMAGE_RENDERER(image)->transform_mode = + MS_IMAGE_RENDERER(image)->default_transform_mode; + MS_IMAGE_RENDERER(image)->approximation_scale = + MS_IMAGE_RENDERER(image)->default_approximation_scale; } MS_IMAGE_RENDERER(image)->startLayer(image, map, layer); - } else if( MS_RENDERER_IMAGEMAP(image->format) ) + } else if (MS_RENDERER_IMAGEMAP(image->format)) msImageStartLayerIM(map, layer, image); - } } - /** * Generic function to tell the underline device that layer * drawing is ending */ -void msImageEndLayer(mapObj *map, layerObj *layer, imageObj *image) -{ - if(image) { - if( MS_RENDERER_PLUGIN(image->format) ) { - MS_IMAGE_RENDERER(image)->endLayer(image,map,layer); +void msImageEndLayer(mapObj *map, layerObj *layer, imageObj *image) { + if (image) { + if (MS_RENDERER_PLUGIN(image->format)) { + MS_IMAGE_RENDERER(image)->endLayer(image, map, layer); } } } @@ -3592,32 +4193,27 @@ void msImageEndLayer(mapObj *map, layerObj *layer, imageObj *image) */ void msDrawStartShape(mapObj *map, layerObj *layer, imageObj *image, - shapeObj *shape) -{ + shapeObj *shape) { (void)map; (void)layer; if (image) { - if(MS_RENDERER_PLUGIN(image->format)) { + if (MS_RENDERER_PLUGIN(image->format)) { if (image->format->vtable->startShape) image->format->vtable->startShape(image, shape); } - - } } - /** * Generic function to tell the underline device that shape * drawing is ending */ void msDrawEndShape(mapObj *map, layerObj *layer, imageObj *image, - shapeObj *shape) -{ + shapeObj *shape) { (void)map; (void)layer; - if(MS_RENDERER_PLUGIN(image->format)) { + if (MS_RENDERER_PLUGIN(image->format)) { if (image->format->vtable->endShape) image->format->vtable->endShape(image, shape); } @@ -3626,11 +4222,10 @@ void msDrawEndShape(mapObj *map, layerObj *layer, imageObj *image, * take the value from the shape and use it to change the * color in the style to match the range map */ -int msShapeToRange(styleObj *style, shapeObj *shape) -{ +int msShapeToRange(styleObj *style, shapeObj *shape) { /*first, get the value of the rangeitem, which should*/ /*evaluate to a double*/ - const char* fieldStr = shape->values[style->rangeitemindex]; + const char *fieldStr = shape->values[style->rangeitemindex]; if (fieldStr == NULL) { /*if there's not value, bail*/ return MS_FAILURE; } @@ -3644,42 +4239,59 @@ int msShapeToRange(styleObj *style, shapeObj *shape) * Ranges. The styls passed in is updated to reflect the right color * based on the fieldVal */ -int msValueToRange(styleObj *style, double fieldVal, colorspace cs) -{ +int msValueToRange(styleObj *style, double fieldVal, colorspace cs) { double range; double scaledVal; range = style->maxvalue - style->minvalue; - scaledVal = (fieldVal - style->minvalue)/range; + scaledVal = (fieldVal - style->minvalue) / range; - if(cs == MS_COLORSPACE_RGB) { + if (cs == MS_COLORSPACE_RGB) { /*At this point, we know where on the range we need to be*/ /*However, we don't know how to map it yet, since RGB(A) can */ /*Go up or down*/ - style->color.red = (int)(MS_MAX(0,(MS_MIN(255, (style->mincolor.red + ((style->maxcolor.red - style->mincolor.red) * scaledVal)))))); - style->color.green = (int)(MS_MAX(0,(MS_MIN(255,(style->mincolor.green + ((style->maxcolor.green - style->mincolor.green) * scaledVal)))))); - style->color.blue = (int)(MS_MAX(0,(MS_MIN(255,(style->mincolor.blue + ((style->maxcolor.blue - style->mincolor.blue) * scaledVal)))))); - style->color.alpha = (int)(MS_MAX(0,(MS_MIN(255,(style->mincolor.alpha + ((style->maxcolor.alpha - style->mincolor.alpha) * scaledVal)))))); + style->color.red = (int)(MS_MAX( + 0, (MS_MIN(255, (style->mincolor.red + + ((style->maxcolor.red - style->mincolor.red) * + scaledVal)))))); + style->color.green = (int)(MS_MAX( + 0, (MS_MIN(255, (style->mincolor.green + + ((style->maxcolor.green - style->mincolor.green) * + scaledVal)))))); + style->color.blue = (int)(MS_MAX( + 0, (MS_MIN(255, (style->mincolor.blue + + ((style->maxcolor.blue - style->mincolor.blue) * + scaledVal)))))); + style->color.alpha = (int)(MS_MAX( + 0, (MS_MIN(255, (style->mincolor.alpha + + ((style->maxcolor.alpha - style->mincolor.alpha) * + scaledVal)))))); } else { /* HSL */ assert(cs == MS_COLORSPACE_HSL); - if(fieldVal <= style->minvalue) style->color = style->mincolor; - else if(fieldVal >= style->maxvalue) style->color = style->maxcolor; + if (fieldVal <= style->minvalue) + style->color = style->mincolor; + else if (fieldVal >= style->maxvalue) + style->color = style->maxcolor; else { - double mh,ms,ml,Mh,Ms,Ml; - msRGBtoHSL(&style->mincolor,&mh,&ms,&ml); - msRGBtoHSL(&style->maxcolor,&Mh,&Ms,&Ml); - mh+=(Mh-mh)*scaledVal; - ms+=(Ms-ms)*scaledVal; - ml+=(Ml-ml)*scaledVal; - msHSLtoRGB(mh,ms,ml,&style->color); - style->color.alpha = style->mincolor.alpha + (style->maxcolor.alpha - style->mincolor.alpha)*scaledVal; + double mh, ms, ml, Mh, Ms, Ml; + msRGBtoHSL(&style->mincolor, &mh, &ms, &ml); + msRGBtoHSL(&style->maxcolor, &Mh, &Ms, &Ml); + mh += (Mh - mh) * scaledVal; + ms += (Ms - ms) * scaledVal; + ml += (Ml - ml) * scaledVal; + msHSLtoRGB(mh, ms, ml, &style->color); + style->color.alpha = + style->mincolor.alpha + + (style->maxcolor.alpha - style->mincolor.alpha) * scaledVal; } } - /*( "msMapRange(): %i %i %i", style->color.red , style->color.green, style->color.blue);*/ + /*( "msMapRange(): %i %i %i", style->color.red , style->color.green, + * style->color.blue);*/ #if ALPHACOLOR_ENABLED - /*NO ALPHA RANGE YET style->color.alpha = style->mincolor.alpha + ((style->maxcolor.alpha - style->mincolor.alpha) * scaledVal);*/ + /*NO ALPHA RANGE YET style->color.alpha = style->mincolor.alpha + + * ((style->maxcolor.alpha - style->mincolor.alpha) * scaledVal);*/ #endif return MS_SUCCESS; diff --git a/mapdrawgdal.c b/mapdrawgdal.c index e97cbfeebd..b3b222e738 100644 --- a/mapdrawgdal.c +++ b/mapdrawgdal.c @@ -35,57 +35,50 @@ #include "mapthread.h" #include "maptime.h" - -extern int InvGeoTransform( double *gt_in, double *gt_out ); +extern int InvGeoTransform(double *gt_in, double *gt_out); #define MAXCOLORS 256 -#define GEO_TRANS(tr,x,y) ((tr)[0]+(tr)[1]*(x)+(tr)[2]*(y)) -#define SKIP_MASK(x,y) (mask_rb && !*(mask_rb->data.rgba.a+(y)*mask_rb->data.rgba.row_step+(x)*mask_rb->data.rgba.pixel_step)) +#define GEO_TRANS(tr, x, y) ((tr)[0] + (tr)[1] * (x) + (tr)[2] * (y)) +#define SKIP_MASK(x, y) \ + (mask_rb && !*(mask_rb->data.rgba.a + (y)*mask_rb->data.rgba.row_step + \ + (x)*mask_rb->data.rgba.pixel_step)) #include "gdal.h" #include "cpl_string.h" #include "gdal_alg.h" -static bool -IsNoData( double dfValue, double dfNoDataValue ); - -static int -LoadGDALImages( GDALDatasetH hDS, int band_numbers[4], int band_count, - layerObj *layer, - int src_xoff, int src_yoff, int src_xsize, int src_ysize, - GByte *pabyBuffer, - int dst_xsize, int dst_ysize, - int *pbHaveRGBNoData, - int *pnNoData1, int *pnNoData2, int *pnNoData3, - bool *pbScaled, double *pdfScaleMin, double *pdfScaleRatio, - bool **ppbIsNoDataBuffer ); -static int -msDrawRasterLayerGDAL_RawMode( - mapObj *map, layerObj *layer, imageObj *image, GDALDatasetH hDS, - int src_xoff, int src_yoff, int src_xsize, int src_ysize, - int dst_xoff, int dst_yoff, int dst_xsize, int dst_ysize ); - -static int -msDrawRasterLayerGDAL_16BitClassification( - mapObj *map, layerObj *layer, rasterBufferObj *rb, - GDALRasterBandH hBand, - int src_xoff, int src_yoff, int src_xsize, int src_ysize, - int dst_xoff, int dst_yoff, int dst_xsize, int dst_ysize ); - +static bool IsNoData(double dfValue, double dfNoDataValue); + +static int LoadGDALImages(GDALDatasetH hDS, int band_numbers[4], int band_count, + layerObj *layer, int src_xoff, int src_yoff, + int src_xsize, int src_ysize, GByte *pabyBuffer, + int dst_xsize, int dst_ysize, int *pbHaveRGBNoData, + int *pnNoData1, int *pnNoData2, int *pnNoData3, + bool *pbScaled, double *pdfScaleMin, + double *pdfScaleRatio, bool **ppbIsNoDataBuffer); +static int msDrawRasterLayerGDAL_RawMode(mapObj *map, layerObj *layer, + imageObj *image, GDALDatasetH hDS, + int src_xoff, int src_yoff, + int src_xsize, int src_ysize, + int dst_xoff, int dst_yoff, + int dst_xsize, int dst_ysize); + +static int msDrawRasterLayerGDAL_16BitClassification( + mapObj *map, layerObj *layer, rasterBufferObj *rb, GDALRasterBandH hBand, + int src_xoff, int src_yoff, int src_xsize, int src_ysize, int dst_xoff, + int dst_yoff, int dst_xsize, int dst_ysize); /* * rasterBufferObj setting macros. */ - - /************************************************************************/ /* msDrawRasterLayerGDAL() */ /************************************************************************/ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, - rasterBufferObj *rb, void *hDSVoid ) + rasterBufferObj *rb, void *hDSVoid) { int i; /* loop counters */ @@ -99,35 +92,37 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, int src_xoff, src_yoff, src_xsize, src_ysize; double llx, lly, urx, ury; rectObj copyRect, mapRect; - unsigned char *pabyRaw1=NULL, *pabyRaw2=NULL, *pabyRaw3=NULL, - *pabyRawAlpha = NULL; + unsigned char *pabyRaw1 = NULL, *pabyRaw2 = NULL, *pabyRaw3 = NULL, + *pabyRawAlpha = NULL; int classified = FALSE; - int red_band=0, green_band=0, blue_band=0, alpha_band=0; + int red_band = 0, green_band = 0, blue_band = 0, alpha_band = 0; int band_count, band_numbers[4]; GDALDatasetH hDS = hDSVoid; - GDALColorTableH hColorMap=NULL; - GDALRasterBandH hBand1=NULL, hBand2=NULL, hBand3=NULL, hBandAlpha=NULL; + GDALColorTableH hColorMap = NULL; + GDALRasterBandH hBand1 = NULL, hBand2 = NULL, hBand3 = NULL, + hBandAlpha = NULL; int bHaveRGBNoData = FALSE; - int nNoData1=-1,nNoData2=-1,nNoData3=-1; + int nNoData1 = -1, nNoData2 = -1, nNoData3 = -1; rasterBufferObj *mask_rb = NULL; rasterBufferObj s_mask_rb; - if(layer->mask) { + if (layer->mask) { int ret; - layerObj *maskLayer = GET_LAYER(map, msGetLayerIndex(map,layer->mask)); + layerObj *maskLayer = GET_LAYER(map, msGetLayerIndex(map, layer->mask)); mask_rb = &s_mask_rb; memset(mask_rb, 0, sizeof(s_mask_rb)); - ret = MS_IMAGE_RENDERER(maskLayer->maskimage)->getRasterBufferHandle(maskLayer->maskimage,mask_rb); - if(ret != MS_SUCCESS) + ret = MS_IMAGE_RENDERER(maskLayer->maskimage) + ->getRasterBufferHandle(maskLayer->maskimage, mask_rb); + if (ret != MS_SUCCESS) return -1; } /*only support rawdata and pluggable renderers*/ - assert(MS_RENDERER_RAWDATA(image->format) || (MS_RENDERER_PLUGIN(image->format) && rb)); + assert(MS_RENDERER_RAWDATA(image->format) || + (MS_RENDERER_PLUGIN(image->format) && rb)); - - memset( cmap, 0xff, MAXCOLORS * sizeof(int) ); - memset( rb_cmap, 0, sizeof(rb_cmap) ); + memset(cmap, 0xff, MAXCOLORS * sizeof(int)); + memset(rb_cmap, 0, sizeof(rb_cmap)); /* -------------------------------------------------------------------- */ /* Test the image format instead of the map format. */ @@ -137,9 +132,8 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, /* and then dumped into the SWF or the PDF file. */ /* -------------------------------------------------------------------- */ - - src_xsize = GDALGetRasterXSize( hDS ); - src_ysize = GDALGetRasterYSize( hDS ); + src_xsize = GDALGetRasterXSize(hDS); + src_ysize = GDALGetRasterYSize(hDS); /* * If the RAW_WINDOW attribute is set, use that to establish what to @@ -147,21 +141,19 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, * problems with rotated maps. */ - if( CSLFetchNameValue( layer->processing, "RAW_WINDOW" ) != NULL ) { + if (CSLFetchNameValue(layer->processing, "RAW_WINDOW") != NULL) { char **papszTokens = - CSLTokenizeString( - CSLFetchNameValue( layer->processing, "RAW_WINDOW" ) ); - - if( layer->debug ) - msDebug( "msDrawGDAL(%s): using RAW_WINDOW=%s, dst=0,0,%d,%d\n", - layer->name, - CSLFetchNameValue( layer->processing, "RAW_WINDOW" ), - image->width, image->height ); - - if( CSLCount(papszTokens) != 4 ) { - CSLDestroy( papszTokens ); - msSetError( MS_IMGERR, "RAW_WINDOW PROCESSING directive corrupt.", - "msDrawGDAL()" ); + CSLTokenizeString(CSLFetchNameValue(layer->processing, "RAW_WINDOW")); + + if (layer->debug) + msDebug("msDrawGDAL(%s): using RAW_WINDOW=%s, dst=0,0,%d,%d\n", + layer->name, CSLFetchNameValue(layer->processing, "RAW_WINDOW"), + image->width, image->height); + + if (CSLCount(papszTokens) != 4) { + CSLDestroy(papszTokens); + msSetError(MS_IMGERR, "RAW_WINDOW PROCESSING directive corrupt.", + "msDrawGDAL()"); return -1; } @@ -175,107 +167,109 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, dst_xsize = image->width; dst_ysize = image->height; - CSLDestroy( papszTokens ); + CSLDestroy(papszTokens); } /* * Compute the georeferenced window of overlap, and do nothing if there * is no overlap between the map extents, and the file we are operating on. */ - else if( layer->transform ) { + else if (layer->transform) { int dst_lrx, dst_lry; - if( layer->debug ) - msDebug( "msDrawRasterLayerGDAL(): Entering transform.\n" ); + if (layer->debug) + msDebug("msDrawRasterLayerGDAL(): Entering transform.\n"); - msGetGDALGeoTransform( hDS, map, layer, adfGeoTransform ); - InvGeoTransform( adfGeoTransform, adfInvGeoTransform ); + msGetGDALGeoTransform(hDS, map, layer, adfGeoTransform); + InvGeoTransform(adfGeoTransform, adfInvGeoTransform); mapRect = map->extent; - mapRect.minx -= map->cellsize*0.5; - mapRect.maxx += map->cellsize*0.5; - mapRect.miny -= map->cellsize*0.5; - mapRect.maxy += map->cellsize*0.5; + mapRect.minx -= map->cellsize * 0.5; + mapRect.maxx += map->cellsize * 0.5; + mapRect.miny -= map->cellsize * 0.5; + mapRect.maxy += map->cellsize * 0.5; copyRect = mapRect; - if( copyRect.minx < GEO_TRANS(adfGeoTransform,0,src_ysize) ) - copyRect.minx = GEO_TRANS(adfGeoTransform,0,src_ysize); - if( copyRect.maxx > GEO_TRANS(adfGeoTransform,src_xsize,0) ) - copyRect.maxx = GEO_TRANS(adfGeoTransform,src_xsize,0); + if (copyRect.minx < GEO_TRANS(adfGeoTransform, 0, src_ysize)) + copyRect.minx = GEO_TRANS(adfGeoTransform, 0, src_ysize); + if (copyRect.maxx > GEO_TRANS(adfGeoTransform, src_xsize, 0)) + copyRect.maxx = GEO_TRANS(adfGeoTransform, src_xsize, 0); - if( copyRect.miny < GEO_TRANS(adfGeoTransform+3,0,src_ysize) ) - copyRect.miny = GEO_TRANS(adfGeoTransform+3,0,src_ysize); - if( copyRect.maxy > GEO_TRANS(adfGeoTransform+3,src_xsize,0) ) - copyRect.maxy = GEO_TRANS(adfGeoTransform+3,src_xsize,0); + if (copyRect.miny < GEO_TRANS(adfGeoTransform + 3, 0, src_ysize)) + copyRect.miny = GEO_TRANS(adfGeoTransform + 3, 0, src_ysize); + if (copyRect.maxy > GEO_TRANS(adfGeoTransform + 3, src_xsize, 0)) + copyRect.maxy = GEO_TRANS(adfGeoTransform + 3, src_xsize, 0); - if( copyRect.minx >= copyRect.maxx || copyRect.miny >= copyRect.maxy ) { - if( layer->debug ) - msDebug( "msDrawRasterLayerGDAL(): Error in overlap calculation.\n" ); + if (copyRect.minx >= copyRect.maxx || copyRect.miny >= copyRect.maxy) { + if (layer->debug) + msDebug("msDrawRasterLayerGDAL(): Error in overlap calculation.\n"); return 0; } /* * Copy the source and destination raster coordinates. */ - llx = GEO_TRANS(adfInvGeoTransform+0,copyRect.minx,copyRect.miny); - lly = GEO_TRANS(adfInvGeoTransform+3,copyRect.minx,copyRect.miny); - urx = GEO_TRANS(adfInvGeoTransform+0,copyRect.maxx,copyRect.maxy); - ury = GEO_TRANS(adfInvGeoTransform+3,copyRect.maxx,copyRect.maxy); - - src_xoff = MS_MAX(0,(int) floor(llx+0.5)); - src_yoff = MS_MAX(0,(int) floor(ury+0.5)); - src_xsize = MS_MIN(MS_MAX(0,(int) (urx - llx + 0.5)), - GDALGetRasterXSize(hDS) - src_xoff); - src_ysize = MS_MIN(MS_MAX(0,(int) (lly - ury + 0.5)), - GDALGetRasterYSize(hDS) - src_yoff); + llx = GEO_TRANS(adfInvGeoTransform + 0, copyRect.minx, copyRect.miny); + lly = GEO_TRANS(adfInvGeoTransform + 3, copyRect.minx, copyRect.miny); + urx = GEO_TRANS(adfInvGeoTransform + 0, copyRect.maxx, copyRect.maxy); + ury = GEO_TRANS(adfInvGeoTransform + 3, copyRect.maxx, copyRect.maxy); + + src_xoff = MS_MAX(0, (int)floor(llx + 0.5)); + src_yoff = MS_MAX(0, (int)floor(ury + 0.5)); + src_xsize = MS_MIN(MS_MAX(0, (int)(urx - llx + 0.5)), + GDALGetRasterXSize(hDS) - src_xoff); + src_ysize = MS_MIN(MS_MAX(0, (int)(lly - ury + 0.5)), + GDALGetRasterYSize(hDS) - src_yoff); /* We want very small windows to use at least one source pixel (#4172) */ - if( src_xsize == 0 && (urx - llx) > 0.0 ) { + if (src_xsize == 0 && (urx - llx) > 0.0) { src_xsize = 1; - src_xoff = MS_MIN(src_xoff,GDALGetRasterXSize(hDS)-1); + src_xoff = MS_MIN(src_xoff, GDALGetRasterXSize(hDS) - 1); } - if( src_ysize == 0 && (lly - ury) > 0.0 ) { + if (src_ysize == 0 && (lly - ury) > 0.0) { src_ysize = 1; - src_yoff = MS_MIN(src_yoff,GDALGetRasterYSize(hDS)-1); + src_yoff = MS_MIN(src_yoff, GDALGetRasterYSize(hDS) - 1); } - if( src_xsize == 0 || src_ysize == 0 ) { - if( layer->debug ) - msDebug( "msDrawRasterLayerGDAL(): no apparent overlap between map view and this window(1).\n" ); + if (src_xsize == 0 || src_ysize == 0) { + if (layer->debug) + msDebug("msDrawRasterLayerGDAL(): no apparent overlap between map view " + "and this window(1).\n"); return 0; } if (map->cellsize == 0) { - if( layer->debug ) - msDebug( "msDrawRasterLayerGDAL(): Cellsize can't be 0.\n" ); + if (layer->debug) + msDebug("msDrawRasterLayerGDAL(): Cellsize can't be 0.\n"); return 0; } - dst_xoff = (int) ((copyRect.minx - mapRect.minx) / map->cellsize); - dst_yoff = (int) ((mapRect.maxy - copyRect.maxy) / map->cellsize); + dst_xoff = (int)((copyRect.minx - mapRect.minx) / map->cellsize); + dst_yoff = (int)((mapRect.maxy - copyRect.maxy) / map->cellsize); - dst_lrx = (int) ((copyRect.maxx - mapRect.minx) / map->cellsize + 0.5); - dst_lry = (int) ((mapRect.maxy - copyRect.miny) / map->cellsize + 0.5); - dst_lrx = MS_MAX(0,MS_MIN(image->width,dst_lrx)); - dst_lry = MS_MAX(0,MS_MIN(image->height,dst_lry)); + dst_lrx = (int)((copyRect.maxx - mapRect.minx) / map->cellsize + 0.5); + dst_lry = (int)((mapRect.maxy - copyRect.miny) / map->cellsize + 0.5); + dst_lrx = MS_MAX(0, MS_MIN(image->width, dst_lrx)); + dst_lry = MS_MAX(0, MS_MIN(image->height, dst_lry)); - dst_xsize = MS_MAX(0,MS_MIN(image->width,dst_lrx - dst_xoff)); - dst_ysize = MS_MAX(0,MS_MIN(image->height,dst_lry - dst_yoff)); + dst_xsize = MS_MAX(0, MS_MIN(image->width, dst_lrx - dst_xoff)); + dst_ysize = MS_MAX(0, MS_MIN(image->height, dst_lry - dst_yoff)); - if( dst_xsize == 0 || dst_ysize == 0 ) { - if( layer->debug ) - msDebug( "msDrawRasterLayerGDAL(): no apparent overlap between map view and this window(2).\n" ); + if (dst_xsize == 0 || dst_ysize == 0) { + if (layer->debug) + msDebug("msDrawRasterLayerGDAL(): no apparent overlap between map view " + "and this window(2).\n"); return 0; } - if( layer->debug ) - msDebug( "msDrawRasterLayerGDAL(): src=%d,%d,%d,%d, dst=%d,%d,%d,%d\n", - src_xoff, src_yoff, src_xsize, src_ysize, - dst_xoff, dst_yoff, dst_xsize, dst_ysize ); + if (layer->debug) + msDebug("msDrawRasterLayerGDAL(): src=%d,%d,%d,%d, dst=%d,%d,%d,%d\n", + src_xoff, src_yoff, src_xsize, src_ysize, dst_xoff, dst_yoff, + dst_xsize, dst_ysize); #ifndef notdef - if( layer->debug ) { + if (layer->debug) { double d_src_xoff, d_src_yoff, geo_x, geo_y; geo_x = mapRect.minx + dst_xoff * map->cellsize; @@ -284,9 +278,9 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, d_src_xoff = (geo_x - adfGeoTransform[0]) / adfGeoTransform[1]; d_src_yoff = (geo_y - adfGeoTransform[3]) / adfGeoTransform[5]; - msDebug( "msDrawRasterLayerGDAL(): source raster PL (%.3f,%.3f) for dst PL (%d,%d).\n", - d_src_xoff, d_src_yoff, - dst_xoff, dst_yoff ); + msDebug("msDrawRasterLayerGDAL(): source raster PL (%.3f,%.3f) for dst " + "PL (%d,%d).\n", + d_src_xoff, d_src_yoff, dst_xoff, dst_yoff); } #endif } @@ -297,19 +291,18 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, else { dst_xoff = src_xoff = 0; dst_yoff = src_yoff = 0; - dst_xsize = src_xsize = MS_MIN(image->width,src_xsize); - dst_ysize = src_ysize = MS_MIN(image->height,src_ysize); + dst_xsize = src_xsize = MS_MIN(image->width, src_xsize); + dst_ysize = src_ysize = MS_MIN(image->height, src_ysize); } /* * In RAWDATA mode we don't fool with colors. Do the raw processing, * and return from the function early. */ - if( MS_RENDERER_RAWDATA( image->format ) ) { + if (MS_RENDERER_RAWDATA(image->format)) { return msDrawRasterLayerGDAL_RawMode( - map, layer, image, hDS, - src_xoff, src_yoff, src_xsize, src_ysize, - dst_xoff, dst_yoff, dst_xsize, dst_ysize ); + map, layer, image, hDS, src_xoff, src_yoff, src_xsize, src_ysize, + dst_xoff, dst_yoff, dst_xsize, dst_ysize); } /* @@ -318,19 +311,19 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, * to treat the raster as classified if there is just a bogus class here * to force inclusion in the legend. */ - for( i = 0; i < layer->numclasses; i++ ) { + for (i = 0; i < layer->numclasses; i++) { int s; /* change colour based on colour range? */ - for(s=0; sclass[i]->numstyles; s++) { - if( MS_VALID_COLOR(layer->class[i]->styles[s]->mincolor) - && MS_VALID_COLOR(layer->class[i]->styles[s]->maxcolor) ) { + for (s = 0; s < layer->class[i] -> numstyles; s++) { + if (MS_VALID_COLOR(layer->class[i] -> styles[s] -> mincolor) && + MS_VALID_COLOR(layer->class[i] -> styles[s] -> maxcolor)) { classified = TRUE; break; } } - if( layer->class[i]->expression.string != NULL ) { + if (layer->class[i] -> expression.string != NULL) { classified = TRUE; break; } @@ -342,35 +335,32 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, * red=1,green=2,blue=3 or red=1,green=2,blue=3,alpha>=4. */ - if( CSLFetchNameValue( layer->processing, "BANDS" ) == NULL ) { - const int gdal_band_count = GDALGetRasterCount( hDS ); + if (CSLFetchNameValue(layer->processing, "BANDS") == NULL) { + const int gdal_band_count = GDALGetRasterCount(hDS); red_band = 1; - if( gdal_band_count >= 4 ) - { - /* The alpha band is not necessarily the 4th one */ - for( i = 4; i <= gdal_band_count; i ++ ) { - if( GDALGetRasterColorInterpretation( - GDALGetRasterBand( hDS, i ) ) == GCI_AlphaBand ) { - alpha_band = i; - break; - } + if (gdal_band_count >= 4) { + /* The alpha band is not necessarily the 4th one */ + for (i = 4; i <= gdal_band_count; i++) { + if (GDALGetRasterColorInterpretation(GDALGetRasterBand(hDS, i)) == + GCI_AlphaBand) { + alpha_band = i; + break; } + } } - if( gdal_band_count >= 3 ) { + if (gdal_band_count >= 3) { green_band = 2; blue_band = 3; } - if( gdal_band_count == 2 - && GDALGetRasterColorInterpretation( - GDALGetRasterBand( hDS, 2 ) ) == GCI_AlphaBand ) + if (gdal_band_count == 2 && GDALGetRasterColorInterpretation( + GDALGetRasterBand(hDS, 2)) == GCI_AlphaBand) alpha_band = 2; - hBand1 = GDALGetRasterBand( hDS, red_band ); - if( classified - || GDALGetRasterColorTable( hBand1 ) != NULL ) { + hBand1 = GDALGetRasterBand(hDS, red_band); + if (classified || GDALGetRasterColorTable(hBand1) != NULL) { alpha_band = 0; green_band = 0; blue_band = 0; @@ -378,15 +368,15 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, } else { int *band_list; - band_list = msGetGDALBandList( layer, hDS, 4, &band_count ); - if( band_list == NULL ) + band_list = msGetGDALBandList(layer, hDS, 4, &band_count); + if (band_list == NULL) return -1; - if( band_count > 0 ) + if (band_count > 0) red_band = band_list[0]; else red_band = 0; - if( band_count > 2 ) { + if (band_count > 2) { green_band = band_list[1]; blue_band = band_list[2]; } else { @@ -394,12 +384,12 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, blue_band = 0; } - if( band_count > 3 ) + if (band_count > 3) alpha_band = band_list[3]; else alpha_band = 0; - free( band_list ); + free(band_list); } band_numbers[0] = red_band; @@ -407,53 +397,53 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, band_numbers[2] = blue_band; band_numbers[3] = 0; - if( blue_band != 0 && alpha_band != 0 ) { + if (blue_band != 0 && alpha_band != 0) { band_numbers[3] = alpha_band; band_count = 4; - } else if( blue_band != 0 && alpha_band == 0 ) + } else if (blue_band != 0 && alpha_band == 0) band_count = 3; - else if( alpha_band != 0 ) { + else if (alpha_band != 0) { band_numbers[1] = alpha_band; band_count = 2; } else band_count = 1; - if( layer->debug > 1 || (layer->debug > 0 && green_band != 0) ) { - msDebug( "msDrawRasterLayerGDAL(): red,green,blue,alpha bands = %d,%d,%d,%d\n", - red_band, green_band, blue_band, alpha_band ); + if (layer->debug > 1 || (layer->debug > 0 && green_band != 0)) { + msDebug( + "msDrawRasterLayerGDAL(): red,green,blue,alpha bands = %d,%d,%d,%d\n", + red_band, green_band, blue_band, alpha_band); } /* * Get band handles for PC256, RGB or RGBA cases. */ - hBand1 = GDALGetRasterBand( hDS, red_band ); - if( hBand1 == NULL ) + hBand1 = GDALGetRasterBand(hDS, red_band); + if (hBand1 == NULL) return -1; hBand2 = hBand3 = hBandAlpha = NULL; - if( green_band != 0 ) { - hBand1 = GDALGetRasterBand( hDS, red_band ); - hBand2 = GDALGetRasterBand( hDS, green_band ); - hBand3 = GDALGetRasterBand( hDS, blue_band ); - if( hBand1 == NULL || hBand2 == NULL || hBand3 == NULL ) + if (green_band != 0) { + hBand1 = GDALGetRasterBand(hDS, red_band); + hBand2 = GDALGetRasterBand(hDS, green_band); + hBand3 = GDALGetRasterBand(hDS, blue_band); + if (hBand1 == NULL || hBand2 == NULL || hBand3 == NULL) return -1; } - if( alpha_band != 0 ) - hBandAlpha = GDALGetRasterBand( hDS, alpha_band ); + if (alpha_band != 0) + hBandAlpha = GDALGetRasterBand(hDS, alpha_band); /* * The logic for a classification rendering of non-8bit raster bands * is sufficiently different than the normal mechanism of loading * into an 8bit buffer, that we isolate it into it's own subfunction. */ - if( classified - && hBand1 != NULL && GDALGetRasterDataType( hBand1 ) != GDT_Byte ) { + if (classified && hBand1 != NULL && + GDALGetRasterDataType(hBand1) != GDT_Byte) { return msDrawRasterLayerGDAL_16BitClassification( - map, layer, rb, hBand1, - src_xoff, src_yoff, src_xsize, src_ysize, - dst_xoff, dst_yoff, dst_xsize, dst_ysize ); + map, layer, rb, hBand1, src_xoff, src_yoff, src_xsize, src_ysize, + dst_xoff, dst_yoff, dst_xsize, dst_ysize); } /* @@ -462,17 +452,17 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, */ bool isDefaultGreyscale = false; - if( hBand2 != NULL ) + if (hBand2 != NULL) hColorMap = NULL; else { - hColorMap = GDALGetRasterColorTable( hBand1 ); - if( hColorMap != NULL ) - hColorMap = GDALCloneColorTable( hColorMap ); + hColorMap = GDALGetRasterColorTable(hBand1); + if (hColorMap != NULL) + hColorMap = GDALCloneColorTable(hColorMap); else { - hColorMap = GDALCreateColorTable( GPI_RGB ); + hColorMap = GDALCreateColorTable(GPI_RGB); isDefaultGreyscale = true; - for( i = 0; i < 256; i++ ) { + for (i = 0; i < 256; i++) { colorObj pixel; GDALColorEntry sEntry; @@ -480,7 +470,7 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, pixel.green = i; pixel.blue = i; - if(MS_COMPARE_COLORS(pixel, layer->offsite)) { + if (MS_COMPARE_COLORS(pixel, layer->offsite)) { sEntry.c1 = 0; sEntry.c2 = 0; sEntry.c3 = 0; @@ -492,7 +482,7 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, sEntry.c4 = 255; } - GDALSetColorEntry( hColorMap, i, &sEntry ); + GDALSetColorEntry(hColorMap, i, &sEntry); } } @@ -500,20 +490,18 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, ** If we have a known NODATA value, mark it now as transparent. */ { - int bGotNoData; - double dfNoDataValue = msGetGDALNoDataValue( layer, hBand1, - &bGotNoData); + int bGotNoData; + double dfNoDataValue = msGetGDALNoDataValue(layer, hBand1, &bGotNoData); - if( bGotNoData && dfNoDataValue >= 0 - && dfNoDataValue < GDALGetColorEntryCount( hColorMap ) ) { + if (bGotNoData && dfNoDataValue >= 0 && + dfNoDataValue < GDALGetColorEntryCount(hColorMap)) { GDALColorEntry sEntry; - memcpy( &sEntry, - GDALGetColorEntry( hColorMap, (int) dfNoDataValue ), - sizeof(GDALColorEntry) ); + memcpy(&sEntry, GDALGetColorEntry(hColorMap, (int)dfNoDataValue), + sizeof(GDALColorEntry)); sEntry.c4 = 0; - GDALSetColorEntry( hColorMap, (int) dfNoDataValue, &sEntry ); + GDALSetColorEntry(hColorMap, (int)dfNoDataValue, &sEntry); } } } @@ -521,20 +509,20 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, /* * Allocate imagery buffers. */ - pabyRaw1 = (unsigned char *) malloc(dst_xsize * dst_ysize * band_count); - if( pabyRaw1 == NULL ) { + pabyRaw1 = (unsigned char *)malloc(dst_xsize * dst_ysize * band_count); + if (pabyRaw1 == NULL) { msSetError(MS_MEMERR, "Allocating work image of size %dx%dx%d failed.", - "msDrawRasterLayerGDAL()", dst_xsize, dst_ysize, band_count ); + "msDrawRasterLayerGDAL()", dst_xsize, dst_ysize, band_count); return -1; } - if( hBand2 != NULL && hBand3 != NULL ) { + if (hBand2 != NULL && hBand3 != NULL) { pabyRaw2 = pabyRaw1 + dst_xsize * dst_ysize * 1; pabyRaw3 = pabyRaw1 + dst_xsize * dst_ysize * 2; } - if( hBandAlpha != NULL ) { - if( hBand2 != NULL ) + if (hBandAlpha != NULL) { + if (hBand2 != NULL) pabyRawAlpha = pabyRaw1 + dst_xsize * dst_ysize * 3; else pabyRawAlpha = pabyRaw1 + dst_xsize * dst_ysize * 1; @@ -546,16 +534,13 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, bool bScaled = false; double dfScaleMin = 0; double dfScaleRatio = 0; - bool* pbIsNoDataBuffer = NULL; - if( LoadGDALImages( hDS, band_numbers, band_count, layer, - src_xoff, src_yoff, src_xsize, src_ysize, - pabyRaw1, dst_xsize, dst_ysize, - &bHaveRGBNoData, - &nNoData1, &nNoData2, &nNoData3, - &bScaled, &dfScaleMin, &dfScaleRatio, - &pbIsNoDataBuffer ) == -1 ) { - free( pabyRaw1 ); - free( pbIsNoDataBuffer ); + bool *pbIsNoDataBuffer = NULL; + if (LoadGDALImages(hDS, band_numbers, band_count, layer, src_xoff, src_yoff, + src_xsize, src_ysize, pabyRaw1, dst_xsize, dst_ysize, + &bHaveRGBNoData, &nNoData1, &nNoData2, &nNoData3, &bScaled, + &dfScaleMin, &dfScaleRatio, &pbIsNoDataBuffer) == -1) { + free(pabyRaw1); + free(pbIsNoDataBuffer); return -1; } @@ -565,93 +550,105 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, * class colors are provided by the MAP file, or where we use the native * color table. */ - if( classified ) { + if (classified) { int c; - const char* pszRangeColorspace = msLayerGetProcessingKey( layer, "RANGE_COLORSPACE" ); + const char *pszRangeColorspace = + msLayerGetProcessingKey(layer, "RANGE_COLORSPACE"); colorspace iRangeColorspace; #ifndef NDEBUG cmap_set = TRUE; #endif - if( hColorMap == NULL ) { + if (hColorMap == NULL) { msSetError(MS_IOERR, "Attempt to classify 24bit image, this is unsupported.", "drawGDAL()"); - free( pabyRaw1 ); - free( pbIsNoDataBuffer ); + free(pabyRaw1); + free(pbIsNoDataBuffer); return -1; } - - if(!pszRangeColorspace || !strcasecmp(pszRangeColorspace, "RGB")) { + + if (!pszRangeColorspace || !strcasecmp(pszRangeColorspace, "RGB")) { iRangeColorspace = MS_COLORSPACE_RGB; - } else if(!strcasecmp(pszRangeColorspace, "HSL")) { + } else if (!strcasecmp(pszRangeColorspace, "HSL")) { iRangeColorspace = MS_COLORSPACE_HSL; } else { msSetError(MS_MISCERR, "Unknown RANGE_COLORSPACE \"%s\", expecting RGB or HSL", "drawGDAL()", pszRangeColorspace); - GDALDestroyColorTable( hColorMap ); - free( pabyRaw1 ); - free( pbIsNoDataBuffer ); + GDALDestroyColorTable(hColorMap); + free(pabyRaw1); + free(pbIsNoDataBuffer); return -1; } int color_count = GDALGetColorEntryCount(hColorMap); const bool bScaleColors = bScaled && !isDefaultGreyscale; - if( !bScaleColors && color_count > 256 ) + if (!bScaleColors && color_count > 256) color_count = 256; - for(i=0; i < color_count; i++) { + for (i = 0; i < color_count; i++) { colorObj pixel; int colormap_index; GDALColorEntry sEntry; - GDALGetColorEntryAsRGB( hColorMap, i, &sEntry ); + GDALGetColorEntryAsRGB(hColorMap, i, &sEntry); - const int j = bScaleColors ? MAX(0, MIN(255, (int) ((i-dfScaleMin)*dfScaleRatio))) : i; + const int j = + bScaleColors + ? MAX(0, MIN(255, (int)((i - dfScaleMin) * dfScaleRatio))) + : i; pixel.red = sEntry.c1; pixel.green = sEntry.c2; pixel.blue = sEntry.c3; colormap_index = i; - if(!MS_COMPARE_COLORS(pixel, layer->offsite)) { + if (!MS_COMPARE_COLORS(pixel, layer->offsite)) { c = msGetClass(layer, &pixel, colormap_index); - if(c != -1) { /* belongs to any class */ + if (c != -1) { /* belongs to any class */ int s; /* change colour based on colour range? Currently we only address the greyscale case properly. */ - if( MS_VALID_COLOR(layer->class[c]->styles[0]->mincolor) ) { - for(s=0; sclass[c]->numstyles; s++) { - if( MS_VALID_COLOR(layer->class[c]->styles[s]->mincolor) - && MS_VALID_COLOR(layer->class[c]->styles[s]->maxcolor)) { - if( sEntry.c1 >= layer->class[c]->styles[s]->minvalue - && sEntry.c1 <= layer->class[c]->styles[s]->maxvalue ) { - msValueToRange(layer->class[c]->styles[s], sEntry.c1, iRangeColorspace); - if(MS_VALID_COLOR(layer->class[c]->styles[s]->color)) { + if (MS_VALID_COLOR(layer->class[c] -> styles[0] -> mincolor)) { + for (s = 0; s < layer->class[c] -> numstyles; s++) { + if (MS_VALID_COLOR(layer->class[c] -> styles[s] -> mincolor) && + MS_VALID_COLOR(layer->class[c] -> styles[s] -> maxcolor)) { + if (sEntry.c1 >= layer->class[c] -> styles[s] + -> minvalue && + sEntry.c1 <= + layer->class[c] -> styles[s] -> maxvalue) { + msValueToRange(layer->class[c] -> styles[s], sEntry.c1, + iRangeColorspace); + if (MS_VALID_COLOR(layer->class[c] -> styles[s] -> color)) { rb_cmap[0][j] = layer->class[c]->styles[s]->color.red; rb_cmap[1][j] = layer->class[c]->styles[s]->color.green; rb_cmap[2][j] = layer->class[c]->styles[s]->color.blue; - rb_cmap[3][j] = (layer->class[c]->styles[s]->color.alpha != 255)?(layer->class[c]->styles[s]->color.alpha):(255*layer->class[c]->styles[0]->opacity / 100); + rb_cmap[3][j] = + (layer->class[c] -> styles[s] -> color.alpha != 255) + ? (layer->class[c] -> styles[s] -> color.alpha) + : (255 * layer->class[c] -> styles[0] -> opacity / + 100); break; } } } } - } - else if( MS_TRANSPARENT_COLOR(layer->class[c]->styles[0]->color)) + } else if (MS_TRANSPARENT_COLOR( + layer->class[c] -> styles[0] -> color)) /* leave it transparent */; - else if( MS_VALID_COLOR(layer->class[c]->styles[0]->color)) { + else if (MS_VALID_COLOR(layer->class[c] -> styles[0] -> color)) { rb_cmap[0][j] = layer->class[c]->styles[0]->color.red; rb_cmap[1][j] = layer->class[c]->styles[0]->color.green; rb_cmap[2][j] = layer->class[c]->styles[0]->color.blue; - rb_cmap[3][j] = (255*layer->class[c]->styles[0]->opacity / 100); + rb_cmap[3][j] = + (255 * layer->class[c] -> styles[0] -> opacity / 100); } else { /* Use raster color */ @@ -663,29 +660,32 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, } } } - } else if( hBand2 == NULL && hColorMap != NULL && rb->type == MS_BUFFER_BYTE_RGBA ) { + } else if (hBand2 == NULL && hColorMap != NULL && + rb->type == MS_BUFFER_BYTE_RGBA) { int color_count; #ifndef NDEBUG cmap_set = TRUE; #endif - color_count = MS_MIN(256,GDALGetColorEntryCount(hColorMap)); + color_count = MS_MIN(256, GDALGetColorEntryCount(hColorMap)); const bool bScaleColors = bScaled && !isDefaultGreyscale; - if( !bScaleColors && color_count > 256 ) + if (!bScaleColors && color_count > 256) color_count = 256; - for(i=0; i < color_count; i++) { + for (i = 0; i < color_count; i++) { GDALColorEntry sEntry; - GDALGetColorEntryAsRGB( hColorMap, i, &sEntry ); - const int j = bScaleColors ? MAX(0, MIN(255, (int) ((i-dfScaleMin)*dfScaleRatio))) : i; + GDALGetColorEntryAsRGB(hColorMap, i, &sEntry); + const int j = + bScaleColors + ? MAX(0, MIN(255, (int)((i - dfScaleMin) * dfScaleRatio))) + : i; - if( sEntry.c4 != 0 - && (!MS_VALID_COLOR( layer->offsite ) - || layer->offsite.red != sEntry.c1 - || layer->offsite.green != sEntry.c2 - || layer->offsite.blue != sEntry.c3 ) ) { + if (sEntry.c4 != 0 && + (!MS_VALID_COLOR(layer->offsite) || layer->offsite.red != sEntry.c1 || + layer->offsite.green != sEntry.c2 || + layer->offsite.blue != sEntry.c3)) { rb_cmap[0][j] = sEntry.c1; rb_cmap[1][j] = sEntry.c2; rb_cmap[2][j] = sEntry.c3; @@ -694,45 +694,43 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, } } - if( bHaveRGBNoData && layer->debug ) - msDebug( "msDrawGDAL(): using RGB nodata values from GDAL dataset.\n" ); + if (bHaveRGBNoData && layer->debug) + msDebug("msDrawGDAL(): using RGB nodata values from GDAL dataset.\n"); /* -------------------------------------------------------------------- */ /* If there was no alpha band, but we have a dataset level mask */ /* load it as massage it so it will function as our alpha for */ /* transparency purposes. */ /* -------------------------------------------------------------------- */ - if( hBandAlpha == NULL ) { + if (hBandAlpha == NULL) { int nMaskFlags = GDALGetMaskFlags(hBand1); - if( CSLTestBoolean(CSLFetchNameValueDef( layer->processing, "USE_MASK_BAND", "YES" )) && + if (CSLTestBoolean( + CSLFetchNameValueDef(layer->processing, "USE_MASK_BAND", "YES")) && (nMaskFlags & GMF_PER_DATASET) != 0 && - (nMaskFlags & (GMF_NODATA|GMF_ALL_VALID)) == 0 ) { + (nMaskFlags & (GMF_NODATA | GMF_ALL_VALID)) == 0) { CPLErr eErr; - unsigned char * pabyOrig = pabyRaw1; + unsigned char *pabyOrig = pabyRaw1; - - if( layer->debug ) - msDebug( "msDrawGDAL(): using GDAL mask band for alpha.\n" ); + if (layer->debug) + msDebug("msDrawGDAL(): using GDAL mask band for alpha.\n"); band_count++; - pabyRaw1 = (unsigned char *) - realloc(pabyOrig,dst_xsize * dst_ysize * band_count); + pabyRaw1 = (unsigned char *)realloc(pabyOrig, + dst_xsize * dst_ysize * band_count); - if( pabyRaw1 == NULL ) { - msSetError(MS_MEMERR, - "Allocating work image of size %dx%dx%d failed.", - "msDrawRasterLayerGDAL()", - dst_xsize, dst_ysize, band_count ); + if (pabyRaw1 == NULL) { + msSetError(MS_MEMERR, "Allocating work image of size %dx%dx%d failed.", + "msDrawRasterLayerGDAL()", dst_xsize, dst_ysize, band_count); free(pabyOrig); - if( hColorMap != NULL ) - GDALDestroyColorTable( hColorMap ); - free( pbIsNoDataBuffer ); + if (hColorMap != NULL) + GDALDestroyColorTable(hColorMap); + free(pbIsNoDataBuffer); return -1; } - if( hBand2 != NULL ) { + if (hBand2 != NULL) { pabyRaw2 = pabyRaw1 + dst_xsize * dst_ysize * 1; pabyRaw3 = pabyRaw1 + dst_xsize * dst_ysize * 2; pabyRawAlpha = pabyRaw1 + dst_xsize * dst_ysize * 3; @@ -742,147 +740,125 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, hBandAlpha = GDALGetMaskBand(hBand1); - eErr = GDALRasterIO( hBandAlpha, GF_Read, - src_xoff, src_yoff, src_xsize, src_ysize, - pabyRawAlpha, dst_xsize, dst_ysize, GDT_Byte, 0,0); - - if( eErr != CE_None ) { - msSetError( MS_IOERR, "GDALRasterIO() failed: %s", - "drawGDAL()", CPLGetLastErrorMsg() ); - if( hColorMap != NULL ) - GDALDestroyColorTable( hColorMap ); - free( pabyRaw1 ); - free( pbIsNoDataBuffer ); + eErr = GDALRasterIO(hBandAlpha, GF_Read, src_xoff, src_yoff, src_xsize, + src_ysize, pabyRawAlpha, dst_xsize, dst_ysize, + GDT_Byte, 0, 0); + + if (eErr != CE_None) { + msSetError(MS_IOERR, "GDALRasterIO() failed: %s", "drawGDAL()", + CPLGetLastErrorMsg()); + if (hColorMap != NULL) + GDALDestroyColorTable(hColorMap); + free(pabyRaw1); + free(pbIsNoDataBuffer); return -1; } /* In case the mask is not an alpha channel, expand values of 1 to 255, */ /* so we can deal as it was an alpha band afterwards */ if ((nMaskFlags & GMF_ALPHA) == 0) { - for(i=0; itype == MS_BUFFER_BYTE_RGBA && hBandAlpha != NULL ) { - assert( cmap_set ); - - int k = 0; - for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ ) { - for( int j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++ ) { - int src_pixel, src_alpha, cmap_alpha, merged_alpha; - if(SKIP_MASK(j,i) || (pbIsNoDataBuffer && pbIsNoDataBuffer[k])) - continue; + /* -------------------------------------------------------------------- */ + /* Single band plus colormap and alpha to truecolor. (RB) */ + /* -------------------------------------------------------------------- */ + if (hBand2 == NULL && rb->type == MS_BUFFER_BYTE_RGBA && hBandAlpha != NULL) { + assert(cmap_set); - src_pixel = pabyRaw1[k]; - src_alpha = pabyRawAlpha[k]; - cmap_alpha = rb_cmap[3][src_pixel]; - - merged_alpha = (src_alpha * cmap_alpha) / 255; - - if( merged_alpha < 2 ) - /* do nothing - transparent */; - else if( merged_alpha > 253 ) { - RB_SET_PIXEL( rb, j, i, - rb_cmap[0][src_pixel], - rb_cmap[1][src_pixel], - rb_cmap[2][src_pixel], - cmap_alpha ); - } else { - RB_MIX_PIXEL( rb, j, i, - rb_cmap[0][src_pixel], - rb_cmap[1][src_pixel], - rb_cmap[2][src_pixel], - merged_alpha ); - } + int k = 0; + for (i = dst_yoff; i < dst_yoff + dst_ysize; i++) { + for (int j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++) { + int src_pixel, src_alpha, cmap_alpha, merged_alpha; + if (SKIP_MASK(j, i) || (pbIsNoDataBuffer && pbIsNoDataBuffer[k])) + continue; + + src_pixel = pabyRaw1[k]; + src_alpha = pabyRawAlpha[k]; + cmap_alpha = rb_cmap[3][src_pixel]; + + merged_alpha = (src_alpha * cmap_alpha) / 255; + + if (merged_alpha < 2) + /* do nothing - transparent */; + else if (merged_alpha > 253) { + RB_SET_PIXEL(rb, j, i, rb_cmap[0][src_pixel], rb_cmap[1][src_pixel], + rb_cmap[2][src_pixel], cmap_alpha); + } else { + RB_MIX_PIXEL(rb, j, i, rb_cmap[0][src_pixel], rb_cmap[1][src_pixel], + rb_cmap[2][src_pixel], merged_alpha); } } } + } /* -------------------------------------------------------------------- */ /* Single band plus colormap (no alpha) to truecolor (RB) */ /* -------------------------------------------------------------------- */ - else if( hBand2 == NULL && rb->type == MS_BUFFER_BYTE_RGBA ) { - assert( cmap_set ); + else if (hBand2 == NULL && rb->type == MS_BUFFER_BYTE_RGBA) { + assert(cmap_set); - int k = 0; - for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ ) { - for( int j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++ ) { - int src_pixel = pabyRaw1[k]; - if(SKIP_MASK(j,i) || (pbIsNoDataBuffer && pbIsNoDataBuffer[k])) - continue; + int k = 0; + for (i = dst_yoff; i < dst_yoff + dst_ysize; i++) { + for (int j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++) { + int src_pixel = pabyRaw1[k]; + if (SKIP_MASK(j, i) || (pbIsNoDataBuffer && pbIsNoDataBuffer[k])) + continue; - if( rb_cmap[3][src_pixel] > 253 ) { - RB_SET_PIXEL( rb, j, i, - rb_cmap[0][src_pixel], - rb_cmap[1][src_pixel], - rb_cmap[2][src_pixel], - rb_cmap[3][src_pixel] ); - } else if( rb_cmap[3][src_pixel] > 1 ) { - RB_MIX_PIXEL( rb, j, i, - rb_cmap[0][src_pixel], - rb_cmap[1][src_pixel], - rb_cmap[2][src_pixel], - rb_cmap[3][src_pixel] ); - } + if (rb_cmap[3][src_pixel] > 253) { + RB_SET_PIXEL(rb, j, i, rb_cmap[0][src_pixel], rb_cmap[1][src_pixel], + rb_cmap[2][src_pixel], rb_cmap[3][src_pixel]); + } else if (rb_cmap[3][src_pixel] > 1) { + RB_MIX_PIXEL(rb, j, i, rb_cmap[0][src_pixel], rb_cmap[1][src_pixel], + rb_cmap[2][src_pixel], rb_cmap[3][src_pixel]); } } } + } /* -------------------------------------------------------------------- */ /* Input is 3 band RGB. Alpha blending is mixed into the loop */ /* since this case is less commonly used and has lots of other */ /* overhead. (RB) */ /* -------------------------------------------------------------------- */ - else if( hBand3 != NULL && rb->type == MS_BUFFER_BYTE_RGBA ) { - int k = 0; - for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ ) { - for( int j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++ ) { - if(SKIP_MASK(j,i) || (pbIsNoDataBuffer && pbIsNoDataBuffer[k])) - continue; - if( MS_VALID_COLOR( layer->offsite ) - && pabyRaw1[k] == layer->offsite.red - && pabyRaw2[k] == layer->offsite.green - && pabyRaw3[k] == layer->offsite.blue ) - continue; + else if (hBand3 != NULL && rb->type == MS_BUFFER_BYTE_RGBA) { + int k = 0; + for (i = dst_yoff; i < dst_yoff + dst_ysize; i++) { + for (int j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++) { + if (SKIP_MASK(j, i) || (pbIsNoDataBuffer && pbIsNoDataBuffer[k])) + continue; + if (MS_VALID_COLOR(layer->offsite) && + pabyRaw1[k] == layer->offsite.red && + pabyRaw2[k] == layer->offsite.green && + pabyRaw3[k] == layer->offsite.blue) + continue; - if( bHaveRGBNoData - && pabyRaw1[k] == nNoData1 - && pabyRaw2[k] == nNoData2 - && pabyRaw3[k] == nNoData3 ) - continue; + if (bHaveRGBNoData && pabyRaw1[k] == nNoData1 && + pabyRaw2[k] == nNoData2 && pabyRaw3[k] == nNoData3) + continue; - if( pabyRawAlpha == NULL || pabyRawAlpha[k] == 255 ) { - RB_SET_PIXEL( rb, j, i, - pabyRaw1[k], - pabyRaw2[k], - pabyRaw3[k], - 255 ); - } else if( pabyRawAlpha[k] != 0 ) { - RB_MIX_PIXEL( rb, j, i, - pabyRaw1[k], - pabyRaw2[k], - pabyRaw3[k], - pabyRawAlpha[k] ); - } + if (pabyRawAlpha == NULL || pabyRawAlpha[k] == 255) { + RB_SET_PIXEL(rb, j, i, pabyRaw1[k], pabyRaw2[k], pabyRaw3[k], 255); + } else if (pabyRawAlpha[k] != 0) { + RB_MIX_PIXEL(rb, j, i, pabyRaw1[k], pabyRaw2[k], pabyRaw3[k], + pabyRawAlpha[k]); } } } - + } /* ** Cleanup */ - free( pabyRaw1 ); - free( pbIsNoDataBuffer ); + free(pabyRaw1); + free(pbIsNoDataBuffer); - if( hColorMap != NULL ) - GDALDestroyColorTable( hColorMap ); + if (hColorMap != NULL) + GDALDestroyColorTable(hColorMap); return 0; } @@ -891,27 +867,27 @@ int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, /* ParseDefaultLUT() */ /************************************************************************/ -static int ParseDefaultLUT( const char *lut_def, GByte *lut, int nMaxValIn ) +static int ParseDefaultLUT(const char *lut_def, GByte *lut, int nMaxValIn) { const char *lut_read; - int last_in=0, last_out=0, all_done=FALSE; + int last_in = 0, last_out = 0, all_done = FALSE; /* -------------------------------------------------------------------- */ /* Parse definition, applying to lut on the fly. */ /* -------------------------------------------------------------------- */ lut_read = lut_def; - while( !all_done ) { - int this_in=0, this_out=0; + while (!all_done) { + int this_in = 0, this_out = 0; int lut_i; - while( isspace(*lut_read) ) + while (isspace(*lut_read)) lut_read++; /* if we are at end, assume nMaxValIn:255 */ - if( *lut_read == '\0' ) { + if (*lut_read == '\0') { all_done = TRUE; - if ( last_in != nMaxValIn ) { + if (last_in != nMaxValIn) { this_in = nMaxValIn; this_out = 255; } @@ -920,35 +896,35 @@ static int ParseDefaultLUT( const char *lut_def, GByte *lut, int nMaxValIn ) /* otherwise read "in:out", and skip past */ else { this_in = atoi(lut_read); - while( *lut_read != ':' && *lut_read ) + while (*lut_read != ':' && *lut_read) lut_read++; - if( *lut_read == ':' ) + if (*lut_read == ':') lut_read++; - while( isspace(*lut_read) ) + while (isspace(*lut_read)) lut_read++; this_out = atoi(lut_read); - while( *lut_read && *lut_read != ',' && *lut_read != '\n' ) + while (*lut_read && *lut_read != ',' && *lut_read != '\n') lut_read++; - if( *lut_read == ',' || *lut_read == '\n' ) + if (*lut_read == ',' || *lut_read == '\n') lut_read++; - while( isspace(*lut_read) ) + while (isspace(*lut_read)) lut_read++; } - this_in = MS_MAX(0,MS_MIN(nMaxValIn,this_in)); - this_out = MS_MAX(0,MS_MIN(255,this_out)); + this_in = MS_MAX(0, MS_MIN(nMaxValIn, this_in)); + this_out = MS_MAX(0, MS_MIN(255, this_out)); /* apply linear values from last in:out to this in:out */ - for( lut_i = last_in; lut_i <= this_in; lut_i++ ) { + for (lut_i = last_in; lut_i <= this_in; lut_i++) { double ratio; - if( last_in == this_in ) + if (last_in == this_in) ratio = 1.0; else - ratio = (lut_i - last_in) / (double) (this_in - last_in); + ratio = (lut_i - last_in) / (double)(this_in - last_in); - lut[lut_i] = (int) - floor(((1.0 - ratio)*last_out + ratio*this_out) + 0.5); + lut[lut_i] = + (int)floor(((1.0 - ratio) * last_out + ratio * this_out) + 0.5); } last_in = this_in; @@ -962,46 +938,46 @@ static int ParseDefaultLUT( const char *lut_def, GByte *lut, int nMaxValIn ) /* LutFromGimpLine() */ /************************************************************************/ -static int LutFromGimpLine( char *lut_line, GByte *lut ) +static int LutFromGimpLine(char *lut_line, GByte *lut) { char wrkLUTDef[1000]; - int i, count = 0; + int i, count = 0; char **tokens; /* cleanup white space at end of line (DOS LF, etc) */ i = strlen(lut_line) - 1; - while( i > 0 && isspace(lut_line[i]) ) + while (i > 0 && isspace(lut_line[i])) lut_line[i--] = '\0'; - while( *lut_line == 10 || *lut_line == 13 ) + while (*lut_line == 10 || *lut_line == 13) lut_line++; /* tokenize line */ - tokens = CSLTokenizeString( lut_line ); - if( CSLCount(tokens) != 17 * 2 ) { - CSLDestroy( tokens ); - msSetError(MS_MISCERR, - "GIMP curve file appears corrupt.", - "LutFromGimpLine()" ); + tokens = CSLTokenizeString(lut_line); + if (CSLCount(tokens) != 17 * 2) { + CSLDestroy(tokens); + msSetError(MS_MISCERR, "GIMP curve file appears corrupt.", + "LutFromGimpLine()"); return -1; } /* Convert to our own format */ wrkLUTDef[0] = '\0'; - for( i = 0; i < 17; i++ ) { - if( atoi(tokens[i*2]) >= 0 ) { - if( count++ > 0 ) - strlcat( wrkLUTDef, ",", sizeof(wrkLUTDef)); - - snprintf( wrkLUTDef + strlen(wrkLUTDef), sizeof(wrkLUTDef)-strlen(wrkLUTDef), - "%s:%s", tokens[i*2], tokens[i*2+1] ); + for (i = 0; i < 17; i++) { + if (atoi(tokens[i * 2]) >= 0) { + if (count++ > 0) + strlcat(wrkLUTDef, ",", sizeof(wrkLUTDef)); + + snprintf(wrkLUTDef + strlen(wrkLUTDef), + sizeof(wrkLUTDef) - strlen(wrkLUTDef), "%s:%s", tokens[i * 2], + tokens[i * 2 + 1]); } } - CSLDestroy( tokens ); + CSLDestroy(tokens); - return ParseDefaultLUT( wrkLUTDef, lut, 255 ); + return ParseDefaultLUT(wrkLUTDef, lut, 255); } /************************************************************************/ @@ -1010,33 +986,30 @@ static int LutFromGimpLine( char *lut_line, GByte *lut ) /* Parse a Gimp style LUT. */ /************************************************************************/ -static int ParseGimpLUT( const char *lut_def, GByte *lut, int iColorIndex ) +static int ParseGimpLUT(const char *lut_def, GByte *lut, int iColorIndex) { int i; GByte lutValue[256]; GByte lutColorBand[256]; - char **lines = - CSLTokenizeStringComplex( lut_def, "\n", FALSE, FALSE ); - - if( !EQUALN(lines[0],"# GIMP Curves File",18) - || CSLCount(lines) < 6 ) { - msSetError(MS_MISCERR, - "GIMP curve file appears corrupt.", - "ParseGimpLUT()" ); - CSLDestroy( lines ); + char **lines = CSLTokenizeStringComplex(lut_def, "\n", FALSE, FALSE); + + if (!EQUALN(lines[0], "# GIMP Curves File", 18) || CSLCount(lines) < 6) { + msSetError(MS_MISCERR, "GIMP curve file appears corrupt.", + "ParseGimpLUT()"); + CSLDestroy(lines); return -1; } /* * Convert the overall curve, and the color band specific curve into LUTs. */ - if( LutFromGimpLine( lines[1], lutValue ) != 0 - || LutFromGimpLine( lines[iColorIndex + 1], lutColorBand ) != 0 ) { - CSLDestroy( lines ); + if (LutFromGimpLine(lines[1], lutValue) != 0 || + LutFromGimpLine(lines[iColorIndex + 1], lutColorBand) != 0) { + CSLDestroy(lines); return -1; } - CSLDestroy( lines ); + CSLDestroy(lines); /* * Compose the two luts as if the raw value passed through the color band @@ -1044,7 +1017,7 @@ static int ParseGimpLUT( const char *lut_def, GByte *lut, int iColorIndex ) * other will be the identity mapping, but not always. */ - for( i = 0; i < 256; i++ ) { + for (i = 0; i < 256; i++) { lut[i] = lutValue[lutColorBand[i]]; } @@ -1057,7 +1030,7 @@ static int ParseGimpLUT( const char *lut_def, GByte *lut, int iColorIndex ) /* Load a LUT according to RFC 21. */ /************************************************************************/ -static int LoadLUT( layerObj *layer, int iColorIndex, char** ppszLutDef ) +static int LoadLUT(layerObj *layer, int iColorIndex, char **ppszLutDef) { const char *lut_def; @@ -1069,37 +1042,35 @@ static int LoadLUT( layerObj *layer, int iColorIndex, char** ppszLutDef ) /* Get lut specifier from processing directives. Do nothing if */ /* none are found. */ /* -------------------------------------------------------------------- */ - sprintf( key, "LUT_%d", iColorIndex ); - lut_def = msLayerGetProcessingKey( layer, key ); - if( lut_def == NULL ) - lut_def = msLayerGetProcessingKey( layer, "LUT" ); - if( lut_def == NULL ) + sprintf(key, "LUT_%d", iColorIndex); + lut_def = msLayerGetProcessingKey(layer, key); + if (lut_def == NULL) + lut_def = msLayerGetProcessingKey(layer, "LUT"); + if (lut_def == NULL) return 0; /* -------------------------------------------------------------------- */ /* Does this look like a file? If so, read it into memory. */ /* -------------------------------------------------------------------- */ - if( strspn(lut_def,"0123456789:, ") != strlen(lut_def) ) { + if (strspn(lut_def, "0123456789:, ") != strlen(lut_def)) { FILE *fp; char path[MS_MAXPATHLEN]; int len; msBuildPath(path, layer->map->mappath, lut_def); - fp = fopen( path, "rb" ); - if( fp == NULL ) { - msSetError(MS_IOERR, - "Failed to open LUT file '%s'.", - "drawGDAL()", path ); + fp = fopen(path, "rb"); + if (fp == NULL) { + msSetError(MS_IOERR, "Failed to open LUT file '%s'.", "drawGDAL()", path); return -1; } - len = fread( lut_def_fromfile, 1, sizeof(lut_def_fromfile), fp ); - fclose( fp ); + len = fread(lut_def_fromfile, 1, sizeof(lut_def_fromfile), fp); + fclose(fp); - if( len == sizeof(lut_def_fromfile) ) { + if (len == sizeof(lut_def_fromfile)) { msSetError(MS_IOERR, - "LUT definition from file %s longer than maximum buffer size (%d bytes).", - "drawGDAL()", - path, (int)sizeof(lut_def_fromfile) ); + "LUT definition from file %s longer than maximum buffer size " + "(%d bytes).", + "drawGDAL()", path, (int)sizeof(lut_def_fromfile)); return -1; } @@ -1111,19 +1082,17 @@ static int LoadLUT( layerObj *layer, int iColorIndex, char** ppszLutDef ) *ppszLutDef = msStrdup(lut_def); return 0; - } /************************************************************************/ /* FreeLUTs() */ /************************************************************************/ -static void FreeLUTs(char** apszLUTs) -{ - int i; - for( i = 0; i < 4; i++ ) - msFree(apszLUTs[i]); - msFree(apszLUTs); +static void FreeLUTs(char **apszLUTs) { + int i; + for (i = 0; i < 4; i++) + msFree(apszLUTs[i]); + msFree(apszLUTs); } /************************************************************************/ @@ -1133,24 +1102,21 @@ static void FreeLUTs(char** apszLUTs) /* or NULL in case of failure. */ /************************************************************************/ -static char** LoadLUTs(layerObj *layer, int band_count) -{ - int i; - char** apszLUTs; - - assert(band_count <= 4); +static char **LoadLUTs(layerObj *layer, int band_count) { + int i; + char **apszLUTs; - apszLUTs = (char**) msSmallCalloc( 4, sizeof(char*) ); - for( i = 0; i < band_count; i++ ) - { - if( LoadLUT( layer, i+1, &apszLUTs[i] ) != 0 ) - { - FreeLUTs(apszLUTs); - return NULL; - } + assert(band_count <= 4); + + apszLUTs = (char **)msSmallCalloc(4, sizeof(char *)); + for (i = 0; i < band_count; i++) { + if (LoadLUT(layer, i + 1, &apszLUTs[i]) != 0) { + FreeLUTs(apszLUTs); + return NULL; } + } - return apszLUTs; + return apszLUTs; } /************************************************************************/ @@ -1161,105 +1127,88 @@ static char** LoadLUTs(layerObj *layer, int band_count) /* must be queries on 16-bits. */ /************************************************************************/ -static GDALDataType GetDataTypeAppropriateForLUTS(char** apszLUTs) -{ - GDALDataType eDT = GDT_Byte; - int i; - for( i = 0; i < 4; i++ ) - { - const char* pszLastTuple; - int nLastInValue; - if( apszLUTs[i] == NULL ) - continue; - if( EQUALN(apszLUTs[i],"# GIMP",6) ) - continue; - /* Find last in:out tuple in string */ - pszLastTuple = strrchr( apszLUTs[i], ',' ); - if( pszLastTuple == NULL ) - pszLastTuple = apszLUTs[i]; - else - pszLastTuple ++; - while( *pszLastTuple == ' ' ) - pszLastTuple ++; - nLastInValue = atoi(pszLastTuple); - if( nLastInValue > 255 ) - { - eDT = GDT_UInt16; - break; - } +static GDALDataType GetDataTypeAppropriateForLUTS(char **apszLUTs) { + GDALDataType eDT = GDT_Byte; + int i; + for (i = 0; i < 4; i++) { + const char *pszLastTuple; + int nLastInValue; + if (apszLUTs[i] == NULL) + continue; + if (EQUALN(apszLUTs[i], "# GIMP", 6)) + continue; + /* Find last in:out tuple in string */ + pszLastTuple = strrchr(apszLUTs[i], ','); + if (pszLastTuple == NULL) + pszLastTuple = apszLUTs[i]; + else + pszLastTuple++; + while (*pszLastTuple == ' ') + pszLastTuple++; + nLastInValue = atoi(pszLastTuple); + if (nLastInValue > 255) { + eDT = GDT_UInt16; + break; } - return eDT; + } + return eDT; } /************************************************************************/ /* ApplyLUT() */ /************************************************************************/ -static int ApplyLUT( int iColorIndex, const char* lut_def, - const void* pInBuffer, GDALDataType eDT, - GByte* pabyOutBuffer, - int nPixelCount ) -{ +static int ApplyLUT(int iColorIndex, const char *lut_def, const void *pInBuffer, + GDALDataType eDT, GByte *pabyOutBuffer, int nPixelCount) { int i, err; GByte byteLut[256]; - GByte* uint16Lut = NULL; - - assert( eDT == GDT_Byte || eDT == GDT_UInt16 ); - - if( lut_def == NULL ) - { - if( pInBuffer != pabyOutBuffer ) - { - GDALCopyWords( (void*)pInBuffer, eDT, GDALGetDataTypeSize(eDT) / 8, - pabyOutBuffer, GDT_Byte, 1, - nPixelCount ); - } - return 0; + GByte *uint16Lut = NULL; + + assert(eDT == GDT_Byte || eDT == GDT_UInt16); + + if (lut_def == NULL) { + if (pInBuffer != pabyOutBuffer) { + GDALCopyWords((void *)pInBuffer, eDT, GDALGetDataTypeSize(eDT) / 8, + pabyOutBuffer, GDT_Byte, 1, nPixelCount); + } + return 0; } /* -------------------------------------------------------------------- */ /* Parse the LUT description. */ /* -------------------------------------------------------------------- */ - if( EQUALN(lut_def,"# GIMP",6) ) { - if( eDT != GDT_Byte ) { - msSetError(MS_MISCERR, - "Cannot apply a GIMP LUT on a 16-bit buffer", + if (EQUALN(lut_def, "# GIMP", 6)) { + if (eDT != GDT_Byte) { + msSetError(MS_MISCERR, "Cannot apply a GIMP LUT on a 16-bit buffer", "ApplyLUT()"); return -1; } - err = ParseGimpLUT( lut_def, byteLut, iColorIndex ); + err = ParseGimpLUT(lut_def, byteLut, iColorIndex); } else { - if( eDT == GDT_Byte ) - err = ParseDefaultLUT( lut_def, byteLut, 255 ); - else - { - uint16Lut = (GByte*) malloc( 65536 ); - if( uint16Lut == NULL ) - { - msSetError(MS_MEMERR, - "Cannot allocate 16-bit LUT", - "ApplyLUT()" ); - return -1; - } - err = ParseDefaultLUT( lut_def, uint16Lut, 65535 ); + if (eDT == GDT_Byte) + err = ParseDefaultLUT(lut_def, byteLut, 255); + else { + uint16Lut = (GByte *)malloc(65536); + if (uint16Lut == NULL) { + msSetError(MS_MEMERR, "Cannot allocate 16-bit LUT", "ApplyLUT()"); + return -1; + } + err = ParseDefaultLUT(lut_def, uint16Lut, 65535); } } /* -------------------------------------------------------------------- */ /* Apply LUT. */ /* -------------------------------------------------------------------- */ - if( eDT == GDT_Byte ) - { - for( i = 0; i < nPixelCount; i++ ) - pabyOutBuffer[i] = byteLut[((GByte*)pInBuffer)[i]]; - } - else - { - for( i = 0; i < nPixelCount; i++ ) - pabyOutBuffer[i] = uint16Lut[((GUInt16*)pInBuffer)[i]]; - free(uint16Lut); + if (eDT == GDT_Byte) { + for (i = 0; i < nPixelCount; i++) + pabyOutBuffer[i] = byteLut[((GByte *)pInBuffer)[i]]; + } else { + for (i = 0; i < nPixelCount; i++) + pabyOutBuffer[i] = uint16Lut[((GUInt16 *)pInBuffer)[i]]; + free(uint16Lut); } - + return err; } @@ -1271,22 +1220,19 @@ static int ApplyLUT( int iColorIndex, const char* lut_def, /* buffer. The processing options include scaling. */ /************************************************************************/ -static int -LoadGDALImages( GDALDatasetH hDS, int band_numbers[4], int band_count, - layerObj *layer, - int src_xoff, int src_yoff, int src_xsize, int src_ysize, - GByte *pabyWholeBuffer, - int dst_xsize, int dst_ysize, - int *pbHaveRGBNoData, - int *pnNoData1, int *pnNoData2, int *pnNoData3, - bool *pbScaled, double *pdfScaleMin, double *pdfScaleRatio, - bool **ppbIsNoDataBuffer ) +static int LoadGDALImages(GDALDatasetH hDS, int band_numbers[4], int band_count, + layerObj *layer, int src_xoff, int src_yoff, + int src_xsize, int src_ysize, GByte *pabyWholeBuffer, + int dst_xsize, int dst_ysize, int *pbHaveRGBNoData, + int *pnNoData1, int *pnNoData2, int *pnNoData3, + bool *pbScaled, double *pdfScaleMin, + double *pdfScaleRatio, bool **ppbIsNoDataBuffer) { - int iColorIndex, result_code=0; + int iColorIndex, result_code = 0; CPLErr eErr; float *pafWholeRawData; - char** papszLUTs; + char **papszLUTs; *pbScaled = false; *pdfScaleMin = 0; @@ -1299,87 +1245,73 @@ LoadGDALImages( GDALDatasetH hDS, int band_numbers[4], int band_count, /* input band, then nodata will already have been adderssed as */ /* part of the real or manufactured color table. */ /* -------------------------------------------------------------------- */ - if( band_count == 3 ) { - *pnNoData1 = (int) - msGetGDALNoDataValue( layer, - GDALGetRasterBand(hDS,band_numbers[0]), - pbHaveRGBNoData); + if (band_count == 3) { + *pnNoData1 = (int)msGetGDALNoDataValue( + layer, GDALGetRasterBand(hDS, band_numbers[0]), pbHaveRGBNoData); - if( *pbHaveRGBNoData ) - *pnNoData2 = (int) - msGetGDALNoDataValue( layer, - GDALGetRasterBand(hDS,band_numbers[1]), - pbHaveRGBNoData); - if( *pbHaveRGBNoData ) - *pnNoData3 = (int) - msGetGDALNoDataValue( layer, - GDALGetRasterBand(hDS,band_numbers[2]), - pbHaveRGBNoData); + if (*pbHaveRGBNoData) + *pnNoData2 = (int)msGetGDALNoDataValue( + layer, GDALGetRasterBand(hDS, band_numbers[1]), pbHaveRGBNoData); + if (*pbHaveRGBNoData) + *pnNoData3 = (int)msGetGDALNoDataValue( + layer, GDALGetRasterBand(hDS, band_numbers[2]), pbHaveRGBNoData); } /* -------------------------------------------------------------------- */ /* Are we doing a simple, non-scaling case? If so, read directly */ /* and return. */ /* -------------------------------------------------------------------- */ - if( CSLFetchNameValue( layer->processing, "SCALE" ) == NULL - && CSLFetchNameValue( layer->processing, "SCALE_1" ) == NULL - && CSLFetchNameValue( layer->processing, "SCALE_2" ) == NULL - && CSLFetchNameValue( layer->processing, "SCALE_3" ) == NULL - && CSLFetchNameValue( layer->processing, "SCALE_4" ) == NULL ) { - + if (CSLFetchNameValue(layer->processing, "SCALE") == NULL && + CSLFetchNameValue(layer->processing, "SCALE_1") == NULL && + CSLFetchNameValue(layer->processing, "SCALE_2") == NULL && + CSLFetchNameValue(layer->processing, "SCALE_3") == NULL && + CSLFetchNameValue(layer->processing, "SCALE_4") == NULL) { + GDALDataType eDT; - GUInt16* panBuffer = NULL; - void* pBuffer; + GUInt16 *panBuffer = NULL; + void *pBuffer; papszLUTs = LoadLUTs(layer, band_count); - if( papszLUTs == NULL ) { - return -1; + if (papszLUTs == NULL) { + return -1; } eDT = GetDataTypeAppropriateForLUTS(papszLUTs); - if( eDT == GDT_UInt16 ) { - panBuffer = - (GUInt16 *) malloc(sizeof(GUInt16) * dst_xsize * dst_ysize * band_count ); - - if( panBuffer == NULL ) { - msSetError(MS_MEMERR, - "Allocating work uint16 image of size %dx%dx%d failed.", - "msDrawRasterLayerGDAL()", - dst_xsize, dst_ysize, band_count ); - FreeLUTs(papszLUTs); - return -1; - } - pBuffer = panBuffer; - } - else - pBuffer = pabyWholeBuffer; - - eErr = GDALDatasetRasterIO( hDS, GF_Read, - src_xoff, src_yoff, src_xsize, src_ysize, - pBuffer, - dst_xsize, dst_ysize, eDT, - band_count, band_numbers, - 0,0,0); - - if( eErr != CE_None ) { - msSetError( MS_IOERR, - "GDALDatasetRasterIO() failed: %s", - "drawGDAL()", - CPLGetLastErrorMsg() ); + if (eDT == GDT_UInt16) { + panBuffer = (GUInt16 *)malloc(sizeof(GUInt16) * dst_xsize * dst_ysize * + band_count); + + if (panBuffer == NULL) { + msSetError(MS_MEMERR, + "Allocating work uint16 image of size %dx%dx%d failed.", + "msDrawRasterLayerGDAL()", dst_xsize, dst_ysize, band_count); + FreeLUTs(papszLUTs); + return -1; + } + pBuffer = panBuffer; + } else + pBuffer = pabyWholeBuffer; + + eErr = GDALDatasetRasterIO(hDS, GF_Read, src_xoff, src_yoff, src_xsize, + src_ysize, pBuffer, dst_xsize, dst_ysize, eDT, + band_count, band_numbers, 0, 0, 0); + + if (eErr != CE_None) { + msSetError(MS_IOERR, "GDALDatasetRasterIO() failed: %s", "drawGDAL()", + CPLGetLastErrorMsg()); FreeLUTs(papszLUTs); msFree(panBuffer); return -1; } - for( iColorIndex = 0; - iColorIndex < band_count && result_code == 0; iColorIndex++ ) { - result_code = ApplyLUT( iColorIndex+1, - papszLUTs[iColorIndex], - (GByte*)pBuffer - + dst_xsize*dst_ysize*iColorIndex*(GDALGetDataTypeSize(eDT)/8), - eDT, - pabyWholeBuffer + dst_xsize*dst_ysize*iColorIndex, - dst_xsize * dst_ysize ); + for (iColorIndex = 0; iColorIndex < band_count && result_code == 0; + iColorIndex++) { + result_code = + ApplyLUT(iColorIndex + 1, papszLUTs[iColorIndex], + (GByte *)pBuffer + dst_xsize * dst_ysize * iColorIndex * + (GDALGetDataTypeSize(eDT) / 8), + eDT, pabyWholeBuffer + dst_xsize * dst_ysize * iColorIndex, + dst_xsize * dst_ysize); } FreeLUTs(papszLUTs); @@ -1406,85 +1338,76 @@ LoadGDALImages( GDALDatasetH hDS, int band_numbers[4], int band_count, /* interleaved). */ /* -------------------------------------------------------------------- */ pafWholeRawData = - (float *) malloc(sizeof(float) * dst_xsize * dst_ysize * band_count ); + (float *)malloc(sizeof(float) * dst_xsize * dst_ysize * band_count); - if( pafWholeRawData == NULL ) { + if (pafWholeRawData == NULL) { msSetError(MS_MEMERR, "Allocating work float image of size %dx%dx%d failed.", - "msDrawRasterLayerGDAL()", - dst_xsize, dst_ysize, band_count ); + "msDrawRasterLayerGDAL()", dst_xsize, dst_ysize, band_count); return -1; } - eErr = GDALDatasetRasterIO( - hDS, GF_Read, - src_xoff, src_yoff, src_xsize, src_ysize, - pafWholeRawData, dst_xsize, dst_ysize, GDT_Float32, - band_count, band_numbers, - 0, 0, 0 ); + eErr = GDALDatasetRasterIO(hDS, GF_Read, src_xoff, src_yoff, src_xsize, + src_ysize, pafWholeRawData, dst_xsize, dst_ysize, + GDT_Float32, band_count, band_numbers, 0, 0, 0); - if( eErr != CE_None ) { - msSetError( MS_IOERR, "GDALDatasetRasterIO() failed: %s", - "drawGDAL()", - CPLGetLastErrorMsg() ); + if (eErr != CE_None) { + msSetError(MS_IOERR, "GDALDatasetRasterIO() failed: %s", "drawGDAL()", + CPLGetLastErrorMsg()); - free( pafWholeRawData ); + free(pafWholeRawData); return -1; } papszLUTs = LoadLUTs(layer, band_count); - if( papszLUTs == NULL ) { - free( pafWholeRawData ); + if (papszLUTs == NULL) { + free(pafWholeRawData); return -1; } - if( GetDataTypeAppropriateForLUTS(papszLUTs) != GDT_Byte ) { - msDebug( "LoadGDALImage(%s): One of the LUT contains a input value > 255.\n" - "This is not properly supported in combination with SCALE\n", - layer->name ); + if (GetDataTypeAppropriateForLUTS(papszLUTs) != GDT_Byte) { + msDebug("LoadGDALImage(%s): One of the LUT contains a input value > 255.\n" + "This is not properly supported in combination with SCALE\n", + layer->name); } /* -------------------------------------------------------------------- */ /* Fetch the scale processing option. */ /* -------------------------------------------------------------------- */ - for( iColorIndex = 0; iColorIndex < band_count; iColorIndex++ ) { + for (iColorIndex = 0; iColorIndex < band_count; iColorIndex++) { unsigned char *pabyBuffer; - double dfScaleMin=0.0, dfScaleMax=255.0, dfScaleRatio, dfNoDataValue; + double dfScaleMin = 0.0, dfScaleMax = 255.0, dfScaleRatio, dfNoDataValue; const char *pszScaleInfo; float *pafRawData; - int nPixelCount = dst_xsize * dst_ysize, i, bGotNoData = FALSE; - GDALRasterBandH hBand =GDALGetRasterBand(hDS,band_numbers[iColorIndex]); - pszScaleInfo = CSLFetchNameValue( layer->processing, "SCALE" ); - if( pszScaleInfo == NULL ) { + int nPixelCount = dst_xsize * dst_ysize, i, bGotNoData = FALSE; + GDALRasterBandH hBand = GDALGetRasterBand(hDS, band_numbers[iColorIndex]); + pszScaleInfo = CSLFetchNameValue(layer->processing, "SCALE"); + if (pszScaleInfo == NULL) { char szBandScalingName[20]; - sprintf( szBandScalingName, "SCALE_%d", iColorIndex+1 ); - pszScaleInfo = CSLFetchNameValue( layer->processing, - szBandScalingName); + sprintf(szBandScalingName, "SCALE_%d", iColorIndex + 1); + pszScaleInfo = CSLFetchNameValue(layer->processing, szBandScalingName); } - if( pszScaleInfo != NULL ) { + if (pszScaleInfo != NULL) { char **papszTokens; - papszTokens = CSLTokenizeStringComplex( pszScaleInfo, " ,", - FALSE, FALSE ); - if( CSLCount(papszTokens) == 1 - && EQUAL(papszTokens[0],"AUTO") ) { + papszTokens = CSLTokenizeStringComplex(pszScaleInfo, " ,", FALSE, FALSE); + if (CSLCount(papszTokens) == 1 && EQUAL(papszTokens[0], "AUTO")) { dfScaleMin = dfScaleMax = 0.0; - } else if( CSLCount(papszTokens) != 2 ) { - free( pafWholeRawData ); - CSLDestroy( papszTokens ); - FreeLUTs( papszLUTs ); - msSetError( MS_MISCERR, - "SCALE PROCESSING option unparsable for layer %s.", - "msDrawGDAL()", - layer->name ); + } else if (CSLCount(papszTokens) != 2) { + free(pafWholeRawData); + CSLDestroy(papszTokens); + FreeLUTs(papszLUTs); + msSetError(MS_MISCERR, + "SCALE PROCESSING option unparsable for layer %s.", + "msDrawGDAL()", layer->name); return -1; } else { dfScaleMin = atof(papszTokens[0]); dfScaleMax = atof(papszTokens[1]); } - CSLDestroy( papszTokens ); + CSLDestroy(papszTokens); } /* -------------------------------------------------------------------- */ @@ -1494,42 +1417,42 @@ LoadGDALImages( GDALDatasetH hDS, int band_numbers[4], int band_count, /* -------------------------------------------------------------------- */ pafRawData = pafWholeRawData + iColorIndex * dst_xsize * dst_ysize; - dfNoDataValue = msGetGDALNoDataValue( layer, hBand, &bGotNoData ); + dfNoDataValue = msGetGDALNoDataValue(layer, hBand, &bGotNoData); /* we force assignment to a float rather than letting pafRawData[i] get promoted to double later to avoid float precision issues. */ - float fNoDataValue = (float) dfNoDataValue; + float fNoDataValue = (float)dfNoDataValue; - if( dfScaleMin == dfScaleMax ) { + if (dfScaleMin == dfScaleMax) { int bMinMaxSet = 0; /* we force assignment to a float rather than letting pafRawData[i] get promoted to double later to avoid float precision issues. */ - float fNoDataValue = (float) dfNoDataValue; + float fNoDataValue = (float)dfNoDataValue; - for( i = 0; i < nPixelCount; i++ ) { - if( bGotNoData && IsNoData(pafRawData[i], fNoDataValue) ) + for (i = 0; i < nPixelCount; i++) { + if (bGotNoData && IsNoData(pafRawData[i], fNoDataValue)) continue; - if( CPLIsNan(pafRawData[i]) ) + if (CPLIsNan(pafRawData[i])) continue; - if( !bMinMaxSet ) { + if (!bMinMaxSet) { dfScaleMin = dfScaleMax = pafRawData[i]; bMinMaxSet = TRUE; } - dfScaleMin = MS_MIN(dfScaleMin,pafRawData[i]); - dfScaleMax = MS_MAX(dfScaleMax,pafRawData[i]); + dfScaleMin = MS_MIN(dfScaleMin, pafRawData[i]); + dfScaleMax = MS_MAX(dfScaleMax, pafRawData[i]); } - if( dfScaleMin == dfScaleMax ) + if (dfScaleMin == dfScaleMax) dfScaleMax = dfScaleMin + 1.0; } - if( layer->debug > 0 ) - msDebug( "msDrawGDAL(%s): scaling to 8bit, src range=%g,%g\n", - layer->name, dfScaleMin, dfScaleMax ); + if (layer->debug > 0) + msDebug("msDrawGDAL(%s): scaling to 8bit, src range=%g,%g\n", layer->name, + dfScaleMin, dfScaleMax); /* -------------------------------------------------------------------- */ /* Now process the data. */ @@ -1537,29 +1460,29 @@ LoadGDALImages( GDALDatasetH hDS, int band_numbers[4], int band_count, dfScaleRatio = 256.0 / (dfScaleMax - dfScaleMin); pabyBuffer = pabyWholeBuffer + iColorIndex * nPixelCount; - if( iColorIndex == 0 && bGotNoData ) + if (iColorIndex == 0 && bGotNoData) *ppbIsNoDataBuffer = (bool *)calloc(nPixelCount, 1); - for( i = 0; i < nPixelCount; i++ ) { + for (i = 0; i < nPixelCount; i++) { float fScaledValue; - if( bGotNoData && IsNoData(pafRawData[i], fNoDataValue) ) { - if( iColorIndex == 0 ) + if (bGotNoData && IsNoData(pafRawData[i], fNoDataValue)) { + if (iColorIndex == 0) (*ppbIsNoDataBuffer)[i] = true; continue; } - fScaledValue = (float) ((pafRawData[i]-dfScaleMin)*dfScaleRatio); + fScaledValue = (float)((pafRawData[i] - dfScaleMin) * dfScaleRatio); - if( fScaledValue < 0.0 ) + if (fScaledValue < 0.0) pabyBuffer[i] = 0; - else if( fScaledValue > 255.0 ) + else if (fScaledValue > 255.0) pabyBuffer[i] = 255; else - pabyBuffer[i] = (int) fScaledValue; + pabyBuffer[i] = (int)fScaledValue; } - if( iColorIndex == 0 ) { + if (iColorIndex == 0) { *pbScaled = true; *pdfScaleMin = dfScaleMin; *pdfScaleRatio = dfScaleRatio; @@ -1570,36 +1493,33 @@ LoadGDALImages( GDALDatasetH hDS, int band_numbers[4], int band_count, /* unable to utilize it since we can't return any pixels marked */ /* as nodata from this function. Need to fix someday. */ /* -------------------------------------------------------------------- */ - if( bGotNoData ) - msDebug( "LoadGDALImage(%s): NODATA value %g in GDAL\n" - "file or PROCESSING directive largely ignored. Not yet fully supported for\n" - "unclassified scaled data. The NODATA value is excluded from auto-scaling\n" - "min/max computation, but will not be transparent.\n", - layer->name, dfNoDataValue ); + if (bGotNoData) + msDebug("LoadGDALImage(%s): NODATA value %g in GDAL\n" + "file or PROCESSING directive largely ignored. Not yet fully " + "supported for\n" + "unclassified scaled data. The NODATA value is excluded from " + "auto-scaling\n" + "min/max computation, but will not be transparent.\n", + layer->name, dfNoDataValue); /* -------------------------------------------------------------------- */ /* Apply LUT if there is one. */ /* -------------------------------------------------------------------- */ - result_code = ApplyLUT( iColorIndex+1, - papszLUTs[iColorIndex], - pabyBuffer, - GDT_Byte, - pabyBuffer, - dst_xsize * dst_ysize ); - if( result_code == -1 ) { - free( pafWholeRawData ); - FreeLUTs( papszLUTs ); + result_code = ApplyLUT(iColorIndex + 1, papszLUTs[iColorIndex], pabyBuffer, + GDT_Byte, pabyBuffer, dst_xsize * dst_ysize); + if (result_code == -1) { + free(pafWholeRawData); + FreeLUTs(papszLUTs); return result_code; } } - free( pafWholeRawData ); - FreeLUTs( papszLUTs ); + free(pafWholeRawData); + FreeLUTs(papszLUTs); return result_code; } - /************************************************************************/ /* msGetGDALGeoTransform() */ /* */ @@ -1608,8 +1528,8 @@ LoadGDALImages( GDALDatasetH hDS, int band_numbers[4], int band_count, /* before this function is called. */ /************************************************************************/ -int msGetGDALGeoTransform( GDALDatasetH hDS, mapObj *map, layerObj *layer, - double *padfGeoTransform ) +int msGetGDALGeoTransform(GDALDatasetH hDS, mapObj *map, layerObj *layer, + double *padfGeoTransform) { const char *extent_priority = NULL; @@ -1620,7 +1540,7 @@ int msGetGDALGeoTransform( GDALDatasetH hDS, mapObj *map, layerObj *layer, char szPath[MS_MAXPATHLEN]; int fullPathLen; int success = 0; - rectObj rect; + rectObj rect; /* -------------------------------------------------------------------- */ /* some GDAL drivers (ie. GIF) don't set geotransform on failure. */ @@ -1635,33 +1555,32 @@ int msGetGDALGeoTransform( GDALDatasetH hDS, mapObj *map, layerObj *layer, /* -------------------------------------------------------------------- */ /* Do we want to override GDAL with a worldfile if one is present? */ /* -------------------------------------------------------------------- */ - extent_priority = CSLFetchNameValue( layer->processing, - "EXTENT_PRIORITY" ); + extent_priority = CSLFetchNameValue(layer->processing, "EXTENT_PRIORITY"); - if( extent_priority != NULL - && EQUALN(extent_priority,"WORLD",5) ) { + if (extent_priority != NULL && EQUALN(extent_priority, "WORLD", 5)) { /* is there a user configured worldfile? */ - value = CSLFetchNameValue( layer->processing, "WORLDFILE" ); + value = CSLFetchNameValue(layer->processing, "WORLDFILE"); - if( value != NULL ) { + if (value != NULL) { /* at this point, fullPath may be a filePath or path only */ fullPath = msBuildPath(szPath, map->mappath, value); /* fullPath is a path only, so let's append the dataset filename */ - if( strrchr(szPath,'.') == NULL ) { + if (strrchr(szPath, '.') == NULL) { fullPathLen = strlen(fullPath); - gdalDesc = msStripPath((char*)GDALGetDescription(hDS)); + gdalDesc = msStripPath((char *)GDALGetDescription(hDS)); - if ( (fullPathLen + strlen(gdalDesc)) < MS_MAXPATHLEN ) { - strcpy((char*)(fullPath + fullPathLen), gdalDesc); + if ((fullPathLen + strlen(gdalDesc)) < MS_MAXPATHLEN) { + strcpy((char *)(fullPath + fullPathLen), gdalDesc); } else { - msDebug("Path length to alternative worldfile exceeds MS_MAXPATHLEN.\n"); + msDebug( + "Path length to alternative worldfile exceeds MS_MAXPATHLEN.\n"); fullPath = NULL; } } /* fullPath has a filename included, so get the extension */ else { - fileExtension = msStrdup(strrchr(szPath,'.') + 1); + fileExtension = msStrdup(strrchr(szPath, '.') + 1); } } /* common behaviour with worldfile generated from basename + .wld */ @@ -1670,18 +1589,18 @@ int msGetGDALGeoTransform( GDALDatasetH hDS, mapObj *map, layerObj *layer, fileExtension = msStrdup("wld"); } - if( fullPath ) + if (fullPath) success = GDALReadWorldFile(fullPath, fileExtension, padfGeoTransform); - if( success && layer->debug >= MS_DEBUGLEVEL_VVV ) { + if (success && layer->debug >= MS_DEBUGLEVEL_VVV) { msDebug("Worldfile location: %s.\n", fullPath); - } else if( layer->debug >= MS_DEBUGLEVEL_VVV ) { + } else if (layer->debug >= MS_DEBUGLEVEL_VVV) { msDebug("Failed using worldfile location: %s.\n", fullPath); } msFree(fileExtension); - if( success ) + if (success) return MS_SUCCESS; } @@ -1694,8 +1613,8 @@ int msGetGDALGeoTransform( GDALDatasetH hDS, mapObj *map, layerObj *layer, /* files with no coordinate system otherwise they break down in */ /* many ways. */ /* -------------------------------------------------------------------- */ - if (GDALGetGeoTransform( hDS, padfGeoTransform ) == CE_None ) { - if( padfGeoTransform[5] == 1.0 && padfGeoTransform[3] == 0.0 ) { + if (GDALGetGeoTransform(hDS, padfGeoTransform) == CE_None) { + if (padfGeoTransform[5] == 1.0 && padfGeoTransform[3] == 0.0) { padfGeoTransform[5] = -1.0; padfGeoTransform[3] = GDALGetRasterYSize(hDS); } @@ -1706,9 +1625,8 @@ int msGetGDALGeoTransform( GDALDatasetH hDS, mapObj *map, layerObj *layer, /* -------------------------------------------------------------------- */ /* Try worldfile. */ /* -------------------------------------------------------------------- */ - if( GDALGetDescription(hDS) != NULL - && GDALReadWorldFile(GDALGetDescription(hDS), "wld", - padfGeoTransform) ) { + if (GDALGetDescription(hDS) != NULL && + GDALReadWorldFile(GDALGetDescription(hDS), "wld", padfGeoTransform)) { return MS_SUCCESS; } @@ -1724,13 +1642,13 @@ int msGetGDALGeoTransform( GDALDatasetH hDS, mapObj *map, layerObj *layer, rect = layer->extent; padfGeoTransform[0] = rect.minx; - padfGeoTransform[1] = (rect.maxx - rect.minx) / - (double) GDALGetRasterXSize( hDS ); + padfGeoTransform[1] = + (rect.maxx - rect.minx) / (double)GDALGetRasterXSize(hDS); padfGeoTransform[2] = 0; padfGeoTransform[3] = rect.maxy; padfGeoTransform[4] = 0; - padfGeoTransform[5] = (rect.miny - rect.maxy) / - (double) GDALGetRasterYSize( hDS ); + padfGeoTransform[5] = + (rect.miny - rect.maxy) / (double)GDALGetRasterYSize(hDS); return MS_SUCCESS; } @@ -1757,47 +1675,48 @@ int msGetGDALGeoTransform( GDALDatasetH hDS, mapObj *map, layerObj *layer, /************************************************************************/ static int -msDrawRasterLayerGDAL_RawMode( - mapObj *map, layerObj *layer, imageObj *image, GDALDatasetH hDS, - int src_xoff, int src_yoff, int src_xsize, int src_ysize, - int dst_xoff, int dst_yoff, int dst_xsize, int dst_ysize ) +msDrawRasterLayerGDAL_RawMode(mapObj *map, layerObj *layer, imageObj *image, + GDALDatasetH hDS, int src_xoff, int src_yoff, + int src_xsize, int src_ysize, int dst_xoff, + int dst_yoff, int dst_xsize, int dst_ysize) { void *pBuffer; GDALDataType eDataType; int *band_list, band_count; - int i, j, k, band; + int i, j, k, band; CPLErr eErr; float *f_nodatas = NULL; unsigned char *b_nodatas = NULL; GInt16 *i_nodatas = NULL; - int got_nodata=FALSE; + int got_nodata = FALSE; rasterBufferObj *mask_rb = NULL; rasterBufferObj s_mask_rb; - if(layer->mask) { + if (layer->mask) { int ret; - layerObj *maskLayer = GET_LAYER(map, msGetLayerIndex(map,layer->mask)); + layerObj *maskLayer = GET_LAYER(map, msGetLayerIndex(map, layer->mask)); mask_rb = &s_mask_rb; memset(mask_rb, 0, sizeof(s_mask_rb)); - ret = MS_IMAGE_RENDERER(maskLayer->maskimage)->getRasterBufferHandle(maskLayer->maskimage,mask_rb); - if(ret != MS_SUCCESS) + ret = MS_IMAGE_RENDERER(maskLayer->maskimage) + ->getRasterBufferHandle(maskLayer->maskimage, mask_rb); + if (ret != MS_SUCCESS) return -1; } - if( image->format->bands > 256 ) { - msSetError( MS_IMGERR, "Too many bands (more than 256).", - "msDrawRasterLayerGDAL_RawMode()" ); + if (image->format->bands > 256) { + msSetError(MS_IMGERR, "Too many bands (more than 256).", + "msDrawRasterLayerGDAL_RawMode()"); return -1; } /* -------------------------------------------------------------------- */ /* What data type do we need? */ /* -------------------------------------------------------------------- */ - if( image->format->imagemode == MS_IMAGEMODE_INT16 ) + if (image->format->imagemode == MS_IMAGEMODE_INT16) eDataType = GDT_Int16; - else if( image->format->imagemode == MS_IMAGEMODE_FLOAT32 ) + else if (image->format->imagemode == MS_IMAGEMODE_FLOAT32) eDataType = GDT_Float32; - else if( image->format->imagemode == MS_IMAGEMODE_BYTE ) + else if (image->format->imagemode == MS_IMAGEMODE_BYTE) eDataType = GDT_Byte; else return -1; @@ -1805,90 +1724,89 @@ msDrawRasterLayerGDAL_RawMode( /* -------------------------------------------------------------------- */ /* Work out the band list. */ /* -------------------------------------------------------------------- */ - band_list = msGetGDALBandList( layer, hDS, image->format->bands, - &band_count ); - if( band_list == NULL ) + band_list = msGetGDALBandList(layer, hDS, image->format->bands, &band_count); + if (band_list == NULL) return -1; - if( band_count != image->format->bands ) { - free( band_list ); - msSetError( MS_IMGERR, "BANDS PROCESSING directive has wrong number of bands, expected %d, got %d.", - "msDrawRasterLayerGDAL_RawMode()", - image->format->bands, band_count ); + if (band_count != image->format->bands) { + free(band_list); + msSetError(MS_IMGERR, + "BANDS PROCESSING directive has wrong number of bands, expected " + "%d, got %d.", + "msDrawRasterLayerGDAL_RawMode()", image->format->bands, + band_count); return -1; } /* -------------------------------------------------------------------- */ /* Do we have nodata values? */ /* -------------------------------------------------------------------- */ - f_nodatas = (float *) calloc(sizeof(float),band_count); + f_nodatas = (float *)calloc(sizeof(float), band_count); if (f_nodatas == NULL) { - msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msDrawRasterLayerGDAL_RawMode()", - __FILE__, __LINE__, (unsigned int)(sizeof(float)*band_count)); - free( band_list ); + msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", + "msDrawRasterLayerGDAL_RawMode()", __FILE__, __LINE__, + (unsigned int)(sizeof(float) * band_count)); + free(band_list); return -1; } - if( band_count <= 3 - && (layer->offsite.red != -1 - || layer->offsite.green != -1 - || layer->offsite.blue != -1) ) { - if( band_count > 0 ) + if (band_count <= 3 && + (layer->offsite.red != -1 || layer->offsite.green != -1 || + layer->offsite.blue != -1)) { + if (band_count > 0) f_nodatas[0] = layer->offsite.red; - if( band_count > 1 ) + if (band_count > 1) f_nodatas[1] = layer->offsite.green; - if( band_count > 2 ) + if (band_count > 2) f_nodatas[2] = layer->offsite.blue; got_nodata = TRUE; } - if( !got_nodata ) { + if (!got_nodata) { got_nodata = TRUE; - for( band = 0; band < band_count && got_nodata; band++ ) { + for (band = 0; band < band_count && got_nodata; band++) { f_nodatas[band] = msGetGDALNoDataValue( - layer, GDALGetRasterBand(hDS,band_list[band]), &got_nodata ); + layer, GDALGetRasterBand(hDS, band_list[band]), &got_nodata); } } - if( !got_nodata ) { - free( f_nodatas ); + if (!got_nodata) { + free(f_nodatas); f_nodatas = NULL; - } else if( eDataType == GDT_Byte ) { - b_nodatas = (unsigned char *) f_nodatas; - for( band = 0; band < band_count; band++ ) - b_nodatas[band] = (unsigned char) f_nodatas[band]; - } else if( eDataType == GDT_Int16 ) { - i_nodatas = (GInt16 *) f_nodatas; - for( band = 0; band < band_count; band++ ) - i_nodatas[band] = (GInt16) f_nodatas[band]; + } else if (eDataType == GDT_Byte) { + b_nodatas = (unsigned char *)f_nodatas; + for (band = 0; band < band_count; band++) + b_nodatas[band] = (unsigned char)f_nodatas[band]; + } else if (eDataType == GDT_Int16) { + i_nodatas = (GInt16 *)f_nodatas; + for (band = 0; band < band_count; band++) + i_nodatas[band] = (GInt16)f_nodatas[band]; } /* -------------------------------------------------------------------- */ /* Allocate buffer, and read data into it. */ /* -------------------------------------------------------------------- */ - pBuffer = malloc(dst_xsize * dst_ysize * image->format->bands - * (GDALGetDataTypeSize(eDataType)/8) ); - if( pBuffer == NULL ) { - msSetError(MS_MEMERR, - "Allocating work image of size %dx%d failed.", - "msDrawRasterLayerGDAL()", dst_xsize, dst_ysize ); - free( band_list ); - free( f_nodatas ); + pBuffer = malloc(dst_xsize * dst_ysize * image->format->bands * + (GDALGetDataTypeSize(eDataType) / 8)); + if (pBuffer == NULL) { + msSetError(MS_MEMERR, "Allocating work image of size %dx%d failed.", + "msDrawRasterLayerGDAL()", dst_xsize, dst_ysize); + free(band_list); + free(f_nodatas); return -1; } - eErr = GDALDatasetRasterIO( hDS, GF_Read, - src_xoff, src_yoff, src_xsize, src_ysize, - pBuffer, dst_xsize, dst_ysize, eDataType, - image->format->bands, band_list, - 0, 0, 0 ); - free( band_list ); + eErr = + GDALDatasetRasterIO(hDS, GF_Read, src_xoff, src_yoff, src_xsize, + src_ysize, pBuffer, dst_xsize, dst_ysize, eDataType, + image->format->bands, band_list, 0, 0, 0); + free(band_list); - if( eErr != CE_None ) { - msSetError( MS_IOERR, "GDALRasterIO() failed: %s", - "msDrawRasterLayerGDAL_RawMode()", CPLGetLastErrorMsg() ); - free( pBuffer ); - free( f_nodatas ); + if (eErr != CE_None) { + msSetError(MS_IOERR, "GDALRasterIO() failed: %s", + "msDrawRasterLayerGDAL_RawMode()", CPLGetLastErrorMsg()); + free(pBuffer); + free(f_nodatas); return -1; } @@ -1896,59 +1814,56 @@ msDrawRasterLayerGDAL_RawMode( /* Transfer the data to the imageObj. */ /* -------------------------------------------------------------------- */ k = 0; - for( band = 0; band < image->format->bands; band++ ) { - for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ ) { - if( image->format->imagemode == MS_IMAGEMODE_INT16 ) { - for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ ) { - int off = j + i * image->width - + band*image->width*image->height; + for (band = 0; band < image->format->bands; band++) { + for (i = dst_yoff; i < dst_yoff + dst_ysize; i++) { + if (image->format->imagemode == MS_IMAGEMODE_INT16) { + for (j = dst_xoff; j < dst_xoff + dst_xsize; j++) { + int off = j + i * image->width + band * image->width * image->height; int off_mask = j + i * image->width; - if( ( i_nodatas && ((GInt16 *) pBuffer)[k] == i_nodatas[band] ) - || SKIP_MASK(j,i)) { + if ((i_nodatas && ((GInt16 *)pBuffer)[k] == i_nodatas[band]) || + SKIP_MASK(j, i)) { k++; continue; } - image->img.raw_16bit[off] = ((GInt16 *) pBuffer)[k++]; - MS_SET_BIT(image->img_mask,off_mask); + image->img.raw_16bit[off] = ((GInt16 *)pBuffer)[k++]; + MS_SET_BIT(image->img_mask, off_mask); } - } else if( image->format->imagemode == MS_IMAGEMODE_FLOAT32 ) { - for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ ) { - int off = j + i * image->width - + band*image->width*image->height; + } else if (image->format->imagemode == MS_IMAGEMODE_FLOAT32) { + for (j = dst_xoff; j < dst_xoff + dst_xsize; j++) { + int off = j + i * image->width + band * image->width * image->height; int off_mask = j + i * image->width; - if( ( f_nodatas && ((float *) pBuffer)[k] == f_nodatas[band] ) - || SKIP_MASK(j,i)) { + if ((f_nodatas && ((float *)pBuffer)[k] == f_nodatas[band]) || + SKIP_MASK(j, i)) { k++; continue; } - image->img.raw_float[off] = ((float *) pBuffer)[k++]; - MS_SET_BIT(image->img_mask,off_mask); + image->img.raw_float[off] = ((float *)pBuffer)[k++]; + MS_SET_BIT(image->img_mask, off_mask); } - } else if( image->format->imagemode == MS_IMAGEMODE_BYTE ) { - for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ ) { - int off = j + i * image->width - + band*image->width*image->height; + } else if (image->format->imagemode == MS_IMAGEMODE_BYTE) { + for (j = dst_xoff; j < dst_xoff + dst_xsize; j++) { + int off = j + i * image->width + band * image->width * image->height; int off_mask = j + i * image->width; - if( ( b_nodatas && ((unsigned char *) pBuffer)[k] == b_nodatas[band] ) - || SKIP_MASK(j,i)) { + if ((b_nodatas && ((unsigned char *)pBuffer)[k] == b_nodatas[band]) || + SKIP_MASK(j, i)) { k++; continue; } - image->img.raw_byte[off] = ((unsigned char *) pBuffer)[k++]; - MS_SET_BIT(image->img_mask,off_mask); + image->img.raw_byte[off] = ((unsigned char *)pBuffer)[k++]; + MS_SET_BIT(image->img_mask, off_mask); } } } } - free( pBuffer ); - free( f_nodatas ); + free(pBuffer); + free(f_nodatas); return 0; } @@ -1965,129 +1880,123 @@ msDrawRasterLayerGDAL_RawMode( /* the 16bit cases at the cost of some complication. */ /************************************************************************/ -static int -msDrawRasterLayerGDAL_16BitClassification( - mapObj *map, layerObj *layer, rasterBufferObj *rb, - GDALRasterBandH hBand, - int src_xoff, int src_yoff, int src_xsize, int src_ysize, - int dst_xoff, int dst_yoff, int dst_xsize, int dst_ysize ) +static int msDrawRasterLayerGDAL_16BitClassification( + mapObj *map, layerObj *layer, rasterBufferObj *rb, GDALRasterBandH hBand, + int src_xoff, int src_yoff, int src_xsize, int src_ysize, int dst_xoff, + int dst_yoff, int dst_xsize, int dst_ysize) { float *pafRawData; - double dfScaleMin=0.0, dfScaleMax=0.0, dfScaleRatio; - int nPixelCount = dst_xsize * dst_ysize, i, nBucketCount=0; + double dfScaleMin = 0.0, dfScaleMax = 0.0, dfScaleRatio; + int nPixelCount = dst_xsize * dst_ysize, i, nBucketCount = 0; GDALDataType eDataType; - float fDataMin=0.0, fDataMax=255.0, fNoDataValue; + float fDataMin = 0.0, fDataMax = 255.0, fNoDataValue; const char *pszScaleInfo; const char *pszBuckets; - int *cmap, c, j, k, bGotNoData = FALSE, bGotFirstValue; + int *cmap, c, j, k, bGotNoData = FALSE, bGotFirstValue; unsigned char *rb_cmap[4]; CPLErr eErr; rasterBufferObj *mask_rb = NULL; rasterBufferObj s_mask_rb; int lastC; - struct mstimeval starttime={0}, endtime={0}; + struct mstimeval starttime = {0}, endtime = {0}; const char *pszClassifyScaled; int bClassifyScaled = FALSE; - if(layer->mask) { + if (layer->mask) { int ret; - layerObj *maskLayer = GET_LAYER(map, msGetLayerIndex(map,layer->mask)); + layerObj *maskLayer = GET_LAYER(map, msGetLayerIndex(map, layer->mask)); mask_rb = &s_mask_rb; memset(mask_rb, 0, sizeof(s_mask_rb)); - ret = MS_IMAGE_RENDERER(maskLayer->maskimage)->getRasterBufferHandle(maskLayer->maskimage,mask_rb); - if(ret != MS_SUCCESS) + ret = MS_IMAGE_RENDERER(maskLayer->maskimage) + ->getRasterBufferHandle(maskLayer->maskimage, mask_rb); + if (ret != MS_SUCCESS) return -1; } - assert( rb->type == MS_BUFFER_BYTE_RGBA ); + assert(rb->type == MS_BUFFER_BYTE_RGBA); /* ==================================================================== */ /* Read the requested data in one gulp into a floating point */ /* buffer. */ /* ==================================================================== */ - pafRawData = (float *) malloc(sizeof(float) * dst_xsize * dst_ysize ); - if( pafRawData == NULL ) { - msSetError( MS_MEMERR, "Out of memory allocating working buffer.", - "msDrawRasterLayerGDAL_16BitClassification()" ); + pafRawData = (float *)malloc(sizeof(float) * dst_xsize * dst_ysize); + if (pafRawData == NULL) { + msSetError(MS_MEMERR, "Out of memory allocating working buffer.", + "msDrawRasterLayerGDAL_16BitClassification()"); return -1; } - eErr = GDALRasterIO( hBand, GF_Read, - src_xoff, src_yoff, src_xsize, src_ysize, - pafRawData, dst_xsize, dst_ysize, GDT_Float32, 0, 0 ); + eErr = GDALRasterIO(hBand, GF_Read, src_xoff, src_yoff, src_xsize, src_ysize, + pafRawData, dst_xsize, dst_ysize, GDT_Float32, 0, 0); - if( eErr != CE_None ) { - free( pafRawData ); - msSetError( MS_IOERR, "GDALRasterIO() failed: %s", - "msDrawRasterLayerGDAL_16BitClassification()", - CPLGetLastErrorMsg() ); + if (eErr != CE_None) { + free(pafRawData); + msSetError(MS_IOERR, "GDALRasterIO() failed: %s", + "msDrawRasterLayerGDAL_16BitClassification()", + CPLGetLastErrorMsg()); return -1; } - fNoDataValue = (float) msGetGDALNoDataValue( layer, hBand, &bGotNoData ); + fNoDataValue = (float)msGetGDALNoDataValue(layer, hBand, &bGotNoData); /* ==================================================================== */ /* Determine scaling. */ /* ==================================================================== */ - eDataType = GDALGetRasterDataType( hBand ); + eDataType = GDALGetRasterDataType(hBand); /* -------------------------------------------------------------------- */ /* Scan for absolute min/max of this block. */ /* -------------------------------------------------------------------- */ bGotFirstValue = FALSE; - for( i = 1; i < nPixelCount; i++ ) { - if( bGotNoData && IsNoData(pafRawData[i], fNoDataValue) ) + for (i = 1; i < nPixelCount; i++) { + if (bGotNoData && IsNoData(pafRawData[i], fNoDataValue)) continue; - if( CPLIsNan(pafRawData[i]) ) + if (CPLIsNan(pafRawData[i])) continue; - if( !bGotFirstValue ) { + if (!bGotFirstValue) { fDataMin = fDataMax = pafRawData[i]; bGotFirstValue = TRUE; } else { - fDataMin = MS_MIN(fDataMin,pafRawData[i]); - fDataMax = MS_MAX(fDataMax,pafRawData[i]); + fDataMin = MS_MIN(fDataMin, pafRawData[i]); + fDataMax = MS_MAX(fDataMax, pafRawData[i]); } } /* -------------------------------------------------------------------- */ /* Fetch the scale classification option. */ /* -------------------------------------------------------------------- */ - pszClassifyScaled = CSLFetchNameValue( layer->processing, "CLASSIFY_SCALED" ); - if( pszClassifyScaled != NULL ) + pszClassifyScaled = CSLFetchNameValue(layer->processing, "CLASSIFY_SCALED"); + if (pszClassifyScaled != NULL) bClassifyScaled = CSLTestBoolean(pszClassifyScaled); /* -------------------------------------------------------------------- */ /* Fetch the scale processing option. */ /* -------------------------------------------------------------------- */ - pszBuckets = CSLFetchNameValue( layer->processing, "SCALE_BUCKETS" ); - pszScaleInfo = CSLFetchNameValue( layer->processing, "SCALE" ); + pszBuckets = CSLFetchNameValue(layer->processing, "SCALE_BUCKETS"); + pszScaleInfo = CSLFetchNameValue(layer->processing, "SCALE"); - if( pszScaleInfo != NULL ) { + if (pszScaleInfo != NULL) { char **papszTokens; - papszTokens = CSLTokenizeStringComplex( pszScaleInfo, " ,", - FALSE, FALSE ); - if( CSLCount(papszTokens) == 1 - && EQUAL(papszTokens[0],"AUTO") ) { + papszTokens = CSLTokenizeStringComplex(pszScaleInfo, " ,", FALSE, FALSE); + if (CSLCount(papszTokens) == 1 && EQUAL(papszTokens[0], "AUTO")) { dfScaleMin = dfScaleMax = 0.0; - } else if( CSLCount(papszTokens) != 2 ) { - free( pafRawData ); - CSLDestroy( papszTokens ); - msSetError( MS_MISCERR, - "SCALE PROCESSING option unparsable for layer %s.", - "msDrawGDAL()", - layer->name ); + } else if (CSLCount(papszTokens) != 2) { + free(pafRawData); + CSLDestroy(papszTokens); + msSetError(MS_MISCERR, "SCALE PROCESSING option unparsable for layer %s.", + "msDrawGDAL()", layer->name); return -1; } else { dfScaleMin = atof(papszTokens[0]); dfScaleMax = atof(papszTokens[1]); } - CSLDestroy( papszTokens ); + CSLDestroy(papszTokens); } /* -------------------------------------------------------------------- */ @@ -2096,23 +2005,23 @@ msDrawRasterLayerGDAL_16BitClassification( /* TODO: Treat Int32 and UInt32 case the same way *if* the min */ /* and max are less than 65536 apart. */ /* -------------------------------------------------------------------- */ - if( eDataType == GDT_Byte || eDataType == GDT_Int16 - || eDataType == GDT_UInt16 ) { - if( pszScaleInfo == NULL ) { + if (eDataType == GDT_Byte || eDataType == GDT_Int16 || + eDataType == GDT_UInt16) { + if (pszScaleInfo == NULL) { dfScaleMin = fDataMin - 0.5; dfScaleMax = fDataMax + 0.5; } - if( pszBuckets == NULL ) { - nBucketCount = (int) floor(fDataMax - fDataMin + 1.1); + if (pszBuckets == NULL) { + nBucketCount = (int)floor(fDataMax - fDataMin + 1.1); } } /* -------------------------------------------------------------------- */ /* General case if no scaling values provided in mapfile. */ /* -------------------------------------------------------------------- */ - else if( dfScaleMin == 0.0 && dfScaleMax == 0.0 ) { - double dfEpsilon = (fDataMax - fDataMin) / (65536*2); + else if (dfScaleMin == 0.0 && dfScaleMax == 0.0) { + double dfEpsilon = (fDataMax - fDataMin) / (65536 * 2); dfScaleMin = fDataMin - dfEpsilon; dfScaleMax = fDataMax + dfEpsilon; } @@ -2120,17 +2029,17 @@ msDrawRasterLayerGDAL_16BitClassification( /* -------------------------------------------------------------------- */ /* How many buckets? Only set if we don't already have a value. */ /* -------------------------------------------------------------------- */ - if( pszBuckets == NULL ) { - if( nBucketCount == 0 ) + if (pszBuckets == NULL) { + if (nBucketCount == 0) nBucketCount = 65536; } else { nBucketCount = atoi(pszBuckets); - if( nBucketCount < 2 ) { - free( pafRawData ); - msSetError( MS_MISCERR, - "SCALE_BUCKETS PROCESSING option is not a value of 2 or more: %s.", - "msDrawRasterLayerGDAL_16BitClassification()", - pszBuckets ); + if (nBucketCount < 2) { + free(pafRawData); + msSetError( + MS_MISCERR, + "SCALE_BUCKETS PROCESSING option is not a value of 2 or more: %s.", + "msDrawRasterLayerGDAL_16BitClassification()", pszBuckets); return -1; } } @@ -2138,87 +2047,94 @@ msDrawRasterLayerGDAL_16BitClassification( /* -------------------------------------------------------------------- */ /* Compute scaling ratio. */ /* -------------------------------------------------------------------- */ - if( dfScaleMax == dfScaleMin ) + if (dfScaleMax == dfScaleMin) dfScaleMax = dfScaleMin + 1.0; dfScaleRatio = nBucketCount / (dfScaleMax - dfScaleMin); - if( layer->debug > 0 ) - msDebug( "msDrawRasterGDAL_16BitClassification(%s):\n" - " scaling to %d buckets from range=%g,%g.\n", - layer->name, nBucketCount, dfScaleMin, dfScaleMax ); + if (layer->debug > 0) + msDebug("msDrawRasterGDAL_16BitClassification(%s):\n" + " scaling to %d buckets from range=%g,%g.\n", + layer->name, nBucketCount, dfScaleMin, dfScaleMax); /* ==================================================================== */ /* Compute classification lookup table. */ /* ==================================================================== */ - cmap = (int *) msSmallCalloc(sizeof(int),nBucketCount); - rb_cmap[0] = (unsigned char *) msSmallCalloc(1,nBucketCount); - rb_cmap[1] = (unsigned char *) msSmallCalloc(1,nBucketCount); - rb_cmap[2] = (unsigned char *) msSmallCalloc(1,nBucketCount); - rb_cmap[3] = (unsigned char *) msSmallCalloc(1,nBucketCount); + cmap = (int *)msSmallCalloc(sizeof(int), nBucketCount); + rb_cmap[0] = (unsigned char *)msSmallCalloc(1, nBucketCount); + rb_cmap[1] = (unsigned char *)msSmallCalloc(1, nBucketCount); + rb_cmap[2] = (unsigned char *)msSmallCalloc(1, nBucketCount); + rb_cmap[3] = (unsigned char *)msSmallCalloc(1, nBucketCount); - - if(layer->debug >= MS_DEBUGLEVEL_TUNING) { + if (layer->debug >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&starttime, NULL); } lastC = -1; - for(i=0; i < nBucketCount; i++) { + for (i = 0; i < nBucketCount; i++) { double dfOriginalValue; cmap[i] = -1; // i = (int) ((dfOriginalValue - dfScaleMin) * dfScaleRatio+1)-1; - dfOriginalValue = (i+0.5) / dfScaleRatio + dfScaleMin; - - /* The creation of buckets takes a significant time when they are many, and many classes - as well. When iterating over buckets, a faster strategy is to reuse first the last used - class index. */ - if(bClassifyScaled == TRUE) - c = msGetClass_FloatRGB_WithFirstClassToTry(layer, (float) i, -1, -1, -1, lastC); + dfOriginalValue = (i + 0.5) / dfScaleRatio + dfScaleMin; + + /* The creation of buckets takes a significant time when they are many, and + many classes as well. When iterating over buckets, a faster strategy is + to reuse first the last used class index. */ + if (bClassifyScaled == TRUE) + c = msGetClass_FloatRGB_WithFirstClassToTry(layer, (float)i, -1, -1, -1, + lastC); else - c = msGetClass_FloatRGB_WithFirstClassToTry(layer, (float) dfOriginalValue, -1, -1, -1, lastC); + c = msGetClass_FloatRGB_WithFirstClassToTry(layer, (float)dfOriginalValue, + -1, -1, -1, lastC); lastC = c; - if( c != -1 ) { + if (c != -1) { int s; int styleindex = 0; /* change colour based on colour range? */ - if( MS_VALID_COLOR(layer->class[c]->styles[0]->mincolor) ) - { + if (MS_VALID_COLOR(layer->class[c] -> styles[0] -> mincolor)) { styleindex = -1; - for(s=0; sclass[c]->numstyles; s++) { - if( MS_VALID_COLOR(layer->class[c]->styles[s]->mincolor) - && MS_VALID_COLOR(layer->class[c]->styles[s]->maxcolor) - && dfOriginalValue + 0.5 / dfScaleRatio >= layer->class[c]->styles[s]->minvalue - && dfOriginalValue - 0.5 / dfScaleRatio <= layer->class[c]->styles[s]->maxvalue ) { - msValueToRange(layer->class[c]->styles[s],dfOriginalValue, MS_COLORSPACE_RGB); + for (s = 0; s < layer->class[c] -> numstyles; s++) { + if (MS_VALID_COLOR(layer->class[c] -> styles[s] -> mincolor) && + MS_VALID_COLOR(layer->class[c] -> styles[s] -> maxcolor) && + dfOriginalValue + 0.5 / dfScaleRatio >= + layer->class[c] -> styles[s] + -> minvalue && dfOriginalValue - 0.5 / dfScaleRatio <= + layer -> class[c] -> styles[s] -> maxvalue) { + msValueToRange(layer->class[c] -> styles[s], dfOriginalValue, + MS_COLORSPACE_RGB); styleindex = s; break; } } } - if( styleindex >= 0 ) { - if( MS_TRANSPARENT_COLOR(layer->class[c]->styles[styleindex]->color) ) { + if (styleindex >= 0) { + if (MS_TRANSPARENT_COLOR( + layer->class[c] -> styles[styleindex] -> color)) { /* leave it transparent */ - } else if( MS_VALID_COLOR(layer->class[c]->styles[styleindex]->color)) { + } else if (MS_VALID_COLOR( + layer->class[c] -> styles[styleindex] -> color)) { /* use class color */ rb_cmap[0][i] = layer->class[c]->styles[styleindex]->color.red; rb_cmap[1][i] = layer->class[c]->styles[styleindex]->color.green; rb_cmap[2][i] = layer->class[c]->styles[styleindex]->color.blue; - rb_cmap[3][i] = (255*layer->class[c]->styles[styleindex]->opacity / 100); + rb_cmap[3][i] = + (255 * layer->class[c] -> styles[styleindex] -> opacity / 100); } } } } - if(layer->debug >= MS_DEBUGLEVEL_TUNING) { + if (layer->debug >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&endtime, NULL); - msDebug("msDrawRasterGDAL_16BitClassification() bucket creation time: %.3fs\n", - (endtime.tv_sec+endtime.tv_usec/1.0e6)- - (starttime.tv_sec+starttime.tv_usec/1.0e6) ); + msDebug( + "msDrawRasterGDAL_16BitClassification() bucket creation time: %.3fs\n", + (endtime.tv_sec + endtime.tv_usec / 1.0e6) - + (starttime.tv_sec + starttime.tv_usec / 1.0e6)); } /* ==================================================================== */ @@ -2226,53 +2142,50 @@ msDrawRasterLayerGDAL_16BitClassification( /* ==================================================================== */ k = 0; - for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ ) { - for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ ) { + for (i = dst_yoff; i < dst_yoff + dst_ysize; i++) { + for (j = dst_xoff; j < dst_xoff + dst_xsize; j++) { float fRawValue = pafRawData[k++]; - int iMapIndex; + int iMapIndex; /* * Skip nodata pixels ... no processing. */ - if( bGotNoData && IsNoData(fRawValue, fNoDataValue) ) + if (bGotNoData && IsNoData(fRawValue, fNoDataValue)) continue; - if( CPLIsNan(fRawValue) ) + if (CPLIsNan(fRawValue)) continue; - if(SKIP_MASK(j,i)) + if (SKIP_MASK(j, i)) continue; /* * The funny +1/-1 is to avoid odd rounding around zero. * We could use floor() but sometimes it is expensive. */ - iMapIndex = (int) ((fRawValue - dfScaleMin) * dfScaleRatio+1)-1; + iMapIndex = (int)((fRawValue - dfScaleMin) * dfScaleRatio + 1) - 1; - if( iMapIndex >= nBucketCount || iMapIndex < 0 ) { + if (iMapIndex >= nBucketCount || iMapIndex < 0) { continue; } /* currently we never have partial alpha so keep simple */ - if( rb_cmap[3][iMapIndex] > 0 ) - RB_SET_PIXEL( rb, j, i, - rb_cmap[0][iMapIndex], - rb_cmap[1][iMapIndex], - rb_cmap[2][iMapIndex], - rb_cmap[3][iMapIndex] ); + if (rb_cmap[3][iMapIndex] > 0) + RB_SET_PIXEL(rb, j, i, rb_cmap[0][iMapIndex], rb_cmap[1][iMapIndex], + rb_cmap[2][iMapIndex], rb_cmap[3][iMapIndex]); } } /* -------------------------------------------------------------------- */ /* Cleanup */ /* -------------------------------------------------------------------- */ - free( pafRawData ); - free( cmap ); - free( rb_cmap[0] ); - free( rb_cmap[1] ); - free( rb_cmap[2] ); - free( rb_cmap[3] ); + free(pafRawData); + free(cmap); + free(rb_cmap[0]); + free(rb_cmap[1]); + free(rb_cmap[2]); + free(rb_cmap[3]); - assert( k == dst_xsize * dst_ysize ); + assert(k == dst_xsize * dst_ysize); return 0; } @@ -2280,17 +2193,14 @@ msDrawRasterLayerGDAL_16BitClassification( /************************************************************************/ /* IsNoData() */ /************************************************************************/ -static bool -IsNoData( double dfValue, double dfNoDataValue ) -{ +static bool IsNoData(double dfValue, double dfNoDataValue) { return isnan(dfValue) || dfValue == dfNoDataValue; } /************************************************************************/ /* msGetGDALNoDataValue() */ /************************************************************************/ -double -msGetGDALNoDataValue( layerObj *layer, void *hBand, int *pbGotNoData ) +double msGetGDALNoDataValue(layerObj *layer, void *hBand, int *pbGotNoData) { const char *pszNODATAOpt; @@ -2300,11 +2210,11 @@ msGetGDALNoDataValue( layerObj *layer, void *hBand, int *pbGotNoData ) /* -------------------------------------------------------------------- */ /* Check for a NODATA setting in the .map file. */ /* -------------------------------------------------------------------- */ - pszNODATAOpt = CSLFetchNameValue(layer->processing,"NODATA"); - if( pszNODATAOpt != NULL ) { - if( EQUAL(pszNODATAOpt,"OFF") || strlen(pszNODATAOpt) == 0 ) + pszNODATAOpt = CSLFetchNameValue(layer->processing, "NODATA"); + if (pszNODATAOpt != NULL) { + if (EQUAL(pszNODATAOpt, "OFF") || strlen(pszNODATAOpt) == 0) return -1234567.0; - if( !EQUAL(pszNODATAOpt,"AUTO") ) { + if (!EQUAL(pszNODATAOpt, "AUTO")) { *pbGotNoData = TRUE; return atof(pszNODATAOpt); } @@ -2313,10 +2223,10 @@ msGetGDALNoDataValue( layerObj *layer, void *hBand, int *pbGotNoData ) /* -------------------------------------------------------------------- */ /* Check for a NODATA setting on the raw file. */ /* -------------------------------------------------------------------- */ - if( hBand == NULL ) + if (hBand == NULL) return -1234567.0; else - return GDALGetRasterNoDataValue( hBand, pbGotNoData ); + return GDALGetRasterNoDataValue(hBand, pbGotNoData); } /************************************************************************/ @@ -2329,19 +2239,18 @@ msGetGDALNoDataValue( layerObj *layer, void *hBand, int *pbGotNoData ) /* returns malloc() list of band numbers (*band_count long). */ /************************************************************************/ -int *msGetGDALBandList( layerObj *layer, void *hDS, - int max_bands, int *band_count ) +int *msGetGDALBandList(layerObj *layer, void *hDS, int max_bands, + int *band_count) { int i, file_bands; int *band_list = NULL; - file_bands = GDALGetRasterCount( hDS ); - if( file_bands == 0 ) { - msSetError( MS_IMGERR, - "Attempt to operate on GDAL file with no bands, layer=%s.", - "msGetGDALBandList()", - layer->name ); + file_bands = GDALGetRasterCount(hDS); + if (file_bands == 0) { + msSetError(MS_IMGERR, + "Attempt to operate on GDAL file with no bands, layer=%s.", + "msGetGDALBandList()", layer->name); return NULL; } @@ -2349,19 +2258,19 @@ int *msGetGDALBandList( layerObj *layer, void *hDS, /* -------------------------------------------------------------------- */ /* Use all (or first) bands. */ /* -------------------------------------------------------------------- */ - if( CSLFetchNameValue( layer->processing, "BANDS" ) == NULL ) { - if( max_bands > 0 ) - *band_count = MS_MIN(file_bands,max_bands); + if (CSLFetchNameValue(layer->processing, "BANDS") == NULL) { + if (max_bands > 0) + *band_count = MS_MIN(file_bands, max_bands); else *band_count = file_bands; - band_list = (int *) malloc(sizeof(int) * *band_count ); + band_list = (int *)malloc(sizeof(int) * *band_count); /* FIXME MS_CHECK_ALLOC leaks papszItems */ MS_CHECK_ALLOC(band_list, sizeof(int) * *band_count, NULL); - for( i = 0; i < *band_count; i++ ) - band_list[i] = i+1; + for (i = 0; i < *band_count; i++) + band_list[i] = i + 1; return band_list; } @@ -2370,38 +2279,40 @@ int *msGetGDALBandList( layerObj *layer, void *hDS, /* -------------------------------------------------------------------- */ else { char **papszItems = CSLTokenizeStringComplex( - CSLFetchNameValue(layer->processing,"BANDS"), " ,", FALSE, FALSE ); + CSLFetchNameValue(layer->processing, "BANDS"), " ,", FALSE, FALSE); - if( CSLCount(papszItems) == 0 ) { - CSLDestroy( papszItems ); - msSetError( MS_IMGERR, "BANDS PROCESSING directive has no items.", - "msGetGDALBandList()" ); + if (CSLCount(papszItems) == 0) { + CSLDestroy(papszItems); + msSetError(MS_IMGERR, "BANDS PROCESSING directive has no items.", + "msGetGDALBandList()"); return NULL; - } else if( max_bands != 0 && CSLCount(papszItems) > max_bands ) { - msSetError( MS_IMGERR, "BANDS PROCESSING directive has wrong number of bands, expected at most %d, got %d.", - "msGetGDALBandList()", - max_bands, CSLCount(papszItems) ); - CSLDestroy( papszItems ); + } else if (max_bands != 0 && CSLCount(papszItems) > max_bands) { + msSetError(MS_IMGERR, + "BANDS PROCESSING directive has wrong number of bands, " + "expected at most %d, got %d.", + "msGetGDALBandList()", max_bands, CSLCount(papszItems)); + CSLDestroy(papszItems); return NULL; } *band_count = CSLCount(papszItems); - band_list = (int *) malloc(sizeof(int) * *band_count); + band_list = (int *)malloc(sizeof(int) * *band_count); MS_CHECK_ALLOC(band_list, sizeof(int) * *band_count, NULL); - for( i = 0; i < *band_count; i++ ) { + for (i = 0; i < *band_count; i++) { band_list[i] = atoi(papszItems[i]); - if( band_list[i] < 1 || band_list[i] > GDALGetRasterCount(hDS) ) { - msSetError( MS_IMGERR, - "BANDS PROCESSING directive includes illegal band '%s', should be from 1 to %d.", - "msGetGDALBandList()", - papszItems[i], GDALGetRasterCount(hDS) ); - CSLDestroy( papszItems ); - free( band_list ); + if (band_list[i] < 1 || band_list[i] > GDALGetRasterCount(hDS)) { + msSetError(MS_IMGERR, + "BANDS PROCESSING directive includes illegal band '%s', " + "should be from 1 to %d.", + "msGetGDALBandList()", papszItems[i], + GDALGetRasterCount(hDS)); + CSLDestroy(papszItems); + free(band_list); return NULL; } } - CSLDestroy( papszItems ); + CSLDestroy(papszItems); return band_list; } diff --git a/mapdummyrenderer.c b/mapdummyrenderer.c index 4c2d571af2..e4d967f63d 100644 --- a/mapdummyrenderer.c +++ b/mapdummyrenderer.c @@ -29,202 +29,200 @@ #include "mapserver.h" -int renderLineDummy(imageObj *img, shapeObj *p, strokeStyleObj *style) -{ +int renderLineDummy(imageObj *img, shapeObj *p, strokeStyleObj *style) { (void)img; (void)p; (void)style; - msSetError(MS_RENDERERERR,"renderLine not implemented","renderLine()"); + msSetError(MS_RENDERERERR, "renderLine not implemented", "renderLine()"); return MS_FAILURE; } -int renderPolygonDummy(imageObj *img, shapeObj *p, colorObj *color) -{ +int renderPolygonDummy(imageObj *img, shapeObj *p, colorObj *color) { (void)img; (void)p; (void)color; - msSetError(MS_RENDERERERR,"renderPolygon not implemented","renderPolygon()"); + msSetError(MS_RENDERERERR, "renderPolygon not implemented", + "renderPolygon()"); return MS_FAILURE; } -int renderPolygonTiledDummy(imageObj *img, shapeObj *p, imageObj *tile) -{ +int renderPolygonTiledDummy(imageObj *img, shapeObj *p, imageObj *tile) { (void)img; (void)p; (void)tile; - msSetError(MS_RENDERERERR,"renderPolygonTiled not implemented","renderPolygonTiled()"); + msSetError(MS_RENDERERERR, "renderPolygonTiled not implemented", + "renderPolygonTiled()"); return MS_FAILURE; } -int renderLineTiledDummy(imageObj *img, shapeObj *p, imageObj *tile) -{ +int renderLineTiledDummy(imageObj *img, shapeObj *p, imageObj *tile) { (void)img; (void)p; (void)tile; - msSetError(MS_RENDERERERR,"renderLineTiled not implemented","renderLineTiled()"); + msSetError(MS_RENDERERERR, "renderLineTiled not implemented", + "renderLineTiled()"); return MS_FAILURE; } int renderRasterGlyphsDummy(imageObj *img, double x, double y, int fontIndex, - colorObj *color, char* text) -{ + colorObj *color, char *text) { (void)img; (void)x; (void)y; (void)fontIndex; (void)color; (void)text; - msSetError(MS_RENDERERERR,"renderRasterGlyphs not implemented","renderRasterGlyphs()"); + msSetError(MS_RENDERERERR, "renderRasterGlyphs not implemented", + "renderRasterGlyphs()"); return MS_FAILURE; } -int renderGlyphsLineDummy(imageObj *img,labelPathObj *labelpath, - labelStyleObj *style, char *text) -{ +int renderGlyphsLineDummy(imageObj *img, labelPathObj *labelpath, + labelStyleObj *style, char *text) { (void)img; (void)labelpath; (void)style; (void)text; - msSetError(MS_RENDERERERR,"renderGlyphsLine not implemented","renderGlyphsLine()"); + msSetError(MS_RENDERERERR, "renderGlyphsLine not implemented", + "renderGlyphsLine()"); return MS_FAILURE; } int renderVectorSymbolDummy(imageObj *img, double x, double y, - symbolObj *symbol, symbolStyleObj *style) -{ + symbolObj *symbol, symbolStyleObj *style) { (void)img; (void)x; (void)y; (void)symbol; (void)style; - msSetError(MS_RENDERERERR,"renderVectorSymbol not implemented","renderVectorSymbol()"); + msSetError(MS_RENDERERERR, "renderVectorSymbol not implemented", + "renderVectorSymbol()"); return MS_FAILURE; } -void* createVectorSymbolTileDummy(int width, int height, - symbolObj *symbol, symbolStyleObj *style) -{ +void *createVectorSymbolTileDummy(int width, int height, symbolObj *symbol, + symbolStyleObj *style) { (void)width; (void)height; (void)symbol; (void)style; - msSetError(MS_RENDERERERR,"createVectorSymbolTile not implemented","createVectorSymbolTile()"); + msSetError(MS_RENDERERERR, "createVectorSymbolTile not implemented", + "createVectorSymbolTile()"); return NULL; } int renderPixmapSymbolDummy(imageObj *img, double x, double y, - symbolObj *symbol, symbolStyleObj *style) -{ + symbolObj *symbol, symbolStyleObj *style) { (void)img; (void)x; (void)y; (void)symbol; (void)style; - msSetError(MS_RENDERERERR,"renderPixmapSymbol not implemented","renderPixmapSymbol()"); + msSetError(MS_RENDERERERR, "renderPixmapSymbol not implemented", + "renderPixmapSymbol()"); return MS_FAILURE; } -void* createPixmapSymbolTileDummy(int width, int height, - symbolObj *symbol, symbolStyleObj *style) -{ +void *createPixmapSymbolTileDummy(int width, int height, symbolObj *symbol, + symbolStyleObj *style) { (void)width; (void)height; (void)symbol; (void)style; - msSetError(MS_RENDERERERR,"createPixmapSymbolTile not implemented","createPixmapSymbolTile()"); + msSetError(MS_RENDERERERR, "createPixmapSymbolTile not implemented", + "createPixmapSymbolTile()"); return NULL; } int renderEllipseSymbolDummy(imageObj *image, double x, double y, - symbolObj *symbol, symbolStyleObj *style) -{ + symbolObj *symbol, symbolStyleObj *style) { (void)image; (void)x; (void)y; (void)symbol; (void)style; - msSetError(MS_RENDERERERR,"renderEllipseSymbol not implemented","renderEllipseSymbol()"); + msSetError(MS_RENDERERERR, "renderEllipseSymbol not implemented", + "renderEllipseSymbol()"); return MS_FAILURE; } -void* createEllipseSymbolTileDummy(int width, int height, - symbolObj *symbol, symbolStyleObj *style) -{ +void *createEllipseSymbolTileDummy(int width, int height, symbolObj *symbol, + symbolStyleObj *style) { (void)width; (void)height; (void)symbol; (void)style; - msSetError(MS_RENDERERERR,"createEllipseSymbolTile not implemented","createEllipseSymbolTile()"); + msSetError(MS_RENDERERERR, "createEllipseSymbolTile not implemented", + "createEllipseSymbolTile()"); return NULL; } int renderTruetypeSymbolDummy(imageObj *img, double x, double y, - symbolObj *symbol, symbolStyleObj *style) -{ + symbolObj *symbol, symbolStyleObj *style) { (void)img; (void)x; (void)y; (void)symbol; (void)style; - msSetError(MS_RENDERERERR,"renderTruetypeSymbol not implemented","renderTruetypeSymbol()"); + msSetError(MS_RENDERERERR, "renderTruetypeSymbol not implemented", + "renderTruetypeSymbol()"); return MS_FAILURE; } -void* createTruetypeSymbolTileDummy(int width, int height, - symbolObj *symbol, symbolStyleObj *style) -{ +void *createTruetypeSymbolTileDummy(int width, int height, symbolObj *symbol, + symbolStyleObj *style) { (void)width; (void)height; (void)symbol; (void)style; - msSetError(MS_RENDERERERR,"createTruetypeSymbolTile not implemented","createTruetypeSymbolTile()"); + msSetError(MS_RENDERERERR, "createTruetypeSymbolTile not implemented", + "createTruetypeSymbolTile()"); return NULL; } -int renderTileDummy(imageObj *img, imageObj *tile, double x, double y) -{ +int renderTileDummy(imageObj *img, imageObj *tile, double x, double y) { (void)img; (void)tile; (void)x; (void)y; - msSetError(MS_RENDERERERR,"renderTile not implemented","renderTile()"); + msSetError(MS_RENDERERERR, "renderTile not implemented", "renderTile()"); return MS_FAILURE; } -rasterBufferObj* loadImageFromFileDummy(char *path) -{ +rasterBufferObj *loadImageFromFileDummy(char *path) { (void)path; - msSetError(MS_RENDERERERR,"loadImageFromFile not implemented","loadImageFromFile()"); + msSetError(MS_RENDERERERR, "loadImageFromFile not implemented", + "loadImageFromFile()"); return NULL; } - -int getRasterBufferHandleDummy(imageObj *img, rasterBufferObj *rb) -{ +int getRasterBufferHandleDummy(imageObj *img, rasterBufferObj *rb) { (void)img; (void)rb; - msSetError(MS_RENDERERERR,"getRasterBufferHandle not implemented","getRasterBufferHandle()"); + msSetError(MS_RENDERERERR, "getRasterBufferHandle not implemented", + "getRasterBufferHandle()"); return MS_FAILURE; } -int getRasterBufferCopyDummy(imageObj *img, rasterBufferObj *rb) -{ +int getRasterBufferCopyDummy(imageObj *img, rasterBufferObj *rb) { (void)img; (void)rb; - msSetError(MS_RENDERERERR,"getRasterBufferCopy not implemented","getRasterBufferCopy()"); + msSetError(MS_RENDERERERR, "getRasterBufferCopy not implemented", + "getRasterBufferCopy()"); return MS_FAILURE; } -rasterBufferObj* createRasterBufferDummy(int width, int height) -{ +rasterBufferObj *createRasterBufferDummy(int width, int height) { (void)width; (void)height; - msSetError(MS_RENDERERERR,"createRasterBuffer not implemented","createRasterBuffer()"); + msSetError(MS_RENDERERERR, "createRasterBuffer not implemented", + "createRasterBuffer()"); return NULL; } -int mergeRasterBufferDummy(imageObj *dest, rasterBufferObj *overlay, double opacity, int srcX, int srcY, int dstX, int dstY, int width, int height) -{ +int mergeRasterBufferDummy(imageObj *dest, rasterBufferObj *overlay, + double opacity, int srcX, int srcY, int dstX, + int dstY, int width, int height) { (void)dest; (void)overlay; (void)opacity; @@ -234,48 +232,49 @@ int mergeRasterBufferDummy(imageObj *dest, rasterBufferObj *overlay, double opac (void)dstY; (void)width; (void)height; - msSetError(MS_RENDERERERR,"mergeRasterBuffer not implemented","mergeRasterBuffer()"); + msSetError(MS_RENDERERERR, "mergeRasterBuffer not implemented", + "mergeRasterBuffer()"); return MS_FAILURE; } -int initializeRasterBufferDummy(rasterBufferObj *rb, int width, int height, int mode) -{ +int initializeRasterBufferDummy(rasterBufferObj *rb, int width, int height, + int mode) { (void)rb; (void)width; (void)height; (void)mode; - msSetError(MS_RENDERERERR,"initializeRasterBuffer not implemented","initializeRasterBuffer()"); + msSetError(MS_RENDERERERR, "initializeRasterBuffer not implemented", + "initializeRasterBuffer()"); return MS_FAILURE; } - - /* image i/o */ -imageObj* createImageDummy(int width, int height, outputFormatObj *format, colorObj* bg) -{ +imageObj *createImageDummy(int width, int height, outputFormatObj *format, + colorObj *bg) { (void)width; (void)height; (void)format; (void)bg; - msSetError(MS_RENDERERERR,"createImage not implemented","createImage()"); + msSetError(MS_RENDERERERR, "createImage not implemented", "createImage()"); return NULL; } -int saveImageDummy(imageObj *img, mapObj *map, FILE *fp, outputFormatObj *format) -{ +int saveImageDummy(imageObj *img, mapObj *map, FILE *fp, + outputFormatObj *format) { (void)img; (void)map; (void)fp; (void)format; - msSetError(MS_RENDERERERR,"saveImage not implemented","saveImage()"); + msSetError(MS_RENDERERERR, "saveImage not implemented", "saveImage()"); return MS_FAILURE; } /*...*/ /* helper functions */ -int getTruetypeTextBBoxDummy(rendererVTableObj *renderer, char **fonts, int numfonts, double size, - char *string,rectObj *rect, double **advances, int bAdjustBaseline) -{ +int getTruetypeTextBBoxDummy(rendererVTableObj *renderer, char **fonts, + int numfonts, double size, char *string, + rectObj *rect, double **advances, + int bAdjustBaseline) { (void)renderer; (void)fonts; (void)numfonts; @@ -284,87 +283,77 @@ int getTruetypeTextBBoxDummy(rendererVTableObj *renderer, char **fonts, int numf (void)rect; (void)advances; (void)bAdjustBaseline; - msSetError(MS_RENDERERERR,"getTruetypeTextBBox not implemented","getTruetypeTextBBox()"); + msSetError(MS_RENDERERERR, "getTruetypeTextBBox not implemented", + "getTruetypeTextBBox()"); return MS_FAILURE; } -int startLayerDummy(imageObj *img, mapObj *map, layerObj *layer) -{ +int startLayerDummy(imageObj *img, mapObj *map, layerObj *layer) { (void)img; (void)map; (void)layer; - msSetError(MS_RENDERERERR,"startLayer not implemented","startLayer()"); + msSetError(MS_RENDERERERR, "startLayer not implemented", "startLayer()"); return MS_FAILURE; } -int endLayerDummy(imageObj *img, mapObj *map, layerObj *layer) -{ +int endLayerDummy(imageObj *img, mapObj *map, layerObj *layer) { (void)img; (void)map; (void)layer; - msSetError(MS_RENDERERERR,"endLayer not implemented","endLayer()"); + msSetError(MS_RENDERERERR, "endLayer not implemented", "endLayer()"); return MS_FAILURE; } -int startShapeDummy(imageObj *img, shapeObj *shape) -{ +int startShapeDummy(imageObj *img, shapeObj *shape) { (void)img; (void)shape; - msSetError(MS_RENDERERERR,"startShape not implemented","startShape()"); + msSetError(MS_RENDERERERR, "startShape not implemented", "startShape()"); return MS_FAILURE; } -int endShapeDummy(imageObj *img, shapeObj *shape) -{ +int endShapeDummy(imageObj *img, shapeObj *shape) { (void)img; (void)shape; - msSetError(MS_RENDERERERR,"endShape not implemented","endShape()"); + msSetError(MS_RENDERERERR, "endShape not implemented", "endShape()"); return MS_FAILURE; } -int setClipDummy(imageObj *img, rectObj clipRect) -{ +int setClipDummy(imageObj *img, rectObj clipRect) { (void)img; (void)clipRect; - msSetError(MS_RENDERERERR,"setClip not implemented","setClip()"); + msSetError(MS_RENDERERERR, "setClip not implemented", "setClip()"); return MS_FAILURE; } -int resetClipDummy(imageObj *img) -{ +int resetClipDummy(imageObj *img) { (void)img; - msSetError(MS_RENDERERERR,"resetClip not implemented","resetClip()"); + msSetError(MS_RENDERERERR, "resetClip not implemented", "resetClip()"); return MS_FAILURE; } -int freeImageDummy(imageObj *image) -{ +int freeImageDummy(imageObj *image) { (void)image; - msSetError(MS_RENDERERERR,"freeImage not implemented","freeImage()"); + msSetError(MS_RENDERERERR, "freeImage not implemented", "freeImage()"); return MS_FAILURE; } -int freeTileDummy(imageObj *tile) -{ +int freeTileDummy(imageObj *tile) { (void)tile; - msSetError(MS_RENDERERERR,"freeTile not implemented","freeTile()"); + msSetError(MS_RENDERERERR, "freeTile not implemented", "freeTile()"); return MS_FAILURE; } -int freeSymbolDummy(symbolObj *symbol) -{ +int freeSymbolDummy(symbolObj *symbol) { (void)symbol; - msSetError(MS_RENDERERERR,"freeSymbol not implemented","freeSymbol()"); + msSetError(MS_RENDERERERR, "freeSymbol not implemented", "freeSymbol()"); return MS_FAILURE; } -int cleanupDummy(void *renderer_data) -{ +int cleanupDummy(void *renderer_data) { (void)renderer_data; return MS_SUCCESS; } -int msInitializeDummyRenderer(rendererVTableObj *renderer) -{ +int msInitializeDummyRenderer(rendererVTableObj *renderer) { renderer->use_imagecache = 0; renderer->supports_pixel_buffer = 0; @@ -375,15 +364,15 @@ int msInitializeDummyRenderer(rendererVTableObj *renderer) renderer->transform_mode = MS_TRANSFORM_SIMPLIFY; renderer->startLayer = &startLayerDummy; renderer->endLayer = &endLayerDummy; - renderer->renderLine=&renderLineDummy; + renderer->renderLine = &renderLineDummy; renderer->renderLineTiled = NULL; - renderer->createImage=&createImageDummy; - renderer->saveImage=&saveImageDummy; - renderer->getRasterBufferHandle=&getRasterBufferHandleDummy; - renderer->getRasterBufferCopy=getRasterBufferCopyDummy; - renderer->initializeRasterBuffer=initializeRasterBufferDummy; - renderer->renderPolygon=&renderPolygonDummy; - renderer->freeImage=&freeImageDummy; + renderer->createImage = &createImageDummy; + renderer->saveImage = &saveImageDummy; + renderer->getRasterBufferHandle = &getRasterBufferHandleDummy; + renderer->getRasterBufferCopy = getRasterBufferCopyDummy; + renderer->initializeRasterBuffer = initializeRasterBufferDummy; + renderer->renderPolygon = &renderPolygonDummy; + renderer->freeImage = &freeImageDummy; renderer->renderEllipseSymbol = &renderEllipseSymbolDummy; renderer->renderVectorSymbol = &renderVectorSymbolDummy; renderer->renderPixmapSymbol = &renderPixmapSymbolDummy; @@ -397,5 +386,3 @@ int msInitializeDummyRenderer(rendererVTableObj *renderer) renderer->renderGlyphs = NULL; return MS_SUCCESS; } - - diff --git a/mapentities.h b/mapentities.h index aa5a716158..b1283f2b64 100644 --- a/mapentities.h +++ b/mapentities.h @@ -41,263 +41,74 @@ extern "C" { #endif - static const struct mapentities_s { - const char *name; - int value; - } mapentities[] = { - {"AElig", 198}, - {"Aacute", 193}, - {"Acirc", 194}, - {"Agrave", 192}, - {"Alpha", 913}, - {"Aring", 197}, - {"Atilde", 195}, - {"Auml", 196}, - {"Beta", 914}, - {"Ccedil", 199}, - {"Chi", 935}, - {"Dagger", 8225}, - {"Delta", 916}, - {"ETH", 208}, - {"Eacute", 201}, - {"Ecirc", 202}, - {"Egrave", 200}, - {"Epsilon", 917}, - {"Eta", 919}, - {"Euml", 203}, - {"Gamma", 915}, - {"Iacute", 205}, - {"Icirc", 206}, - {"Igrave", 204}, - {"Iota", 921}, - {"Iuml", 207}, - {"Kappa", 922}, - {"Lambda", 923}, - {"Mu", 924}, - {"Ntilde", 209}, - {"Nu", 925}, - {"OElig", 338}, - {"Oacute", 211}, - {"Ocirc", 212}, - {"Ograve", 210}, - {"Omega", 937}, - {"Omicron", 927}, - {"Oslash", 216}, - {"Otilde", 213}, - {"Ouml", 214}, - {"Phi", 934}, - {"Pi", 928}, - {"Prime", 8243}, - {"Psi", 936}, - {"Rho", 929}, - {"Scaron", 352}, - {"Sigma", 931}, - {"THORN", 222}, - {"Tau", 932}, - {"Theta", 920}, - {"Uacute", 218}, - {"Ucirc", 219}, - {"Ugrave", 217}, - {"Upsilon", 933}, - {"Uuml", 220}, - {"Xi", 926}, - {"Yacute", 221}, - {"Yuml", 376}, - {"Zeta", 918}, - {"aacute", 225}, - {"acirc", 226}, - {"acute", 180}, - {"aelig", 230}, - {"agrave", 224}, - {"alefsym", 8501}, - {"alpha", 945}, - {"amp", 38}, - {"and", 8743}, - {"ang", 8736}, - {"aring", 229}, - {"asymp", 8776}, - {"atilde", 227}, - {"auml", 228}, - {"bdquo", 8222}, - {"beta", 946}, - {"brvbar", 166}, - {"bull", 8226}, - {"cap", 8745}, - {"ccedil", 231}, - {"cedil", 184}, - {"cent", 162}, - {"chi", 967}, - {"circ", 710}, - {"clubs", 9827}, - {"cong", 8773}, - {"copy", 169}, - {"crarr", 8629}, - {"cup", 8746}, - {"curren", 164}, - {"dArr", 8659}, - {"dagger", 8224}, - {"darr", 8595}, - {"deg", 176}, - {"delta", 948}, - {"diams", 9830}, - {"divide", 247}, - {"eacute", 233}, - {"ecirc", 234}, - {"egrave", 232}, - {"empty", 8709}, - {"emsp", 8195}, - {"ensp", 8194}, - {"epsilon", 949}, - {"equiv", 8801}, - {"eta", 951}, - {"eth", 240}, - {"euml", 235}, - {"euro", 8364}, - {"exist", 8707}, - {"fnof", 402}, - {"forall", 8704}, - {"frac12", 189}, - {"frac14", 188}, - {"frac34", 190}, - {"frasl", 8260}, - {"gamma", 947}, - {"ge", 8805}, - {"gt", 62}, - {"hArr", 8660}, - {"harr", 8596}, - {"hearts", 9829}, - {"hellip", 8230}, - {"iacute", 237}, - {"icirc", 238}, - {"iexcl", 161}, - {"igrave", 236}, - {"image", 8465}, - {"infin", 8734}, - {"int", 8747}, - {"iota", 953}, - {"iquest", 191}, - {"isin", 8712}, - {"iuml", 239}, - {"kappa", 954}, - {"lArr", 8656}, - {"lambda", 955}, - {"lang", 9001}, - {"laquo", 171}, - {"larr", 8592}, - {"lceil", 8968}, - {"ldquo", 8220}, - {"le", 8804}, - {"lfloor", 8970}, - {"lowast", 8727}, - {"loz", 9674}, - {"lrm", 8206}, - {"lsaquo", 8249}, - {"lsquo", 8216}, - {"lt", 60}, - {"macr", 175}, - {"mdash", 8212}, - {"micro", 181}, - {"middot", 183}, - {"minus", 8722}, - {"mu", 956}, - {"nabla", 8711}, - {"nbsp", 160}, - {"ndash", 8211}, - {"ne", 8800}, - {"ni", 8715}, - {"not", 172}, - {"notin", 8713}, - {"nsub", 8836}, - {"ntilde", 241}, - {"nu", 957}, - {"oacute", 243}, - {"ocirc", 244}, - {"oelig", 339}, - {"ograve", 242}, - {"oline", 8254}, - {"omega", 969}, - {"omicron", 959}, - {"oplus", 8853}, - {"or", 8744}, - {"ordf", 170}, - {"ordm", 186}, - {"oslash", 248}, - {"otilde", 245}, - {"otimes", 8855}, - {"ouml", 246}, - {"para", 182}, - {"part", 8706}, - {"permil", 8240}, - {"perp", 8869}, - {"phi", 966}, - {"pi", 960}, - {"piv", 982}, - {"plusmn", 177}, - {"pound", 163}, - {"prime", 8242}, - {"prod", 8719}, - {"prop", 8733}, - {"psi", 968}, - {"quot", 34}, - {"rArr", 8658}, - {"radic", 8730}, - {"rang", 9002}, - {"raquo", 187}, - {"rarr", 8594}, - {"rceil", 8969}, - {"rdquo", 8221}, - {"real", 8476}, - {"reg", 174}, - {"rfloor", 8971}, - {"rho", 961}, - {"rlm", 8207}, - {"rsaquo", 8250}, - {"rsquo", 8217}, - {"sbquo", 8218}, - {"scaron", 353}, - {"sdot", 8901}, - {"sect", 167}, - {"shy", 173}, - {"sigma", 963}, - {"sigmaf", 962}, - {"sim", 8764}, - {"spades", 9824}, - {"sub", 8834}, - {"sube", 8838}, - {"sum", 8721}, - {"sup", 8835}, - {"sup1", 185}, - {"sup2", 178}, - {"sup3", 179}, - {"supe", 8839}, - {"szlig", 223}, - {"tau", 964}, - {"there4", 8756}, - {"theta", 952}, - {"thetasym", 977}, - {"thinsp", 8201}, - {"thorn", 254}, - {"tilde", 732}, - {"times", 215}, - {"trade", 8482}, - {"uArr", 8657}, - {"uacute", 250}, - {"uarr", 8593}, - {"ucirc", 251}, - {"ugrave", 249}, - {"uml", 168}, - {"upsih", 978}, - {"upsilon", 965}, - {"uuml", 252}, - {"weierp", 8472}, - {"xi", 958}, - {"yacute", 253}, - {"yen", 165}, - {"yuml", 255}, - {"zeta", 950}, - {"zwj", 8205}, - {"zwnj", 8204}, - }; +static const struct mapentities_s { + const char *name; + int value; +} mapentities[] = { + {"AElig", 198}, {"Aacute", 193}, {"Acirc", 194}, {"Agrave", 192}, + {"Alpha", 913}, {"Aring", 197}, {"Atilde", 195}, {"Auml", 196}, + {"Beta", 914}, {"Ccedil", 199}, {"Chi", 935}, {"Dagger", 8225}, + {"Delta", 916}, {"ETH", 208}, {"Eacute", 201}, {"Ecirc", 202}, + {"Egrave", 200}, {"Epsilon", 917}, {"Eta", 919}, {"Euml", 203}, + {"Gamma", 915}, {"Iacute", 205}, {"Icirc", 206}, {"Igrave", 204}, + {"Iota", 921}, {"Iuml", 207}, {"Kappa", 922}, {"Lambda", 923}, + {"Mu", 924}, {"Ntilde", 209}, {"Nu", 925}, {"OElig", 338}, + {"Oacute", 211}, {"Ocirc", 212}, {"Ograve", 210}, {"Omega", 937}, + {"Omicron", 927}, {"Oslash", 216}, {"Otilde", 213}, {"Ouml", 214}, + {"Phi", 934}, {"Pi", 928}, {"Prime", 8243}, {"Psi", 936}, + {"Rho", 929}, {"Scaron", 352}, {"Sigma", 931}, {"THORN", 222}, + {"Tau", 932}, {"Theta", 920}, {"Uacute", 218}, {"Ucirc", 219}, + {"Ugrave", 217}, {"Upsilon", 933}, {"Uuml", 220}, {"Xi", 926}, + {"Yacute", 221}, {"Yuml", 376}, {"Zeta", 918}, {"aacute", 225}, + {"acirc", 226}, {"acute", 180}, {"aelig", 230}, {"agrave", 224}, + {"alefsym", 8501}, {"alpha", 945}, {"amp", 38}, {"and", 8743}, + {"ang", 8736}, {"aring", 229}, {"asymp", 8776}, {"atilde", 227}, + {"auml", 228}, {"bdquo", 8222}, {"beta", 946}, {"brvbar", 166}, + {"bull", 8226}, {"cap", 8745}, {"ccedil", 231}, {"cedil", 184}, + {"cent", 162}, {"chi", 967}, {"circ", 710}, {"clubs", 9827}, + {"cong", 8773}, {"copy", 169}, {"crarr", 8629}, {"cup", 8746}, + {"curren", 164}, {"dArr", 8659}, {"dagger", 8224}, {"darr", 8595}, + {"deg", 176}, {"delta", 948}, {"diams", 9830}, {"divide", 247}, + {"eacute", 233}, {"ecirc", 234}, {"egrave", 232}, {"empty", 8709}, + {"emsp", 8195}, {"ensp", 8194}, {"epsilon", 949}, {"equiv", 8801}, + {"eta", 951}, {"eth", 240}, {"euml", 235}, {"euro", 8364}, + {"exist", 8707}, {"fnof", 402}, {"forall", 8704}, {"frac12", 189}, + {"frac14", 188}, {"frac34", 190}, {"frasl", 8260}, {"gamma", 947}, + {"ge", 8805}, {"gt", 62}, {"hArr", 8660}, {"harr", 8596}, + {"hearts", 9829}, {"hellip", 8230}, {"iacute", 237}, {"icirc", 238}, + {"iexcl", 161}, {"igrave", 236}, {"image", 8465}, {"infin", 8734}, + {"int", 8747}, {"iota", 953}, {"iquest", 191}, {"isin", 8712}, + {"iuml", 239}, {"kappa", 954}, {"lArr", 8656}, {"lambda", 955}, + {"lang", 9001}, {"laquo", 171}, {"larr", 8592}, {"lceil", 8968}, + {"ldquo", 8220}, {"le", 8804}, {"lfloor", 8970}, {"lowast", 8727}, + {"loz", 9674}, {"lrm", 8206}, {"lsaquo", 8249}, {"lsquo", 8216}, + {"lt", 60}, {"macr", 175}, {"mdash", 8212}, {"micro", 181}, + {"middot", 183}, {"minus", 8722}, {"mu", 956}, {"nabla", 8711}, + {"nbsp", 160}, {"ndash", 8211}, {"ne", 8800}, {"ni", 8715}, + {"not", 172}, {"notin", 8713}, {"nsub", 8836}, {"ntilde", 241}, + {"nu", 957}, {"oacute", 243}, {"ocirc", 244}, {"oelig", 339}, + {"ograve", 242}, {"oline", 8254}, {"omega", 969}, {"omicron", 959}, + {"oplus", 8853}, {"or", 8744}, {"ordf", 170}, {"ordm", 186}, + {"oslash", 248}, {"otilde", 245}, {"otimes", 8855}, {"ouml", 246}, + {"para", 182}, {"part", 8706}, {"permil", 8240}, {"perp", 8869}, + {"phi", 966}, {"pi", 960}, {"piv", 982}, {"plusmn", 177}, + {"pound", 163}, {"prime", 8242}, {"prod", 8719}, {"prop", 8733}, + {"psi", 968}, {"quot", 34}, {"rArr", 8658}, {"radic", 8730}, + {"rang", 9002}, {"raquo", 187}, {"rarr", 8594}, {"rceil", 8969}, + {"rdquo", 8221}, {"real", 8476}, {"reg", 174}, {"rfloor", 8971}, + {"rho", 961}, {"rlm", 8207}, {"rsaquo", 8250}, {"rsquo", 8217}, + {"sbquo", 8218}, {"scaron", 353}, {"sdot", 8901}, {"sect", 167}, + {"shy", 173}, {"sigma", 963}, {"sigmaf", 962}, {"sim", 8764}, + {"spades", 9824}, {"sub", 8834}, {"sube", 8838}, {"sum", 8721}, + {"sup", 8835}, {"sup1", 185}, {"sup2", 178}, {"sup3", 179}, + {"supe", 8839}, {"szlig", 223}, {"tau", 964}, {"there4", 8756}, + {"theta", 952}, {"thetasym", 977}, {"thinsp", 8201}, {"thorn", 254}, + {"tilde", 732}, {"times", 215}, {"trade", 8482}, {"uArr", 8657}, + {"uacute", 250}, {"uarr", 8593}, {"ucirc", 251}, {"ugrave", 249}, + {"uml", 168}, {"upsih", 978}, {"upsilon", 965}, {"uuml", 252}, + {"weierp", 8472}, {"xi", 958}, {"yacute", 253}, {"yen", 165}, + {"yuml", 255}, {"zeta", 950}, {"zwj", 8205}, {"zwnj", 8204}, +}; #define MAP_ENTITY_NAME_LENGTH_MAX 8 #define MAP_NR_OF_ENTITIES 252 diff --git a/maperror.c b/maperror.c index b1bb1cd71f..8e6d1b54aa 100644 --- a/maperror.c +++ b/maperror.c @@ -41,58 +41,58 @@ #include "cpl_conv.h" -static char *const ms_errorCodes[MS_NUMERRORCODES] = { "", - "Unable to access file.", - "Memory allocation error.", - "Incorrect data type.", - "Symbol definition error.", - "Regular expression error.", - "TrueType Font error.", - "DBASE file error.", - "GD library error.", - "Unknown identifier.", - "Premature End-of-File.", - "Projection library error.", - "General error message.", - "CGI error.", - "Web application error.", - "Image handling error.", - "Hash table error.", - "Join error.", - "Search returned no results.", - "Shapefile error.", - "Expression parser error.", - "SDE error.", - "OGR error.", - "Query error.", - "WMS server error.", - "WMS connection error.", - "OracleSpatial error.", - "WFS server error.", - "WFS connection error.", - "WMS Map Context error.", - "HTTP request error.", - "Child array error.", - "WCS server error.", - "GEOS library error.", - "Invalid rectangle.", - "Date/time error.", - "GML encoding error.", - "SOS server error.", - "NULL parent pointer error.", - "AGG library error.", - "OWS error.", - "OpenGL renderer error.", - "Renderer error.", - "V8 engine error.", - "OCG API error." -}; +static char *const ms_errorCodes[MS_NUMERRORCODES] = { + "", + "Unable to access file.", + "Memory allocation error.", + "Incorrect data type.", + "Symbol definition error.", + "Regular expression error.", + "TrueType Font error.", + "DBASE file error.", + "GD library error.", + "Unknown identifier.", + "Premature End-of-File.", + "Projection library error.", + "General error message.", + "CGI error.", + "Web application error.", + "Image handling error.", + "Hash table error.", + "Join error.", + "Search returned no results.", + "Shapefile error.", + "Expression parser error.", + "SDE error.", + "OGR error.", + "Query error.", + "WMS server error.", + "WMS connection error.", + "OracleSpatial error.", + "WFS server error.", + "WFS connection error.", + "WMS Map Context error.", + "HTTP request error.", + "Child array error.", + "WCS server error.", + "GEOS library error.", + "Invalid rectangle.", + "Date/time error.", + "GML encoding error.", + "SOS server error.", + "NULL parent pointer error.", + "AGG library error.", + "OWS error.", + "OpenGL renderer error.", + "Renderer error.", + "V8 engine error.", + "OCG API error.", + "Flatgeobuf error."}; #ifndef USE_THREAD // Get the MapServer error object -errorObj *msGetErrorObj() -{ +errorObj *msGetErrorObj() { static errorObj ms_error = {MS_NOERR, "", "", MS_FALSE, 0, NULL}; return &ms_error; } @@ -108,33 +108,33 @@ typedef struct te_info { static te_info_t *error_list = NULL; -errorObj *msGetErrorObj() -{ +errorObj *msGetErrorObj() { te_info_t *link; void *thread_id; errorObj *ret_obj; - msAcquireLock( TLOCK_ERROROBJ ); + msAcquireLock(TLOCK_ERROROBJ); thread_id = msGetThreadId(); /* find link for this thread */ - for( link = error_list; - link != NULL && link->thread_id != thread_id - && link->next != NULL && link->next->thread_id != thread_id; - link = link->next ) {} + for (link = error_list; + link != NULL && link->thread_id != thread_id && link->next != NULL && + link->next->thread_id != thread_id; + link = link->next) { + } /* If the target thread link is already at the head of the list were ok */ - if( error_list != NULL && error_list->thread_id == thread_id ) { + if (error_list != NULL && error_list->thread_id == thread_id) { } /* We don't have one ... initialize one. */ - else if( link == NULL || link->next == NULL ) { + else if (link == NULL || link->next == NULL) { te_info_t *new_link; - errorObj error_obj = { MS_NOERR, "", "", 0, 0, NULL }; + errorObj error_obj = {MS_NOERR, "", "", 0, 0, NULL, 0}; - new_link = (te_info_t *) malloc(sizeof(te_info_t)); + new_link = (te_info_t *)malloc(sizeof(te_info_t)); new_link->next = error_list; new_link->thread_id = thread_id; new_link->ms_error = error_obj; @@ -153,7 +153,7 @@ errorObj *msGetErrorObj() ret_obj = &(error_list->ms_error); - msReleaseLock( TLOCK_ERROROBJ ); + msReleaseLock(TLOCK_ERROROBJ); return ret_obj; } @@ -175,12 +175,11 @@ errorObj *msGetErrorObj() ** the head is moved to the new errorObj, freeing the head errorObj to receive ** the new error information. */ -static errorObj *msInsertErrorObj(void) -{ +static errorObj *msInsertErrorObj(void) { errorObj *ms_error; ms_error = msGetErrorObj(); - if (ms_error->code != MS_NOERR) { + if (ms_error->code != MS_NOERR && ms_error->totalerrorcount < 100) { /* Head of the list already in use, insert a new errorObj after the head * and move head contents to this new errorObj, freeing the errorObj * for reuse. @@ -196,8 +195,10 @@ static errorObj *msInsertErrorObj(void) new_error->next = ms_error->next; new_error->code = ms_error->code; new_error->isreported = ms_error->isreported; - strlcpy(new_error->routine, ms_error->routine, sizeof(new_error->routine)); - strlcpy(new_error->message, ms_error->message, sizeof(new_error->message)); + strlcpy(new_error->routine, ms_error->routine, + sizeof(new_error->routine)); + strlcpy(new_error->message, ms_error->message, + sizeof(new_error->message)); new_error->errorcount = ms_error->errorcount; ms_error->next = new_error; @@ -207,6 +208,7 @@ static errorObj *msInsertErrorObj(void) ms_error->message[0] = '\0'; ms_error->errorcount = 0; } + ms_error->totalerrorcount++; } return ms_error; @@ -216,13 +218,12 @@ static errorObj *msInsertErrorObj(void) ** ** Clear the list of error objects. */ -void msResetErrorList() -{ +void msResetErrorList() { errorObj *ms_error, *this_error; ms_error = msGetErrorObj(); this_error = ms_error->next; - while( this_error != NULL) { + while (this_error != NULL) { errorObj *next_error; next_error = this_error->next; @@ -232,9 +233,11 @@ void msResetErrorList() ms_error->next = NULL; ms_error->code = MS_NOERR; + ms_error->isreported = MS_FALSE; ms_error->routine[0] = '\0'; ms_error->message[0] = '\0'; ms_error->errorcount = 0; + ms_error->totalerrorcount = 0; /* -------------------------------------------------------------------- */ /* Cleanup our entry in the thread list. This is mainly */ @@ -242,41 +245,41 @@ void msResetErrorList() /* -------------------------------------------------------------------- */ #ifdef USE_THREAD { - void* thread_id = msGetThreadId(); + void *thread_id = msGetThreadId(); te_info_t *link; - msAcquireLock( TLOCK_ERROROBJ ); + msAcquireLock(TLOCK_ERROROBJ); /* find link for this thread */ - for( link = error_list; - link != NULL && link->thread_id != thread_id - && link->next != NULL && link->next->thread_id != thread_id; - link = link->next ) {} + for (link = error_list; + link != NULL && link->thread_id != thread_id && link->next != NULL && + link->next->thread_id != thread_id; + link = link->next) { + } - if( link->thread_id == thread_id ) { + if (link->thread_id == thread_id) { /* presumably link is at head of list. */ - if( error_list == link ) + if (error_list == link) error_list = link->next; - free( link ); - } else if( link->next != NULL && link->next->thread_id == thread_id ) { + free(link); + } else if (link->next != NULL && link->next->thread_id == thread_id) { te_info_t *next_link = link->next; link->next = link->next->next; - free( next_link ); + free(next_link); } - msReleaseLock( TLOCK_ERROROBJ ); + msReleaseLock(TLOCK_ERROROBJ); } #endif } -char *msGetErrorCodeString(int code) -{ +char *msGetErrorCodeString(int code) { - if(code<0 || code>MS_NUMERRORCODES-1) - return("Invalid error code."); + if (code < 0 || code > MS_NUMERRORCODES - 1) + return ("Invalid error code."); - return(ms_errorCodes[code]); + return (ms_errorCodes[code]); } /* -------------------------------------------------------------------- */ @@ -284,98 +287,131 @@ char *msGetErrorCodeString(int code) /* and reallocates the memory enough to hold the characters. */ /* If source is null returns a newly allocated string */ /* -------------------------------------------------------------------- */ -char *msAddErrorDisplayString(char *source, errorObj *error) -{ - if((source = msStringConcatenate(source, error->routine)) == NULL) return(NULL); - if((source = msStringConcatenate(source, ": ")) == NULL) return(NULL); - if((source = msStringConcatenate(source, ms_errorCodes[error->code])) == NULL) return(NULL); - if((source = msStringConcatenate(source, " ")) == NULL) return(NULL); - if((source = msStringConcatenate(source, error->message)) == NULL) return(NULL); +char *msAddErrorDisplayString(char *source, errorObj *error) { + if ((source = msStringConcatenate(source, error->routine)) == NULL) + return (NULL); + if ((source = msStringConcatenate(source, ": ")) == NULL) + return (NULL); + if ((source = msStringConcatenate(source, ms_errorCodes[error->code])) == + NULL) + return (NULL); + if ((source = msStringConcatenate(source, " ")) == NULL) + return (NULL); + if ((source = msStringConcatenate(source, error->message)) == NULL) + return (NULL); if (error->errorcount > 0) { - char* pszTmp; - if((source = msStringConcatenate(source, " (message repeated ")) == NULL) return(NULL); + char *pszTmp; + if ((source = msStringConcatenate(source, " (message repeated ")) == NULL) + return (NULL); pszTmp = msIntToString(error->errorcount); - if((source = msStringConcatenate(source, pszTmp)) == NULL) { + if ((source = msStringConcatenate(source, pszTmp)) == NULL) { msFree(pszTmp); - return(NULL); + return (NULL); } msFree(pszTmp); - if((source = msStringConcatenate(source, " times)")) == NULL) return(NULL); + if ((source = msStringConcatenate(source, " times)")) == NULL) + return (NULL); } return source; } -char *msGetErrorString(const char *delimiter) -{ - char *errstr=NULL; +char *msGetErrorString(const char *delimiter) { + char *errstr = NULL; errorObj *error = msGetErrorObj(); - if(!delimiter || !error) return(NULL); + if (!delimiter || !error) + return (NULL); - while(error && error->code != MS_NOERR) { - if((errstr = msAddErrorDisplayString(errstr, error)) == NULL) return(NULL); + while (error && error->code != MS_NOERR) { + if ((errstr = msAddErrorDisplayString(errstr, error)) == NULL) + return (NULL); - if(error->next && error->next->code != MS_NOERR) { /* (peek ahead) more errors, use delimiter */ - if((errstr = msStringConcatenate(errstr, delimiter)) == NULL) return(NULL); + if (error->next && + error->next->code != + MS_NOERR) { /* (peek ahead) more errors, use delimiter */ + if ((errstr = msStringConcatenate(errstr, delimiter)) == NULL) + return (NULL); } error = error->next; } - return(errstr); + return (errstr); } -void msSetError(int code, const char *message_fmt, const char *routine, ...) -{ +void msRedactString(char *str, const char *keyword, const char delimeter) { + + char *password = strstr(str, keyword); + if (password != NULL) { + char *ptr = password + strlen(keyword); + while (*ptr != '\0' && *ptr != delimeter) { + *ptr = '*'; + ptr++; + } + } +} + +void msRedactCredentials(char *str) { + + // postgres formats + msRedactString(str, "password=", ' '); + // mssql use semi-colons as delimeters for parameters + msRedactString(str, "password=", ';'); + // ODBC connections can use pwd rather than password + msRedactString(str, "pwd=", ';'); +} + +void msSetError(int code, const char *message_fmt, const char *routine, ...) { errorObj *ms_error; va_list args; char message[MESSAGELENGTH]; - if(!message_fmt) + if (!message_fmt) strcpy(message, ""); else { va_start(args, routine); - vsnprintf( message, MESSAGELENGTH, message_fmt, args ); + vsnprintf(message, MESSAGELENGTH, message_fmt, args); va_end(args); } ms_error = msGetErrorObj(); /* Insert the error to the list if it is not the same as the previous error*/ - if (ms_error->code != code || !EQUAL(message, ms_error->message) || - !EQUAL(routine, ms_error->routine)) { - ms_error = msInsertErrorObj(); - if(!routine) - strcpy(ms_error->routine, ""); - else { - strlcpy(ms_error->routine, routine, sizeof(ms_error->routine)); - } - strlcpy(ms_error->message, message, sizeof(ms_error->message)); - ms_error->code = code; - ms_error->errorcount = 0; - } - else - ++ms_error->errorcount; - - /* Log a copy of errors to MS_ERRORFILE if set (handled automatically inside msDebug()) */ - msDebug("%s: %s %s\n", ms_error->routine, ms_errorCodes[ms_error->code], ms_error->message); - + if (ms_error->code != code || !EQUAL(message, ms_error->message) || + !EQUAL(routine, ms_error->routine)) { + ms_error = msInsertErrorObj(); + if (!routine) + strcpy(ms_error->routine, ""); + else { + strlcpy(ms_error->routine, routine, sizeof(ms_error->routine)); + } + strlcpy(ms_error->message, message, sizeof(ms_error->message)); + ms_error->code = code; + ms_error->errorcount = 0; + } else + ++ms_error->errorcount; + + msRedactCredentials(ms_error->message); + + /* Log a copy of errors to MS_ERRORFILE if set (handled automatically inside + * msDebug()) */ + msDebug("%s: %s %s\n", ms_error->routine, ms_errorCodes[ms_error->code], + ms_error->message); } -void msWriteError(FILE *stream) -{ +void msWriteError(FILE *stream) { errorObj *ms_error = msGetErrorObj(); while (ms_error && ms_error->code != MS_NOERR) { - msIO_fprintf(stream, "%s: %s %s
\n", ms_error->routine, ms_errorCodes[ms_error->code], ms_error->message); + msIO_fprintf(stream, "%s: %s %s
\n", ms_error->routine, + ms_errorCodes[ms_error->code], ms_error->message); ms_error->isreported = MS_TRUE; ms_error = ms_error->next; } } -void msWriteErrorXML(FILE *stream) -{ +void msWriteErrorXML(FILE *stream) { char *message; errorObj *ms_error = msGetErrorObj(); @@ -391,28 +427,28 @@ void msWriteErrorXML(FILE *stream) } } -void msWriteErrorImage(mapObj *map, char *filename, int blank) -{ +void msWriteErrorImage(mapObj *map, char *filename, int blank) { imageObj *img; - int width=400, height=300; - const int nMargin =5; + int width = 400, height = 300; + const int nMargin = 5; char **papszLines = NULL; - pointObj pnt = { 0 }; + pointObj pnt = {0}; outputFormatObj *format = NULL; char *errormsg = msGetErrorString("; "); errorObj *error = msGetErrorObj(); char *imagepath = NULL, *imageurl = NULL; - colorObj imagecolor, *imagecolorptr=NULL; + colorObj imagecolor, *imagecolorptr = NULL; textSymbolObj ts; labelObj label; - int charWidth = 5, charHeight = 8; /* hardcoded, should be looked up from ft face */ - if(!errormsg) { + int charWidth = 5, + charHeight = 8; /* hardcoded, should be looked up from ft face */ + if (!errormsg) { errormsg = msStrdup("No error found sorry. This is likely a bug"); } if (map) { - if( map->width > 0 && map->height > 0 ) { + if (map->width > 0 && map->height > 0) { width = map->width; height = map->height; } @@ -423,68 +459,73 @@ void msWriteErrorImage(mapObj *map, char *filename, int blank) /* Default to GIF if no suitable GD output format set */ if (format == NULL || !MS_RENDERER_PLUGIN(format)) - format = msCreateDefaultOutputFormat( NULL, "AGG/PNG8", "png", NULL ); + format = msCreateDefaultOutputFormat(NULL, "AGG/PNG8", "png", NULL); - if(!format->transparent) { - if(map && MS_VALID_COLOR(map->imagecolor)) { + if (!format->transparent) { + if (map && MS_VALID_COLOR(map->imagecolor)) { imagecolorptr = &map->imagecolor; } else { - MS_INIT_COLOR(imagecolor,255,255,255,255); + MS_INIT_COLOR(imagecolor, 255, 255, 255, 255); imagecolorptr = &imagecolor; } } - img = msImageCreate(width,height,format,imagepath,imageurl,MS_DEFAULT_RESOLUTION,MS_DEFAULT_RESOLUTION,imagecolorptr); + img = msImageCreate(width, height, format, imagepath, imageurl, + MS_DEFAULT_RESOLUTION, MS_DEFAULT_RESOLUTION, + imagecolorptr); const int nTextLength = strlen(errormsg); - const int nWidthTxt = nTextLength * charWidth; - const int nUsableWidth = width - (nMargin*2); + const int nWidthTxt = nTextLength * charWidth; + const int nUsableWidth = width - (nMargin * 2); - /* Check to see if it all fits on one line. If not, split the text on several lines. */ - if(!blank) { + /* Check to see if it all fits on one line. If not, split the text on several + * lines. */ + if (!blank) { int nLines; if (nWidthTxt > nUsableWidth) { - const int nMaxCharsPerLine = nUsableWidth/charWidth; - nLines = (int) ceil ((double)nTextLength / (double)nMaxCharsPerLine); + const int nMaxCharsPerLine = nUsableWidth / charWidth; + nLines = (int)ceil((double)nTextLength / (double)nMaxCharsPerLine); if (nLines > 0) { - papszLines = (char **)malloc(nLines*sizeof(char *)); - for (int i=0; i nTextLength) nEnd = nTextLength; - const int nLength = nEnd-nStart; + const int nLength = nEnd - nStart; - strncpy(papszLines[i], errormsg+nStart, nLength); + strncpy(papszLines[i], errormsg + nStart, nLength); papszLines[i][nLength] = '\0'; } } } else { nLines = 1; - papszLines = (char **)malloc(nLines*sizeof(char *)); + papszLines = (char **)malloc(nLines * sizeof(char *)); papszLines[0] = msStrdup(errormsg); } initLabel(&label); - MS_INIT_COLOR(label.color,0,0,0,255); - MS_INIT_COLOR(label.outlinecolor,255,255,255,255); + MS_INIT_COLOR(label.color, 0, 0, 0, 255); + MS_INIT_COLOR(label.outlinecolor, 255, 255, 255, 255); label.outlinewidth = 1; label.size = MS_SMALL; MS_REFCNT_INCR((&label)); - for (int i=0; icode != MS_NOERR) { + while (error && error->code != MS_NOERR) { error->isreported = MS_TRUE; error = error->next; } @@ -513,14 +554,24 @@ void msWriteErrorImage(mapObj *map, char *filename, int blank) msFree(errormsg); } -char *msGetVersion() -{ - static char version[1024]; - - if(CPLGetConfigOption("MS_NO_VERSION", NULL) != NULL) return ""; // supressing version information +char *msGetVersion() { + static char version[2048]; sprintf(version, "MapServer version %s", MS_VERSION); + // add versions of required dependencies +#if PROJ_VERSION_MAJOR >= 6 + static char PROJVersion[20]; + sprintf(PROJVersion, " PROJ version %d.%d", PROJ_VERSION_MAJOR, + PROJ_VERSION_MINOR); + strcat(version, PROJVersion); +#endif + + static char GDALVersion[20]; + sprintf(GDALVersion, " GDAL version %d.%d", GDAL_VERSION_MAJOR, + GDAL_VERSION_MINOR); + strcat(version, GDALVersion); + #if (defined USE_PNG) strcat(version, " OUTPUT=PNG"); #endif @@ -538,11 +589,11 @@ char *msGetVersion() #endif #if defined(USE_SVG_CAIRO) || defined(USE_RSVG) strcat(version, " SUPPORTS=SVG_SYMBOLS"); - #ifdef USE_SVG_CAIRO - strcat(version, " SUPPORTS=SVGCAIRO"); - #else - strcat(version, " SUPPORTS=RSVG"); - #endif +#ifdef USE_SVG_CAIRO + strcat(version, " SUPPORTS=SVGCAIRO"); +#else + strcat(version, " SUPPORTS=RSVG"); +#endif #endif #ifdef USE_OGL strcat(version, " SUPPORTS=OPENGL"); @@ -608,10 +659,7 @@ char *msGetVersion() strcat(version, " INPUT=GDAL"); strcat(version, " INPUT=SHAPEFILE"); strcat(version, " INPUT=FLATGEOBUF"); - return(version); + return (version); } -int msGetVersionInt() -{ - return MS_VERSION_NUM; -} +int msGetVersionInt() { return MS_VERSION_NUM; } diff --git a/maperror.h b/maperror.h index 8a7c87c23a..9da4704a18 100644 --- a/maperror.h +++ b/maperror.h @@ -36,9 +36,9 @@ extern "C" { #endif - /*==================================================================== - * maperror.c - *====================================================================*/ +/*==================================================================== + * maperror.c + *====================================================================*/ #define MS_NOERR 0 /* general error codes */ #define MS_IOERR 1 @@ -63,14 +63,14 @@ extern "C" { #define MS_UNUSEDERR 21 #define MS_OGRERR 22 #define MS_QUERYERR 23 -#define MS_WMSERR 24 /* WMS server error */ -#define MS_WMSCONNERR 25 /* WMS connectiontype error */ +#define MS_WMSERR 24 /* WMS server error */ +#define MS_WMSCONNERR 25 /* WMS connectiontype error */ #define MS_ORACLESPATIALERR 26 -#define MS_WFSERR 27 /* WFS server error */ -#define MS_WFSCONNERR 28 /* WFS connectiontype error */ +#define MS_WFSERR 27 /* WFS server error */ +#define MS_WFSCONNERR 28 /* WFS connectiontype error */ #define MS_MAPCONTEXTERR 29 /* Map Context error */ #define MS_HTTPERR 30 -#define MS_CHILDERR 31 /* Errors involving arrays of child objects */ +#define MS_CHILDERR 31 /* Errors involving arrays of child objects */ #define MS_WCSERR 32 #define MS_GEOSERR 33 #define MS_RECTERR 34 @@ -93,115 +93,129 @@ extern "C" { #define MS_ERROR_LANGUAGE "en-US" #if defined(_WIN32) && !defined(__CYGWIN__) -# define MS_DLL_EXPORT __declspec(dllexport) +#define MS_DLL_EXPORT __declspec(dllexport) #else -#define MS_DLL_EXPORT +#define MS_DLL_EXPORT #endif #ifndef MS_PRINT_FUNC_FORMAT #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP) -#define MS_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx))) +#define MS_PRINT_FUNC_FORMAT(format_idx, arg_idx) \ + __attribute__((__format__(__printf__, format_idx, arg_idx))) #else -#define MS_PRINT_FUNC_FORMAT( format_idx, arg_idx ) +#define MS_PRINT_FUNC_FORMAT(format_idx, arg_idx) #endif #endif /** -This class allows inspection of the MapServer error stack. -Instances of errorObj are created internally by MapServer as errors happen. -Errors are managed as a chained list with the first item being the most recent error. +This class allows inspection of the MapServer error stack. +Instances of errorObj are created internally by MapServer as errors happen. +Errors are managed as a chained list with the first item being the most recent +error. */ - typedef struct errorObj { - int code; ///< MapServer error code such as :data:`MS_IMGERR` - char routine[ROUTINELENGTH]; ///< MapServer function in which the error was set - char message[MESSAGELENGTH]; ///< Context-dependent error message - int isreported; ///< :data:`MS_TRUE` or :data:`MS_FALSE` flag indicating if the error has been output - int errorcount; ///< Number of subsequent errors +typedef struct errorObj { + int code; ///< MapServer error code such as :data:`MS_IMGERR` + char + routine[ROUTINELENGTH]; ///< MapServer function in which the error was set + char message[MESSAGELENGTH]; ///< Context-dependent error message + int isreported; ///< :data:`MS_TRUE` or :data:`MS_FALSE` flag indicating if + ///< the error has been output + int errorcount; ///< Number of subsequent errors #ifndef SWIG - struct errorObj *next; + struct errorObj *next; + int totalerrorcount; #endif - } errorObj; - - /* - ** Function prototypes - */ - - /** - Get the MapServer error object - */ - MS_DLL_EXPORT errorObj *msGetErrorObj(void); - /** - Clear the list of error objects - */ - MS_DLL_EXPORT void msResetErrorList(void); - /** - Returns a string containing MapServer version information, and details on what optional components - are built in - the same report as produced by ``mapserv -v`` - */ - MS_DLL_EXPORT char *msGetVersion(void); - /** - Returns the MapServer version number (x.y.z) as an integer (x*10000 + y*100 + z) - e.g. V7.4.2 would return 70402 - */ - MS_DLL_EXPORT int msGetVersionInt(void); - /** - Return a string of all errors - */ - MS_DLL_EXPORT char *msGetErrorString(const char *delimiter); +} errorObj; -#ifndef SWIG - MS_DLL_EXPORT void msSetError(int code, const char *message, const char *routine, ...) MS_PRINT_FUNC_FORMAT(2,4) ; - MS_DLL_EXPORT void msWriteError(FILE *stream); - MS_DLL_EXPORT void msWriteErrorXML(FILE *stream); - MS_DLL_EXPORT char *msGetErrorCodeString(int code); - MS_DLL_EXPORT char *msAddErrorDisplayString(char *source, errorObj *error); +/* +** Function prototypes +*/ - struct mapObj; - MS_DLL_EXPORT void msWriteErrorImage(struct mapObj *map, char *filename, int blank); +/** +Get the MapServer error object +*/ +MS_DLL_EXPORT errorObj *msGetErrorObj(void); +/** +Clear the list of error objects +*/ +MS_DLL_EXPORT void msResetErrorList(void); +/** +Returns a string containing MapServer version information, and details on what +optional components are built in - the same report as produced by ``mapserv -v`` +*/ +MS_DLL_EXPORT char *msGetVersion(void); +/** +Returns the MapServer version number (x.y.z) as an integer (x*10000 + y*100 + z) +e.g. V7.4.2 would return 70402 +*/ +MS_DLL_EXPORT int msGetVersionInt(void); +/** +Return a string of all errors +*/ +MS_DLL_EXPORT char *msGetErrorString(const char *delimiter); -#endif /* SWIG */ +#ifndef SWIG +MS_DLL_EXPORT void msRedactCredentials(char *str); +MS_DLL_EXPORT void msSetError(int code, const char *message, + const char *routine, ...) + MS_PRINT_FUNC_FORMAT(2, 4); +MS_DLL_EXPORT void msWriteError(FILE *stream); +MS_DLL_EXPORT void msWriteErrorXML(FILE *stream); +MS_DLL_EXPORT char *msGetErrorCodeString(int code); +MS_DLL_EXPORT char *msAddErrorDisplayString(char *source, errorObj *error); + +struct mapObj; +MS_DLL_EXPORT void msWriteErrorImage(struct mapObj *map, char *filename, + int blank); - /*==================================================================== - * mapdebug.c (See also MS-RFC-28) - *====================================================================*/ +#endif /* SWIG */ - typedef enum { MS_DEBUGLEVEL_ERRORSONLY = 0, /* DEBUG OFF, log fatal errors */ - MS_DEBUGLEVEL_DEBUG = 1, /* DEBUG ON */ - MS_DEBUGLEVEL_TUNING = 2, /* Reports timing info */ - MS_DEBUGLEVEL_V = 3, /* Verbose */ - MS_DEBUGLEVEL_VV = 4, /* Very verbose */ - MS_DEBUGLEVEL_VVV = 5, /* Very very verbose */ - MS_DEBUGLEVEL_DEVDEBUG = 20, /* Undocumented, will trigger debug messages only useful for developers */ - } debugLevel; +/*==================================================================== + * mapdebug.c (See also MS-RFC-28) + *====================================================================*/ + +typedef enum { + MS_DEBUGLEVEL_ERRORSONLY = 0, /* DEBUG OFF, log fatal errors */ + MS_DEBUGLEVEL_DEBUG = 1, /* DEBUG ON */ + MS_DEBUGLEVEL_TUNING = 2, /* Reports timing info */ + MS_DEBUGLEVEL_V = 3, /* Verbose */ + MS_DEBUGLEVEL_VV = 4, /* Very verbose */ + MS_DEBUGLEVEL_VVV = 5, /* Very very verbose */ + MS_DEBUGLEVEL_DEVDEBUG = 20, /* Undocumented, will trigger debug messages only + useful for developers */ +} debugLevel; #ifndef SWIG - typedef enum { MS_DEBUGMODE_OFF, - MS_DEBUGMODE_FILE, - MS_DEBUGMODE_STDERR, - MS_DEBUGMODE_STDOUT, - MS_DEBUGMODE_WINDOWSDEBUG - } debugMode; - - typedef struct debug_info_obj { - debugLevel global_debug_level; - debugMode debug_mode; - char *errorfile; - FILE *fp; - /* The following 2 members are used only with USE_THREAD (but we won't #ifndef them) */ - void* thread_id; - struct debug_info_obj *next; - } debugInfoObj; - - - MS_DLL_EXPORT void msDebug( const char * pszFormat, ... ) MS_PRINT_FUNC_FORMAT(1,2) ; - MS_DLL_EXPORT int msSetErrorFile(const char *pszErrorFile, const char *pszRelToPath); - MS_DLL_EXPORT void msCloseErrorFile( void ); - MS_DLL_EXPORT const char *msGetErrorFile( void ); - MS_DLL_EXPORT void msSetGlobalDebugLevel(int level); - MS_DLL_EXPORT debugLevel msGetGlobalDebugLevel( void ); - MS_DLL_EXPORT int msDebugInitFromEnv( void ); - MS_DLL_EXPORT void msDebugCleanup( void ); +typedef enum { + MS_DEBUGMODE_OFF, + MS_DEBUGMODE_FILE, + MS_DEBUGMODE_STDERR, + MS_DEBUGMODE_STDOUT, + MS_DEBUGMODE_WINDOWSDEBUG +} debugMode; + +typedef struct debug_info_obj { + debugLevel global_debug_level; + debugMode debug_mode; + char *errorfile; + FILE *fp; + /* The following 2 members are used only with USE_THREAD (but we won't #ifndef + * them) */ + void *thread_id; + struct debug_info_obj *next; +} debugInfoObj; + +MS_DLL_EXPORT void msDebug(const char *pszFormat, ...) + MS_PRINT_FUNC_FORMAT(1, 2); +MS_DLL_EXPORT int msSetErrorFile(const char *pszErrorFile, + const char *pszRelToPath); +MS_DLL_EXPORT void msCloseErrorFile(void); +MS_DLL_EXPORT const char *msGetErrorFile(void); +MS_DLL_EXPORT void msSetGlobalDebugLevel(int level); +MS_DLL_EXPORT debugLevel msGetGlobalDebugLevel(void); +MS_DLL_EXPORT int msDebugInitFromEnv(void); +MS_DLL_EXPORT void msDebugCleanup(void); #endif /* SWIG */ diff --git a/mapfile.c b/mapfile.c old mode 100755 new mode 100644 index 9e94ab761b..6c3bdddc37 --- a/mapfile.c +++ b/mapfile.c @@ -32,6 +32,7 @@ #endif #include +#include #include #include #include @@ -61,24 +62,31 @@ extern char *msyystring_buffer; extern int msyystring_icase; extern int loadSymbol(symbolObj *s, char *symbolpath); /* in mapsymbol.c */ -extern void writeSymbol(symbolObj *s, FILE *stream); /* in mapsymbol.c */ -static int loadGrid( layerObj *pLayer ); +extern void writeSymbol(symbolObj *s, FILE *stream); /* in mapsymbol.c */ +static int loadGrid(layerObj *pLayer); static int loadStyle(styleObj *style); -static void writeStyle(FILE* stream, int indent, styleObj *style); +static void writeStyle(FILE *stream, int indent, styleObj *style); static int resolveSymbolNames(mapObj *map); static int loadExpression(expressionObj *exp); -static void writeExpression(FILE *stream, int indent, const char *name, expressionObj *exp); - +static void writeExpression(FILE *stream, int indent, const char *name, + expressionObj *exp); /* ** Symbol to string static arrays needed for writing map files. ** Must be kept in sync with enumerations and defines found in mapserver.h. */ -/* static char *msUnits[9]={"INCHES", "FEET", "MILES", "METERS", "KILOMETERS", "DD", "PIXELS", "PERCENTAGES", "NAUTICALMILES"}; */ -/* static char *msLayerTypes[10]={"POINT", "LINE", "POLYGON", "RASTER", "ANNOTATION", "QUERY", "CIRCLE", "TILEINDEX","CHART"}; */ -char *msPositionsText[MS_POSITIONS_LENGTH] = {"UL", "LR", "UR", "LL", "CR", "CL", "UC", "LC", "CC", "AUTO", "XY", "FOLLOW"}; /* msLabelPositions[] also used in mapsymbols.c (not static) */ -/* static char *msBitmapFontSizes[5]={"TINY", "SMALL", "MEDIUM", "LARGE", "GIANT"}; */ -/* static char *msQueryMapStyles[4]={"NORMAL", "HILITE", "SELECTED", "INVERTED"}; */ +/* static char *msUnits[9]={"INCHES", "FEET", "MILES", "METERS", "KILOMETERS", + * "DD", "PIXELS", "PERCENTAGES", "NAUTICALMILES"}; */ +/* static char *msLayerTypes[10]={"POINT", "LINE", "POLYGON", "RASTER", + * "ANNOTATION", "QUERY", "CIRCLE", "TILEINDEX","CHART"}; */ +char *msPositionsText[MS_POSITIONS_LENGTH] = { + "UL", "LR", "UR", "LL", "CR", "CL", "UC", + "LC", "CC", "AUTO", "XY", "FOLLOW"}; /* msLabelPositions[] also used in + mapsymbols.c (not static) */ +/* static char *msBitmapFontSizes[5]={"TINY", "SMALL", "MEDIUM", "LARGE", + * "GIANT"}; */ +/* static char *msQueryMapStyles[4]={"NORMAL", "HILITE", "SELECTED", + * "INVERTED"}; */ /* static char *msStatus[4]={"OFF", "ON", "DEFAULT", "EMBED"}; */ /* static char *msOnOff[2]={"OFF", "ON"}; */ /* static char *msTrueFalse[2]={"FALSE", "TRUE"}; */ @@ -87,84 +95,93 @@ char *msPositionsText[MS_POSITIONS_LENGTH] = {"UL", "LR", "UR", "LL", "CR", "CL" /* static char *msAlignValue[3]={"LEFT","CENTER","RIGHT"}; */ /* -** Validates a string (value) against a series of patterns. We support up to four to allow cascading from classObj to +** Validates a string (value) against a series of patterns. We support up to +*four to allow cascading from classObj to ** layerObj to webObj plus a legacy pattern like TEMPLATEPATTERN. */ -int msValidateParameter(const char *value, const char *pattern1, const char *pattern2, const char *pattern3, const char *pattern4) -{ - if(msEvalRegex(pattern1, value) == MS_TRUE) return MS_SUCCESS; - if(msEvalRegex(pattern2, value) == MS_TRUE) return MS_SUCCESS; - if(msEvalRegex(pattern3, value) == MS_TRUE) return MS_SUCCESS; - if(msEvalRegex(pattern4, value) == MS_TRUE) return MS_SUCCESS; +int msValidateParameter(const char *value, const char *pattern1, + const char *pattern2, const char *pattern3, + const char *pattern4) { + if (msEvalRegex(pattern1, value) == MS_TRUE) + return MS_SUCCESS; + if (msEvalRegex(pattern2, value) == MS_TRUE) + return MS_SUCCESS; + if (msEvalRegex(pattern3, value) == MS_TRUE) + return MS_SUCCESS; + if (msEvalRegex(pattern4, value) == MS_TRUE) + return MS_SUCCESS; - return(MS_FAILURE); + return (MS_FAILURE); } -int msIsValidRegex(const char* e) { +int msIsValidRegex(const char *e) { ms_regex_t re; - if(ms_regcomp(&re, e, MS_REG_EXTENDED|MS_REG_NOSUB) != 0) { - msSetError(MS_REGEXERR, "Failed to compile expression (%s).", "msEvalRegex()", e); - return(MS_FALSE); + if (ms_regcomp(&re, e, MS_REG_EXTENDED | MS_REG_NOSUB) != 0) { + msSetError(MS_REGEXERR, "Failed to compile expression (%s).", + "msEvalRegex()", e); + return (MS_FALSE); } ms_regfree(&re); return MS_TRUE; } -int msEvalRegex(const char *e, const char *s) -{ +int msEvalRegex(const char *e, const char *s) { ms_regex_t re; - if(!e || !s) return(MS_FALSE); + if (!e || !s) + return (MS_FALSE); - if(ms_regcomp(&re, e, MS_REG_EXTENDED|MS_REG_NOSUB) != 0) { - msSetError(MS_REGEXERR, "Failed to compile expression (%s).", "msEvalRegex()", e); - return(MS_FALSE); + if (ms_regcomp(&re, e, MS_REG_EXTENDED | MS_REG_NOSUB) != 0) { + msSetError(MS_REGEXERR, "Failed to compile expression (%s).", + "msEvalRegex()", e); + return (MS_FALSE); } - if(ms_regexec(&re, s, 0, NULL, 0) != 0) { /* no match */ + if (ms_regexec(&re, s, 0, NULL, 0) != 0) { /* no match */ ms_regfree(&re); - return(MS_FALSE); + return (MS_FALSE); } ms_regfree(&re); - return(MS_TRUE); + return (MS_TRUE); } -int msCaseEvalRegex(const char *e, const char *s) -{ +int msCaseEvalRegex(const char *e, const char *s) { ms_regex_t re; - if(!e || !s) return(MS_FALSE); + if (!e || !s) + return (MS_FALSE); - if(ms_regcomp(&re, e, MS_REG_EXTENDED|MS_REG_ICASE|MS_REG_NOSUB) != 0) { - msSetError(MS_REGEXERR, "Failed to compile expression (%s).", "msEvalRegex()", e); - return(MS_FALSE); + if (ms_regcomp(&re, e, MS_REG_EXTENDED | MS_REG_ICASE | MS_REG_NOSUB) != 0) { + msSetError(MS_REGEXERR, "Failed to compile expression (%s).", + "msEvalRegex()", e); + return (MS_FALSE); } - if(ms_regexec(&re, s, 0, NULL, 0) != 0) { /* no match */ + if (ms_regexec(&re, s, 0, NULL, 0) != 0) { /* no match */ ms_regfree(&re); - return(MS_FALSE); + return (MS_FALSE); } ms_regfree(&re); - return(MS_TRUE); + return (MS_TRUE); } #ifdef USE_MSFREE -void msFree(void *p) -{ - if(p) free(p); +void msFree(void *p) { + if (p) + free(p); } #endif /* ** Free memory allocated for a character array */ -void msFreeCharArray(char **array, int num_items) -{ +void msFreeCharArray(char **array, int num_items) { int i; - if(!array) return; - for(i=0; i= value1 && number <= value2) { + } else if (num_check_type == MS_NUM_CHECK_RANGE && number >= value1 && + number <= value2) { return MS_SUCCESS; - } else if(num_check_type == MS_NUM_CHECK_GT && number > value1) { + } else if (num_check_type == MS_NUM_CHECK_GT && number > value1) { return MS_SUCCESS; - } else if(num_check_type == MS_NUM_CHECK_GTE && number >= value1) { + } else if (num_check_type == MS_NUM_CHECK_GTE && number >= value1) { return MS_SUCCESS; } @@ -267,55 +283,56 @@ int msCheckNumber(double number, int num_check_type, double value1, double value /* ** Load a floating point number from the map file. (see lexer.l) */ -int getDouble(double *d, int num_check_type, double value1, double value2) -{ - if(msyylex() == MS_NUMBER) { - if(msCheckNumber(msyynumber, num_check_type, value1, value2) == MS_SUCCESS) { +int getDouble(double *d, int num_check_type, double value1, double value2) { + if (msyylex() == MS_NUMBER) { + if (msCheckNumber(msyynumber, num_check_type, value1, value2) == + MS_SUCCESS) { *d = msyynumber; - return(0); + return (0); } } - msSetError(MS_SYMERR, "Parsing error near (%s):(line %d)", "getDouble()", msyystring_buffer, msyylineno); - return(-1); + msSetError(MS_SYMERR, "Parsing error near (%s):(line %d)", "getDouble()", + msyystring_buffer, msyylineno); + return (-1); } /* ** Load a integer from the map file. (see lexer.l) */ -int getInteger(int *i, int num_check_type, int value1, int value2) -{ - if(msyylex() == MS_NUMBER) { - if(msCheckNumber(msyynumber, num_check_type, value1, value2) == MS_SUCCESS) { +int getInteger(int *i, int num_check_type, int value1, int value2) { + if (msyylex() == MS_NUMBER) { + if (msCheckNumber(msyynumber, num_check_type, value1, value2) == + MS_SUCCESS) { *i = (int)msyynumber; - return(0); + return (0); } } - msSetError(MS_SYMERR, "Parsing error near (%s):(line %d)", "getInteger()", msyystring_buffer, msyylineno); - return(-1); + msSetError(MS_SYMERR, "Parsing error near (%s):(line %d)", "getInteger()", + msyystring_buffer, msyylineno); + return (-1); } -int getCharacter(char *c) -{ - if(msyylex() == MS_STRING) { +int getCharacter(char *c) { + if (msyylex() == MS_STRING) { *c = msyystring_buffer[0]; - return(0); + return (0); } - msSetError(MS_SYMERR, "Parsing error near (%s):(line %d)", "getCharacter()", msyystring_buffer, msyylineno); - return(-1); + msSetError(MS_SYMERR, "Parsing error near (%s):(line %d)", "getCharacter()", + msyystring_buffer, msyylineno); + return (-1); } /* ** Try to load as an integer, then try as a named symbol. ** Part of work on bug 490. */ -int getIntegerOrSymbol(int *i, int n, ...) -{ +int getIntegerOrSymbol(int *i, int n, ...) { int symbol; va_list argp; - int j=0; + int j = 0; symbol = msyylex(); @@ -325,8 +342,8 @@ int getIntegerOrSymbol(int *i, int n, ...) } va_start(argp, n); - while (jconfigoptions), "MS_PLUGIN_DIR"); - /* do nothing on windows, filename without .dll will be loaded by default*/ + /* do nothing on windows, filename without .dll will be loaded by default*/ #if !defined(_WIN32) if (lib_str) { size_t len = strlen(lib_str); - if (3 < len && strcmp(lib_str + len-3, ".so")) { + if (3 < len && strcmp(lib_str + len - 3, ".so")) { strlcpy(szLibPathExt, lib_str, MS_MAXPATHLEN); strlcat(szLibPathExt, ".so", MS_MAXPATHLEN); lib_str = szLibPathExt; @@ -369,6 +384,7 @@ int msBuildPluginLibraryPath(char **dest, const char *lib_str, mapObj *map) if (NULL == msBuildPath(szLibPath, plugin_dir, lib_str)) { return MS_FAILURE; } + msFree(*dest); *dest = msStrdup(szLibPath); return MS_SUCCESS; @@ -380,70 +396,78 @@ int msBuildPluginLibraryPath(char **dest, const char *lib_str, mapObj *map) ** If try_addimage_if_notfound==MS_TRUE then msAddImageSymbol() will be called ** to try to allocate the symbol as an image symbol. */ -int msGetSymbolIndex(symbolSetObj *symbols, char *name, int try_addimage_if_notfound) -{ +int msGetSymbolIndex(symbolSetObj *symbols, char *name, + int try_addimage_if_notfound) { int i; - if(!symbols || !name) return(-1); + if (!symbols || !name) + return (-1); /* symbol 0 has no name */ - for(i=1; inumsymbols; i++) { - if(symbols->symbol[i]->name) - if(strcasecmp(symbols->symbol[i]->name, name) == 0) return(i); + for (i = 1; i < symbols->numsymbols; i++) { + if (symbols->symbol[i]->name) + if (strcasecmp(symbols->symbol[i]->name, name) == 0) + return (i); } if (try_addimage_if_notfound) - return(msAddImageSymbol(symbols, name)); /* make sure it's not a filename */ + return ( + msAddImageSymbol(symbols, name)); /* make sure it's not a filename */ - return(-1); + return (-1); } /* ** Return the index number for a given layer based on its name. */ -int msGetLayerIndex(mapObj *map, const char *name) -{ +int msGetLayerIndex(mapObj *map, const char *name) { int i; - if(!name) return(-1); + if (!name) + return (-1); - for(i=0; inumlayers; i++) { - if(!GET_LAYER(map, i)->name) /* skip it */ + for (i = 0; i < map->numlayers; i++) { + if (!GET_LAYER(map, i)->name) /* skip it */ continue; - if(strcmp(name, GET_LAYER(map, i)->name) == 0) - return(i); + if (strcmp(name, GET_LAYER(map, i)->name) == 0) + return (i); } - return(-1); + return (-1); } -int loadColor(colorObj *color, attributeBindingObj *binding) -{ +int loadColor(colorObj *color, attributeBindingObj *binding) { int symbol; char hex[2]; /* - ** Note that negative color values can be used to suppress or change behavior. For example, referenceObj uses + ** Note that negative color values can be used to suppress or change behavior. + *For example, referenceObj uses ** a negative color component to suppress rectangle fills. */ - if(binding) { - if((symbol = getSymbol(3, MS_NUMBER, MS_BINDING, MS_STRING)) == -1) return MS_FAILURE; + if (binding) { + if ((symbol = getSymbol(3, MS_NUMBER, MS_BINDING, MS_STRING)) == -1) + return MS_FAILURE; } else { - if((symbol = getSymbol(2, MS_NUMBER, MS_STRING)) == -1) return MS_FAILURE; + if ((symbol = getSymbol(2, MS_NUMBER, MS_STRING)) == -1) + return MS_FAILURE; } - color->alpha=255; - if(symbol == MS_NUMBER) { - if(msyynumber >= -255 && msyynumber <= 255) { - color->red = (int) msyynumber; + color->alpha = 255; + if (symbol == MS_NUMBER) { + if (msyynumber >= -255 && msyynumber <= 255) { + color->red = (int)msyynumber; } else { return MS_FAILURE; } - if(getInteger(&(color->green), MS_NUM_CHECK_RANGE, -255, 255) == -1) return MS_FAILURE; - if(getInteger(&(color->blue), MS_NUM_CHECK_RANGE, -255, 255) == -1) return MS_FAILURE; - } else if(symbol == MS_STRING) { + if (getInteger(&(color->green), MS_NUM_CHECK_RANGE, -255, 255) == -1) + return MS_FAILURE; + if (getInteger(&(color->blue), MS_NUM_CHECK_RANGE, -255, 255) == -1) + return MS_FAILURE; + } else if (symbol == MS_STRING) { int len = strlen(msyystring_buffer); - if(msyystring_buffer[0] == '#' && (len == 7 || len == 9)) { /* got a hex color w/optional alpha */ + if (msyystring_buffer[0] == '#' && + (len == 7 || len == 9)) { /* got a hex color w/optional alpha */ hex[0] = msyystring_buffer[1]; hex[1] = msyystring_buffer[2]; color->red = msHexToInt(hex); @@ -453,18 +477,20 @@ int loadColor(colorObj *color, attributeBindingObj *binding) hex[0] = msyystring_buffer[5]; hex[1] = msyystring_buffer[6]; color->blue = msHexToInt(hex); - if(len == 9) { + if (len == 9) { hex[0] = msyystring_buffer[7]; hex[1] = msyystring_buffer[8]; color->alpha = msHexToInt(hex); } } else { /* TODO: consider named colors here */ - msSetError(MS_SYMERR, "Invalid hex color (%s):(line %d)", "loadColor()", msyystring_buffer, msyylineno); + msSetError(MS_SYMERR, "Invalid hex color (%s):(line %d)", "loadColor()", + msyystring_buffer, msyylineno); return MS_FAILURE; } } else { assert(binding); + msFree(binding->item); binding->item = msStrdup(msyystring_buffer); binding->index = -1; } @@ -473,18 +499,18 @@ int loadColor(colorObj *color, attributeBindingObj *binding) } #if ALPHACOLOR_ENABLED -int loadColorWithAlpha(colorObj *color) -{ +int loadColorWithAlpha(colorObj *color) { char hex[2]; - /* - ** Note that negative color values can be used to suppress or change behavior. For example, referenceObj uses + ** Note that negative color values can be used to suppress or change behavior. + *For example, referenceObj uses ** a negative color component to suppress rectangle fills. */ - if(getInteger(&(color->red), MS_NUM_CHECK_RANGE, -255, 255) == -1) { - if(msyystring_buffer[0] == '#' && strlen(msyystring_buffer) == 7) { /* got a hex color */ + if (getInteger(&(color->red), MS_NUM_CHECK_RANGE, -255, 255) == -1) { + if (msyystring_buffer[0] == '#' && + strlen(msyystring_buffer) == 7) { /* got a hex color */ hex[0] = msyystring_buffer[1]; hex[1] = msyystring_buffer[2]; color->red = msHexToInt(hex); @@ -496,8 +522,10 @@ int loadColorWithAlpha(colorObj *color) color->blue = msHexToInt(hex); color->alpha = 0; - return(MS_SUCCESS); - } else if(msyystring_buffer[0] == '#' && strlen(msyystring_buffer) == 9) { /* got a hex color with alpha */ + return (MS_SUCCESS); + } else if (msyystring_buffer[0] == '#' && + strlen(msyystring_buffer) == + 9) { /* got a hex color with alpha */ hex[0] = msyystring_buffer[1]; hex[1] = msyystring_buffer[2]; color->red = msHexToInt(hex); @@ -510,56 +538,55 @@ int loadColorWithAlpha(colorObj *color) hex[0] = msyystring_buffer[7]; hex[1] = msyystring_buffer[8]; color->alpha = msHexToInt(hex); - return(MS_SUCCESS); + return (MS_SUCCESS); } - return(MS_FAILURE); + return (MS_FAILURE); } - if(getInteger(&(color->green), MS_NUM_CHECK_RANGE, -255, 255) == -1) return(MS_FAILURE); - if(getInteger(&(color->blue), MS_NUM_CHECK_RANGE, -255, 255) == -1) return(MS_FAILURE); - if(getInteger(&(color->alpha), MS_NUM_CHECK_RANGE, 0, 255) == -1) return(MS_FAILURE); + if (getInteger(&(color->green), MS_NUM_CHECK_RANGE, -255, 255) == -1) + return (MS_FAILURE); + if (getInteger(&(color->blue), MS_NUM_CHECK_RANGE, -255, 255) == -1) + return (MS_FAILURE); + if (getInteger(&(color->alpha), MS_NUM_CHECK_RANGE, 0, 255) == -1) + return (MS_FAILURE); - return(MS_SUCCESS); + return (MS_SUCCESS); } #endif /* ** Helper functions for writing mapfiles. */ -static void writeLineFeed(FILE *stream) -{ - msIO_fprintf(stream, "\n"); -} +static void writeLineFeed(FILE *stream) { msIO_fprintf(stream, "\n"); } -static void writeIndent(FILE *stream, int indent) -{ - const char *str=" "; /* change this string to define the indent */ +static void writeIndent(FILE *stream, int indent) { + const char *str = " "; /* change this string to define the indent */ int i; - for(i=0; iitem) return; +static void writeAttributeBinding(FILE *stream, int indent, const char *name, + attributeBindingObj *binding) { + if (!binding || !binding->item) + return; writeIndent(stream, ++indent); msIO_fprintf(stream, "%s [%s]\n", name, binding->item); } -static void writeColor(FILE *stream, int indent, const char *name, colorObj *defaultColor, colorObj *color) -{ - if (!defaultColor && !MS_VALID_COLOR(*color)) return; - else if(defaultColor && MS_COMPARE_COLOR(*defaultColor, *color)) return; /* if defaultColor has the same value than the color, return.*/ +static void writeColor(FILE *stream, int indent, const char *name, + colorObj *defaultColor, colorObj *color) { + if (!defaultColor && !MS_VALID_COLOR(*color)) + return; + else if (defaultColor && MS_COMPARE_COLOR(*defaultColor, *color)) + return; /* if defaultColor has the same value than the color, return.*/ writeIndent(stream, ++indent); #if ALPHACOLOR_ENABLED - msIO_fprintf(stream, "%s %d %d %d\n", name, color->red, color->green, color->blue, color->alpha); + msIO_fprintf(stream, "%s %d %d %d\n", name, color->red, color->green, + color->blue, color->alpha); #else - if(color->alpha != 255) { + if (color->alpha != 255) { char buffer[9]; sprintf(buffer, "%02x", color->red); - sprintf(buffer+2, "%02x", color->green); - sprintf(buffer+4, "%02x", color->blue); - sprintf(buffer+6, "%02x", color->alpha); - *(buffer+8) = 0; + sprintf(buffer + 2, "%02x", color->green); + sprintf(buffer + 4, "%02x", color->blue); + sprintf(buffer + 6, "%02x", color->alpha); + *(buffer + 8) = 0; msIO_fprintf(stream, "%s \"#%s\"\n", name, buffer); } else { - msIO_fprintf(stream, "%s %d %d %d\n", name, color->red, color->green, color->blue); + msIO_fprintf(stream, "%s %d %d %d\n", name, color->red, color->green, + color->blue); } #endif } /* todo: deal with alpha's... */ -static void writeColorRange(FILE *stream, int indent, const char *name, colorObj *mincolor, colorObj *maxcolor) -{ - if(!MS_VALID_COLOR(*mincolor) || !MS_VALID_COLOR(*maxcolor)) return; +static void writeColorRange(FILE *stream, int indent, const char *name, + colorObj *mincolor, colorObj *maxcolor) { + if (!MS_VALID_COLOR(*mincolor) || !MS_VALID_COLOR(*maxcolor)) + return; writeIndent(stream, ++indent); - msIO_fprintf(stream, "%s %d %d %d %d %d %d\n", name, mincolor->red, mincolor->green, mincolor->blue, maxcolor->red, maxcolor->green, maxcolor->blue); + msIO_fprintf(stream, "%s %d %d %d %d %d %d\n", name, mincolor->red, + mincolor->green, mincolor->blue, maxcolor->red, maxcolor->green, + maxcolor->blue); } /* ** Initialize, load and free a single join */ -void initJoin(joinObj *join) -{ +void initJoin(joinObj *join) { join->numitems = 0; join->name = NULL; /* unique join name, used for variable substitution */ - join->items = NULL; /* array to hold item names for the joined table */ + join->items = NULL; /* array to hold item names for the joined table */ join->values = NULL; /* arrays of strings to holds one record worth of data */ join->table = NULL; @@ -749,8 +801,7 @@ void initJoin(joinObj *join) join->connectiontype = MS_DB_XBASE; } -void freeJoin(joinObj *join) -{ +void freeJoin(joinObj *join) { msFree(join->name); msFree(join->table); msFree(join->from); @@ -760,7 +811,8 @@ void freeJoin(joinObj *join) msFree(join->template); msFree(join->footer); - msFreeCharArray(join->items, join->numitems); /* these may have been free'd elsewhere */ + msFreeCharArray(join->items, + join->numitems); /* these may have been free'd elsewhere */ msFreeCharArray(join->values, join->numitems); join->numitems = 0; @@ -768,63 +820,80 @@ void freeJoin(joinObj *join) msFree(join->connection); } -int loadJoin(joinObj *join) -{ +int loadJoin(joinObj *join) { int nTmp; initJoin(join); - for(;;) { - switch(msyylex()) { - case(CONNECTION): - if(getString(&join->connection) == MS_FAILURE) return(-1); - break; - case(CONNECTIONTYPE): - if((nTmp = getSymbol(5, MS_DB_XBASE, MS_DB_MYSQL, MS_DB_ORACLE, MS_DB_POSTGRES, MS_DB_CSV)) == -1) return(-1); - join->connectiontype = nTmp; - break; - case(EOF): - msSetError(MS_EOFERR, NULL, "loadJoin()"); - return(-1); - case(END): - if((join->from == NULL) || (join->to == NULL) || (join->table == NULL)) { - msSetError(MS_EOFERR, "Join must define table, name, from and to properties.", "loadJoin()"); - return(-1); - } - if((join->type == MS_MULTIPLE) && ((join->template == NULL) || (join->name == NULL))) { - msSetError(MS_EOFERR, "One-to-many joins must define template and name properties.", "loadJoin()"); - return(-1); - } - return(0); - case(FOOTER): - if(getString(&join->footer) == MS_FAILURE) return(-1); - break; - case(FROM): - if(getString(&join->from) == MS_FAILURE) return(-1); - break; - case(HEADER): - if(getString(&join->header) == MS_FAILURE) return(-1); - break; - case(JOIN): - break; /* for string loads */ - case(NAME): - if(getString(&join->name) == MS_FAILURE) return(-1); - break; - case(TABLE): - if(getString(&join->table) == MS_FAILURE) return(-1); - break; - case(TEMPLATE): - if(getString(&join->template) == MS_FAILURE) return(-1); - break; - case(TO): - if(getString(&join->to) == MS_FAILURE) return(-1); - break; - case(TYPE): - if((nTmp = getSymbol(2, MS_JOIN_ONE_TO_ONE, MS_JOIN_ONE_TO_MANY)) == -1) return(-1); - join->type = nTmp; - break; - default: - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadJoin()", msyystring_buffer, msyylineno); - return(-1); + for (;;) { + switch (msyylex()) { + case (CONNECTION): + if (getString(&join->connection) == MS_FAILURE) + return (-1); + break; + case (CONNECTIONTYPE): + if ((nTmp = getSymbol(5, MS_DB_XBASE, MS_DB_MYSQL, MS_DB_ORACLE, + MS_DB_POSTGRES, MS_DB_CSV)) == -1) + return (-1); + join->connectiontype = nTmp; + break; + case (EOF): + msSetError(MS_EOFERR, NULL, "loadJoin()"); + return (-1); + case (END): + if ((join->from == NULL) || (join->to == NULL) || (join->table == NULL)) { + msSetError(MS_EOFERR, + "Join must define table, name, from and to properties.", + "loadJoin()"); + return (-1); + } + if ((join->type == MS_MULTIPLE) && + ((join->template == NULL) || (join->name == NULL))) { + msSetError( + MS_EOFERR, + "One-to-many joins must define template and name properties.", + "loadJoin()"); + return (-1); + } + return (0); + case (FOOTER): + if (getString(&join->footer) == MS_FAILURE) + return (-1); + break; + case (FROM): + if (getString(&join->from) == MS_FAILURE) + return (-1); + break; + case (HEADER): + if (getString(&join->header) == MS_FAILURE) + return (-1); + break; + case (JOIN): + break; /* for string loads */ + case (NAME): + if (getString(&join->name) == MS_FAILURE) + return (-1); + break; + case (TABLE): + if (getString(&join->table) == MS_FAILURE) + return (-1); + break; + case (TEMPLATE): + if (getString(&join->template) == MS_FAILURE) + return (-1); + break; + case (TO): + if (getString(&join->to) == MS_FAILURE) + return (-1); + break; + case (TYPE): + if ((nTmp = getSymbol(2, MS_JOIN_ONE_TO_ONE, MS_JOIN_ONE_TO_MANY)) == -1) + return (-1); + join->type = nTmp; + break; + default: + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadJoin()", + msyystring_buffer, msyylineno); + return (-1); } } /* next token */ } @@ -832,22 +901,21 @@ int loadJoin(joinObj *join) static void writeScaleToken(FILE *stream, int indent, scaleTokenObj *token) { int i; indent++; - writeBlockBegin(stream,indent,"SCALETOKEN"); + writeBlockBegin(stream, indent, "SCALETOKEN"); writeString(stream, indent, "NAME", NULL, token->name); indent++; - writeBlockBegin(stream,indent,"VALUES"); - for(i=0;in_entries;i++) { + writeBlockBegin(stream, indent, "VALUES"); + for (i = 0; i < token->n_entries; i++) { char minscale[32]; - sprintf(minscale,"%g",token->tokens[i].minscale); + sprintf(minscale, "%g", token->tokens[i].minscale); writeNameValuePair(stream, indent, minscale, token->tokens[i].value); } - writeBlockEnd(stream,indent,"VALUES"); + writeBlockEnd(stream, indent, "VALUES"); indent--; - writeBlockEnd(stream,indent,"SCALETOKEN"); + writeBlockEnd(stream, indent, "SCALETOKEN"); } -static void writeJoin(FILE *stream, int indent, joinObj *join) -{ +static void writeJoin(FILE *stream, int indent, joinObj *join) { indent++; writeBlockBegin(stream, indent, "JOIN"); writeString(stream, indent, "FOOTER", NULL, join->footer); @@ -857,36 +925,44 @@ static void writeJoin(FILE *stream, int indent, joinObj *join) writeString(stream, indent, "TABLE", NULL, join->table); writeString(stream, indent, "TEMPLATE", NULL, join->template); writeString(stream, indent, "TO", NULL, join->to); - writeKeyword(stream, indent, "CONNECTIONTYPE", join->connectiontype, 3, MS_DB_CSV, "CSV", MS_DB_POSTGRES, "POSTGRESQL", MS_DB_MYSQL, "MYSQL"); - writeKeyword(stream, indent, "TYPE", join->type, 1, MS_JOIN_ONE_TO_MANY, "ONE-TO-MANY"); + writeKeyword(stream, indent, "CONNECTIONTYPE", join->connectiontype, 3, + MS_DB_CSV, "CSV", MS_DB_POSTGRES, "POSTGRESQL", MS_DB_MYSQL, + "MYSQL"); + writeKeyword(stream, indent, "TYPE", join->type, 1, MS_JOIN_ONE_TO_MANY, + "ONE-TO-MANY"); writeBlockEnd(stream, indent, "JOIN"); } /* inserts a feature at the end of the list, can create a new list */ -featureListNodeObjPtr insertFeatureList(featureListNodeObjPtr *list, shapeObj *shape) -{ +featureListNodeObjPtr insertFeatureList(featureListNodeObjPtr *list, + shapeObj *shape) { featureListNodeObjPtr node; - node = (featureListNodeObjPtr) msSmallMalloc(sizeof(featureListNodeObj)); + node = (featureListNodeObjPtr)msSmallMalloc(sizeof(featureListNodeObj)); msInitShape(&(node->shape)); - if(msCopyShape(shape, &(node->shape)) == -1) { + if (msCopyShape(shape, &(node->shape)) == -1) { msFree(node); - return(NULL); + return (NULL); } - /* AJS - alans@wunderground.com O(n^2) -> O(n) conversion, keep a pointer to the end */ + /* AJS - alans@wunderground.com O(n^2) -> O(n) conversion, keep a pointer to + * the end */ - /* set the tailifhead to NULL, since it is only set for the head of the list */ + /* set the tailifhead to NULL, since it is only set for the head of the list + */ node->tailifhead = NULL; node->next = NULL; - /* if we are at the head of the list, we need to set the list to node, before pointing tailifhead somewhere */ - if(*list == NULL) { - *list=node; + /* if we are at the head of the list, we need to set the list to node, before + * pointing tailifhead somewhere */ + if (*list == NULL) { + *list = node; } else { - if((*list)->tailifhead!=NULL) /* this should never be NULL, but just in case */ - (*list)->tailifhead->next=node; /* put the node at the end of the list */ + if ((*list)->tailifhead != + NULL) /* this should never be NULL, but just in case */ + (*list)->tailifhead->next = + node; /* put the node at the end of the list */ } /* repoint the head of the list to the end - our new element @@ -894,13 +970,12 @@ featureListNodeObjPtr insertFeatureList(featureListNodeObjPtr *list, shapeObj *s walk in a loop */ (*list)->tailifhead = node; - return(node); /* a pointer to last object in the list */ + return (node); /* a pointer to last object in the list */ } -void freeFeatureList(featureListNodeObjPtr list) -{ +void freeFeatureList(featureListNodeObjPtr list) { featureListNodeObjPtr listNext = NULL; - while (list!=NULL) { + while (list != NULL) { listNext = list->next; msFreeShape(&(list->shape)); msFree(list); @@ -909,156 +984,184 @@ void freeFeatureList(featureListNodeObjPtr list) } /* lineObj = multipointObj */ -static int loadFeaturePoints(lineObj *points) -{ - int buffer_size=0; +static int loadFeaturePoints(lineObj *points) { + int ret = -1; + int buffer_size = 0; - points->point = (pointObj *)malloc(sizeof(pointObj)*MS_FEATUREINITSIZE); - MS_CHECK_ALLOC(points->point, sizeof(pointObj)*MS_FEATUREINITSIZE, MS_FAILURE); + points->point = (pointObj *)malloc(sizeof(pointObj) * MS_FEATUREINITSIZE); + MS_CHECK_ALLOC(points->point, sizeof(pointObj) * MS_FEATUREINITSIZE, + MS_FAILURE); points->numpoints = 0; buffer_size = MS_FEATUREINITSIZE; - for(;;) { - switch(msyylex()) { - case(EOF): - msSetError(MS_EOFERR, NULL, "loadFeaturePoints()"); - return(MS_FAILURE); - case(END): - return(MS_SUCCESS); - case(MS_NUMBER): - if(points->numpoints == buffer_size) { /* just add it to the end */ - points->point = (pointObj *) realloc(points->point, sizeof(pointObj)*(buffer_size+MS_FEATUREINCREMENT)); - MS_CHECK_ALLOC(points->point, sizeof(pointObj)*(buffer_size+MS_FEATUREINCREMENT), MS_FAILURE); - buffer_size+=MS_FEATUREINCREMENT; + while (ret < 0) { + switch (msyylex()) { + case (EOF): + msSetError(MS_EOFERR, NULL, "loadFeaturePoints()"); + ret = MS_FAILURE; + break; + case (END): + ret = MS_SUCCESS; + break; + case (MS_NUMBER): + if (points->numpoints == buffer_size) { /* just add it to the end */ + pointObj *newPoints = (pointObj *)realloc( + points->point, + sizeof(pointObj) * (buffer_size + MS_FEATUREINCREMENT)); + if (newPoints == NULL) { + msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", + __FUNCTION__, __FILE__, __LINE__, + (unsigned int)(sizeof(pointObj) * + (buffer_size + MS_FEATUREINCREMENT))); + ret = MS_FAILURE; + break; } + points->point = newPoints; + buffer_size += MS_FEATUREINCREMENT; + } - points->point[points->numpoints].x = atof(msyystring_buffer); - if(getDouble(&(points->point[points->numpoints].y), MS_NUM_CHECK_NONE, -1, -1) == -1) return(MS_FAILURE); - - points->numpoints++; + points->point[points->numpoints].x = atof(msyystring_buffer); + if (getDouble(&(points->point[points->numpoints].y), MS_NUM_CHECK_NONE, + -1, -1) == -1) { + ret = MS_FAILURE; break; - default: - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadFeaturePoints()", msyystring_buffer, msyylineno ); - return(MS_FAILURE); + } + points->numpoints++; + break; + default: + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadFeaturePoints()", msyystring_buffer, msyylineno); + ret = MS_FAILURE; + break; } } + + if (ret == MS_FAILURE) { + msFree(points->point); /* clean up */ + points->point = NULL; + points->numpoints = 0; + } + return ret; } -static int loadFeature(layerObj *player, int type) -{ - int status=MS_SUCCESS; +static int loadFeature(layerObj *player, int type) { + int status = MS_SUCCESS; featureListNodeObjPtr *list = &(player->features); - multipointObj points= {0,NULL}; - shapeObj *shape=NULL; + multipointObj points = {0, NULL}; + shapeObj *shape = NULL; - shape = (shapeObj *) malloc(sizeof(shapeObj)); + shape = (shapeObj *)malloc(sizeof(shapeObj)); MS_CHECK_ALLOC(shape, sizeof(shapeObj), MS_FAILURE); msInitShape(shape); shape->type = type; - for(;;) { - switch(msyylex()) { - case(EOF): - msSetError(MS_EOFERR, NULL, "loadFeature()"); + for (;;) { + switch (msyylex()) { + case (EOF): + msSetError(MS_EOFERR, NULL, "loadFeature()"); + msFreeShape(shape); /* clean up */ + msFree(shape); + return (MS_FAILURE); + case (END): + if (player->features != NULL && player->features->tailifhead != NULL) + shape->index = player->features->tailifhead->shape.index + 1; + else + shape->index = 0; + if (insertFeatureList(list, shape) == NULL) + status = MS_FAILURE; + + msFreeShape(shape); /* clean up */ + msFree(shape); + + return (status); + case (FEATURE): + break; /* for string loads */ + case (POINTS): + if (loadFeaturePoints(&points) == MS_FAILURE) { msFreeShape(shape); /* clean up */ msFree(shape); - return(MS_FAILURE); - case(END): - if(player->features != NULL && player->features->tailifhead != NULL) - shape->index = player->features->tailifhead->shape.index + 1; - else - shape->index = 0; - if(insertFeatureList(list, shape) == NULL) - status = MS_FAILURE; + return (MS_FAILURE); + } + status = msAddLine(shape, &points); + msFree(points.point); /* clean up */ + points.numpoints = 0; + + if (status == MS_FAILURE) { msFreeShape(shape); /* clean up */ msFree(shape); - - return(status); - case(FEATURE): - break; /* for string loads */ - case(POINTS): - if(loadFeaturePoints(&points) == MS_FAILURE) { - msFreeShape(shape); /* clean up */ - msFree(shape); - return(MS_FAILURE); - } - status = msAddLine(shape, &points); - - msFree(points.point); /* clean up */ - points.numpoints = 0; - - if(status == MS_FAILURE) { - msFreeShape(shape); /* clean up */ - msFree(shape); - return(MS_FAILURE); - } - break; - case(ITEMS): { - char *string=NULL; - if(getString(&string) == MS_FAILURE) { - msFreeShape(shape); /* clean up */ - msFree(shape); - return(MS_FAILURE); - } - if (string) { - if(shape->values) msFreeCharArray(shape->values, shape->numvalues); - shape->values = msStringSplitComplex(string, ";", &shape->numvalues,MS_ALLOWEMPTYTOKENS); - msFree(string); /* clean up */ - } - break; + return (MS_FAILURE); } - case(TEXT): - if(getString(&shape->text) == MS_FAILURE) { - msFreeShape(shape); /* clean up */ - msFree(shape); - return(MS_FAILURE); - } - break; - case(WKT): { - char *string=NULL; + break; + case (ITEMS): { + char *string = NULL; + if (getString(&string) == MS_FAILURE) { + msFreeShape(shape); /* clean up */ + msFree(shape); + return (MS_FAILURE); + } + if (string) { + if (shape->values) + msFreeCharArray(shape->values, shape->numvalues); + shape->values = msStringSplitComplex(string, ";", &shape->numvalues, + MS_ALLOWEMPTYTOKENS); + msFree(string); /* clean up */ + } + break; + } + case (TEXT): + if (getString(&shape->text) == MS_FAILURE) { + msFreeShape(shape); /* clean up */ + msFree(shape); + return (MS_FAILURE); + } + break; + case (WKT): { + char *string = NULL; - /* todo, what do we do with multiple WKT property occurances? */ + /* todo, what do we do with multiple WKT property occurances? */ - msFreeShape(shape); - msFree(shape); - if(getString(&string) == MS_FAILURE) return(MS_FAILURE); + msFreeShape(shape); + msFree(shape); + if (getString(&string) == MS_FAILURE) + return (MS_FAILURE); - if((shape = msShapeFromWKT(string)) == NULL) - status = MS_FAILURE; + if ((shape = msShapeFromWKT(string)) == NULL) + status = MS_FAILURE; - msFree(string); /* clean up */ + msFree(string); /* clean up */ - if(status == MS_FAILURE) { - msFreeShape(shape); /* clean up */ - msFree(shape); - return(MS_FAILURE); - } - break; - } - default: - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadfeature()", msyystring_buffer, msyylineno); + if (status == MS_FAILURE) { msFreeShape(shape); /* clean up */ msFree(shape); - return(MS_FAILURE); + return (MS_FAILURE); + } + break; + } + default: + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadfeature()", msyystring_buffer, msyylineno); + msFreeShape(shape); /* clean up */ + msFree(shape); + return (MS_FAILURE); } } /* next token */ } -static void writeFeature(FILE *stream, int indent, shapeObj *feature) -{ - int i,j; +static void writeFeature(FILE *stream, int indent, shapeObj *feature) { + int i, j; indent++; writeBlockBegin(stream, indent, "FEATURE"); indent++; - for(i=0; inumlines; i++) { + for (i = 0; i < feature->numlines; i++) { writeBlockBegin(stream, indent, "POINTS"); - for(j=0; jline[i].numpoints; j++) { + for (j = 0; j < feature->line[i].numpoints; j++) { writeIndent(stream, indent); - msIO_fprintf(stream, "%.15g %.15g\n", feature->line[i].point[j].x, feature->line[i].point[j].y); + msIO_fprintf(stream, "%.15g %.15g\n", feature->line[i].point[j].x, + feature->line[i].point[j].y); } writeBlockEnd(stream, indent, "POINTS"); } @@ -1067,7 +1170,7 @@ static void writeFeature(FILE *stream, int indent, shapeObj *feature) if (feature->numvalues) { writeIndent(stream, indent); msIO_fprintf(stream, "ITEMS \""); - for (i=0; inumvalues; i++) { + for (i = 0; i < feature->numvalues; i++) { if (i == 0) msIO_fprintf(stream, "%s", feature->values[i]); else @@ -1080,71 +1183,77 @@ static void writeFeature(FILE *stream, int indent, shapeObj *feature) writeBlockEnd(stream, indent, "FEATURE"); } -void initGrid( graticuleObj *pGraticule ) -{ - memset( pGraticule, 0, sizeof( graticuleObj ) ); +void initGrid(graticuleObj *pGraticule) { + memset(pGraticule, 0, sizeof(graticuleObj)); } -void freeGrid( graticuleObj *pGraticule ) -{ +void freeGrid(graticuleObj *pGraticule) { msFree(pGraticule->labelformat); msFree(pGraticule->pboundingpoints); msFree(pGraticule->pboundinglines); } -static int loadGrid( layerObj *pLayer ) -{ - for(;;) { - switch(msyylex()) { - case(EOF): - msSetError(MS_EOFERR, NULL, "loadGrid()"); - return(-1); - case(END): - return(0); - case(GRID): - break; /* for string loads */ - case( LABELFORMAT ): - if(getString(&(pLayer->grid->labelformat)) == MS_FAILURE) { - if(strcasecmp(msyystring_buffer, "DD") == 0) /* DD triggers a symbol to be returned instead of a string so check for this special case */ - pLayer->grid->labelformat = msStrdup("DD"); - else - return(-1); - } - break; - case( MINARCS ): - if(getDouble(&(pLayer->grid->minarcs), MS_NUM_CHECK_GT, 0, -1) == -1) - return(-1); - break; - case( MAXARCS ): - if(getDouble(&(pLayer->grid->maxarcs), MS_NUM_CHECK_GT, 0, -1) == -1) - return(-1); - break; - case( MININTERVAL ): - if(getDouble(&(pLayer->grid->minincrement), MS_NUM_CHECK_GT, 0, -1) == -1) - return(-1); - break; - case( MAXINTERVAL ): - if(getDouble(&(pLayer->grid->maxincrement), MS_NUM_CHECK_GT, 0, -1) == -1) - return(-1); - break; - case( MINSUBDIVIDE ): - if(getDouble(&(pLayer->grid->minsubdivides), MS_NUM_CHECK_GT, 0, -1) == -1) - return(-1); - break; - case( MAXSUBDIVIDE ): - if(getDouble(&(pLayer->grid->maxsubdivides), MS_NUM_CHECK_GT, 0, -1) == -1) - return(-1); - break; - default: - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadGrid()", msyystring_buffer, msyylineno); - return(-1); +static int loadGrid(layerObj *pLayer) { + for (;;) { + switch (msyylex()) { + case (EOF): + msSetError(MS_EOFERR, NULL, "loadGrid()"); + return (-1); + case (END): + return (0); + case (GRID): + break; /* for string loads */ + case (LABELFORMAT): + if (getString(&(pLayer->grid->labelformat)) == MS_FAILURE) { + if (strcasecmp(msyystring_buffer, "DD") == + 0) /* DD triggers a symbol to be returned instead of a string so + check for this special case */ + { + msFree(pLayer->grid->labelformat); + pLayer->grid->labelformat = msStrdup("DD"); + } else + return (-1); + } + break; + case (MINARCS): + if (getDouble(&(pLayer->grid->minarcs), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (MAXARCS): + if (getDouble(&(pLayer->grid->maxarcs), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (MININTERVAL): + if (getDouble(&(pLayer->grid->minincrement), MS_NUM_CHECK_GT, 0, -1) == + -1) + return (-1); + break; + case (MAXINTERVAL): + if (getDouble(&(pLayer->grid->maxincrement), MS_NUM_CHECK_GT, 0, -1) == + -1) + return (-1); + break; + case (MINSUBDIVIDE): + if (getDouble(&(pLayer->grid->minsubdivides), MS_NUM_CHECK_GT, 0, -1) == + -1) + return (-1); + break; + case (MAXSUBDIVIDE): + if (getDouble(&(pLayer->grid->maxsubdivides), MS_NUM_CHECK_GT, 0, -1) == + -1) + return (-1); + break; + default: + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadGrid()", + msyystring_buffer, msyylineno); + return (-1); } } } -static void writeGrid(FILE *stream, int indent, graticuleObj *pGraticule) -{ - if(!pGraticule) return; +static void writeGrid(FILE *stream, int indent, graticuleObj *pGraticule) { + if (!pGraticule) + return; indent++; writeBlockBegin(stream, indent, "GRID"); @@ -1158,94 +1267,98 @@ static void writeGrid(FILE *stream, int indent, graticuleObj *pGraticule) writeBlockEnd(stream, indent, "GRID"); } -static int loadProjection(projectionObj *p) -{ - int i=0; - +static int loadProjection(projectionObj *p) { p->gt.need_geotransform = MS_FALSE; - if ( p->proj != NULL ) { - msSetError(MS_MISCERR, "Projection is already initialized. Multiple projection definitions are not allowed in this object. (line %d)", + if (p->proj != NULL || p->numargs != 0) { + msSetError(MS_MISCERR, + "Projection is already initialized. Multiple projection " + "definitions are not allowed in this object. (line %d)", "loadProjection()", msyylineno); - return(-1); - } - - for(;;) { - switch(msyylex()) { - case(EOF): - msSetError(MS_EOFERR, NULL, "loadProjection()"); - return(-1); - case(END): - if( i == 1 && strstr(p->args[0],"+") != NULL ) { - char *one_line_def = p->args[0]; - int result; - - p->args[0] = NULL; - result = msLoadProjectionString( p, one_line_def ); - free( one_line_def ); - return result; - } else { - p->numargs = i; - if(p->numargs != 0) - return msProcessProjection(p); - else - return 0; - } - break; - case(MS_STRING): - case(MS_AUTO): - p->args[i] = msStrdup(msyystring_buffer); - p->automatic = MS_TRUE; - i++; - break; - default: - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadProjection()", - msyystring_buffer, msyylineno); - return(-1); + return (-1); + } + + for (;;) { + switch (msyylex()) { + case (EOF): + msSetError(MS_EOFERR, NULL, "loadProjection()"); + return (-1); + case (END): + if (p->numargs == 1 && strstr(p->args[0], "+") != NULL) { + char *one_line_def = p->args[0]; + int result; + + p->args[0] = NULL; + p->numargs = 0; + result = msLoadProjectionString(p, one_line_def); + free(one_line_def); + return result; + } else { + if (p->numargs != 0) + return msProcessProjection(p); + else + return 0; + } + break; + case (MS_STRING): + case (MS_AUTO): + if (p->numargs == MS_MAXPROJARGS) { + msSetError(MS_MISCERR, + "Parsing error near (%s):(line %d): Too many arguments in " + "projection string", + "loadProjection()", msyystring_buffer, msyylineno); + return -1; + } + p->args[p->numargs] = msStrdup(msyystring_buffer); + p->automatic = MS_TRUE; + p->numargs++; + break; + default: + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadProjection()", msyystring_buffer, msyylineno); + return (-1); } } /* next token */ } - /************************************************************************/ /* msLoadProjectionStringEPSGLike */ /************************************************************************/ static int msLoadProjectionStringEPSGLike(projectionObj *p, const char *value, - const char* pszPrefix, - int bFollowEPSGAxisOrder) -{ - size_t buffer_size = 0; - char *init_string = NULL; - const char *code; - const char *next_sep; - size_t prefix_len; - - prefix_len = strlen(pszPrefix); - if( strncasecmp(value, pszPrefix, prefix_len) != 0 ) - return -1; + const char *pszPrefix, + int bFollowEPSGAxisOrder) { + size_t buffer_size = 0; + char *init_string = NULL; + const char *code; + const char *next_sep; + size_t prefix_len; - code = value + prefix_len; - next_sep = strchr(code, pszPrefix[prefix_len-1]); - if( next_sep != NULL ) - code = next_sep + 1; + prefix_len = strlen(pszPrefix); + if (strncasecmp(value, pszPrefix, prefix_len) != 0) + return -1; - buffer_size = 10 + strlen(code) + 1; - init_string = (char*)msSmallMalloc(buffer_size); + code = value + prefix_len; + next_sep = strchr(code, pszPrefix[prefix_len - 1]); + if (next_sep != NULL) + code = next_sep + 1; - /* translate into PROJ.4 format. */ - snprintf( init_string, buffer_size, "init=epsg:%s", code ); + buffer_size = 10 + strlen(code) + 1; + init_string = (char *)msSmallMalloc(buffer_size); - p->args = (char**)msSmallMalloc(sizeof(char*) * 2); - p->args[0] = init_string; - p->numargs = 1; + /* translate into PROJ.4 format. */ + snprintf(init_string, buffer_size, "init=epsg:%s", code); - if( bFollowEPSGAxisOrder && msIsAxisInverted(atoi(code))) { - p->args[1] = msStrdup("+epsgaxis=ne"); - p->numargs = 2; - } + p->args = (char **)msSmallMalloc(sizeof(char *) * 2); + p->args[0] = init_string; + p->numargs = 1; - return 0; + if (bFollowEPSGAxisOrder && msIsAxisInverted(atoi(code))) { + p->args[1] = msStrdup("+epsgaxis=ne"); + p->numargs = 2; + } + + return 0; } /************************************************************************/ @@ -1253,43 +1366,40 @@ static int msLoadProjectionStringEPSGLike(projectionObj *p, const char *value, /************************************************************************/ static int msLoadProjectionStringCRSLike(projectionObj *p, const char *value, - const char* pszPrefix) -{ - char init_string[100]; - const char *id; - const char *next_sep; - size_t prefix_len; - - prefix_len = strlen(pszPrefix); - if( strncasecmp(value, pszPrefix, prefix_len) != 0 ) - return -1; - - id = value + prefix_len; - next_sep = strchr(id, pszPrefix[prefix_len-1]); - if( next_sep != NULL ) - id = next_sep + 1; - - init_string[0] = '\0'; - - if( strcasecmp(id,"84") == 0 || strcasecmp(id,"CRS84") == 0 ) - strncpy( init_string, "init=epsg:4326", sizeof(init_string) ); - else if( strcasecmp(id,"83") == 0 || strcasecmp(id,"CRS83") == 0 ) - strncpy( init_string, "init=epsg:4269", sizeof(init_string) ); - else if( strcasecmp(id,"27") == 0 || strcasecmp(id,"CRS27") == 0 ) - strncpy( init_string, "init=epsg:4267", sizeof(init_string) ); - else { - msSetError( MS_PROJERR, - "Unrecognised OGC CRS def '%s'.", - "msLoadProjectionString()", - value ); - return -1; - } + const char *pszPrefix) { + char init_string[100]; + const char *id; + const char *next_sep; + size_t prefix_len; + + prefix_len = strlen(pszPrefix); + if (strncasecmp(value, pszPrefix, prefix_len) != 0) + return -1; + + id = value + prefix_len; + next_sep = strchr(id, pszPrefix[prefix_len - 1]); + if (next_sep != NULL) + id = next_sep + 1; + + init_string[0] = '\0'; + + if (strcasecmp(id, "84") == 0 || strcasecmp(id, "CRS84") == 0) + strncpy(init_string, "init=epsg:4326", sizeof(init_string)); + else if (strcasecmp(id, "83") == 0 || strcasecmp(id, "CRS83") == 0) + strncpy(init_string, "init=epsg:4269", sizeof(init_string)); + else if (strcasecmp(id, "27") == 0 || strcasecmp(id, "CRS27") == 0) + strncpy(init_string, "init=epsg:4267", sizeof(init_string)); + else { + msSetError(MS_PROJERR, "Unrecognised OGC CRS def '%s'.", + "msLoadProjectionString()", value); + return -1; + } - p->args = (char**)msSmallMalloc(sizeof(char*) * 2); - p->args[0] = msStrdup(init_string); - p->numargs = 1; + p->args = (char **)msSmallMalloc(sizeof(char *) * 2); + p->args[0] = msStrdup(init_string); + p->numargs = 1; - return 0; + return 0; } /************************************************************************/ @@ -1299,33 +1409,30 @@ static int msLoadProjectionStringCRSLike(projectionObj *p, const char *value, /* certain code ranges. */ /* Use for now in WMS 1.3.0 and WFS >= 1.1.0 */ /************************************************************************/ -int msLoadProjectionStringEPSG(projectionObj *p, const char *value) -{ +int msLoadProjectionStringEPSG(projectionObj *p, const char *value) { assert(p); msFreeProjectionExceptContext(p); p->gt.need_geotransform = MS_FALSE; #ifdef USE_PROJ_FASTPATHS - if(strcasestr(value,"epsg:4326")) { + if (strcasestr(value, "epsg:4326")) { p->wellknownprojection = wkp_lonlat; - } else if(strcasestr(value,"epsg:3857")) { + } else if (strcasestr(value, "epsg:3857")) { p->wellknownprojection = wkp_gmerc; } else { p->wellknownprojection = wkp_none; } #endif - if( msLoadProjectionStringEPSGLike(p, value, "EPSG:", MS_TRUE) == 0 ) - { - return msProcessProjection( p ); + if (msLoadProjectionStringEPSGLike(p, value, "EPSG:", MS_TRUE) == 0) { + return msProcessProjection(p); } return msLoadProjectionString(p, value); } -int msLoadProjectionString(projectionObj *p, const char *value) -{ +int msLoadProjectionString(projectionObj *p, const char *value) { assert(p); p->gt.need_geotransform = MS_FALSE; @@ -1337,70 +1444,80 @@ int msLoadProjectionString(projectionObj *p, const char *value) * eg. * "+proj=utm +zone=11 +ellps=WGS84" */ - if( value[0] == '+' ) { - char *trimmed; - int i, i_out=0; + if (value[0] == '+') { + char *trimmed; + int i, i_out = 0; - trimmed = msStrdup(value+1); - for( i = 1; value[i] != '\0'; i++ ) { - if( !isspace( value[i] ) ) + trimmed = msStrdup(value + 1); + for (i = 1; value[i] != '\0'; i++) { + if (!isspace(value[i])) trimmed[i_out++] = value[i]; } trimmed[i_out] = '\0'; - p->args = msStringSplit(trimmed,'+', &p->numargs); - free( trimmed ); + p->args = msStringSplit(trimmed, '+', &p->numargs); + free(trimmed); } else if (strncasecmp(value, "AUTO:", 5) == 0 || strncasecmp(value, "AUTO2:", 6) == 0) { /* WMS/WFS AUTO projection: "AUTO:proj_id,units_id,lon0,lat0" */ /* WMS 1.3.0 projection: "AUTO2:auto_crs_id,factor,lon0,lat0"*/ /* Keep the projection defn into a single token for writeProjection() */ /* to work fine. */ - p->args = (char**)msSmallMalloc(sizeof(char*)); + p->args = (char **)msSmallMalloc(sizeof(char *)); p->args[0] = msStrdup(value); p->numargs = 1; - } else if (msLoadProjectionStringEPSGLike(p, value, "EPSG:", MS_FALSE) == 0 ) { - /* Assume lon/lat ordering. Use msLoadProjectionStringEPSG() if wanting to follow EPSG axis */ - } else if (msLoadProjectionStringEPSGLike(p, value, "urn:ogc:def:crs:EPSG:", MS_TRUE) == 0 ) { - } else if (msLoadProjectionStringEPSGLike(p, value, "urn:EPSG:geographicCRS:", MS_TRUE) == 0 ) { - } else if (msLoadProjectionStringEPSGLike(p, value, "urn:x-ogc:def:crs:EPSG:", MS_TRUE) == 0 ) { + } else if (msLoadProjectionStringEPSGLike(p, value, "EPSG:", MS_FALSE) == 0) { + /* Assume lon/lat ordering. Use msLoadProjectionStringEPSG() if wanting to + * follow EPSG axis */ + } else if (msLoadProjectionStringEPSGLike( + p, value, "urn:ogc:def:crs:EPSG:", MS_TRUE) == 0) { + } else if (msLoadProjectionStringEPSGLike( + p, value, "urn:EPSG:geographicCRS:", MS_TRUE) == 0) { + } else if (msLoadProjectionStringEPSGLike( + p, value, "urn:x-ogc:def:crs:EPSG:", MS_TRUE) == 0) { /*this case is to account for OGC CITE tests where x-ogc was used before the ogc name became an official NID. Note also we also account - for the fact that a space for the version of the espg is not used with CITE tests. - (Syntax used could be urn:ogc:def:objectType:authority:code)*/ - } else if (msLoadProjectionStringCRSLike(p, value, "urn:ogc:def:crs:OGC:") == 0 ) { - } else if (msLoadProjectionStringEPSGLike(p, value, "http://www.opengis.net/def/crs/EPSG/", MS_TRUE) == 0 ) { + for the fact that a space for the version of the espg is not used with + CITE tests. (Syntax used could be urn:ogc:def:objectType:authority:code)*/ + } else if (msLoadProjectionStringCRSLike(p, value, "urn:ogc:def:crs:OGC:") == + 0) { + } else if (msLoadProjectionStringEPSGLike( + p, value, "http://www.opengis.net/def/crs/EPSG/", MS_TRUE) == + 0) { /* URI projection support */ - } else if (msLoadProjectionStringCRSLike(p, value, "http://www.opengis.net/def/crs/OGC/") == 0 ) { - /* Mandatory support for this URI format specified in WFS1.1 (also in 1.0?) */ - } else if (msLoadProjectionStringEPSGLike(p, value, "http://www.opengis.net/gml/srs/epsg.xml#", MS_FALSE) == 0 ) { + } else if (msLoadProjectionStringCRSLike( + p, value, "http://www.opengis.net/def/crs/OGC/") == 0) { + /* Mandatory support for this URI format specified in WFS1.1 (also in 1.0?) + */ + } else if (msLoadProjectionStringEPSGLike( + p, value, "http://www.opengis.net/gml/srs/epsg.xml#", + MS_FALSE) == 0) { /* We assume always lon/lat ordering, as that is what GeoServer does... */ - } else if (msLoadProjectionStringCRSLike(p, value, "CRS:") == 0 ) { + } else if (msLoadProjectionStringCRSLike(p, value, "CRS:") == 0) { } /* * Handle old style comma delimited. eg. "proj=utm,zone=11,ellps=WGS84". */ else { - p->args = msStringSplit(value,',', &p->numargs); + p->args = msStringSplit(value, ',', &p->numargs); } - return msProcessProjection( p ); + return msProcessProjection(p); } -static void writeProjection(FILE *stream, int indent, projectionObj *p) -{ +static void writeProjection(FILE *stream, int indent, projectionObj *p) { int i; - if(!p || p->numargs <= 0) return; + if (!p || p->numargs <= 0) + return; indent++; writeBlockBegin(stream, indent, "PROJECTION"); - for(i=0; inumargs; i++) + for (i = 0; i < p->numargs; i++) writeString(stream, indent, NULL, NULL, p->args[i]); writeBlockEnd(stream, indent, "PROJECTION"); } -void initLeader(labelLeaderObj *leader) -{ +void initLeader(labelLeaderObj *leader) { leader->gridstep = 5; leader->maxdistance = 0; @@ -1414,18 +1531,17 @@ void initLeader(labelLeaderObj *leader) /* ** Initialize, load and free a labelObj structure */ -void initLabel(labelObj *label) -{ +void initLabel(labelObj *label) { int i; MS_REFCNT_INIT(label); label->align = MS_ALIGN_DEFAULT; - MS_INIT_COLOR(label->color, 0,0,0,255); - MS_INIT_COLOR(label->outlinecolor, -1,-1,-1,255); /* don't use it */ - label->outlinewidth=1; + MS_INIT_COLOR(label->color, 0, 0, 0, 255); + MS_INIT_COLOR(label->outlinecolor, -1, -1, -1, 255); /* don't use it */ + label->outlinewidth = 1; - MS_INIT_COLOR(label->shadowcolor, -1,-1,-1,255); /* don't use it */ + MS_INIT_COLOR(label->shadowcolor, -1, -1, -1, 255); /* don't use it */ label->shadowsizex = label->shadowsizey = 1; label->font = NULL; @@ -1438,17 +1554,17 @@ void initLabel(labelObj *label) label->maxsize = MS_MAXFONTSIZE; label->buffer = 0; label->offsetx = label->offsety = 0; - label->minscaledenom=-1; - label->maxscaledenom=-1; + label->minscaledenom = -1; + label->maxscaledenom = -1; label->minfeaturesize = -1; /* no limit */ label->autominfeaturesize = MS_FALSE; - label->mindistance = -1; /* no limit */ - label->repeatdistance = 0; /* no repeat */ + label->mindistance = -1; /* no limit */ + label->repeatdistance = 0; /* no repeat */ label->maxoverlapangle = 22.5; /* default max overlap angle */ label->partials = MS_FALSE; label->wrap = '\0'; label->maxlength = 0; - label->space_size_10=0.0; + label->space_size_10 = 0.0; label->encoding = NULL; @@ -1463,7 +1579,7 @@ void initLabel(labelObj *label) label->numbindings = 0; label->nexprbindings = 0; - for(i=0; ibindings[i].item = NULL; label->bindings[i].index = -1; msInitExpression(&(label->exprBindings[i])); @@ -1480,37 +1596,37 @@ void initLabel(labelObj *label) return; } -int freeLabelLeader(labelLeaderObj *leader) -{ +int freeLabelLeader(labelLeaderObj *leader) { int i; - for(i=0; inumstyles; i++) { - msFree(leader->styles[i]); + for (i = 0; i < leader->numstyles; i++) { + if (freeStyle(leader->styles[i]) == MS_SUCCESS) { + msFree(leader->styles[i]); + } } msFree(leader->styles); return MS_SUCCESS; } -int freeLabel(labelObj *label) -{ +int freeLabel(labelObj *label) { int i; - if( MS_REFCNT_DECR_IS_NOT_ZERO(label) ) { + if (MS_REFCNT_DECR_IS_NOT_ZERO(label)) { return MS_FAILURE; } msFree(label->font); msFree(label->encoding); - for(i=0; inumstyles; i++) { /* each style */ - if(label->styles[i]!=NULL) { - if(freeStyle(label->styles[i]) == MS_SUCCESS) { + for (i = 0; i < label->numstyles; i++) { /* each style */ + if (label->styles[i] != NULL) { + if (freeStyle(label->styles[i]) == MS_SUCCESS) { msFree(label->styles[i]); } } } msFree(label->styles); - for(i=0; ibindings[i].item); msFreeExpression(&(label->exprBindings[i])); } @@ -1518,7 +1634,7 @@ int freeLabel(labelObj *label) msFreeExpression(&(label->expression)); msFreeExpression(&(label->text)); - if(label->leader) { + if (label->leader) { freeLabelLeader(label->leader); msFree(label->leader); label->leader = NULL; @@ -1527,320 +1643,403 @@ int freeLabel(labelObj *label) return MS_SUCCESS; } -static int loadLeader(labelLeaderObj *leader) -{ - for(;;) { - switch(msyylex()) { - case(END): - return(0); - break; - case(EOF): - msSetError(MS_EOFERR, NULL, "loadLeader()"); - return(-1); - case GRIDSTEP: - if(getInteger(&(leader->gridstep), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case MAXDISTANCE: - if(getInteger(&(leader->maxdistance), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case STYLE: - if(msGrowLeaderStyles(leader) == NULL) - return(-1); - initStyle(leader->styles[leader->numstyles]); - if(loadStyle(leader->styles[leader->numstyles]) != MS_SUCCESS) return(-1); - leader->numstyles++; - break; - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadLeader()", msyystring_buffer, msyylineno); - return(-1); - } else { - return(0); /* end of a string, not an error */ - } +static int loadLeader(labelLeaderObj *leader) { + for (;;) { + switch (msyylex()) { + case (END): + return (0); + break; + case (EOF): + msSetError(MS_EOFERR, NULL, "loadLeader()"); + return (-1); + case GRIDSTEP: + if (getInteger(&(leader->gridstep), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case MAXDISTANCE: + if (getInteger(&(leader->maxdistance), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case STYLE: + if (msGrowLeaderStyles(leader) == NULL) + return (-1); + initStyle(leader->styles[leader->numstyles]); + if (loadStyle(leader->styles[leader->numstyles]) != MS_SUCCESS) { + freeStyle(leader->styles[leader->numstyles]); + free(leader->styles[leader->numstyles]); + leader->styles[leader->numstyles] = NULL; + return -1; + } + leader->numstyles++; + break; + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadLeader()", msyystring_buffer, msyylineno); + return (-1); + } else { + return (0); /* end of a string, not an error */ + } } } } -static int loadLabel(labelObj *label) -{ +static int loadLabel(labelObj *label) { int symbol; - for(;;) { - switch(msyylex()) { - case(ANGLE): - if((symbol = getSymbol(5, MS_NUMBER,MS_AUTO,MS_AUTO2,MS_FOLLOW,MS_BINDING)) == -1) - return(-1); + for (;;) { + switch (msyylex()) { + case (ANGLE): + if ((symbol = getSymbol(5, MS_NUMBER, MS_AUTO, MS_AUTO2, MS_FOLLOW, + MS_BINDING)) == -1) + return (-1); - if(symbol == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, -360.0, 360.0) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid ANGLE, must be between -360 and 360 (line %d)", "loadLabel()", msyylineno); - return(MS_FAILURE); - } - label->angle = (double) msyynumber; - } else if(symbol == MS_BINDING) { - if (label->bindings[MS_LABEL_BINDING_ANGLE].item != NULL) - msFree(label->bindings[MS_LABEL_BINDING_ANGLE].item); - label->bindings[MS_LABEL_BINDING_ANGLE].item = msStrdup(msyystring_buffer); - label->numbindings++; - } else { - label->anglemode = symbol; - } - break; - case(ALIGN): - if((symbol = getSymbol(4, MS_ALIGN_LEFT,MS_ALIGN_CENTER,MS_ALIGN_RIGHT,MS_BINDING)) == -1) - return(-1); - if((symbol == MS_ALIGN_LEFT)||(symbol == MS_ALIGN_CENTER)||(symbol == MS_ALIGN_RIGHT)) { - label->align = symbol; - } else { - if (label->bindings[MS_LABEL_BINDING_ALIGN].item != NULL) - msFree(label->bindings[MS_LABEL_BINDING_ALIGN].item); - label->bindings[MS_LABEL_BINDING_ALIGN].item = msStrdup(msyystring_buffer); - label->numbindings++; - } - break; - case(ANTIALIAS): /*ignore*/ - msyylex(); - break; - case(BUFFER): - if(getInteger(&(label->buffer), MS_NUM_CHECK_NONE, -1, -1) == -1) return(-1); - break; - case(COLOR): - if(loadColor(&(label->color), &(label->bindings[MS_LABEL_BINDING_COLOR])) != MS_SUCCESS) return(-1); - if(label->bindings[MS_LABEL_BINDING_COLOR].item) label->numbindings++; - break; - case(ENCODING): - if((getString(&label->encoding)) == MS_FAILURE) return(-1); - break; - case(END): - return(0); - break; - case(EOF): - msSetError(MS_EOFERR, NULL, "loadLabel()"); - freeLabel(label); /* free any structures allocated before EOF */ - return(-1); - case(EXPRESSION): - if(loadExpression(&(label->expression)) == -1) return(-1); /* loadExpression() cleans up previously allocated expression */ - break; - case(FONT): - if((symbol = getSymbol(2, MS_STRING, MS_BINDING)) == -1) - return(-1); - - if(symbol == MS_STRING) { - if (label->font != NULL) - msFree(label->font); - label->font = msStrdup(msyystring_buffer); - } else { - if (label->bindings[MS_LABEL_BINDING_FONT].item != NULL) - msFree(label->bindings[MS_LABEL_BINDING_FONT].item); - label->bindings[MS_LABEL_BINDING_FONT].item = msStrdup(msyystring_buffer); - label->numbindings++; - } - break; - case(FORCE): - switch(msyylex()) { - case MS_ON: - label->force = MS_ON; - break; - case MS_OFF: - label->force = MS_OFF; - break; - case GROUP: - label->force = MS_LABEL_FORCE_GROUP; - break; - default: - msSetError(MS_MISCERR, "Invalid FORCE, must be ON,OFF,or GROUP (line %d)" , "loadLabel()", msyylineno); - return(-1); + if (symbol == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, -360.0, 360.0) == + MS_FAILURE) { + msSetError(MS_MISCERR, + "Invalid ANGLE, must be between -360 and 360 (line %d)", + "loadLabel()", msyylineno); + return (MS_FAILURE); } + label->angle = (double)msyynumber; + } else if (symbol == MS_BINDING) { + if (label->bindings[MS_LABEL_BINDING_ANGLE].item != NULL) + msFree(label->bindings[MS_LABEL_BINDING_ANGLE].item); + label->bindings[MS_LABEL_BINDING_ANGLE].item = + msStrdup(msyystring_buffer); + label->numbindings++; + } else { + label->anglemode = symbol; + } + break; + case (ALIGN): + if ((symbol = getSymbol(4, MS_ALIGN_LEFT, MS_ALIGN_CENTER, MS_ALIGN_RIGHT, + MS_BINDING)) == -1) + return (-1); + if ((symbol == MS_ALIGN_LEFT) || (symbol == MS_ALIGN_CENTER) || + (symbol == MS_ALIGN_RIGHT)) { + label->align = symbol; + } else { + if (label->bindings[MS_LABEL_BINDING_ALIGN].item != NULL) + msFree(label->bindings[MS_LABEL_BINDING_ALIGN].item); + label->bindings[MS_LABEL_BINDING_ALIGN].item = + msStrdup(msyystring_buffer); + label->numbindings++; + } + break; + case (ANTIALIAS): /*ignore*/ + msyylex(); + break; + case (BUFFER): + if (getInteger(&(label->buffer), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (-1); + break; + case (COLOR): + if (loadColor(&(label->color), + &(label->bindings[MS_LABEL_BINDING_COLOR])) != MS_SUCCESS) + return (-1); + if (label->bindings[MS_LABEL_BINDING_COLOR].item) + label->numbindings++; + break; + case (ENCODING): + if ((getString(&label->encoding)) == MS_FAILURE) + return (-1); + break; + case (END): + return (0); + break; + case (EOF): + msSetError(MS_EOFERR, NULL, "loadLabel()"); + return (-1); + case (EXPRESSION): + if (loadExpression(&(label->expression)) == -1) + return (-1); /* loadExpression() cleans up previously allocated + expression */ + break; + case (FONT): + if ((symbol = getSymbol(2, MS_STRING, MS_BINDING)) == -1) + return (-1); + + if (symbol == MS_STRING) { + if (label->font != NULL) + msFree(label->font); + label->font = msStrdup(msyystring_buffer); + } else { + if (label->bindings[MS_LABEL_BINDING_FONT].item != NULL) + msFree(label->bindings[MS_LABEL_BINDING_FONT].item); + label->bindings[MS_LABEL_BINDING_FONT].item = + msStrdup(msyystring_buffer); + label->numbindings++; + } + break; + case (FORCE): + switch (msyylex()) { + case MS_ON: + label->force = MS_ON; break; - case(LABEL): - break; /* for string loads */ - case(LEADER): - msSetError(MS_MISCERR, "LABEL LEADER not implemented. LEADER goes at the CLASS level (line %d)" , "loadLabel()", msyylineno); - return(-1); - case(MAXSIZE): - if(getInteger(&(label->maxsize), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(MAXSCALEDENOM): - if(getDouble(&(label->maxscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); - break; - case(MAXLENGTH): - if(getInteger(&(label->maxlength), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(MINDISTANCE): - if(getInteger(&(label->mindistance), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(REPEATDISTANCE): - if(getInteger(&(label->repeatdistance), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(MAXOVERLAPANGLE): - if(getDouble(&(label->maxoverlapangle), MS_NUM_CHECK_RANGE, 0, 360) == -1) return(-1); - break; - case(MINFEATURESIZE): - if((symbol = getSymbol(2, MS_NUMBER,MS_AUTO)) == -1) return(-1); - if(symbol == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_GT, 0, -1) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid MINFEATURESIZE, must be greater than 0 (line %d)", "loadLabel()", msyylineno); - return(MS_FAILURE); - } - label->minfeaturesize = (int)msyynumber; - } else - label->autominfeaturesize = MS_TRUE; - break; - case(MINSCALEDENOM): - if(getDouble(&(label->minscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); + case MS_OFF: + label->force = MS_OFF; break; - case(MINSIZE): - if(getInteger(&(label->minsize), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); + case GROUP: + label->force = MS_LABEL_FORCE_GROUP; break; - case(OFFSET): - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) - label->offsetx = (int) msyynumber; // any integer ok - else { - if (label->bindings[MS_LABEL_BINDING_OFFSET_X].item != NULL) - msFree(label->bindings[MS_LABEL_BINDING_OFFSET_X].item); - label->bindings[MS_LABEL_BINDING_OFFSET_X].item = msStrdup(msyystring_buffer); - label->numbindings++; + default: + msSetError(MS_MISCERR, + "Invalid FORCE, must be ON,OFF,or GROUP (line %d)", + "loadLabel()", msyylineno); + return (-1); + } + break; + case (LABEL): + break; /* for string loads */ + case (LEADER): + msSetError(MS_MISCERR, + "LABEL LEADER not implemented. LEADER goes at the CLASS level " + "(line %d)", + "loadLabel()", msyylineno); + return (-1); + case (MAXSIZE): + if (getInteger(&(label->maxsize), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (MAXSCALEDENOM): + if (getDouble(&(label->maxscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (-1); + break; + case (MAXLENGTH): + if (getInteger(&(label->maxlength), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (MINDISTANCE): + if (getInteger(&(label->mindistance), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (REPEATDISTANCE): + if (getInteger(&(label->repeatdistance), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (MAXOVERLAPANGLE): + if (getDouble(&(label->maxoverlapangle), MS_NUM_CHECK_RANGE, 0, 360) == + -1) + return (-1); + break; + case (MINFEATURESIZE): + if ((symbol = getSymbol(2, MS_NUMBER, MS_AUTO)) == -1) + return (-1); + if (symbol == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_GT, 0, -1) == MS_FAILURE) { + msSetError(MS_MISCERR, + "Invalid MINFEATURESIZE, must be greater than 0 (line %d)", + "loadLabel()", msyylineno); + return (MS_FAILURE); } + label->minfeaturesize = (int)msyynumber; + } else + label->autominfeaturesize = MS_TRUE; + break; + case (MINSCALEDENOM): + if (getDouble(&(label->minscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (-1); + break; + case (MINSIZE): + if (getInteger(&(label->minsize), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (OFFSET): + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) + label->offsetx = (int)msyynumber; // any integer ok + else { + if (label->bindings[MS_LABEL_BINDING_OFFSET_X].item != NULL) + msFree(label->bindings[MS_LABEL_BINDING_OFFSET_X].item); + label->bindings[MS_LABEL_BINDING_OFFSET_X].item = + msStrdup(msyystring_buffer); + label->numbindings++; + } - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) - label->offsety = (int) msyynumber; // any integer ok - else { - if (label->bindings[MS_LABEL_BINDING_OFFSET_Y].item != NULL) - msFree(label->bindings[MS_LABEL_BINDING_OFFSET_Y].item); - label->bindings[MS_LABEL_BINDING_OFFSET_Y].item = msStrdup(msyystring_buffer); - label->numbindings++; - } - break; - case(OUTLINECOLOR): - if(loadColor(&(label->outlinecolor), &(label->bindings[MS_LABEL_BINDING_OUTLINECOLOR])) != MS_SUCCESS) return(-1); - if(label->bindings[MS_LABEL_BINDING_OUTLINECOLOR].item) label->numbindings++; - break; - case(OUTLINEWIDTH): - if(getInteger(&(label->outlinewidth), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(PARTIALS): - if((label->partials = getSymbol(2, MS_TRUE,MS_FALSE)) == -1) return(-1); - break; - case(POSITION): - if((label->position = getSymbol(11, MS_UL,MS_UC,MS_UR,MS_CL,MS_CC,MS_CR,MS_LL,MS_LC,MS_LR,MS_AUTO,MS_BINDING)) == -1) - return(-1); - if(label->position == MS_BINDING) { - if(label->bindings[MS_LABEL_BINDING_POSITION].item != NULL) - msFree(label->bindings[MS_LABEL_BINDING_POSITION].item); - label->bindings[MS_LABEL_BINDING_POSITION].item = msStrdup(msyystring_buffer); - label->numbindings++; - } - break; - case(PRIORITY): - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(-1); - if(symbol == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, 1, MS_MAX_LABEL_PRIORITY) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid PRIORITY, must be an integer between 1 and %d (line %d)" , "loadLabel()", MS_MAX_LABEL_PRIORITY, msyylineno); - return(-1); - } - label->priority = (int) msyynumber; - } else { - if (label->bindings[MS_LABEL_BINDING_PRIORITY].item != NULL) - msFree(label->bindings[MS_LABEL_BINDING_PRIORITY].item); - label->bindings[MS_LABEL_BINDING_PRIORITY].item = msStrdup(msyystring_buffer); - label->numbindings++; - } - break; - case(SHADOWCOLOR): - if(loadColor(&(label->shadowcolor), NULL) != MS_SUCCESS) return(-1); - break; - case(SHADOWSIZE): - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(-1); - if(symbol == MS_NUMBER) { - label->shadowsizex = (int) msyynumber; // x offset, any int ok - } else { - if (label->bindings[MS_LABEL_BINDING_SHADOWSIZEX].item != NULL) - msFree(label->bindings[MS_LABEL_BINDING_SHADOWSIZEX].item); - label->bindings[MS_LABEL_BINDING_SHADOWSIZEX].item = msStrdup(msyystring_buffer); - label->numbindings++; + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) + label->offsety = (int)msyynumber; // any integer ok + else { + if (label->bindings[MS_LABEL_BINDING_OFFSET_Y].item != NULL) + msFree(label->bindings[MS_LABEL_BINDING_OFFSET_Y].item); + label->bindings[MS_LABEL_BINDING_OFFSET_Y].item = + msStrdup(msyystring_buffer); + label->numbindings++; + } + break; + case (OUTLINECOLOR): + if (loadColor(&(label->outlinecolor), + &(label->bindings[MS_LABEL_BINDING_OUTLINECOLOR])) != + MS_SUCCESS) + return (-1); + if (label->bindings[MS_LABEL_BINDING_OUTLINECOLOR].item) + label->numbindings++; + break; + case (OUTLINEWIDTH): + if (getInteger(&(label->outlinewidth), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (PARTIALS): + if ((label->partials = getSymbol(2, MS_TRUE, MS_FALSE)) == -1) + return (-1); + break; + case (POSITION): + if ((label->position = + getSymbol(11, MS_UL, MS_UC, MS_UR, MS_CL, MS_CC, MS_CR, MS_LL, + MS_LC, MS_LR, MS_AUTO, MS_BINDING)) == -1) + return (-1); + if (label->position == MS_BINDING) { + if (label->bindings[MS_LABEL_BINDING_POSITION].item != NULL) + msFree(label->bindings[MS_LABEL_BINDING_POSITION].item); + label->bindings[MS_LABEL_BINDING_POSITION].item = + msStrdup(msyystring_buffer); + label->numbindings++; + } + break; + case (PRIORITY): + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (-1); + if (symbol == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, 1, + MS_MAX_LABEL_PRIORITY) == MS_FAILURE) { + msSetError( + MS_MISCERR, + "Invalid PRIORITY, must be an integer between 1 and %d (line %d)", + "loadLabel()", MS_MAX_LABEL_PRIORITY, msyylineno); + return (-1); } + label->priority = (int)msyynumber; + } else { + if (label->bindings[MS_LABEL_BINDING_PRIORITY].item != NULL) + msFree(label->bindings[MS_LABEL_BINDING_PRIORITY].item); + label->bindings[MS_LABEL_BINDING_PRIORITY].item = + msStrdup(msyystring_buffer); + label->numbindings++; + } + break; + case (SHADOWCOLOR): + if (loadColor(&(label->shadowcolor), NULL) != MS_SUCCESS) + return (-1); + break; + case (SHADOWSIZE): + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (-1); + if (symbol == MS_NUMBER) { + label->shadowsizex = (int)msyynumber; // x offset, any int ok + } else { + if (label->bindings[MS_LABEL_BINDING_SHADOWSIZEX].item != NULL) + msFree(label->bindings[MS_LABEL_BINDING_SHADOWSIZEX].item); + label->bindings[MS_LABEL_BINDING_SHADOWSIZEX].item = + msStrdup(msyystring_buffer); + label->numbindings++; + } - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(-1); - if(symbol == MS_NUMBER) { - label->shadowsizey = (int) msyynumber; // y offset, any int ok - } else { - if (label->bindings[MS_LABEL_BINDING_SHADOWSIZEY].item != NULL) - msFree(label->bindings[MS_LABEL_BINDING_SHADOWSIZEY].item); - label->bindings[MS_LABEL_BINDING_SHADOWSIZEY].item = msStrdup(msyystring_buffer); - label->numbindings++; - } - break; - case(SIZE): - if(label->bindings[MS_LABEL_BINDING_SIZE].item) { - msFree(label->bindings[MS_LABEL_BINDING_SIZE].item); - label->bindings[MS_LABEL_BINDING_SIZE].item = NULL; - label->numbindings--; - } - if (label->exprBindings[MS_LABEL_BINDING_SIZE].string) { - msFreeExpression(&label->exprBindings[MS_LABEL_BINDING_SIZE]); - label->nexprbindings--; - } + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (-1); + if (symbol == MS_NUMBER) { + label->shadowsizey = (int)msyynumber; // y offset, any int ok + } else { + if (label->bindings[MS_LABEL_BINDING_SHADOWSIZEY].item != NULL) + msFree(label->bindings[MS_LABEL_BINDING_SHADOWSIZEY].item); + label->bindings[MS_LABEL_BINDING_SHADOWSIZEY].item = + msStrdup(msyystring_buffer); + label->numbindings++; + } + break; + case (SIZE): + if (label->bindings[MS_LABEL_BINDING_SIZE].item) { + msFree(label->bindings[MS_LABEL_BINDING_SIZE].item); + label->bindings[MS_LABEL_BINDING_SIZE].item = NULL; + label->numbindings--; + } + if (label->exprBindings[MS_LABEL_BINDING_SIZE].string) { + msFreeExpression(&label->exprBindings[MS_LABEL_BINDING_SIZE]); + label->nexprbindings--; + } - if((symbol = getSymbol(8, MS_EXPRESSION,MS_NUMBER,MS_BINDING,MS_TINY,MS_SMALL,MS_MEDIUM,MS_LARGE,MS_GIANT)) == -1) - return(-1); + if ((symbol = getSymbol(8, MS_EXPRESSION, MS_NUMBER, MS_BINDING, MS_TINY, + MS_SMALL, MS_MEDIUM, MS_LARGE, MS_GIANT)) == -1) + return (-1); - if(symbol == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_GT, 0, -1) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid SIZE, must be greater than 0 (line %d)" , "loadLabel()", msyylineno); - return(-1); - } - label->size = (double) msyynumber; - } else if(symbol == MS_BINDING) { - label->bindings[MS_LABEL_BINDING_SIZE].item = msStrdup(msyystring_buffer); - label->numbindings++; - } else if (symbol == MS_EXPRESSION) { - msFree(label->exprBindings[MS_LABEL_BINDING_SIZE].string); - label->exprBindings[MS_LABEL_BINDING_SIZE].string = msStrdup(msyystring_buffer); - label->exprBindings[MS_LABEL_BINDING_SIZE].type = MS_EXPRESSION; - label->nexprbindings++; - } else - label->size = symbol; - break; - case(STYLE): - if(msGrowLabelStyles(label) == NULL) - return(-1); - initStyle(label->styles[label->numstyles]); - if(loadStyle(label->styles[label->numstyles]) != MS_SUCCESS) return(-1); - if(label->styles[label->numstyles]->_geomtransform.type == MS_GEOMTRANSFORM_NONE) - label->styles[label->numstyles]->_geomtransform.type = MS_GEOMTRANSFORM_LABELPOINT; /* set a default, a marker? */ - label->numstyles++; - break; - case(TEXT): - if(loadExpression(&(label->text)) == -1) return(-1); /* loadExpression() cleans up previously allocated expression */ - if((label->text.type != MS_STRING) && (label->text.type != MS_EXPRESSION)) { - msSetError(MS_MISCERR, "Text expressions support constant or tagged replacement strings." , "loadLabel()"); - return(-1); - } - break; - case(TYPE): - if(getSymbol(2, MS_TRUETYPE,MS_BITMAP) == -1) return(-1); /* ignore TYPE */ - break; - case(WRAP): - if(getCharacter(&(label->wrap)) == -1) return(-1); - break; - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadLabel()", msyystring_buffer, msyylineno); - return(-1); - } else { - return(0); /* end of a string, not an error */ + if (symbol == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_GT, 0, -1) == MS_FAILURE) { + msSetError(MS_MISCERR, + "Invalid SIZE, must be greater than 0 (line %d)", + "loadLabel()", msyylineno); + return (-1); } + label->size = (double)msyynumber; + } else if (symbol == MS_BINDING) { + label->bindings[MS_LABEL_BINDING_SIZE].item = + msStrdup(msyystring_buffer); + label->numbindings++; + } else if (symbol == MS_EXPRESSION) { + msFree(label->exprBindings[MS_LABEL_BINDING_SIZE].string); + label->exprBindings[MS_LABEL_BINDING_SIZE].string = + msStrdup(msyystring_buffer); + label->exprBindings[MS_LABEL_BINDING_SIZE].type = MS_EXPRESSION; + label->nexprbindings++; + } else + label->size = symbol; + break; + case (STYLE): + if (msGrowLabelStyles(label) == NULL) + return (-1); + initStyle(label->styles[label->numstyles]); + if (loadStyle(label->styles[label->numstyles]) != MS_SUCCESS) { + freeStyle(label->styles[label->numstyles]); + free(label->styles[label->numstyles]); + label->styles[label->numstyles] = NULL; + return (-1); + } + if (label->styles[label->numstyles]->_geomtransform.type == + MS_GEOMTRANSFORM_NONE) + label->styles[label->numstyles]->_geomtransform.type = + MS_GEOMTRANSFORM_LABELPOINT; /* set a default, a marker? */ + label->numstyles++; + break; + case (TEXT): + if (loadExpression(&(label->text)) == -1) + return (-1); /* loadExpression() cleans up previously allocated + expression */ + if ((label->text.type != MS_STRING) && + (label->text.type != MS_EXPRESSION)) { + msSetError( + MS_MISCERR, + "Text expressions support constant or tagged replacement strings.", + "loadLabel()"); + return (-1); + } + break; + case (TYPE): + if (getSymbol(2, MS_TRUETYPE, MS_BITMAP) == -1) + return (-1); /* ignore TYPE */ + break; + case (WRAP): + if (getCharacter(&(label->wrap)) == -1) + return (-1); + break; + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadLabel()", msyystring_buffer, msyylineno); + return (-1); + } else { + return (0); /* end of a string, not an error */ + } } } /* next token */ } -int msUpdateLabelFromString(labelObj *label, char *string) -{ - if(!label || !string) return MS_FAILURE; +int msUpdateLabelFromString(labelObj *label, char *string) { + if (!label || !string) + return MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_STRING; msyystring = string; @@ -1848,101 +2047,128 @@ int msUpdateLabelFromString(labelObj *label, char *string) msyylineno = 1; /* start at line 1 */ - if(loadLabel(label) == -1) { - msReleaseLock( TLOCK_PARSER ); - return MS_FAILURE; /* parse error */; + if (loadLabel(label) == -1) { + msReleaseLock(TLOCK_PARSER); + return MS_FAILURE; /* parse error */ + ; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msyylex_destroy(); return MS_SUCCESS; } -static void writeLeader(FILE *stream, int indent, labelLeaderObj *leader) -{ +static void writeLeader(FILE *stream, int indent, labelLeaderObj *leader) { int i; - if(leader->maxdistance == 0 && leader->numstyles == 0) { + if (leader->maxdistance == 0 && leader->numstyles == 0) { return; } indent++; writeBlockBegin(stream, indent, "LEADER"); writeNumber(stream, indent, "MAXDISTANCE", 0, leader->maxdistance); writeNumber(stream, indent, "GRIDSTEP", 5, leader->gridstep); - for(i=0; inumstyles; i++) + for (i = 0; i < leader->numstyles; i++) writeStyle(stream, indent, leader->styles[i]); writeBlockEnd(stream, indent, "LEADER"); } -static void writeLabel(FILE *stream, int indent, labelObj *label) -{ +static void writeLabel(FILE *stream, int indent, labelObj *label) { int i; colorObj c; - if(label->size == -1) return; /* there is no default label anymore */ + if (label->size == -1) + return; /* there is no default label anymore */ indent++; writeBlockBegin(stream, indent, "LABEL"); - if(label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_ANGLE].item) - writeAttributeBinding(stream, indent, "ANGLE", &(label->bindings[MS_LABEL_BINDING_ANGLE])); - else writeNumberOrKeyword(stream, indent, "ANGLE", 0, label->angle, label->anglemode, 3, MS_FOLLOW, "FOLLOW", MS_AUTO, "AUTO", MS_AUTO2, "AUTO2"); + if (label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_ANGLE].item) + writeAttributeBinding(stream, indent, "ANGLE", + &(label->bindings[MS_LABEL_BINDING_ANGLE])); + else + writeNumberOrKeyword(stream, indent, "ANGLE", 0, label->angle, + label->anglemode, 3, MS_FOLLOW, "FOLLOW", MS_AUTO, + "AUTO", MS_AUTO2, "AUTO2"); writeExpression(stream, indent, "EXPRESSION", &(label->expression)); - if(label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_FONT].item) - writeAttributeBinding(stream, indent, "FONT", &(label->bindings[MS_LABEL_BINDING_FONT])); - else writeString(stream, indent, "FONT", NULL, label->font); + if (label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_FONT].item) + writeAttributeBinding(stream, indent, "FONT", + &(label->bindings[MS_LABEL_BINDING_FONT])); + else + writeString(stream, indent, "FONT", NULL, label->font); - writeNumber(stream, indent, "MAXSIZE", MS_MAXFONTSIZE, label->maxsize); - writeNumber(stream, indent, "MINSIZE", MS_MINFONTSIZE, label->minsize); + writeNumber(stream, indent, "MAXSIZE", MS_MAXFONTSIZE, label->maxsize); + writeNumber(stream, indent, "MINSIZE", MS_MINFONTSIZE, label->minsize); - if(label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_SIZE].item) - writeAttributeBinding(stream, indent, "SIZE", &(label->bindings[MS_LABEL_BINDING_SIZE])); - else writeNumber(stream, indent, "SIZE", -1, label->size); + if (label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_SIZE].item) + writeAttributeBinding(stream, indent, "SIZE", + &(label->bindings[MS_LABEL_BINDING_SIZE])); + else + writeNumber(stream, indent, "SIZE", -1, label->size); - writeKeyword(stream, indent, "ALIGN", label->align, 3, MS_ALIGN_LEFT, "LEFT", MS_ALIGN_CENTER, "CENTER", MS_ALIGN_RIGHT, "RIGHT"); + writeKeyword(stream, indent, "ALIGN", label->align, 3, MS_ALIGN_LEFT, "LEFT", + MS_ALIGN_CENTER, "CENTER", MS_ALIGN_RIGHT, "RIGHT"); writeNumber(stream, indent, "BUFFER", 0, label->buffer); - if(label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_COLOR].item) - writeAttributeBinding(stream, indent, "COLOR", &(label->bindings[MS_LABEL_BINDING_COLOR])); + if (label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_COLOR].item) + writeAttributeBinding(stream, indent, "COLOR", + &(label->bindings[MS_LABEL_BINDING_COLOR])); else { - MS_INIT_COLOR(c,0,0,0,255); + MS_INIT_COLOR(c, 0, 0, 0, 255); writeColor(stream, indent, "COLOR", &c, &(label->color)); } writeString(stream, indent, "ENCODING", NULL, label->encoding); - if(label->leader) - writeLeader(stream,indent,label->leader); - writeKeyword(stream, indent, "FORCE", label->force, 2, MS_TRUE, "TRUE", MS_LABEL_FORCE_GROUP, "GROUP"); + if (label->leader) + writeLeader(stream, indent, label->leader); + writeKeyword(stream, indent, "FORCE", label->force, 2, MS_TRUE, "TRUE", + MS_LABEL_FORCE_GROUP, "GROUP"); writeNumber(stream, indent, "MAXLENGTH", 0, label->maxlength); writeNumber(stream, indent, "MAXSCALEDENOM", -1, label->maxscaledenom); writeNumber(stream, indent, "MINDISTANCE", -1, label->mindistance); - writeNumberOrKeyword(stream, indent, "MINFEATURESIZE", -1, label->minfeaturesize, 1, label->autominfeaturesize, MS_TRUE, "AUTO"); + writeNumberOrKeyword(stream, indent, "MINFEATURESIZE", -1, + label->minfeaturesize, 1, label->autominfeaturesize, + MS_TRUE, "AUTO"); writeNumber(stream, indent, "MINSCALEDENOM", -1, label->minscaledenom); - writeDimension(stream, indent, "OFFSET", label->offsetx, label->offsety, NULL, NULL); + writeDimension(stream, indent, "OFFSET", label->offsetx, label->offsety, NULL, + NULL); - if(label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_OUTLINECOLOR].item) - writeAttributeBinding(stream, indent, "OUTLINECOLOR", &(label->bindings[MS_LABEL_BINDING_OUTLINECOLOR])); - else writeColor(stream, indent, "OUTLINECOLOR", NULL, &(label->outlinecolor)); + if (label->numbindings > 0 && + label->bindings[MS_LABEL_BINDING_OUTLINECOLOR].item) + writeAttributeBinding(stream, indent, "OUTLINECOLOR", + &(label->bindings[MS_LABEL_BINDING_OUTLINECOLOR])); + else + writeColor(stream, indent, "OUTLINECOLOR", NULL, &(label->outlinecolor)); writeNumber(stream, indent, "OUTLINEWIDTH", 1, label->outlinewidth); writeKeyword(stream, indent, "PARTIALS", label->partials, 1, MS_TRUE, "TRUE"); - if(label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_POSITION].item) - writeAttributeBinding(stream, indent, "POSITION", &(label->bindings[MS_LABEL_BINDING_POSITION])); - else writeKeyword(stream, indent, "POSITION", label->position, 10, MS_UL, "UL", MS_UC, "UC", MS_UR, "UR", MS_CL, "CL", MS_CC, "CC", MS_CR, "CR", MS_LL, "LL", MS_LC, "LC", MS_LR, "LR", MS_AUTO, "AUTO"); + if (label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_POSITION].item) + writeAttributeBinding(stream, indent, "POSITION", + &(label->bindings[MS_LABEL_BINDING_POSITION])); + else + writeKeyword(stream, indent, "POSITION", label->position, 10, MS_UL, "UL", + MS_UC, "UC", MS_UR, "UR", MS_CL, "CL", MS_CC, "CC", MS_CR, + "CR", MS_LL, "LL", MS_LC, "LC", MS_LR, "LR", MS_AUTO, "AUTO"); - if(label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_PRIORITY].item) - writeAttributeBinding(stream, indent, "PRIORITY", &(label->bindings[MS_LABEL_BINDING_PRIORITY])); - else writeNumber(stream, indent, "PRIORITY", MS_DEFAULT_LABEL_PRIORITY, label->priority); + if (label->numbindings > 0 && label->bindings[MS_LABEL_BINDING_PRIORITY].item) + writeAttributeBinding(stream, indent, "PRIORITY", + &(label->bindings[MS_LABEL_BINDING_PRIORITY])); + else + writeNumber(stream, indent, "PRIORITY", MS_DEFAULT_LABEL_PRIORITY, + label->priority); writeNumber(stream, indent, "REPEATDISTANCE", 0, label->repeatdistance); writeColor(stream, indent, "SHADOWCOLOR", NULL, &(label->shadowcolor)); - writeDimension(stream, indent, "SHADOWSIZE", label->shadowsizex, label->shadowsizey, label->bindings[MS_LABEL_BINDING_SHADOWSIZEX].item, label->bindings[MS_LABEL_BINDING_SHADOWSIZEY].item); + writeDimension(stream, indent, "SHADOWSIZE", label->shadowsizex, + label->shadowsizey, + label->bindings[MS_LABEL_BINDING_SHADOWSIZEX].item, + label->bindings[MS_LABEL_BINDING_SHADOWSIZEY].item); writeNumber(stream, indent, "MAXOVERLAPANGLE", 22.5, label->maxoverlapangle); - for(i=0; inumstyles; i++) + for (i = 0; i < label->numstyles; i++) writeStyle(stream, indent, label->styles[i]); writeExpression(stream, indent, "TEXT", &(label->text)); @@ -1951,9 +2177,8 @@ static void writeLabel(FILE *stream, int indent, labelObj *label) writeBlockEnd(stream, indent, "LABEL"); } -char* msWriteLabelToString(labelObj *label) -{ - msIOContext context; +char *msWriteLabelToString(labelObj *label) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -1964,53 +2189,52 @@ char* msWriteLabelToString(labelObj *label) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeLabel(stdout, -1, label); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } -void msInitExpression(expressionObj *exp) -{ +void msInitExpression(expressionObj *exp) { memset(exp, 0, sizeof(*exp)); exp->type = MS_STRING; } -void msFreeExpressionTokens(expressionObj *exp) -{ +void msFreeExpressionTokens(expressionObj *exp) { tokenListNodeObjPtr node = NULL; tokenListNodeObjPtr nextNode = NULL; - if(!exp) return; + if (!exp) + return; - if(exp->tokens) { + if (exp->tokens) { node = exp->tokens; while (node != NULL) { nextNode = node->next; msFree(node->tokensrc); /* not set very often */ - switch(node->token) { - case MS_TOKEN_BINDING_DOUBLE: - case MS_TOKEN_BINDING_INTEGER: - case MS_TOKEN_BINDING_STRING: - case MS_TOKEN_BINDING_TIME: - msFree(node->tokenval.bindval.item); - break; - case MS_TOKEN_LITERAL_TIME: - /* anything to do? */ - break; - case MS_TOKEN_LITERAL_STRING: - msFree(node->tokenval.strval); - break; - case MS_TOKEN_LITERAL_SHAPE: - msFreeShape(node->tokenval.shpval); - free(node->tokenval.shpval); - break; + switch (node->token) { + case MS_TOKEN_BINDING_DOUBLE: + case MS_TOKEN_BINDING_INTEGER: + case MS_TOKEN_BINDING_STRING: + case MS_TOKEN_BINDING_TIME: + msFree(node->tokenval.bindval.item); + break; + case MS_TOKEN_LITERAL_TIME: + /* anything to do? */ + break; + case MS_TOKEN_LITERAL_STRING: + msFree(node->tokenval.strval); + break; + case MS_TOKEN_LITERAL_SHAPE: + msFreeShape(node->tokenval.shpval); + free(node->tokenval.shpval); + break; } msFree(node); @@ -2020,22 +2244,25 @@ void msFreeExpressionTokens(expressionObj *exp) } } -void msFreeExpression(expressionObj *exp) -{ - if(!exp) return; +void msFreeExpression(expressionObj *exp) { + if (!exp) + return; msFree(exp->string); msFree(exp->native_string); - if((exp->type == MS_REGEX) && exp->compiled) ms_regfree(&(exp->regex)); + if ((exp->type == MS_REGEX) && exp->compiled) + ms_regfree(&(exp->regex)); msFreeExpressionTokens(exp); msInitExpression(exp); /* re-initialize */ } -int loadExpression(expressionObj *exp) -{ - /* TODO: should we call msFreeExpression if exp->string != NULL? We do some checking to avoid a leak but is it enough... */ +int loadExpression(expressionObj *exp) { + /* TODO: should we call msFreeExpression if exp->string != NULL? We do some + * checking to avoid a leak but is it enough... */ msyystring_icase = MS_TRUE; - if((exp->type = getSymbol(6, MS_STRING,MS_EXPRESSION,MS_REGEX,MS_ISTRING,MS_IREGEX,MS_LIST)) == -1) return(-1); + if ((exp->type = getSymbol(6, MS_STRING, MS_EXPRESSION, MS_REGEX, MS_ISTRING, + MS_IREGEX, MS_LIST)) == -1) + return (-1); if (exp->string != NULL) { msFree(exp->string); msFree(exp->native_string); @@ -2043,15 +2270,15 @@ int loadExpression(expressionObj *exp) exp->string = msStrdup(msyystring_buffer); exp->native_string = NULL; - if(exp->type == MS_ISTRING) { + if (exp->type == MS_ISTRING) { exp->flags = exp->flags | MS_EXP_INSENSITIVE; exp->type = MS_STRING; - } else if(exp->type == MS_IREGEX) { + } else if (exp->type == MS_IREGEX) { exp->flags = exp->flags | MS_EXP_INSENSITIVE; exp->type = MS_REGEX; } - return(0); + return (0); } /* --------------------------------------------------------------------------- @@ -2066,46 +2293,47 @@ int loadExpression(expressionObj *exp) See bug 339 for more details -- SG. ------------------------------------------------------------------------ */ -int msLoadExpressionString(expressionObj *exp, char *value) -{ +int msLoadExpressionString(expressionObj *exp, char *value) { int retval = MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); - retval = loadExpressionString( exp, value ); - msReleaseLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); + retval = loadExpressionString(exp, value); + msReleaseLock(TLOCK_PARSER); return retval; } -int loadExpressionString(expressionObj *exp, char *value) -{ +int loadExpressionString(expressionObj *exp, char *value) { msyystate = MS_TOKENIZE_STRING; msyystring = value; msyylex(); /* sets things up but processes no tokens */ - msFreeExpression(exp); /* we're totally replacing the old expression so free (which re-inits) to start over */ + msFreeExpression(exp); /* we're totally replacing the old expression so free + (which re-inits) to start over */ msyystring_icase = MS_TRUE; - if((exp->type = getSymbol2(5, MS_EXPRESSION,MS_REGEX,MS_IREGEX,MS_ISTRING,MS_LIST)) != -1) { + if ((exp->type = getSymbol2(5, MS_EXPRESSION, MS_REGEX, MS_IREGEX, MS_ISTRING, + MS_LIST)) != -1) { exp->string = msStrdup(msyystring_buffer); - if(exp->type == MS_ISTRING) { + if (exp->type == MS_ISTRING) { exp->type = MS_STRING; exp->flags = exp->flags | MS_EXP_INSENSITIVE; - } else if(exp->type == MS_IREGEX) { + } else if (exp->type == MS_IREGEX) { exp->type = MS_REGEX; exp->flags = exp->flags | MS_EXP_INSENSITIVE; } } else { - /* failure above is not an error since we'll consider anything not matching (like an unquoted number) as a STRING) */ + /* failure above is not an error since we'll consider anything not matching + * (like an unquoted number) as a STRING) */ exp->type = MS_STRING; - if((strlen(value) - strlen(msyystring_buffer)) == 2) + if ((strlen(value) - strlen(msyystring_buffer)) == 2) exp->string = msStrdup(msyystring_buffer); /* value was quoted */ else exp->string = msStrdup(value); /* use the whole value */ } - return(0); + return (0); } /* msGetExpressionString() @@ -2115,132 +2343,143 @@ int loadExpressionString(expressionObj *exp, char *value) * * Returns a newly allocated buffer that should be freed by the caller or NULL. */ -char *msGetExpressionString(expressionObj *exp) -{ - if(exp->string) { +char *msGetExpressionString(expressionObj *exp) { + if (exp->string) { char *exprstring; size_t buffer_size; const char *case_insensitive = ""; - if(exp->flags & MS_EXP_INSENSITIVE) + if (exp->flags & MS_EXP_INSENSITIVE) case_insensitive = "i"; /* Alloc buffer big enough for string + 2 delimiters + 'i' + \0 */ - buffer_size = strlen(exp->string)+4; - exprstring = (char*)msSmallMalloc(buffer_size); - - switch(exp->type) { - case(MS_REGEX): - snprintf(exprstring, buffer_size, "/%s/%s", exp->string, case_insensitive); - return exprstring; - case(MS_STRING): - snprintf(exprstring, buffer_size, "\"%s\"%s", exp->string, case_insensitive); - return exprstring; - case(MS_EXPRESSION): - snprintf(exprstring, buffer_size, "(%s)", exp->string); - return exprstring; - case(MS_LIST): - snprintf(exprstring, buffer_size, "{%s}", exp->string); - return exprstring; - default: - /* We should never get to here really! */ - free(exprstring); - return NULL; + buffer_size = strlen(exp->string) + 4; + exprstring = (char *)msSmallMalloc(buffer_size); + + switch (exp->type) { + case (MS_REGEX): + snprintf(exprstring, buffer_size, "/%s/%s", exp->string, + case_insensitive); + return exprstring; + case (MS_STRING): + snprintf(exprstring, buffer_size, "\"%s\"%s", exp->string, + case_insensitive); + return exprstring; + case (MS_EXPRESSION): + snprintf(exprstring, buffer_size, "(%s)", exp->string); + return exprstring; + case (MS_LIST): + snprintf(exprstring, buffer_size, "{%s}", exp->string); + return exprstring; + default: + /* We should never get to here really! */ + free(exprstring); + return NULL; } } return NULL; } -static void writeExpression(FILE *stream, int indent, const char *name, expressionObj *exp) -{ - if(!exp || !exp->string) return; +static void writeExpression(FILE *stream, int indent, const char *name, + expressionObj *exp) { + if (!exp || !exp->string) + return; writeIndent(stream, ++indent); - switch(exp->type) { - case(MS_LIST): - fprintf(stream, "%s {%s}", name, exp->string); - break; - case(MS_REGEX): - msIO_fprintf(stream, "%s /%s/", name, exp->string); - break; - case(MS_STRING): - msIO_fprintf(stream, "%s ", name); - writeStringElement(stream, exp->string); - break; - case(MS_EXPRESSION): - msIO_fprintf(stream, "%s (%s)", name, exp->string); - break; - } - if((exp->type == MS_STRING || exp->type == MS_REGEX) && (exp->flags & MS_EXP_INSENSITIVE)) + switch (exp->type) { + case (MS_LIST): + fprintf(stream, "%s {%s}", name, exp->string); + break; + case (MS_REGEX): + msIO_fprintf(stream, "%s /%s/", name, exp->string); + break; + case (MS_STRING): + msIO_fprintf(stream, "%s ", name); + writeStringElement(stream, exp->string); + break; + case (MS_EXPRESSION): + msIO_fprintf(stream, "%s (%s)", name, exp->string); + break; + } + if ((exp->type == MS_STRING || exp->type == MS_REGEX) && + (exp->flags & MS_EXP_INSENSITIVE)) msIO_fprintf(stream, "i"); writeLineFeed(stream); } -int loadHashTable(hashTableObj *ptable) -{ - char *key=NULL, *data=NULL; +int loadHashTable(hashTableObj *ptable) { assert(ptable); - for(;;) { - switch(msyylex()) { - case(EOF): - msSetError(MS_EOFERR, NULL, "loadHashTable()"); - return(MS_FAILURE); - case(END): - return(MS_SUCCESS); - case(MS_STRING): - key = msStrdup(msyystring_buffer); /* the key is *always* a string */ - if(getString(&data) == MS_FAILURE) return(MS_FAILURE); - msInsertHashTable(ptable, key, data); - + for (;;) { + switch (msyylex()) { + case (EOF): + msSetError(MS_EOFERR, NULL, "loadHashTable()"); + return (MS_FAILURE); + case (END): + return (MS_SUCCESS); + case (MS_STRING): { + char *data = NULL; + char *key = + msStrdup(msyystring_buffer); /* the key is *always* a string */ + if (getString(&data) == MS_FAILURE) { free(key); - free(data); - data=NULL; - break; - default: - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadHashTable()", msyystring_buffer, msyylineno ); - return(MS_FAILURE); + return (MS_FAILURE); + } + msInsertHashTable(ptable, key, data); + + free(key); + free(data); + break; + } + default: + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadHashTable()", msyystring_buffer, msyylineno); + return (MS_FAILURE); } } - return(MS_SUCCESS); + return (MS_SUCCESS); } -static void writeHashTable(FILE *stream, int indent, const char *title, hashTableObj *table) -{ +static void writeHashTable(FILE *stream, int indent, const char *title, + hashTableObj *table) { struct hashObj *tp; int i; - if(!table) return; - if(msHashIsEmpty(table)) return; + if (!table) + return; + if (msHashIsEmpty(table)) + return; indent++; writeBlockBegin(stream, indent, title); - for (i=0; iitems[i] != NULL) { - for (tp=table->items[i]; tp!=NULL; tp=tp->next) + for (tp = table->items[i]; tp != NULL; tp = tp->next) writeNameValuePair(stream, indent, tp->key, tp->data); } } writeBlockEnd(stream, indent, title); } -static void writeHashTableInline(FILE *stream, int indent, char *name, hashTableObj* table) -{ +static void writeHashTableInline(FILE *stream, int indent, char *name, + hashTableObj *table) { struct hashObj *tp = NULL; int i; - if(!table) return; - if(msHashIsEmpty(table)) return; + if (!table) + return; + if (msHashIsEmpty(table)) + return; ++indent; - for (i=0; iitems[i] != NULL) { - for (tp=table->items[i]; tp!=NULL; tp=tp->next) { + for (tp = table->items[i]; tp != NULL; tp = tp->next) { writeIndent(stream, indent); msIO_fprintf(stream, "%s ", name); writeStringElement(stream, tp->key); - msIO_fprintf(stream," "); + msIO_fprintf(stream, " "); writeStringElement(stream, tp->data); writeLineFeed(stream); } @@ -2251,8 +2490,7 @@ static void writeHashTableInline(FILE *stream, int indent, char *name, hashTable /* ** Initialize, load and free a cluster object */ -void initCluster(clusterObj *cluster) -{ +void initCluster(clusterObj *cluster) { cluster->maxdistance = 10; cluster->buffer = 0; cluster->region = NULL; @@ -2260,55 +2498,58 @@ void initCluster(clusterObj *cluster) msInitExpression(&(cluster->filter)); } -void freeCluster(clusterObj *cluster) -{ +void freeCluster(clusterObj *cluster) { msFree(cluster->region); msFreeExpression(&(cluster->group)); msFreeExpression(&(cluster->filter)); } -int loadCluster(clusterObj *cluster) -{ - for(;;) { - switch(msyylex()) { - case(CLUSTER): - break; /* for string loads */ - case(MAXDISTANCE): - if(getDouble(&(cluster->maxdistance), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(BUFFER): - if(getDouble(&(cluster->buffer), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(REGION): - if(getString(&cluster->region) == MS_FAILURE) return(-1); - break; - case(END): - return(0); - break; - case(GROUP): - if(loadExpression(&(cluster->group)) == -1) return(-1); - break; - case(FILTER): - if(loadExpression(&(cluster->filter)) == -1) return(-1); - break; - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadCluster()", msyystring_buffer, msyylineno); - return(-1); - } else { - return(0); /* end of a string, not an error */ - } - +int loadCluster(clusterObj *cluster) { + for (;;) { + switch (msyylex()) { + case (CLUSTER): + break; /* for string loads */ + case (MAXDISTANCE): + if (getDouble(&(cluster->maxdistance), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (BUFFER): + if (getDouble(&(cluster->buffer), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (REGION): + if (getString(&cluster->region) == MS_FAILURE) + return (-1); + break; + case (END): + return (0); + break; + case (GROUP): + if (loadExpression(&(cluster->group)) == -1) + return (-1); + break; + case (FILTER): + if (loadExpression(&(cluster->filter)) == -1) + return (-1); + break; + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadCluster()", msyystring_buffer, msyylineno); + return (-1); + } else { + return (0); /* end of a string, not an error */ + } } } - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msUpdateClusterFromString(clusterObj *cluster, char *string) -{ - if(!cluster || !string) return MS_FAILURE; +int msUpdateClusterFromString(clusterObj *cluster, char *string) { + if (!cluster || !string) + return MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_STRING; msyystring = string; @@ -2316,25 +2557,23 @@ int msUpdateClusterFromString(clusterObj *cluster, char *string) msyylineno = 1; /* start at line 1 */ - if(loadCluster(cluster) == -1) { - msReleaseLock( TLOCK_PARSER ); - return MS_FAILURE; /* parse error */; + if (loadCluster(cluster) == -1) { + msReleaseLock(TLOCK_PARSER); + return MS_FAILURE; /* parse error */ + ; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msyylex_destroy(); return MS_SUCCESS; } -static void writeCluster(FILE *stream, int indent, clusterObj *cluster) -{ +static void writeCluster(FILE *stream, int indent, clusterObj *cluster) { - if (cluster->maxdistance == 10 && - cluster->buffer == 0.0 && - cluster->region == NULL && - cluster->group.string == NULL && + if (cluster->maxdistance == 10 && cluster->buffer == 0.0 && + cluster->region == NULL && cluster->group.string == NULL && cluster->filter.string == NULL) - return; /* Nothing to write */ + return; /* Nothing to write */ indent++; writeBlockBegin(stream, indent, "CLUSTER"); @@ -2346,9 +2585,8 @@ static void writeCluster(FILE *stream, int indent, clusterObj *cluster) writeBlockEnd(stream, indent, "CLUSTER"); } -char* msWriteClusterToString(clusterObj *cluster) -{ - msIOContext context; +char *msWriteClusterToString(clusterObj *cluster) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -2359,28 +2597,27 @@ char* msWriteClusterToString(clusterObj *cluster) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeCluster(stdout, -1, cluster); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } /* ** Initialize, load and free a single style */ -int initStyle(styleObj *style) -{ +int initStyle(styleObj *style) { int i; MS_REFCNT_INIT(style); - MS_INIT_COLOR(style->color, -1,-1,-1,255); /* must explictly set colors */ - MS_INIT_COLOR(style->outlinecolor, -1,-1,-1,255); + MS_INIT_COLOR(style->color, -1, -1, -1, 255); /* must explictly set colors */ + MS_INIT_COLOR(style->outlinecolor, -1, -1, -1, 255); /* New Color Range fields*/ - MS_INIT_COLOR(style->mincolor, -1,-1,-1,255); - MS_INIT_COLOR(style->maxcolor, -1,-1,-1,255); + MS_INIT_COLOR(style->mincolor, -1, -1, -1, 255); + MS_INIT_COLOR(style->maxcolor, -1, -1, -1, 255); style->minvalue = 0.0; style->maxvalue = 1.0; style->rangeitem = NULL; @@ -2390,15 +2627,15 @@ int initStyle(styleObj *style) style->size = -1; /* in SIZEUNITS (layerObj) */ style->minsize = MS_MINSYMBOLSIZE; style->maxsize = MS_MAXSYMBOLSIZE; - style->width = 1; /* in pixels */ + style->width = 1; /* in pixels */ style->outlinewidth = 0; /* in pixels */ style->minwidth = MS_MINSYMBOLWIDTH; style->maxwidth = MS_MAXSYMBOLWIDTH; - style->minscaledenom=style->maxscaledenom = -1.0; - style->offsetx = style->offsety = 0; /* no offset */ + style->minscaledenom = style->maxscaledenom = -1.0; + style->offsetx = style->offsety = 0; /* no offset */ style->polaroffsetpixel = style->polaroffsetangle = 0; /* no polar offset */ style->angle = 0; - style->autoangle= MS_FALSE; + style->autoangle = MS_FALSE; style->antialiased = MS_TRUE; style->opacity = 100; /* fully opaque */ @@ -2414,7 +2651,7 @@ int initStyle(styleObj *style) style->numbindings = 0; style->nexprbindings = 0; - for(i=0; ibindings[i].item = NULL; style->bindings[i].index = -1; msInitExpression(&(style->exprBindings[i])); @@ -2426,295 +2663,362 @@ int initStyle(styleObj *style) return MS_SUCCESS; } -int loadStyle(styleObj *style) -{ +int loadStyle(styleObj *style) { int symbol; - for(;;) { - switch(msyylex()) { - /* New Color Range fields*/ - case (COLORRANGE): - /*These are both in one line now*/ - if(loadColor(&(style->mincolor), NULL) != MS_SUCCESS) return(MS_FAILURE); - if(loadColor(&(style->maxcolor), NULL) != MS_SUCCESS) return(MS_FAILURE); - break; - case(DATARANGE): - /*These are both in one line now*/ - if(getDouble(&(style->minvalue), MS_NUM_CHECK_NONE, -1, -1) == -1) return(MS_FAILURE); - if(getDouble(&(style->maxvalue), MS_NUM_CHECK_NONE, -1, -1) == -1) return(MS_FAILURE); - break; - case(RANGEITEM): - if(getString(&style->rangeitem) == MS_FAILURE) return(MS_FAILURE); - break; - /* End Range fields*/ - case(ANGLE): - if((symbol = getSymbol(3, MS_NUMBER,MS_BINDING,MS_AUTO)) == -1) return(MS_FAILURE); - - if(symbol == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, -360.0, 360.0) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid ANGLE, must be between -360 and 360 (line %d)", "loadStyle()", msyylineno); - return(MS_FAILURE); - } - style->angle = (double) msyynumber; - } else if(symbol==MS_BINDING) { - if (style->bindings[MS_STYLE_BINDING_ANGLE].item != NULL) - msFree(style->bindings[MS_STYLE_BINDING_ANGLE].item); - style->bindings[MS_STYLE_BINDING_ANGLE].item = msStrdup(msyystring_buffer); - style->numbindings++; - } else { - style->autoangle=MS_TRUE; - } - break; - case(ANTIALIAS): - if ((symbol = getSymbol(2, MS_TRUE,MS_FALSE)) == -1) return(MS_FAILURE); - if (symbol == MS_FALSE) { - style->antialiased = MS_FALSE; + for (;;) { + switch (msyylex()) { + /* New Color Range fields*/ + case (COLORRANGE): + /*These are both in one line now*/ + if (loadColor(&(style->mincolor), NULL) != MS_SUCCESS) + return (MS_FAILURE); + if (loadColor(&(style->maxcolor), NULL) != MS_SUCCESS) + return (MS_FAILURE); + break; + case (DATARANGE): + /*These are both in one line now*/ + if (getDouble(&(style->minvalue), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (MS_FAILURE); + if (getDouble(&(style->maxvalue), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (MS_FAILURE); + break; + case (RANGEITEM): + if (getString(&style->rangeitem) == MS_FAILURE) + return (MS_FAILURE); + break; + /* End Range fields*/ + case (ANGLE): + if ((symbol = getSymbol(3, MS_NUMBER, MS_BINDING, MS_AUTO)) == -1) + return (MS_FAILURE); + + if (symbol == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, -360.0, 360.0) == + MS_FAILURE) { + msSetError(MS_MISCERR, + "Invalid ANGLE, must be between -360 and 360 (line %d)", + "loadStyle()", msyylineno); + return (MS_FAILURE); } - break; - case(COLOR): - if(loadColor(&(style->color), &(style->bindings[MS_STYLE_BINDING_COLOR])) != MS_SUCCESS) return(MS_FAILURE); - if(style->bindings[MS_STYLE_BINDING_COLOR].item) style->numbindings++; - break; - case(EOF): - msSetError(MS_EOFERR, NULL, "loadStyle()"); - return(MS_FAILURE); /* missing END (probably) */ - case(END): { - int alpha; + style->angle = (double)msyynumber; + } else if (symbol == MS_BINDING) { + if (style->bindings[MS_STYLE_BINDING_ANGLE].item != NULL) + msFree(style->bindings[MS_STYLE_BINDING_ANGLE].item); + style->bindings[MS_STYLE_BINDING_ANGLE].item = + msStrdup(msyystring_buffer); + style->numbindings++; + } else { + style->autoangle = MS_TRUE; + } + break; + case (ANTIALIAS): + if ((symbol = getSymbol(2, MS_TRUE, MS_FALSE)) == -1) + return (MS_FAILURE); + if (symbol == MS_FALSE) { + style->antialiased = MS_FALSE; + } + break; + case (COLOR): + if (loadColor(&(style->color), + &(style->bindings[MS_STYLE_BINDING_COLOR])) != MS_SUCCESS) + return (MS_FAILURE); + if (style->bindings[MS_STYLE_BINDING_COLOR].item) + style->numbindings++; + break; + case (EOF): + msSetError(MS_EOFERR, NULL, "loadStyle()"); + return (MS_FAILURE); /* missing END (probably) */ + case (END): { + int alpha; - /* apply opacity as the alpha channel color(s) */ - if(style->opacity < 100) { - alpha = MS_NINT(style->opacity*2.55); + /* apply opacity as the alpha channel color(s) */ + if (style->opacity < 100) { + alpha = MS_NINT(style->opacity * 2.55); - style->color.alpha = alpha; - style->outlinecolor.alpha = alpha; + style->color.alpha = alpha; + style->outlinecolor.alpha = alpha; - style->mincolor.alpha = alpha; - style->maxcolor.alpha = alpha; - } + style->mincolor.alpha = alpha; + style->maxcolor.alpha = alpha; + } - return(MS_SUCCESS); + return (MS_SUCCESS); + } break; + case (GAP): + if (getDouble(&(style->gap), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (MS_FAILURE); + break; + case (INITIALGAP): + if (getDouble(&(style->initialgap), MS_NUM_CHECK_GTE, 0, -1) == + -1) { // zero is ok + msSetError(MS_MISCERR, + "INITIALGAP requires a positive values (line %d)", + "loadStyle()", msyylineno); + return (MS_FAILURE); } break; - case(GAP): - if(getDouble(&(style->gap), MS_NUM_CHECK_NONE, -1, -1) == -1) return(MS_FAILURE); - break; - case(INITIALGAP): - if(getDouble(&(style->initialgap), MS_NUM_CHECK_GTE, 0, -1) == -1) { // zero is ok - msSetError(MS_MISCERR, "INITIALGAP requires a positive values (line %d)", "loadStyle()", msyylineno); - return(MS_FAILURE); - } - break; - case(MAXSCALEDENOM): - if(getDouble(&(style->maxscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) return(MS_FAILURE); - break; - case(MINSCALEDENOM): - if(getDouble(&(style->minscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) return(MS_FAILURE); - break; - case(GEOMTRANSFORM): { - int s; - if((s = getSymbol(2, MS_STRING, MS_EXPRESSION)) == -1) return(MS_FAILURE); - if(s == MS_STRING) - msStyleSetGeomTransform(style, msyystring_buffer); - else { - /* handle expression case here for the moment */ - msFree(style->_geomtransform.string); - style->_geomtransform.string = msStrdup(msyystring_buffer); - style->_geomtransform.type = MS_GEOMTRANSFORM_EXPRESSION; - } + case (MAXSCALEDENOM): + if (getDouble(&(style->maxscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (MS_FAILURE); + break; + case (MINSCALEDENOM): + if (getDouble(&(style->minscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (MS_FAILURE); + break; + case (GEOMTRANSFORM): { + int s; + if ((s = getSymbol(2, MS_STRING, MS_EXPRESSION)) == -1) + return (MS_FAILURE); + if (s == MS_STRING) + msStyleSetGeomTransform(style, msyystring_buffer); + else { + /* handle expression case here for the moment */ + msFree(style->_geomtransform.string); + style->_geomtransform.string = msStrdup(msyystring_buffer); + style->_geomtransform.type = MS_GEOMTRANSFORM_EXPRESSION; } + } break; + case (LINECAP): + if ((style->linecap = getSymbol(4, MS_CJC_BUTT, MS_CJC_ROUND, + MS_CJC_SQUARE, MS_CJC_TRIANGLE)) == -1) + return (MS_FAILURE); break; - case(LINECAP): - if((style->linecap = getSymbol(4,MS_CJC_BUTT, MS_CJC_ROUND, MS_CJC_SQUARE, MS_CJC_TRIANGLE)) == -1) return(MS_FAILURE); - break; - case(LINEJOIN): - if((style->linejoin = getSymbol(4,MS_CJC_NONE, MS_CJC_ROUND, MS_CJC_MITER, MS_CJC_BEVEL)) == -1) return(MS_FAILURE); - break; - case(LINEJOINMAXSIZE): - if(getDouble(&(style->linejoinmaxsize), MS_NUM_CHECK_GT, 0, -1) == -1) return(MS_FAILURE); - break; - case(MAXSIZE): - if(getDouble(&(style->maxsize), MS_NUM_CHECK_GT, 0, -1) == -1) return(MS_FAILURE); - break; - case(MINSIZE): - if(getDouble(&(style->minsize), MS_NUM_CHECK_GTE, 0, -1) == -1) return(MS_FAILURE); - break; - case(MAXWIDTH): - if(getDouble(&(style->maxwidth), MS_NUM_CHECK_GT, 0, -1) == -1) return(MS_FAILURE); - break; - case(MINWIDTH): - if(getDouble(&(style->minwidth), MS_NUM_CHECK_GTE, 0, -1) == -1) return(MS_FAILURE); - break; - case(OFFSET): - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) - style->offsetx = (double) msyynumber; // any double ok - else { - if (style->bindings[MS_STYLE_BINDING_OFFSET_X].item != NULL) - msFree(style->bindings[MS_STYLE_BINDING_OFFSET_X].item); - style->bindings[MS_STYLE_BINDING_OFFSET_X].item = msStrdup(msyystring_buffer); - style->numbindings++; - } + case (LINEJOIN): + if ((style->linejoin = getSymbol(4, MS_CJC_NONE, MS_CJC_ROUND, + MS_CJC_MITER, MS_CJC_BEVEL)) == -1) + return (MS_FAILURE); + break; + case (LINEJOINMAXSIZE): + if (getDouble(&(style->linejoinmaxsize), MS_NUM_CHECK_GT, 0, -1) == -1) + return (MS_FAILURE); + break; + case (MAXSIZE): + if (getDouble(&(style->maxsize), MS_NUM_CHECK_GT, 0, -1) == -1) + return (MS_FAILURE); + break; + case (MINSIZE): + if (getDouble(&(style->minsize), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (MS_FAILURE); + break; + case (MAXWIDTH): + if (getDouble(&(style->maxwidth), MS_NUM_CHECK_GT, 0, -1) == -1) + return (MS_FAILURE); + break; + case (MINWIDTH): + if (getDouble(&(style->minwidth), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (MS_FAILURE); + break; + case (OFFSET): + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) + style->offsetx = (double)msyynumber; // any double ok + else { + if (style->bindings[MS_STYLE_BINDING_OFFSET_X].item != NULL) + msFree(style->bindings[MS_STYLE_BINDING_OFFSET_X].item); + style->bindings[MS_STYLE_BINDING_OFFSET_X].item = + msStrdup(msyystring_buffer); + style->numbindings++; + } - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) - style->offsety = (double) msyynumber; // any double ok - else { - if (style->bindings[MS_STYLE_BINDING_OFFSET_Y].item != NULL) - msFree(style->bindings[MS_STYLE_BINDING_OFFSET_Y].item); - style->bindings[MS_STYLE_BINDING_OFFSET_Y].item = msStrdup(msyystring_buffer); - style->numbindings++; - } - break; - case(OPACITY): - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) - style->opacity = MS_MAX(MS_MIN((int) msyynumber, 100), 0); /* force opacity to between 0 and 100 */ - else { - if (style->bindings[MS_STYLE_BINDING_OPACITY].item != NULL) - msFree(style->bindings[MS_STYLE_BINDING_OPACITY].item); - style->bindings[MS_STYLE_BINDING_OPACITY].item = msStrdup(msyystring_buffer); - style->numbindings++; - } - break; - case(OUTLINECOLOR): - if(loadColor(&(style->outlinecolor), &(style->bindings[MS_STYLE_BINDING_OUTLINECOLOR])) != MS_SUCCESS) return(MS_FAILURE); - if(style->bindings[MS_STYLE_BINDING_OUTLINECOLOR].item) style->numbindings++; - break; - case(PATTERN): { - int done = MS_FALSE; - for(;;) { /* read till the next END */ - switch(msyylex()) { - case(END): - if(style->patternlength < 2) { - msSetError(MS_SYMERR, "Not enough pattern elements. A minimum of 2 are required (line %d)", "loadStyle()", msyylineno); - return(MS_FAILURE); - } - done = MS_TRUE; - break; - case(MS_NUMBER): /* read the pattern values */ - if(style->patternlength == MS_MAXPATTERNLENGTH) { - msSetError(MS_SYMERR, "Pattern too long.", "loadStyle()"); - return(MS_FAILURE); - } - style->pattern[style->patternlength] = atof(msyystring_buffer); // good enough? - style->patternlength++; - break; - default: - msSetError(MS_TYPEERR, "Parsing error near (%s):(line %d)", "loadStyle()", msyystring_buffer, msyylineno); - return(MS_FAILURE); - } - if(done == MS_TRUE) - break; - } - break; + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) + style->offsety = (double)msyynumber; // any double ok + else { + if (style->bindings[MS_STYLE_BINDING_OFFSET_Y].item != NULL) + msFree(style->bindings[MS_STYLE_BINDING_OFFSET_Y].item); + style->bindings[MS_STYLE_BINDING_OFFSET_Y].item = + msStrdup(msyystring_buffer); + style->numbindings++; + } + break; + case (OPACITY): + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) + style->opacity = MS_MAX(MS_MIN((int)msyynumber, 100), + 0); /* force opacity to between 0 and 100 */ + else { + if (style->bindings[MS_STYLE_BINDING_OPACITY].item != NULL) + msFree(style->bindings[MS_STYLE_BINDING_OPACITY].item); + style->bindings[MS_STYLE_BINDING_OPACITY].item = + msStrdup(msyystring_buffer); + style->numbindings++; } - case(OUTLINEWIDTH): - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_GTE, 0, -1) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid OUTLINEWIDTH, must be greater then or equal to 0 (line %d)", "loadStyle()", msyylineno); - return(MS_FAILURE); + break; + case (OUTLINECOLOR): + if (loadColor(&(style->outlinecolor), + &(style->bindings[MS_STYLE_BINDING_OUTLINECOLOR])) != + MS_SUCCESS) + return (MS_FAILURE); + if (style->bindings[MS_STYLE_BINDING_OUTLINECOLOR].item) + style->numbindings++; + break; + case (PATTERN): { + int done = MS_FALSE; + for (;;) { /* read till the next END */ + switch (msyylex()) { + case (END): + if (style->patternlength < 2) { + msSetError(MS_SYMERR, + "Not enough pattern elements. A minimum of 2 are " + "required (line %d)", + "loadStyle()", msyylineno); + return (MS_FAILURE); } - style->outlinewidth = (double) msyynumber; - } else { - if (style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH].item != NULL) - msFree(style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH].item); - style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH].item = msStrdup(msyystring_buffer); - style->numbindings++; - } - break; - case(SIZE): - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_GT, 0, -1) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid SIZE, must be greater than 0 (line %d)", "loadStyle()", msyylineno); - return(MS_FAILURE); + done = MS_TRUE; + break; + case (MS_NUMBER): /* read the pattern values */ + if (style->patternlength == MS_MAXPATTERNLENGTH) { + msSetError(MS_SYMERR, "Pattern too long.", "loadStyle()"); + return (MS_FAILURE); } - style->size = (double) msyynumber; - } else { - if (style->bindings[MS_STYLE_BINDING_SIZE].item != NULL) - msFree(style->bindings[MS_STYLE_BINDING_SIZE].item); - style->bindings[MS_STYLE_BINDING_SIZE].item = msStrdup(msyystring_buffer); - style->numbindings++; + style->pattern[style->patternlength] = + atof(msyystring_buffer); // good enough? + style->patternlength++; + break; + default: + msSetError(MS_TYPEERR, "Parsing error near (%s):(line %d)", + "loadStyle()", msyystring_buffer, msyylineno); + return (MS_FAILURE); } - break; - case(STYLE): - break; /* for string loads */ - case(SYMBOL): - if((symbol = getSymbol(3, MS_NUMBER,MS_STRING,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_GTE, 0, -1) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid SYMBOL id, must be greater than or equal to 0 (line %d)", "loadStyle()", msyylineno); - return(MS_FAILURE); - } - if(style->symbolname != NULL) { - msFree(style->symbolname); - style->symbolname = NULL; - } - style->symbol = (int) msyynumber; - } else if(symbol == MS_STRING) { - if (style->symbolname != NULL) - msFree(style->symbolname); - style->symbolname = msStrdup(msyystring_buffer); - } else { - if (style->bindings[MS_STYLE_BINDING_SYMBOL].item != NULL) - msFree(style->bindings[MS_STYLE_BINDING_SYMBOL].item); - style->bindings[MS_STYLE_BINDING_SYMBOL].item = msStrdup(msyystring_buffer); - style->numbindings++; + if (done == MS_TRUE) + break; + } + break; + } + case (OUTLINEWIDTH): + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_GTE, 0, -1) == MS_FAILURE) { + msSetError(MS_MISCERR, + "Invalid OUTLINEWIDTH, must be greater then or equal to 0 " + "(line %d)", + "loadStyle()", msyylineno); + return (MS_FAILURE); } - break; - case(WIDTH): - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_GTE, 0, -1) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid WIDTH, must be greater than or equal to 0 (line %d)", "loadStyle()", msyylineno); - return(MS_FAILURE); - } - style->width = (double) msyynumber; - } else { - if (style->bindings[MS_STYLE_BINDING_WIDTH].item != NULL) - msFree(style->bindings[MS_STYLE_BINDING_WIDTH].item); - style->bindings[MS_STYLE_BINDING_WIDTH].item = msStrdup(msyystring_buffer); - style->numbindings++; + style->outlinewidth = (double)msyynumber; + } else { + if (style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH].item != NULL) + msFree(style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH].item); + style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH].item = + msStrdup(msyystring_buffer); + style->numbindings++; + } + break; + case (SIZE): + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_GT, 0, -1) == MS_FAILURE) { + msSetError(MS_MISCERR, + "Invalid SIZE, must be greater than 0 (line %d)", + "loadStyle()", msyylineno); + return (MS_FAILURE); } - break; - case(POLAROFFSET): - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) { - style->polaroffsetpixel = (double) msyynumber; // ok? - } else { - if (style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].item != NULL) - msFree(style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].item); - style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].item = msStrdup(msyystring_buffer); - style->numbindings++; + style->size = (double)msyynumber; + } else { + if (style->bindings[MS_STYLE_BINDING_SIZE].item != NULL) + msFree(style->bindings[MS_STYLE_BINDING_SIZE].item); + style->bindings[MS_STYLE_BINDING_SIZE].item = + msStrdup(msyystring_buffer); + style->numbindings++; + } + break; + case (STYLE): + break; /* for string loads */ + case (SYMBOL): + if ((symbol = getSymbol(3, MS_NUMBER, MS_STRING, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_GTE, 0, -1) == MS_FAILURE) { + msSetError( + MS_MISCERR, + "Invalid SYMBOL id, must be greater than or equal to 0 (line %d)", + "loadStyle()", msyylineno); + return (MS_FAILURE); } - - if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE); - if(symbol == MS_NUMBER) { - style->polaroffsetangle = (double) msyynumber; // ok? - } else { - if (style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].item != NULL) - msFree(style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].item); - style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].item = msStrdup(msyystring_buffer); - style->numbindings++; + if (style->symbolname != NULL) { + msFree(style->symbolname); + style->symbolname = NULL; } - break; - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadStyle()", msyystring_buffer, msyylineno); - return(MS_FAILURE); - } else { - return(MS_SUCCESS); /* end of a string, not an error */ + style->symbol = (int)msyynumber; + } else if (symbol == MS_STRING) { + if (style->symbolname != NULL) + msFree(style->symbolname); + style->symbolname = msStrdup(msyystring_buffer); + } else { + if (style->bindings[MS_STYLE_BINDING_SYMBOL].item != NULL) + msFree(style->bindings[MS_STYLE_BINDING_SYMBOL].item); + style->bindings[MS_STYLE_BINDING_SYMBOL].item = + msStrdup(msyystring_buffer); + style->numbindings++; + } + break; + case (WIDTH): + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_GTE, 0, -1) == MS_FAILURE) { + msSetError( + MS_MISCERR, + "Invalid WIDTH, must be greater than or equal to 0 (line %d)", + "loadStyle()", msyylineno); + return (MS_FAILURE); } + style->width = (double)msyynumber; + } else { + if (style->bindings[MS_STYLE_BINDING_WIDTH].item != NULL) + msFree(style->bindings[MS_STYLE_BINDING_WIDTH].item); + style->bindings[MS_STYLE_BINDING_WIDTH].item = + msStrdup(msyystring_buffer); + style->numbindings++; + } + break; + case (POLAROFFSET): + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) { + style->polaroffsetpixel = (double)msyynumber; // ok? + } else { + if (style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].item != NULL) + msFree(style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].item); + style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].item = + msStrdup(msyystring_buffer); + style->numbindings++; + } + + if ((symbol = getSymbol(2, MS_NUMBER, MS_BINDING)) == -1) + return (MS_FAILURE); + if (symbol == MS_NUMBER) { + style->polaroffsetangle = (double)msyynumber; // ok? + } else { + if (style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].item != NULL) + msFree(style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].item); + style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].item = + msStrdup(msyystring_buffer); + style->numbindings++; + } + break; + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadStyle()", msyystring_buffer, msyylineno); + return (MS_FAILURE); + } else { + return (MS_SUCCESS); /* end of a string, not an error */ + } } } } -int msUpdateStyleFromString(styleObj *style, char *string) -{ - if(!style || !string) return MS_FAILURE; +int msUpdateStyleFromString(styleObj *style, char *string) { + if (!style || !string) + return MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_STRING; msyystring = string; @@ -2722,21 +3026,21 @@ int msUpdateStyleFromString(styleObj *style, char *string) msyylineno = 1; /* start at line 1 */ - if(loadStyle(style) == -1) { - msReleaseLock( TLOCK_PARSER ); - return MS_FAILURE; /* parse error */; + if (loadStyle(style) == -1) { + msReleaseLock(TLOCK_PARSER); + return MS_FAILURE; /* parse error */ + ; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msyylex_destroy(); return MS_SUCCESS; } -int freeStyle(styleObj *style) -{ +int freeStyle(styleObj *style) { int i; - if( MS_REFCNT_DECR_IS_NOT_ZERO(style) ) { + if (MS_REFCNT_DECR_IS_NOT_ZERO(style)) { return MS_FAILURE; } @@ -2744,7 +3048,7 @@ int freeStyle(styleObj *style) msFreeExpression(&style->_geomtransform); msFree(style->rangeitem); - for(i=0; ibindings[i].item); msFreeExpression(&(style->exprBindings[i])); } @@ -2752,57 +3056,52 @@ int freeStyle(styleObj *style) return MS_SUCCESS; } -void writeStyle(FILE *stream, int indent, styleObj *style) -{ +void writeStyle(FILE *stream, int indent, styleObj *style) { indent++; writeBlockBegin(stream, indent, "STYLE"); - if(style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_ANGLE].item) - writeAttributeBinding(stream, indent, "ANGLE", &(style->bindings[MS_STYLE_BINDING_ANGLE])); - else writeNumberOrKeyword(stream, indent, "ANGLE", 0, style->angle, style->autoangle, 1, MS_TRUE, "AUTO"); + if (style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_ANGLE].item) + writeAttributeBinding(stream, indent, "ANGLE", + &(style->bindings[MS_STYLE_BINDING_ANGLE])); + else + writeNumberOrKeyword(stream, indent, "ANGLE", 0, style->angle, + style->autoangle, 1, MS_TRUE, "AUTO"); - if(style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_COLOR].item) - writeAttributeBinding(stream, indent, "COLOR", &(style->bindings[MS_STYLE_BINDING_COLOR])); - else writeColor(stream, indent, "COLOR", NULL, &(style->color)); + if (style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_COLOR].item) + writeAttributeBinding(stream, indent, "COLOR", + &(style->bindings[MS_STYLE_BINDING_COLOR])); + else + writeColor(stream, indent, "COLOR", NULL, &(style->color)); writeNumber(stream, indent, "GAP", 0, style->gap); writeNumber(stream, indent, "INITIALGAP", -1, style->initialgap); - if(style->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) { + if (style->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) { writeIndent(stream, indent + 1); msIO_fprintf(stream, "GEOMTRANSFORM (%s)\n", style->_geomtransform.string); - } - else if(style->_geomtransform.type != MS_GEOMTRANSFORM_NONE) { + } else if (style->_geomtransform.type != MS_GEOMTRANSFORM_NONE) { writeKeyword(stream, indent, "GEOMTRANSFORM", style->_geomtransform.type, 8, - MS_GEOMTRANSFORM_BBOX, "\"bbox\"", - MS_GEOMTRANSFORM_END, "\"end\"", - MS_GEOMTRANSFORM_LABELPOINT, "\"labelpnt\"", + MS_GEOMTRANSFORM_BBOX, "\"bbox\"", MS_GEOMTRANSFORM_END, + "\"end\"", MS_GEOMTRANSFORM_LABELPOINT, "\"labelpnt\"", MS_GEOMTRANSFORM_LABELPOLY, "\"labelpoly\"", MS_GEOMTRANSFORM_LABELCENTER, "\"labelcenter\"", - MS_GEOMTRANSFORM_START, "\"start\"", - MS_GEOMTRANSFORM_VERTICES, "\"vertices\"", - MS_GEOMTRANSFORM_CENTROID, "\"centroid\"" - ); + MS_GEOMTRANSFORM_START, "\"start\"", MS_GEOMTRANSFORM_VERTICES, + "\"vertices\"", MS_GEOMTRANSFORM_CENTROID, "\"centroid\""); } - if(style->linecap != MS_CJC_DEFAULT_CAPS) { - writeKeyword(stream,indent,"LINECAP",(int)style->linecap,5, - MS_CJC_NONE,"NONE", - MS_CJC_ROUND, "ROUND", - MS_CJC_SQUARE, "SQUARE", - MS_CJC_BUTT, "BUTT", - MS_CJC_TRIANGLE, "TRIANGLE"); + if (style->linecap != MS_CJC_DEFAULT_CAPS) { + writeKeyword(stream, indent, "LINECAP", (int)style->linecap, 5, MS_CJC_NONE, + "NONE", MS_CJC_ROUND, "ROUND", MS_CJC_SQUARE, "SQUARE", + MS_CJC_BUTT, "BUTT", MS_CJC_TRIANGLE, "TRIANGLE"); } - if(style->linejoin != MS_CJC_DEFAULT_JOINS) { - writeKeyword(stream,indent,"LINEJOIN",(int)style->linejoin,5, - MS_CJC_NONE,"NONE", - MS_CJC_ROUND, "ROUND", - MS_CJC_BEVEL, "BEVEL", - MS_CJC_MITER, "MITER"); + if (style->linejoin != MS_CJC_DEFAULT_JOINS) { + writeKeyword(stream, indent, "LINEJOIN", (int)style->linejoin, 5, + MS_CJC_NONE, "NONE", MS_CJC_ROUND, "ROUND", MS_CJC_BEVEL, + "BEVEL", MS_CJC_MITER, "MITER"); } - writeNumber(stream, indent, "LINEJOINMAXSIZE", MS_CJC_DEFAULT_JOIN_MAXSIZE , style->linejoinmaxsize); - + writeNumber(stream, indent, "LINEJOINMAXSIZE", MS_CJC_DEFAULT_JOIN_MAXSIZE, + style->linejoinmaxsize); writeNumber(stream, indent, "MAXSCALEDENOM", -1, style->maxscaledenom); writeNumber(stream, indent, "MAXSIZE", MS_MAXSYMBOLSIZE, style->maxsize); @@ -2810,61 +3109,88 @@ void writeStyle(FILE *stream, int indent, styleObj *style) writeNumber(stream, indent, "MINSCALEDENOM", -1, style->minscaledenom); writeNumber(stream, indent, "MINSIZE", MS_MINSYMBOLSIZE, style->minsize); writeNumber(stream, indent, "MINWIDTH", MS_MINSYMBOLWIDTH, style->minwidth); - if((style->numbindings > 0 && (style->bindings[MS_STYLE_BINDING_OFFSET_X].item||style->bindings[MS_STYLE_BINDING_OFFSET_Y].item))||style->offsetx!=0||style->offsety!=0) - writeDimension(stream, indent, "OFFSET", style->offsetx, style->offsety, style->bindings[MS_STYLE_BINDING_OFFSET_X].item, style->bindings[MS_STYLE_BINDING_OFFSET_Y].item); - if((style->numbindings > 0 && (style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].item||style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].item))||style->polaroffsetangle!=0||style->polaroffsetpixel!=0) - writeDimension(stream, indent, "POLAROFFSET", style->polaroffsetpixel, style->polaroffsetangle, - style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].item, style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].item); - - if(style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_OPACITY].item) - writeAttributeBinding(stream, indent, "OPACITY", &(style->bindings[MS_STYLE_BINDING_OPACITY])); - else writeNumber(stream, indent, "OPACITY", 100, style->opacity); + if ((style->numbindings > 0 && + (style->bindings[MS_STYLE_BINDING_OFFSET_X].item || + style->bindings[MS_STYLE_BINDING_OFFSET_Y].item)) || + style->offsetx != 0 || style->offsety != 0) + writeDimension(stream, indent, "OFFSET", style->offsetx, style->offsety, + style->bindings[MS_STYLE_BINDING_OFFSET_X].item, + style->bindings[MS_STYLE_BINDING_OFFSET_Y].item); + if ((style->numbindings > 0 && + (style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].item || + style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].item)) || + style->polaroffsetangle != 0 || style->polaroffsetpixel != 0) + writeDimension(stream, indent, "POLAROFFSET", style->polaroffsetpixel, + style->polaroffsetangle, + style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].item, + style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].item); + + if (style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_OPACITY].item) + writeAttributeBinding(stream, indent, "OPACITY", + &(style->bindings[MS_STYLE_BINDING_OPACITY])); + else + writeNumber(stream, indent, "OPACITY", 100, style->opacity); - if(style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_OUTLINECOLOR].item) - writeAttributeBinding(stream, indent, "OUTLINECOLOR", &(style->bindings[MS_STYLE_BINDING_OUTLINECOLOR])); - else writeColor(stream, indent, "OUTLINECOLOR", NULL, &(style->outlinecolor)); + if (style->numbindings > 0 && + style->bindings[MS_STYLE_BINDING_OUTLINECOLOR].item) + writeAttributeBinding(stream, indent, "OUTLINECOLOR", + &(style->bindings[MS_STYLE_BINDING_OUTLINECOLOR])); + else + writeColor(stream, indent, "OUTLINECOLOR", NULL, &(style->outlinecolor)); - if(style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH].item) - writeAttributeBinding(stream, indent, "OUTLINEWIDTH", &(style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH])); - else writeNumber(stream, indent, "OUTLINEWIDTH", 0, style->outlinewidth); + if (style->numbindings > 0 && + style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH].item) + writeAttributeBinding(stream, indent, "OUTLINEWIDTH", + &(style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH])); + else + writeNumber(stream, indent, "OUTLINEWIDTH", 0, style->outlinewidth); /* PATTERN */ - if(style->patternlength != 0) { + if (style->patternlength != 0) { int i; indent++; - writeBlockBegin(stream,indent,"PATTERN"); + writeBlockBegin(stream, indent, "PATTERN"); writeIndent(stream, indent); - for(i=0; ipatternlength; i++) + for (i = 0; i < style->patternlength; i++) msIO_fprintf(stream, " %.2f", style->pattern[i]); - msIO_fprintf(stream,"\n"); - writeBlockEnd(stream,indent,"PATTERN"); + msIO_fprintf(stream, "\n"); + writeBlockEnd(stream, indent, "PATTERN"); indent--; } - if(style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_SIZE].item) - writeAttributeBinding(stream, indent, "SIZE", &(style->bindings[MS_STYLE_BINDING_SIZE])); - else writeNumber(stream, indent, "SIZE", -1, style->size); + if (style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_SIZE].item) + writeAttributeBinding(stream, indent, "SIZE", + &(style->bindings[MS_STYLE_BINDING_SIZE])); + else + writeNumber(stream, indent, "SIZE", -1, style->size); - if(style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_SYMBOL].item) - writeAttributeBinding(stream, indent, "SYMBOL", &(style->bindings[MS_STYLE_BINDING_SYMBOL])); - else writeNumberOrString(stream, indent, "SYMBOL", 0, style->symbol, style->symbolname); + if (style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_SYMBOL].item) + writeAttributeBinding(stream, indent, "SYMBOL", + &(style->bindings[MS_STYLE_BINDING_SYMBOL])); + else + writeNumberOrString(stream, indent, "SYMBOL", 0, style->symbol, + style->symbolname); - if(style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_WIDTH].item) - writeAttributeBinding(stream, indent, "WIDTH", &(style->bindings[MS_STYLE_BINDING_WIDTH])); - else writeNumber(stream, indent, "WIDTH", 1, style->width); + if (style->numbindings > 0 && style->bindings[MS_STYLE_BINDING_WIDTH].item) + writeAttributeBinding(stream, indent, "WIDTH", + &(style->bindings[MS_STYLE_BINDING_WIDTH])); + else + writeNumber(stream, indent, "WIDTH", 1, style->width); - if(style->rangeitem) { - writeString(stream, indent, "RANGEITEM", NULL, style->rangeitem); - writeColorRange(stream, indent, "COLORRANGE", &(style->mincolor), &(style->maxcolor)); - writeDoubleRange(stream, indent, "DATARANGE", style->minvalue, style->maxvalue); + writeString(stream, indent, "RANGEITEM", NULL, style->rangeitem); + /* If COLORRANGE is valid, assume DATARANGE also needs to be written */ + if (MS_VALID_COLOR(style->mincolor) && MS_VALID_COLOR(style->maxcolor)) { + writeColorRange(stream, indent, "COLORRANGE", &(style->mincolor), + &(style->maxcolor)); + writeDoubleRange(stream, indent, "DATARANGE", style->minvalue, + style->maxvalue); } writeBlockEnd(stream, indent, "STYLE"); } -char* msWriteStyleToString(styleObj *style) -{ - msIOContext context; +char *msWriteStyleToString(styleObj *style) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -2875,21 +3201,20 @@ char* msWriteStyleToString(styleObj *style) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeStyle(stdout, -1, style); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } /* ** Initialize, load and free a single class */ -int initClass(classObj *class) -{ +int initClass(classObj *class) { class->status = MS_ON; class->debug = MS_OFF; MS_REFCNT_INIT(class); @@ -2926,14 +3251,13 @@ int initClass(classObj *class) class->sizeunits = MS_INHERIT; class->scalefactor = 1.0; - return(0); + return (0); } -int freeClass(classObj *class) -{ +int freeClass(classObj *class) { int i; - if( MS_REFCNT_DECR_IS_NOT_ZERO(class) ) { + if (MS_REFCNT_DECR_IS_NOT_ZERO(class)) { return MS_FAILURE; } @@ -2944,21 +3268,23 @@ int freeClass(classObj *class) msFree(class->template); msFree(class->group); - if (&(class->metadata)) msFreeHashItems(&(class->metadata)); - if (&(class->validation)) msFreeHashItems(&(class->validation)); + if (&(class->metadata)) + msFreeHashItems(&(class->metadata)); + if (&(class->validation)) + msFreeHashItems(&(class->validation)); - for(i=0; inumstyles; i++) { /* each style */ - if(class->styles[i]!=NULL) { - if(freeStyle(class->styles[i]) == MS_SUCCESS) { + for (i = 0; i < class->numstyles; i++) { /* each style */ + if (class->styles[i] != NULL) { + if (freeStyle(class->styles[i]) == MS_SUCCESS) { msFree(class->styles[i]); } } } msFree(class->styles); - for(i=0; inumlabels; i++) { /* each label */ - if(class->labels[i]!=NULL) { - if(freeLabel(class->labels[i]) == MS_SUCCESS) { + for (i = 0; i < class->numlabels; i++) { /* each label */ + if (class->labels[i] != NULL) { + if (freeLabel(class->labels[i]) == MS_SUCCESS) { msFree(class->labels[i]); } } @@ -2967,7 +3293,7 @@ int freeClass(classObj *class) msFree(class->keyimage); - if(class->leader) { + if (class->leader) { freeLabelLeader(class->leader); msFree(class->leader); class->leader = NULL; @@ -2988,8 +3314,7 @@ int freeClass(classObj *class) ** ** Returns a reference to the new styleObj on success, NULL on error. */ -styleObj *msGrowClassStyles( classObj *class ) -{ +styleObj *msGrowClassStyles(classObj *class) { /* Do we need to increase the size of styles[] by MS_STYLE_ALLOCSIZE? */ if (class->numstyles == class->maxstyles) { @@ -2999,18 +3324,19 @@ styleObj *msGrowClassStyles( classObj *class ) newsize = class->maxstyles + MS_STYLE_ALLOCSIZE; /* Alloc/realloc styles */ - newStylePtr = (styleObj**)realloc(class->styles, newsize*sizeof(styleObj*)); - MS_CHECK_ALLOC(newStylePtr, newsize*sizeof(styleObj*), NULL); + newStylePtr = + (styleObj **)realloc(class->styles, newsize * sizeof(styleObj *)); + MS_CHECK_ALLOC(newStylePtr, newsize * sizeof(styleObj *), NULL); class->styles = newStylePtr; class->maxstyles = newsize; - for(i=class->numstyles; imaxstyles; i++) { + for (i = class->numstyles; i < class->maxstyles; i++) { class->styles[i] = NULL; } } - if (class->styles[class->numstyles]==NULL) { - class->styles[class->numstyles]=(styleObj*)calloc(1,sizeof(styleObj)); + if (class->styles[class->numstyles] == NULL) { + class->styles[class->numstyles] = (styleObj *)calloc(1, sizeof(styleObj)); MS_CHECK_ALLOC(class->styles[class->numstyles], sizeof(styleObj), NULL); } @@ -3018,8 +3344,7 @@ styleObj *msGrowClassStyles( classObj *class ) } /* exactly the same as for a classObj */ -styleObj *msGrowLabelStyles( labelObj *label ) -{ +styleObj *msGrowLabelStyles(labelObj *label) { /* Do we need to increase the size of styles[] by MS_STYLE_ALLOCSIZE? */ if (label->numstyles == label->maxstyles) { @@ -3029,18 +3354,19 @@ styleObj *msGrowLabelStyles( labelObj *label ) newsize = label->maxstyles + MS_STYLE_ALLOCSIZE; /* Alloc/realloc styles */ - newStylePtr = (styleObj**)realloc(label->styles, newsize*sizeof(styleObj*)); - MS_CHECK_ALLOC(newStylePtr, newsize*sizeof(styleObj*), NULL); + newStylePtr = + (styleObj **)realloc(label->styles, newsize * sizeof(styleObj *)); + MS_CHECK_ALLOC(newStylePtr, newsize * sizeof(styleObj *), NULL); label->styles = newStylePtr; label->maxstyles = newsize; - for(i=label->numstyles; imaxstyles; i++) { + for (i = label->numstyles; i < label->maxstyles; i++) { label->styles[i] = NULL; } } - if (label->styles[label->numstyles]==NULL) { - label->styles[label->numstyles]=(styleObj*)calloc(1,sizeof(styleObj)); + if (label->styles[label->numstyles] == NULL) { + label->styles[label->numstyles] = (styleObj *)calloc(1, sizeof(styleObj)); MS_CHECK_ALLOC(label->styles[label->numstyles], sizeof(styleObj), NULL); } @@ -3048,8 +3374,7 @@ styleObj *msGrowLabelStyles( labelObj *label ) } /* exactly the same as for a labelLeaderObj, needs refactoring */ -styleObj *msGrowLeaderStyles( labelLeaderObj *leader ) -{ +styleObj *msGrowLeaderStyles(labelLeaderObj *leader) { /* Do we need to increase the size of styles[] by MS_STYLE_ALLOCSIZE? */ if (leader->numstyles == leader->maxstyles) { @@ -3059,19 +3384,19 @@ styleObj *msGrowLeaderStyles( labelLeaderObj *leader ) newsize = leader->maxstyles + MS_STYLE_ALLOCSIZE; /* Alloc/realloc styles */ - newStylePtr = (styleObj**)realloc(leader->styles, - newsize*sizeof(styleObj*)); - MS_CHECK_ALLOC(newStylePtr, newsize*sizeof(styleObj*), NULL); + newStylePtr = + (styleObj **)realloc(leader->styles, newsize * sizeof(styleObj *)); + MS_CHECK_ALLOC(newStylePtr, newsize * sizeof(styleObj *), NULL); leader->styles = newStylePtr; leader->maxstyles = newsize; - for(i=leader->numstyles; imaxstyles; i++) { + for (i = leader->numstyles; i < leader->maxstyles; i++) { leader->styles[i] = NULL; } } - if (leader->styles[leader->numstyles]==NULL) { - leader->styles[leader->numstyles]=(styleObj*)calloc(1,sizeof(styleObj)); + if (leader->styles[leader->numstyles] == NULL) { + leader->styles[leader->numstyles] = (styleObj *)calloc(1, sizeof(styleObj)); MS_CHECK_ALLOC(leader->styles[leader->numstyles], sizeof(styleObj), NULL); } @@ -3084,47 +3409,48 @@ styleObj *msGrowLeaderStyles( labelLeaderObj *leader ) ** ** Returns MS_SUCCESS/MS_FAILURE. */ -int msMaybeAllocateClassStyle(classObj* c, int idx) -{ - if (c==NULL) return MS_FAILURE; +int msMaybeAllocateClassStyle(classObj *c, int idx) { + if (c == NULL) + return MS_FAILURE; - if ( idx < 0 ) { - msSetError(MS_MISCERR, "Invalid style index: %d", "msMaybeAllocateClassStyle()", idx); + if (idx < 0) { + msSetError(MS_MISCERR, "Invalid style index: %d", + "msMaybeAllocateClassStyle()", idx); return MS_FAILURE; } /* Alloc empty styles as needed up to idx. * Nothing to do if requested style already exists */ - while(c->numstyles <= idx) { + while (c->numstyles <= idx) { if (msGrowClassStyles(c) == NULL) return MS_FAILURE; - if ( initStyle(c->styles[c->numstyles]) == MS_FAILURE ) { + if (initStyle(c->styles[c->numstyles]) == MS_FAILURE) { msSetError(MS_MISCERR, "Failed to init new styleObj", "msMaybeAllocateClassStyle()"); - return(MS_FAILURE); + freeStyle(c->styles[c->numstyles]); + free(c->styles[c->numstyles]); + c->styles[c->numstyles] = NULL; + return (MS_FAILURE); } c->numstyles++; } return MS_SUCCESS; } - - /* * Reset style info in the class to defaults * the only members we don't touch are name, expression, and join/query stuff * This is used with STYLEITEM before overwriting the contents of a class. */ -void resetClassStyle(classObj *class) -{ +void resetClassStyle(classObj *class) { int i; /* reset labels */ - for(i=0; inumlabels; i++) { - if(class->labels[i] != NULL) { - if(freeLabel(class->labels[i]) == MS_SUCCESS ) { + for (i = 0; i < class->numlabels; i++) { + if (class->labels[i] != NULL) { + if (freeLabel(class->labels[i]) == MS_SUCCESS) { msFree(class->labels[i]); } class->labels[i] = NULL; @@ -3136,9 +3462,9 @@ void resetClassStyle(classObj *class) msInitExpression(&(class->text)); /* reset styles */ - for(i=0; inumstyles; i++) { - if(class->styles[i] != NULL) { - if( freeStyle(class->styles[i]) == MS_SUCCESS ) { + for (i = 0; i < class->numstyles; i++) { + if (class->styles[i] != NULL) { + if (freeStyle(class->styles[i]) == MS_SUCCESS) { msFree(class->styles[i]); } class->styles[i] = NULL; @@ -3149,8 +3475,7 @@ void resetClassStyle(classObj *class) class->layer = NULL; } -labelObj *msGrowClassLabels( classObj *class ) -{ +labelObj *msGrowClassLabels(classObj *class) { /* Do we need to increase the size of labels[] by MS_LABEL_ALLOCSIZE? */ @@ -3161,152 +3486,197 @@ labelObj *msGrowClassLabels( classObj *class ) newsize = class->maxlabels + MS_LABEL_ALLOCSIZE; /* Alloc/realloc labels */ - newLabelPtr = (labelObj**)realloc(class->labels, newsize*sizeof(labelObj*)); - MS_CHECK_ALLOC(newLabelPtr, newsize*sizeof(labelObj*), NULL); + newLabelPtr = + (labelObj **)realloc(class->labels, newsize * sizeof(labelObj *)); + MS_CHECK_ALLOC(newLabelPtr, newsize * sizeof(labelObj *), NULL); class->labels = newLabelPtr; class->maxlabels = newsize; - for(i=class->numlabels; imaxlabels; i++) { + for (i = class->numlabels; i < class->maxlabels; i++) { class->labels[i] = NULL; } } - if (class->labels[class->numlabels]==NULL) { - class->labels[class->numlabels]=(labelObj*)calloc(1,sizeof(labelObj)); + if (class->labels[class->numlabels] == NULL) { + class->labels[class->numlabels] = (labelObj *)calloc(1, sizeof(labelObj)); MS_CHECK_ALLOC(class->labels[class->numlabels], sizeof(labelObj), NULL); } return class->labels[class->numlabels]; } -int loadClass(classObj *class, layerObj *layer) -{ - if(!class || !layer) return(-1); +int loadClass(classObj *class, layerObj *layer) { + if (!class || !layer) + return (-1); - class->layer = (layerObj *) layer; + class->layer = (layerObj *)layer; - for(;;) { - switch(msyylex()) { - case(CLASS): - break; /* for string loads */ - case(DEBUG): - if((class->debug = getSymbol(3, MS_ON,MS_OFF, MS_NUMBER)) == -1) return(-1); - if(class->debug == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, 0, 5) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid DEBUG level, must be between 0 and 5 (line %d)", "loadClass()", msyylineno); - return(-1); - } - class->debug = (int) msyynumber; - } - break; - case(EOF): - msSetError(MS_EOFERR, NULL, "loadClass()"); - return(-1); - case(END): - return(0); - break; - case(EXPRESSION): - if(loadExpression(&(class->expression)) == -1) return(-1); /* loadExpression() cleans up previously allocated expression */ - break; - case(GROUP): - if(getString(&class->group) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(KEYIMAGE): - if(getString(&class->keyimage) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(LABEL): - if(msGrowClassLabels(class) == NULL) return(-1); - initLabel(class->labels[class->numlabels]); - class->labels[class->numlabels]->size = MS_MEDIUM; /* only set a default if the LABEL section is present */ - if(loadLabel(class->labels[class->numlabels]) == -1) { - msFree(class->labels[class->numlabels]); - return(-1); - } - class->numlabels++; - break; - case(LEADER): - if(!class->leader) { - class->leader = msSmallMalloc(sizeof(labelLeaderObj)); - initLeader(class->leader); - } - if(loadLeader(class->leader) == -1) return(-1); - break; - case(MAXSCALE): - case(MAXSCALEDENOM): - if(getDouble(&(class->maxscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); - break; - case(METADATA): - if(loadHashTable(&(class->metadata)) != MS_SUCCESS) return(-1); - break; - case(MINSCALE): - case(MINSCALEDENOM): - if(getDouble(&(class->minscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); - break; - case(MINFEATURESIZE): - if(getInteger(&(class->minfeaturesize), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(NAME): - if(getString(&class->name) == MS_FAILURE) return(-1); - break; - case(STATUS): - if((class->status = getSymbol(2, MS_ON,MS_OFF)) == -1) return(-1); - break; - case(STYLE): - if(msGrowClassStyles(class) == NULL) - return(-1); - initStyle(class->styles[class->numstyles]); - if(loadStyle(class->styles[class->numstyles]) != MS_SUCCESS) return(-1); - class->numstyles++; - break; - case(TEMPLATE): - if(getString(&class->template) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(TEXT): - if(loadExpression(&(class->text)) == -1) return(-1); /* loadExpression() cleans up previously allocated expression */ - if((class->text.type != MS_STRING) && (class->text.type != MS_EXPRESSION)) { - msSetError(MS_MISCERR, "Text expressions support constant or tagged replacement strings." , "loadClass()"); - return(-1); - } - break; - case(TITLE): - if(getString(&class->title) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(VALIDATION): - if(loadHashTable(&(class->validation)) != MS_SUCCESS) return(-1); - break; - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadClass()", msyystring_buffer, msyylineno); - return(-1); - } else { - return(0); /* end of a string, not an error */ + for (;;) { + switch (msyylex()) { + case (CLASS): + break; /* for string loads */ + case (DEBUG): + if ((class->debug = getSymbol(3, MS_ON, MS_OFF, MS_NUMBER)) == -1) + return (-1); + if (class->debug == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, 0, 5) == MS_FAILURE) { + msSetError(MS_MISCERR, + "Invalid DEBUG level, must be between 0 and 5 (line %d)", + "loadClass()", msyylineno); + return (-1); } + class->debug = (int)msyynumber; + } + break; + case (EOF): + msSetError(MS_EOFERR, NULL, "loadClass()"); + return (-1); + case (END): + return (0); + break; + case (EXPRESSION): + if (loadExpression(&(class->expression)) == -1) + return (-1); /* loadExpression() cleans up previously allocated + expression */ + break; + case (GROUP): + if (getString(&class->group) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (KEYIMAGE): + if (getString(&class->keyimage) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (LABEL): + if (msGrowClassLabels(class) == NULL) + return (-1); + initLabel(class->labels[class->numlabels]); + class->labels[class->numlabels]->size = + MS_MEDIUM; /* only set a default if the LABEL section is present */ + if (loadLabel(class->labels[class->numlabels]) == -1) { + freeLabel(class->labels[class->numlabels]); + free(class->labels[class->numlabels]); + class->labels[class->numlabels] = NULL; + return (-1); + } + class->numlabels++; + break; + case (LEADER): + if (!class->leader) { + class->leader = msSmallMalloc(sizeof(labelLeaderObj)); + initLeader(class->leader); + } + if (loadLeader(class->leader) == -1) + return (-1); + break; + case (MAXSCALE): + case (MAXSCALEDENOM): + if (getDouble(&(class->maxscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (-1); + break; + case (METADATA): + if (loadHashTable(&(class->metadata)) != MS_SUCCESS) + return (-1); + break; + case (MINSCALE): + case (MINSCALEDENOM): + if (getDouble(&(class->minscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (-1); + break; + case (MINFEATURESIZE): + if (getInteger(&(class->minfeaturesize), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (NAME): + if (getString(&class->name) == MS_FAILURE) + return (-1); + break; + case (STATUS): + if ((class->status = getSymbol(2, MS_ON, MS_OFF)) == -1) + return (-1); + break; + case (STYLE): + if (msGrowClassStyles(class) == NULL) + return (-1); + initStyle(class->styles[class->numstyles]); + if (loadStyle(class->styles[class->numstyles]) != MS_SUCCESS) { + freeStyle(class->styles[class->numstyles]); + free(class->styles[class->numstyles]); + class->styles[class->numstyles] = NULL; + return (-1); + } + class->numstyles++; + break; + case (TEMPLATE): + if (getString(&class->template) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (TEXT): + if (loadExpression(&(class->text)) == -1) + return (-1); /* loadExpression() cleans up previously allocated + expression */ + if ((class->text.type != MS_STRING) && + (class->text.type != MS_EXPRESSION)) { + msSetError( + MS_MISCERR, + "Text expressions support constant or tagged replacement strings.", + "loadClass()"); + return (-1); + } + break; + case (TITLE): + if (getString(&class->title) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (VALIDATION): + if (loadHashTable(&(class->validation)) != MS_SUCCESS) + return (-1); + break; + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadClass()", msyystring_buffer, msyylineno); + return (-1); + } else { + return (0); /* end of a string, not an error */ + } } } } -static int classResolveSymbolNames(classObj *class) -{ - int i,j; +static int classResolveSymbolNames(classObj *class) { + int i, j; int try_addimage_if_notfound = MS_TRUE; /* step through styles and labels to resolve symbol names */ /* class styles */ - for(i=0; inumstyles; i++) { - if(class->styles[i]->symbolname) { - if((class->styles[i]->symbol = msGetSymbolIndex(&(class->layer->map->symbolset), class->styles[i]->symbolname, try_addimage_if_notfound)) == -1) { - msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class, style %d of layer %s.", "classResolveSymbolNames()", class->styles[i]->symbolname, i, class->layer->name); + for (i = 0; i < class->numstyles; i++) { + if (class->styles[i]->symbolname) { + if ((class->styles[i]->symbol = msGetSymbolIndex( + &(class->layer->map->symbolset), class->styles[i]->symbolname, + try_addimage_if_notfound)) == -1) { + msSetError(MS_MISCERR, + "Undefined symbol \"%s\" in class, style %d of layer %s.", + "classResolveSymbolNames()", class->styles[i]->symbolname, i, + class->layer->name); return MS_FAILURE; } } } /* label styles */ - for(i=0; inumlabels; i++) { - for(j=0; jlabels[i]->numstyles; j++) { - if(class->labels[i]->styles[j]->symbolname) { - if((class->labels[i]->styles[j]->symbol = msGetSymbolIndex(&(class->layer->map->symbolset), class->labels[i]->styles[j]->symbolname, try_addimage_if_notfound)) == -1) { - msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class, label style %d of layer %s.", "classResolveSymbolNames()", class->labels[i]->styles[j]->symbolname, j, class->layer->name); + for (i = 0; i < class->numlabels; i++) { + for (j = 0; j < class->labels[i]->numstyles; j++) { + if (class->labels[i]->styles[j]->symbolname) { + if ((class->labels[i]->styles[j]->symbol = + msGetSymbolIndex(&(class->layer->map->symbolset), + class->labels[i]->styles[j]->symbolname, + try_addimage_if_notfound)) == -1) { + msSetError( + MS_MISCERR, + "Undefined symbol \"%s\" in class, label style %d of layer %s.", + "classResolveSymbolNames()", + class->labels[i]->styles[j]->symbolname, j, class->layer->name); return MS_FAILURE; } } @@ -3316,11 +3686,11 @@ static int classResolveSymbolNames(classObj *class) return MS_SUCCESS; } -int msUpdateClassFromString(classObj *class, char *string) -{ - if(!class || !string) return MS_FAILURE; +int msUpdateClassFromString(classObj *class, char *string) { + if (!class || !string) + return MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_STRING; msyystring = string; @@ -3328,24 +3698,26 @@ int msUpdateClassFromString(classObj *class, char *string) msyylineno = 1; /* start at line 1 */ - if(loadClass(class, class->layer) == -1) { - msReleaseLock( TLOCK_PARSER ); - return MS_FAILURE; /* parse error */; + if (loadClass(class, class->layer) == -1) { + msReleaseLock(TLOCK_PARSER); + return MS_FAILURE; /* parse error */ + ; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msyylex_destroy(); - if(classResolveSymbolNames(class) != MS_SUCCESS) return MS_FAILURE; + if (classResolveSymbolNames(class) != MS_SUCCESS) + return MS_FAILURE; return MS_SUCCESS; } -static void writeClass(FILE *stream, int indent, classObj *class) -{ +static void writeClass(FILE *stream, int indent, classObj *class) { int i; - if(class->status == MS_DELETE) return; + if (class->status == MS_DELETE) + return; indent++; writeBlockBegin(stream, indent, "CLASS"); @@ -3354,15 +3726,17 @@ static void writeClass(FILE *stream, int indent, classObj *class) writeNumber(stream, indent, "DEBUG", 0, class->debug); writeExpression(stream, indent, "EXPRESSION", &(class->expression)); writeString(stream, indent, "KEYIMAGE", NULL, class->keyimage); - for(i=0; inumlabels; i++) writeLabel(stream, indent, class->labels[i]); - if(class->leader) - writeLeader(stream,indent,class->leader); + for (i = 0; i < class->numlabels; i++) + writeLabel(stream, indent, class->labels[i]); + if (class->leader) + writeLeader(stream, indent, class->leader); writeNumber(stream, indent, "MAXSCALEDENOM", -1, class->maxscaledenom); writeHashTable(stream, indent, "METADATA", &(class->metadata)); writeNumber(stream, indent, "MINSCALEDENOM", -1, class->minscaledenom); writeNumber(stream, indent, "MINFEATURESIZE", -1, class->minfeaturesize); writeKeyword(stream, indent, "STATUS", class->status, 1, MS_OFF, "OFF"); - for(i=0; inumstyles; i++) writeStyle(stream, indent, class->styles[i]); + for (i = 0; i < class->numstyles; i++) + writeStyle(stream, indent, class->styles[i]); writeString(stream, indent, "TEMPLATE", NULL, class->template); writeExpression(stream, indent, "TEXT", &(class->text)); writeString(stream, indent, "TITLE", NULL, class->title); @@ -3370,9 +3744,8 @@ static void writeClass(FILE *stream, int indent, classObj *class) writeBlockEnd(stream, indent, "CLASS"); } -char* msWriteClassToString(classObj *class) -{ - msIOContext context; +char *msWriteClassToString(classObj *class) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -3383,14 +3756,14 @@ char* msWriteClassToString(classObj *class) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeClass(stdout, -1, class); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } int initCompositingFilter(CompositingFilter *filter) { @@ -3400,8 +3773,9 @@ int initCompositingFilter(CompositingFilter *filter) { } void freeCompositingFilter(CompositingFilter *filter) { - if(!filter) return; - if(filter->next) + if (!filter) + return; + if (filter->next) freeCompositingFilter(filter->next); free(filter->filter); free(filter); @@ -3416,8 +3790,9 @@ int initLayerCompositer(LayerCompositer *compositer) { } void freeLayerCompositer(LayerCompositer *compositer) { - if(!compositer) return; - if(compositer->next) + if (!compositer) + return; + if (compositer->next) freeLayerCompositer(compositer->next); freeCompositingFilter(compositer->filter); free(compositer); @@ -3426,11 +3801,10 @@ void freeLayerCompositer(LayerCompositer *compositer) { /* ** Initialize, load and free a single layer structure */ -int initLayer(layerObj *layer, mapObj *map) -{ - if (layer==NULL) { +int initLayer(layerObj *layer, mapObj *map) { + if (layer == NULL) { msSetError(MS_MEMERR, "Layer is null", "initLayer()"); - return(-1); + return (-1); } layer->debug = (int)msGetGlobalDebugLevel(); MS_REFCNT_INIT(layer); @@ -3453,7 +3827,8 @@ int initLayer(layerObj *layer, mapObj *map) layer->type = -1; layer->toleranceunits = MS_PIXELS; - layer->tolerance = -1; /* perhaps this should have a different value based on type */ + layer->tolerance = + -1; /* perhaps this should have a different value based on type */ layer->symbolscaledenom = -1.0; /* -1 means nothing is set */ layer->scalefactor = 1.0; @@ -3466,7 +3841,7 @@ int initLayer(layerObj *layer, mapObj *map) layer->sizeunits = MS_PIXELS; layer->maxfeatures = -1; /* no quota */ - layer->startindex = -1; /*used for pagination*/ + layer->startindex = -1; /*used for pagination*/ layer->scaletokens = NULL; layer->numscaletokens = 0; @@ -3479,10 +3854,10 @@ int initLayer(layerObj *layer, mapObj *map) layer->classitemindex = -1; layer->units = MS_METERS; - if(msInitProjection(&(layer->projection)) == -1) return(-1); + if (msInitProjection(&(layer->projection)) == -1) + return (-1); - if( map ) - { + if (map) { msProjectionInheritContextFrom(&(layer->projection), &(map->projection)); } @@ -3492,7 +3867,7 @@ int initLayer(layerObj *layer, mapObj *map) initCluster(&layer->cluster); - MS_INIT_COLOR(layer->offsite, -1,-1,-1, 255); + MS_INIT_COLOR(layer->offsite, -1, -1, -1, 255); layer->labelcache = MS_ON; layer->postlabelcache = MS_FALSE; @@ -3527,13 +3902,15 @@ int initLayer(layerObj *layer, mapObj *map) layer->iteminfo = NULL; layer->numitems = 0; - layer->resultcache= NULL; + layer->resultcache = NULL; msInitExpression(&(layer->filter)); layer->filteritem = NULL; layer->filteritemindex = -1; - layer->requires = layer->labelrequires = NULL; + layer-> + requires + = layer->labelrequires = NULL; initHashTable(&(layer->metadata)); initHashTable(&(layer->bindvals)); @@ -3545,8 +3922,8 @@ int initLayer(layerObj *layer, mapObj *map) layer->numprocessing = 0; layer->processing = NULL; layer->numjoins = 0; - layer->joins = (joinObj *) malloc(MS_MAXJOINS*sizeof(joinObj)); - MS_CHECK_ALLOC(layer->joins, MS_MAXJOINS*sizeof(joinObj), -1); + layer->joins = (joinObj *)malloc(MS_MAXJOINS * sizeof(joinObj)); + MS_CHECK_ALLOC(layer->joins, MS_MAXJOINS * sizeof(joinObj), -1); layer->extent.minx = -1.0; layer->extent.miny = -1.0; @@ -3574,17 +3951,17 @@ int initLayer(layerObj *layer, mapObj *map) initHashTable(&(layer->connectionoptions)); - return(0); + return (0); } -int initScaleToken(scaleTokenObj* token) { +int initScaleToken(scaleTokenObj *token) { token->n_entries = 0; token->name = NULL; token->tokens = NULL; return MS_SUCCESS; } -int freeScaleTokenEntry( scaleTokenEntryObj *token) { +int freeScaleTokenEntry(scaleTokenEntryObj *token) { msFree(token->value); return MS_SUCCESS; } @@ -3592,25 +3969,25 @@ int freeScaleTokenEntry( scaleTokenEntryObj *token) { int freeScaleToken(scaleTokenObj *scaletoken) { int i; msFree(scaletoken->name); - for(i=0;in_entries;i++) { + for (i = 0; i < scaletoken->n_entries; i++) { freeScaleTokenEntry(&scaletoken->tokens[i]); } msFree(scaletoken->tokens); return MS_SUCCESS; } -int freeLayer(layerObj *layer) -{ +int freeLayer(layerObj *layer) { int i; - if (!layer) return MS_FAILURE; - if( MS_REFCNT_DECR_IS_NOT_ZERO(layer) ) { + if (!layer) + return MS_FAILURE; + if (MS_REFCNT_DECR_IS_NOT_ZERO(layer)) { return MS_FAILURE; } if (layer->debug >= MS_DEBUGLEVEL_VVV) - msDebug("freeLayer(): freeing layer at %p.\n",layer); + msDebug("freeLayer(): freeing layer at %p.\n", layer); - if(msLayerIsOpen(layer)) + if (msLayerIsOpen(layer)) msLayerClose(layer); msFree(layer->name); @@ -3639,27 +4016,27 @@ int freeLayer(layerObj *layer) freeCluster(&layer->cluster); - for(i=0; imaxclasses; i++) { + for (i = 0; i < layer->maxclasses; i++) { if (layer->class[i] != NULL) { - layer->class[i]->layer=NULL; - if ( freeClass(layer->class[i]) == MS_SUCCESS ) { + layer->class[i]->layer = NULL; + if (freeClass(layer->class[i]) == MS_SUCCESS) { msFree(layer->class[i]); } } } msFree(layer->class); - if(layer->numscaletokens>0) { - for(i=0;inumscaletokens;i++) { + if (layer->numscaletokens > 0) { + for (i = 0; i < layer->numscaletokens; i++) { freeScaleToken(&layer->scaletokens[i]); } msFree(layer->scaletokens); } - if(layer->features) + if (layer->features) freeFeatureList(layer->features); - if(layer->resultcache) { + if (layer->resultcache) { cleanupResultCache(layer->resultcache); msFree(layer->resultcache); } @@ -3672,14 +4049,17 @@ int freeLayer(layerObj *layer) msFree(layer->requires); msFree(layer->labelrequires); - if(&(layer->metadata)) msFreeHashItems(&(layer->metadata)); - if(&(layer->validation)) msFreeHashItems(&(layer->validation)); - if(&(layer->bindvals)) msFreeHashItems(&layer->bindvals); + if (&(layer->metadata)) + msFreeHashItems(&(layer->metadata)); + if (&(layer->validation)) + msFreeHashItems(&(layer->validation)); + if (&(layer->bindvals)) + msFreeHashItems(&layer->bindvals); - if(layer->numprocessing > 0) + if (layer->numprocessing > 0) msFreeCharArray(layer->processing, layer->numprocessing); - for(i=0; inumjoins; i++) /* each join */ + for (i = 0; i < layer->numjoins; i++) /* each join */ freeJoin(&(layer->joins[i])); msFree(layer->joins); layer->numjoins = 0; @@ -3687,11 +4067,11 @@ int freeLayer(layerObj *layer) layer->classgroup = NULL; msFree(layer->mask); - if(layer->maskimage) { + if (layer->maskimage) { msFreeImage(layer->maskimage); } - if(layer->compositer) { + if (layer->compositer) { freeLayerCompositer(layer->compositer); } @@ -3703,11 +4083,12 @@ int freeLayer(layerObj *layer) msFreeExpression(&(layer->utfdata)); msFree(layer->utfitem); - for(i=0;isortBy.nProperties;i++) - msFree(layer->sortBy.properties[i].item); + for (i = 0; i < layer->sortBy.nProperties; i++) + msFree(layer->sortBy.properties[i].item); msFree(layer->sortBy.properties); - if(&(layer->connectionoptions)) msFreeHashItems(&layer->connectionoptions); + if (&(layer->connectionoptions)) + msFreeHashItems(&layer->connectionoptions); return MS_SUCCESS; } @@ -3724,8 +4105,7 @@ int freeLayer(layerObj *layer) ** ** Returns a reference to the new classObj on success, NULL on error. */ -classObj *msGrowLayerClasses( layerObj *layer ) -{ +classObj *msGrowLayerClasses(layerObj *layer) { /* Do we need to increase the size of class[] by MS_CLASS_ALLOCSIZE? */ if (layer->numclasses == layer->maxclasses) { @@ -3735,545 +4115,657 @@ classObj *msGrowLayerClasses( layerObj *layer ) newsize = layer->maxclasses + MS_CLASS_ALLOCSIZE; /* Alloc/realloc classes */ - newClassPtr = (classObj**)realloc(layer->class, - newsize*sizeof(classObj*)); - MS_CHECK_ALLOC(newClassPtr, newsize*sizeof(classObj*), NULL); + newClassPtr = + (classObj **)realloc(layer->class, newsize * sizeof(classObj *)); + MS_CHECK_ALLOC(newClassPtr, newsize * sizeof(classObj *), NULL); layer->class = newClassPtr; layer->maxclasses = newsize; - for(i=layer->numclasses; imaxclasses; i++) { + for (i = layer->numclasses; i < layer->maxclasses; i++) { layer->class[i] = NULL; } } - if (layer->class[layer->numclasses]==NULL) { - layer->class[layer->numclasses]=(classObj*)calloc(1,sizeof(classObj)); + if (layer->class[layer->numclasses] == NULL) { + layer->class[layer->numclasses] = (classObj *)calloc(1, sizeof(classObj)); MS_CHECK_ALLOC(layer->class[layer->numclasses], sizeof(classObj), NULL); } return layer->class[layer->numclasses]; } -scaleTokenObj *msGrowLayerScaletokens( layerObj *layer ) -{ - layer->scaletokens = msSmallRealloc(layer->scaletokens,(layer->numscaletokens+1)*sizeof(scaleTokenObj)); - memset(&layer->scaletokens[layer->numscaletokens],0,sizeof(scaleTokenObj)); +scaleTokenObj *msGrowLayerScaletokens(layerObj *layer) { + layer->scaletokens = msSmallRealloc( + layer->scaletokens, (layer->numscaletokens + 1) * sizeof(scaleTokenObj)); + memset(&layer->scaletokens[layer->numscaletokens], 0, sizeof(scaleTokenObj)); return &layer->scaletokens[layer->numscaletokens]; } int loadScaletoken(scaleTokenObj *token, layerObj *layer) { (void)layer; - for(;;) { + for (;;) { int stop = 0; - switch(msyylex()) { - case(EOF): - msSetError(MS_EOFERR, NULL, "loadScaletoken()"); - return(MS_FAILURE); - case(NAME): - if(getString(&token->name) == MS_FAILURE) return(MS_FAILURE); - break; - case(VALUES): - for(;;) { - if(stop) break; - switch(msyylex()) { - case(EOF): - msSetError(MS_EOFERR, NULL, "loadScaletoken()"); - return(MS_FAILURE); - case(END): - stop = 1; - if(token->n_entries == 0) { - msSetError(MS_PARSEERR,"Scaletoken (line:%d) has no VALUES defined","loadScaleToken()",msyylineno); - return(MS_FAILURE); - } - token->tokens[token->n_entries-1].maxscale = DBL_MAX; - break; - case(MS_STRING): - /* we have a key */ - token->tokens = msSmallRealloc(token->tokens,(token->n_entries+1)*sizeof(scaleTokenEntryObj)); - - if(1 != sscanf(msyystring_buffer,"%lf",&token->tokens[token->n_entries].minscale)) { - msSetError(MS_PARSEERR, "failed to parse SCALETOKEN VALUE (%s):(line %d), expecting \"minscale\"", "loadScaletoken()", - msyystring_buffer,msyylineno); - return(MS_FAILURE); - } - if(token->n_entries == 0) { - /* check supplied value was 0*/ - if(token->tokens[0].minscale != 0) { - msSetError(MS_PARSEERR, "First SCALETOKEN VALUE (%s):(line %d) must be zero, expecting \"0\"", "loadScaletoken()", - msyystring_buffer,msyylineno); - return(MS_FAILURE); - } - } else { - /* set max scale of previous token */ - token->tokens[token->n_entries-1].maxscale = token->tokens[token->n_entries].minscale; - } - token->tokens[token->n_entries].value = NULL; - if(getString(&(token->tokens[token->n_entries].value)) == MS_FAILURE) return(MS_FAILURE); - token->n_entries++; - break; - default: - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadScaletoken()", msyystring_buffer, msyylineno ); - return(MS_FAILURE); - } - } - break; - case(END): - if(!token->name || !*(token->name)) { - msSetError(MS_PARSEERR,"ScaleToken missing mandatory NAME entry (line %d)","loadScaleToken()",msyylineno); - return MS_FAILURE; - } - if(token->n_entries == 0) { - msSetError(MS_PARSEERR,"ScaleToken missing at least one VALUES entry (line %d)","loadScaleToken()",msyylineno); - return MS_FAILURE; + switch (msyylex()) { + case (EOF): + msSetError(MS_EOFERR, NULL, "loadScaletoken()"); + return (MS_FAILURE); + case (NAME): + if (getString(&token->name) == MS_FAILURE) + return (MS_FAILURE); + break; + case (VALUES): + for (;;) { + if (stop) + break; + switch (msyylex()) { + case (EOF): + msSetError(MS_EOFERR, NULL, "loadScaletoken()"); + return (MS_FAILURE); + case (END): + stop = 1; + if (token->n_entries == 0) { + msSetError(MS_PARSEERR, + "Scaletoken (line:%d) has no VALUES defined", + "loadScaleToken()", msyylineno); + return (MS_FAILURE); + } + token->tokens[token->n_entries - 1].maxscale = DBL_MAX; + break; + case (MS_STRING): + /* we have a key */ + token->tokens = + msSmallRealloc(token->tokens, (token->n_entries + 1) * + sizeof(scaleTokenEntryObj)); + + if (1 != sscanf(msyystring_buffer, "%lf", + &token->tokens[token->n_entries].minscale)) { + msSetError(MS_PARSEERR, + "failed to parse SCALETOKEN VALUE (%s):(line %d), " + "expecting \"minscale\"", + "loadScaletoken()", msyystring_buffer, msyylineno); + return (MS_FAILURE); + } + if (token->n_entries == 0) { + /* check supplied value was 0*/ + if (token->tokens[0].minscale != 0) { + msSetError(MS_PARSEERR, + "First SCALETOKEN VALUE (%s):(line %d) must be zero, " + "expecting \"0\"", + "loadScaletoken()", msyystring_buffer, msyylineno); + return (MS_FAILURE); + } + } else { + /* set max scale of previous token */ + token->tokens[token->n_entries - 1].maxscale = + token->tokens[token->n_entries].minscale; + } + token->tokens[token->n_entries].value = NULL; + if (getString(&(token->tokens[token->n_entries].value)) == MS_FAILURE) + return (MS_FAILURE); + token->n_entries++; + break; + default: + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadScaletoken()", msyystring_buffer, msyylineno); + return (MS_FAILURE); } - return MS_SUCCESS; - default: - msSetError(MS_IDENTERR, "Parsing error 2 near (%s):(line %d)", "loadScaletoken()", msyystring_buffer, msyylineno ); - return(MS_FAILURE); + } + break; + case (END): + if (!token->name || !*(token->name)) { + msSetError(MS_PARSEERR, + "ScaleToken missing mandatory NAME entry (line %d)", + "loadScaleToken()", msyylineno); + return MS_FAILURE; + } + if (token->n_entries == 0) { + msSetError(MS_PARSEERR, + "ScaleToken missing at least one VALUES entry (line %d)", + "loadScaleToken()", msyylineno); + return MS_FAILURE; + } + return MS_SUCCESS; + default: + msSetError(MS_IDENTERR, "Parsing error 2 near (%s):(line %d)", + "loadScaletoken()", msyystring_buffer, msyylineno); + return (MS_FAILURE); } } /* next token*/ } int loadLayerCompositer(LayerCompositer *compositer) { - for(;;) { - switch(msyylex()) { - case COMPFILTER: { - CompositingFilter **filter = &compositer->filter; - while(*filter) { - filter = &((*filter)->next); - } - *filter = msSmallMalloc(sizeof(CompositingFilter)); - initCompositingFilter(*filter); - if(getString(&((*filter)->filter)) == MS_FAILURE) return(MS_FAILURE); + for (;;) { + switch (msyylex()) { + case COMPFILTER: { + CompositingFilter **filter = &compositer->filter; + while (*filter) { + filter = &((*filter)->next); } - break; - case COMPOP: { - char *compop=NULL; - if(getString(&compop) == MS_FAILURE) return(MS_FAILURE); - else if(!strcmp(compop,"clear")) - compositer->comp_op = MS_COMPOP_CLEAR; - else if(!strcmp(compop,"color-burn")) - compositer->comp_op = MS_COMPOP_COLOR_BURN; - else if(!strcmp(compop,"color-dodge")) - compositer->comp_op = MS_COMPOP_COLOR_DODGE; - else if(!strcmp(compop,"contrast")) - compositer->comp_op = MS_COMPOP_CONTRAST; - else if(!strcmp(compop,"darken")) - compositer->comp_op = MS_COMPOP_DARKEN; - else if(!strcmp(compop,"difference")) - compositer->comp_op = MS_COMPOP_DIFFERENCE; - else if(!strcmp(compop,"dst")) - compositer->comp_op = MS_COMPOP_DST; - else if(!strcmp(compop,"dst-atop")) - compositer->comp_op = MS_COMPOP_DST_ATOP; - else if(!strcmp(compop,"dst-in")) - compositer->comp_op = MS_COMPOP_DST_IN; - else if(!strcmp(compop,"dst-out")) - compositer->comp_op = MS_COMPOP_DST_OUT; - else if(!strcmp(compop,"dst-over")) - compositer->comp_op = MS_COMPOP_DST_OVER; - else if(!strcmp(compop,"exclusion")) - compositer->comp_op = MS_COMPOP_EXCLUSION; - else if(!strcmp(compop,"hard-light")) - compositer->comp_op = MS_COMPOP_HARD_LIGHT; - else if(!strcmp(compop,"invert")) - compositer->comp_op = MS_COMPOP_INVERT; - else if(!strcmp(compop,"invert-rgb")) - compositer->comp_op = MS_COMPOP_INVERT_RGB; - else if(!strcmp(compop,"lighten")) - compositer->comp_op = MS_COMPOP_LIGHTEN; - else if(!strcmp(compop,"minus")) - compositer->comp_op = MS_COMPOP_MINUS; - else if(!strcmp(compop,"multiply")) - compositer->comp_op = MS_COMPOP_MULTIPLY; - else if(!strcmp(compop,"overlay")) - compositer->comp_op = MS_COMPOP_OVERLAY; - else if(!strcmp(compop,"plus")) - compositer->comp_op = MS_COMPOP_PLUS; - else if(!strcmp(compop,"screen")) - compositer->comp_op = MS_COMPOP_SCREEN; - else if(!strcmp(compop,"soft-light")) - compositer->comp_op = MS_COMPOP_SOFT_LIGHT; - else if(!strcmp(compop,"src")) - compositer->comp_op = MS_COMPOP_SRC; - else if(!strcmp(compop,"src-atop")) - compositer->comp_op = MS_COMPOP_SRC_ATOP; - else if(!strcmp(compop,"src-in")) - compositer->comp_op = MS_COMPOP_SRC_IN; - else if(!strcmp(compop,"src-out")) - compositer->comp_op = MS_COMPOP_SRC_OUT; - else if(!strcmp(compop,"src-over")) - compositer->comp_op = MS_COMPOP_SRC_OVER; - else if(!strcmp(compop,"xor")) - compositer->comp_op = MS_COMPOP_XOR; - else { - msSetError(MS_PARSEERR,"Unknown COMPOP \"%s\"", "loadLayerCompositer()", compop); - free(compop); - if (compositer->filter) { - msFree(compositer->filter->filter); - msFree(compositer->filter); - compositer->filter=NULL; - } - return MS_FAILURE; - } + *filter = msSmallMalloc(sizeof(CompositingFilter)); + initCompositingFilter(*filter); + if (getString(&((*filter)->filter)) == MS_FAILURE) + return (MS_FAILURE); + } break; + case COMPOP: { + char *compop = NULL; + if (getString(&compop) == MS_FAILURE) + return (MS_FAILURE); + else if (!strcmp(compop, "clear")) + compositer->comp_op = MS_COMPOP_CLEAR; + else if (!strcmp(compop, "color-burn")) + compositer->comp_op = MS_COMPOP_COLOR_BURN; + else if (!strcmp(compop, "color-dodge")) + compositer->comp_op = MS_COMPOP_COLOR_DODGE; + else if (!strcmp(compop, "contrast")) + compositer->comp_op = MS_COMPOP_CONTRAST; + else if (!strcmp(compop, "darken")) + compositer->comp_op = MS_COMPOP_DARKEN; + else if (!strcmp(compop, "difference")) + compositer->comp_op = MS_COMPOP_DIFFERENCE; + else if (!strcmp(compop, "dst")) + compositer->comp_op = MS_COMPOP_DST; + else if (!strcmp(compop, "dst-atop")) + compositer->comp_op = MS_COMPOP_DST_ATOP; + else if (!strcmp(compop, "dst-in")) + compositer->comp_op = MS_COMPOP_DST_IN; + else if (!strcmp(compop, "dst-out")) + compositer->comp_op = MS_COMPOP_DST_OUT; + else if (!strcmp(compop, "dst-over")) + compositer->comp_op = MS_COMPOP_DST_OVER; + else if (!strcmp(compop, "exclusion")) + compositer->comp_op = MS_COMPOP_EXCLUSION; + else if (!strcmp(compop, "hard-light")) + compositer->comp_op = MS_COMPOP_HARD_LIGHT; + else if (!strcmp(compop, "invert")) + compositer->comp_op = MS_COMPOP_INVERT; + else if (!strcmp(compop, "invert-rgb")) + compositer->comp_op = MS_COMPOP_INVERT_RGB; + else if (!strcmp(compop, "lighten")) + compositer->comp_op = MS_COMPOP_LIGHTEN; + else if (!strcmp(compop, "minus")) + compositer->comp_op = MS_COMPOP_MINUS; + else if (!strcmp(compop, "multiply")) + compositer->comp_op = MS_COMPOP_MULTIPLY; + else if (!strcmp(compop, "overlay")) + compositer->comp_op = MS_COMPOP_OVERLAY; + else if (!strcmp(compop, "plus")) + compositer->comp_op = MS_COMPOP_PLUS; + else if (!strcmp(compop, "screen")) + compositer->comp_op = MS_COMPOP_SCREEN; + else if (!strcmp(compop, "soft-light")) + compositer->comp_op = MS_COMPOP_SOFT_LIGHT; + else if (!strcmp(compop, "src")) + compositer->comp_op = MS_COMPOP_SRC; + else if (!strcmp(compop, "src-atop")) + compositer->comp_op = MS_COMPOP_SRC_ATOP; + else if (!strcmp(compop, "src-in")) + compositer->comp_op = MS_COMPOP_SRC_IN; + else if (!strcmp(compop, "src-out")) + compositer->comp_op = MS_COMPOP_SRC_OUT; + else if (!strcmp(compop, "src-over")) + compositer->comp_op = MS_COMPOP_SRC_OVER; + else if (!strcmp(compop, "xor")) + compositer->comp_op = MS_COMPOP_XOR; + else { + msSetError(MS_PARSEERR, "Unknown COMPOP \"%s\"", + "loadLayerCompositer()", compop); free(compop); + return MS_FAILURE; } - break; - case END: - return MS_SUCCESS; - case OPACITY: - if (getInteger(&(compositer->opacity), MS_NUM_CHECK_RANGE, 0, 100) == -1) { - if (compositer->filter) { - msFree(compositer->filter->filter); - msFree(compositer->filter); - compositer->filter=NULL; - } - msSetError(MS_PARSEERR,"OPACITY must be between 0 and 100 (line %d)","loadLayerCompositer()",msyylineno); - return MS_FAILURE; - } - break; - default: - if (compositer->filter) { - msFree(compositer->filter->filter); - msFree(compositer->filter); - compositer->filter=NULL; - } - msSetError(MS_IDENTERR, "Parsing error 2 near (%s):(line %d)", "loadLayerCompositer()", msyystring_buffer, msyylineno ); - return(MS_FAILURE); + free(compop); + } break; + case END: + return MS_SUCCESS; + case OPACITY: + if (getInteger(&(compositer->opacity), MS_NUM_CHECK_RANGE, 0, 100) == + -1) { + msSetError(MS_PARSEERR, "OPACITY must be between 0 and 100 (line %d)", + "loadLayerCompositer()", msyylineno); + return MS_FAILURE; + } + break; + default: + msSetError(MS_IDENTERR, "Parsing error 2 near (%s):(line %d)", + "loadLayerCompositer()", msyystring_buffer, msyylineno); + return (MS_FAILURE); } } } -int loadLayer(layerObj *layer, mapObj *map) -{ +int loadLayer(layerObj *layer, mapObj *map) { int type; layer->map = (mapObj *)map; - for(;;) { - switch(msyylex()) { - case(BINDVALS): - if(loadHashTable(&(layer->bindvals)) != MS_SUCCESS) return(-1); - break; - case(CLASS): - if (msGrowLayerClasses(layer) == NULL) - return(-1); - initClass(layer->class[layer->numclasses]); - if(loadClass(layer->class[layer->numclasses], layer) == -1) return(-1); - layer->numclasses++; - break; - case(CLUSTER): - initCluster(&layer->cluster); - if(loadCluster(&layer->cluster) == -1) return(-1); - break; - case(CLASSGROUP): - if(getString(&layer->classgroup) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(CLASSITEM): - if(getString(&layer->classitem) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(COMPOSITE): { - LayerCompositer *compositer = msSmallMalloc(sizeof(LayerCompositer)); - initLayerCompositer(compositer); - if(MS_FAILURE == loadLayerCompositer(compositer)) { - msFree(compositer); - return -1; - } - if(!layer->compositer) { - layer->compositer = compositer; - } else { - LayerCompositer *lctmp = layer->compositer; - while(lctmp->next) lctmp = lctmp->next; - lctmp->next = compositer; - } - break; + for (;;) { + switch (msyylex()) { + case (BINDVALS): + if (loadHashTable(&(layer->bindvals)) != MS_SUCCESS) + return (-1); + break; + case (CLASS): + if (msGrowLayerClasses(layer) == NULL) + return (-1); + initClass(layer->class[layer->numclasses]); + if (loadClass(layer->class[layer->numclasses], layer) == -1) { + freeClass(layer->class[layer->numclasses]); + free(layer->class[layer->numclasses]); + layer->class[layer->numclasses] = NULL; + return (-1); } - case(CONNECTION): - if(getString(&layer->connection) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(CONNECTIONTYPE): - if((type = getSymbol(13, MS_OGR, MS_POSTGIS, MS_WMS, MS_ORACLESPATIAL, MS_WFS, MS_GRATICULE, MS_PLUGIN, MS_UNION, MS_UVRASTER, MS_CONTOUR, MS_KERNELDENSITY, MS_IDW, MS_FLATGEOBUF)) == -1) return(-1); - layer->connectiontype = type; - break; - case(DATA): - if(getString(&layer->data) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(DEBUG): - if((layer->debug = getSymbol(3, MS_ON,MS_OFF, MS_NUMBER)) == -1) return(-1); - if(layer->debug == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, 0, 5) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid DEBUG level, must be between 0 and 5 (line %d)", "loadLayer()", msyylineno); - return(-1); - } - layer->debug = (int) msyynumber; - } - break; - case(EOF): - msSetError(MS_EOFERR, NULL, "loadLayer()"); - return(-1); - break; - case(ENCODING): - if(getString(&layer->encoding) == MS_FAILURE) return(-1); - break; - case(END): - if((int)layer->type == -1) { - msSetError(MS_MISCERR, "Layer type not set.", "loadLayer()"); - return(-1); - } - - return(0); - break; - case(EXTENT): { - if(getDouble(&(layer->extent.minx), MS_NUM_CHECK_NONE, -1, -1) == -1) return(-1); - if(getDouble(&(layer->extent.miny), MS_NUM_CHECK_NONE, -1, -1) == -1) return(-1); - if(getDouble(&(layer->extent.maxx), MS_NUM_CHECK_NONE, -1, -1) == -1) return(-1); - if(getDouble(&(layer->extent.maxy), MS_NUM_CHECK_NONE, -1, -1) == -1) return(-1); - if (!MS_VALID_EXTENT(layer->extent)) { - msSetError(MS_MISCERR, "Given layer extent is invalid. Check that it is in the form: minx, miny, maxx, maxy", "loadLayer()"); - return(-1); - } - break; + layer->numclasses++; + break; + case (CLUSTER): + if (loadCluster(&layer->cluster) == -1) + return (-1); + break; + case (CLASSGROUP): + if (getString(&layer->classgroup) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (CLASSITEM): + if (getString(&layer->classitem) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (COMPOSITE): { + LayerCompositer *compositer = msSmallMalloc(sizeof(LayerCompositer)); + initLayerCompositer(compositer); + if (MS_FAILURE == loadLayerCompositer(compositer)) { + freeLayerCompositer(compositer); + return -1; } - case(FEATURE): - if((int)layer->type == -1) { - msSetError(MS_MISCERR, "Layer type must be set before defining inline features.", "loadLayer()"); - return(-1); + if (!layer->compositer) { + layer->compositer = compositer; + } else { + LayerCompositer *lctmp = layer->compositer; + while (lctmp->next) + lctmp = lctmp->next; + lctmp->next = compositer; + } + break; + } + case (CONNECTION): + if (getString(&layer->connection) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (CONNECTIONTYPE): + if ((type = getSymbol(13, MS_OGR, MS_POSTGIS, MS_WMS, MS_ORACLESPATIAL, + MS_WFS, MS_GRATICULE, MS_PLUGIN, MS_UNION, + MS_UVRASTER, MS_CONTOUR, MS_KERNELDENSITY, MS_IDW, + MS_FLATGEOBUF)) == -1) + return (-1); + layer->connectiontype = type; + break; + case (DATA): + if (getString(&layer->data) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (DEBUG): + if ((layer->debug = getSymbol(3, MS_ON, MS_OFF, MS_NUMBER)) == -1) + return (-1); + if (layer->debug == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, 0, 5) == MS_FAILURE) { + msSetError(MS_MISCERR, + "Invalid DEBUG level, must be between 0 and 5 (line %d)", + "loadLayer()", msyylineno); + return (-1); } + layer->debug = (int)msyynumber; + } + break; + case (EOF): + msSetError(MS_EOFERR, NULL, "loadLayer()"); + return (-1); + break; + case (ENCODING): + if (getString(&layer->encoding) == MS_FAILURE) + return (-1); + break; + case (END): + if ((int)layer->type == -1) { + msSetError(MS_MISCERR, "Layer type not set.", "loadLayer()"); + return (-1); + } - if(layer->type == MS_LAYER_POLYGON) - type = MS_SHAPE_POLYGON; - else if(layer->type == MS_LAYER_LINE) - type = MS_SHAPE_LINE; - else - type = MS_SHAPE_POINT; + return (0); + break; + case (EXTENT): { + if (getDouble(&(layer->extent.minx), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (-1); + if (getDouble(&(layer->extent.miny), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (-1); + if (getDouble(&(layer->extent.maxx), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (-1); + if (getDouble(&(layer->extent.maxy), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (-1); + if (!MS_VALID_EXTENT(layer->extent)) { + msSetError(MS_MISCERR, + "Given layer extent is invalid. Check that it is in the " + "form: minx, miny, maxx, maxy", + "loadLayer()"); + return (-1); + } + break; + } + case (FEATURE): + if ((int)layer->type == -1) { + msSetError(MS_MISCERR, + "Layer type must be set before defining inline features.", + "loadLayer()"); + return (-1); + } - layer->connectiontype = MS_INLINE; + if (layer->type == MS_LAYER_POLYGON) + type = MS_SHAPE_POLYGON; + else if (layer->type == MS_LAYER_LINE) + type = MS_SHAPE_LINE; + else + type = MS_SHAPE_POINT; - if(loadFeature(layer, type) == MS_FAILURE) return(-1); - break; - case(FILTER): - if(loadExpression(&(layer->filter)) == -1) return(-1); /* loadExpression() cleans up previously allocated expression */ - break; - case(FILTERITEM): - if(getString(&layer->filteritem) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(FOOTER): - if(getString(&layer->footer) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(GRID): - layer->connectiontype = MS_GRATICULE; - if (layer->grid) { - freeGrid(layer->grid); - msFree(layer->grid); - } - layer->grid = (void *) malloc(sizeof(graticuleObj)); - MS_CHECK_ALLOC(layer->grid, sizeof(graticuleObj), -1); + layer->connectiontype = MS_INLINE; - initGrid(layer->grid); - loadGrid(layer); - break; - case(GROUP): - if(getString(&layer->group) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(GEOMTRANSFORM): { - int s; - if((s = getSymbol(1, MS_EXPRESSION)) == -1) return(MS_FAILURE); - /* handle expression case here for the moment */ - msFree(layer->_geomtransform.string); - layer->_geomtransform.string = msStrdup(msyystring_buffer); - layer->_geomtransform.type = MS_GEOMTRANSFORM_EXPRESSION; + if (loadFeature(layer, type) == MS_FAILURE) + return (-1); + break; + case (FILTER): + if (loadExpression(&(layer->filter)) == -1) + return (-1); /* loadExpression() cleans up previously allocated + expression */ + break; + case (FILTERITEM): + if (getString(&layer->filteritem) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (FOOTER): + if (getString(&layer->footer) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (GRID): + layer->connectiontype = MS_GRATICULE; + if (layer->grid) { + freeGrid(layer->grid); + msFree(layer->grid); } + layer->grid = (void *)malloc(sizeof(graticuleObj)); + MS_CHECK_ALLOC(layer->grid, sizeof(graticuleObj), -1); + + initGrid(layer->grid); + loadGrid(layer); break; - case(HEADER): - if(getString(&layer->header) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(JOIN): - if(layer->numjoins == MS_MAXJOINS) { /* no room */ - msSetError(MS_IDENTERR, "Maximum number of joins reached.", "loadLayer()"); - return(-1); - } + case (GROUP): + if (getString(&layer->group) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (GEOMTRANSFORM): { + int s; + if ((s = getSymbol(1, MS_EXPRESSION)) == -1) + return (MS_FAILURE); + /* handle expression case here for the moment */ + msFree(layer->_geomtransform.string); + layer->_geomtransform.string = msStrdup(msyystring_buffer); + layer->_geomtransform.type = MS_GEOMTRANSFORM_EXPRESSION; + } break; + case (HEADER): + if (getString(&layer->header) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (JOIN): + if (layer->numjoins == MS_MAXJOINS) { /* no room */ + msSetError(MS_IDENTERR, "Maximum number of joins reached.", + "loadLayer()"); + return (-1); + } - if(loadJoin(&(layer->joins[layer->numjoins])) == -1) return(-1); - layer->numjoins++; - break; - case(LABELCACHE): - if((layer->labelcache = getSymbol(2, MS_ON, MS_OFF)) == -1) return(-1); - break; - case(LABELITEM): - if(getString(&layer->labelitem) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(LABELMAXSCALE): - case(LABELMAXSCALEDENOM): - if(getDouble(&(layer->labelmaxscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); - break; - case(LABELMINSCALE): - case(LABELMINSCALEDENOM): - if(getDouble(&(layer->labelminscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); - break; - case(LABELREQUIRES): - if(getString(&layer->labelrequires) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(LAYER): - break; /* for string loads */ - case(MASK): - if(getString(&layer->mask) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(MAXFEATURES): - if(getInteger(&(layer->maxfeatures), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(MAXSCALE): - case(MAXSCALEDENOM): - if(getDouble(&(layer->maxscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); - break; - case(MAXGEOWIDTH): - if(getDouble(&(layer->maxgeowidth), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(METADATA): - if(loadHashTable(&(layer->metadata)) != MS_SUCCESS) return(-1); - break; - case(MINSCALE): - case(MINSCALEDENOM): - if(getDouble(&(layer->minscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); - break; - case(MINGEOWIDTH): - if(getDouble(&(layer->mingeowidth), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(MINFEATURESIZE): - if(getInteger(&(layer->minfeaturesize), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(NAME): - if(getString(&layer->name) == MS_FAILURE) return(-1); - break; - case(OFFSITE): - if(loadColor(&(layer->offsite), NULL) != MS_SUCCESS) return(-1); - break; + if (loadJoin(&(layer->joins[layer->numjoins])) == -1) { + freeJoin(&(layer->joins[layer->numjoins])); + return (-1); + } + layer->numjoins++; + break; + case (LABELCACHE): + if ((layer->labelcache = getSymbol(2, MS_ON, MS_OFF)) == -1) + return (-1); + break; + case (LABELITEM): + if (getString(&layer->labelitem) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (LABELMAXSCALE): + case (LABELMAXSCALEDENOM): + if (getDouble(&(layer->labelmaxscaledenom), MS_NUM_CHECK_GTE, 0, -1) == + -1) + return (-1); + break; + case (LABELMINSCALE): + case (LABELMINSCALEDENOM): + if (getDouble(&(layer->labelminscaledenom), MS_NUM_CHECK_GTE, 0, -1) == + -1) + return (-1); + break; + case (LABELREQUIRES): + if (getString(&layer->labelrequires) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (LAYER): + break; /* for string loads */ + case (MASK): + if (getString(&layer->mask) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (MAXFEATURES): + if (getInteger(&(layer->maxfeatures), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (MAXSCALE): + case (MAXSCALEDENOM): + if (getDouble(&(layer->maxscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (-1); + break; + case (MAXGEOWIDTH): + if (getDouble(&(layer->maxgeowidth), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (METADATA): + if (loadHashTable(&(layer->metadata)) != MS_SUCCESS) + return (-1); + break; + case (MINSCALE): + case (MINSCALEDENOM): + if (getDouble(&(layer->minscaledenom), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (-1); + break; + case (MINGEOWIDTH): + if (getDouble(&(layer->mingeowidth), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (MINFEATURESIZE): + if (getInteger(&(layer->minfeaturesize), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (NAME): + if (getString(&layer->name) == MS_FAILURE) + return (-1); + break; + case (OFFSITE): + if (loadColor(&(layer->offsite), NULL) != MS_SUCCESS) + return (-1); + break; - case(CONNECTIONOPTIONS): - if(loadHashTable(&(layer->connectionoptions)) != MS_SUCCESS) return(-1); - break; - case(MS_PLUGIN): { - int rv; - if(map->config) { // value *must* represent a config key - char *value = NULL; - const char *plugin_library = NULL; - - if(getString(&value) == MS_FAILURE) return(-1); - plugin_library = msConfigGetPlugin(map->config, value); - msFree(value); - if(!plugin_library) { - msSetError(MS_MISCERR, "Plugin value not found in config file. See mapserver.org/config_file.html for more information." , "loadLayer()"); - return(-1); - } - layer->plugin_library_original = strdup(plugin_library); - } else { - if(getString(&layer->plugin_library_original) == MS_FAILURE) return(-1); + case (CONNECTIONOPTIONS): + if (loadHashTable(&(layer->connectionoptions)) != MS_SUCCESS) + return (-1); + break; + case (MS_PLUGIN): { + int rv; + if (map->config) { // value *must* represent a config key + char *value = NULL; + const char *plugin_library = NULL; + + if (getString(&value) == MS_FAILURE) + return (-1); + plugin_library = msConfigGetPlugin(map->config, value); + msFree(value); + if (!plugin_library) { + msSetError(MS_MISCERR, + "Plugin value not found in config file. See " + "mapserver.org/mapfile/config.html for more information.", + "loadLayer()"); + return (-1); } - rv = msBuildPluginLibraryPath(&layer->plugin_library, layer->plugin_library_original, map); - if (rv == MS_FAILURE) return(-1); + msFree(layer->plugin_library_original); + layer->plugin_library_original = strdup(plugin_library); + } else { + if (getString(&layer->plugin_library_original) == MS_FAILURE) + return (-1); } + rv = msBuildPluginLibraryPath(&layer->plugin_library, + layer->plugin_library_original, map); + if (rv == MS_FAILURE) + return (-1); + } break; + case (PROCESSING): { + /* NOTE: processing array maintained as size+1 with NULL terminator. + This ensure that CSL (GDAL string list) functions can be + used on the list for easy processing. */ + char *value = NULL; + if (getString(&value) == MS_FAILURE) + return (-1); + msLayerAddProcessing(layer, value); + free(value); + value = NULL; + } break; + case (POSTLABELCACHE): + if ((layer->postlabelcache = getSymbol(2, MS_TRUE, MS_FALSE)) == -1) + return (-1); + if (layer->postlabelcache) + layer->labelcache = MS_OFF; break; - case(PROCESSING): { - /* NOTE: processing array maintained as size+1 with NULL terminator. - This ensure that CSL (GDAL string list) functions can be - used on the list for easy processing. */ - char *value=NULL; - if(getString(&value) == MS_FAILURE) return(-1); - msLayerAddProcessing( layer, value ); - free(value); - value=NULL; + case (PROJECTION): + if (loadProjection(&(layer->projection)) == -1) + return (-1); + layer->project = MS_TRUE; + break; + case (REQUIRES): + if (getString(&layer->requires) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (SCALETOKEN): + if (msGrowLayerScaletokens(layer) == NULL) + return (-1); + initScaleToken(&layer->scaletokens[layer->numscaletokens]); + if (loadScaletoken(&layer->scaletokens[layer->numscaletokens], layer) == + -1) { + freeScaleToken(&layer->scaletokens[layer->numscaletokens]); + return (-1); } + layer->numscaletokens++; break; - case(POSTLABELCACHE): - if((layer->postlabelcache = getSymbol(2, MS_TRUE, MS_FALSE)) == -1) return(-1); - if(layer->postlabelcache) - layer->labelcache = MS_OFF; - break; - case(PROJECTION): - if(loadProjection(&(layer->projection)) == -1) return(-1); - layer->project = MS_TRUE; - break; - case(REQUIRES): - if(getString(&layer->requires) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(SCALETOKEN): - if (msGrowLayerScaletokens(layer) == NULL) - return(-1); - initScaleToken(&layer->scaletokens[layer->numscaletokens]); - if(loadScaletoken(&layer->scaletokens[layer->numscaletokens], layer) == -1) return(-1); - layer->numscaletokens++; - break; - case(SIZEUNITS): - if((layer->sizeunits = getSymbol(8, MS_INCHES,MS_FEET,MS_MILES,MS_METERS,MS_KILOMETERS,MS_NAUTICALMILES,MS_DD,MS_PIXELS)) == -1) return(-1); - break; - case(STATUS): - if((layer->status = getSymbol(3, MS_ON,MS_OFF,MS_DEFAULT)) == -1) return(-1); - break; - case(STYLEITEM): - if(getString(&layer->styleitem) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(SYMBOLSCALE): - case(SYMBOLSCALEDENOM): - if(getDouble(&(layer->symbolscaledenom), MS_NUM_CHECK_GTE, 1, -1) == -1) return(-1); - break; - case(TEMPLATE): - if(getString(&layer->template) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(TILEINDEX): - if(getString(&layer->tileindex) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(TILEITEM): - if(getString(&layer->tileitem) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(TILESRS): - if(getString(&layer->tilesrs) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(TOLERANCE): - if(getDouble(&(layer->tolerance), MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); - break; - case(TOLERANCEUNITS): - if((layer->toleranceunits = getSymbol(8, MS_INCHES,MS_FEET,MS_MILES,MS_METERS,MS_KILOMETERS,MS_NAUTICALMILES,MS_DD,MS_PIXELS)) == -1) return(-1); - break; - case(TRANSFORM): - if((layer->transform = getSymbol(11, MS_TRUE,MS_FALSE, MS_UL,MS_UC,MS_UR,MS_CL,MS_CC,MS_CR,MS_LL,MS_LC,MS_LR)) == -1) return(-1); - break; - case(TYPE): - if((type = getSymbol(9, MS_LAYER_POINT,MS_LAYER_LINE,MS_LAYER_RASTER,MS_LAYER_POLYGON,MS_LAYER_ANNOTATION,MS_LAYER_QUERY,MS_LAYER_CIRCLE,MS_LAYER_CHART,TILEINDEX)) == -1) return(-1); - if(type == TILEINDEX) type = MS_LAYER_TILEINDEX; /* TILEINDEX is also a parameter */ - if(type == MS_LAYER_ANNOTATION) { - msSetError(MS_IDENTERR, "Annotation Layers have been removed. To obtain same functionality, use a layer with label->styles and no class->styles", "loadLayer()"); - return -1; - } - layer->type = type; - break; - case(UNITS): - if((layer->units = getSymbol(9, MS_INCHES,MS_FEET,MS_MILES,MS_METERS,MS_KILOMETERS,MS_NAUTICALMILES,MS_DD,MS_PIXELS,MS_PERCENTAGES)) == -1) return(-1); - break; - case(UTFDATA): - if(loadExpression(&(layer->utfdata)) == -1) return(-1); /* loadExpression() cleans up previously allocated expression */ - break; - case(UTFITEM): - if(getString(&layer->utfitem) == MS_FAILURE) return(-1); - break; - case(VALIDATION): - if(loadHashTable(&(layer->validation)) != MS_SUCCESS) return(-1); - break; - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadLayer()", msyystring_buffer, msyylineno); - return(-1); - } else { - return(0); /* end of a string, not an error */ - } + case (SIZEUNITS): + if ((layer->sizeunits = getSymbol( + 8, MS_INCHES, MS_FEET, MS_MILES, MS_METERS, MS_KILOMETERS, + MS_NAUTICALMILES, MS_DD, MS_PIXELS)) == -1) + return (-1); + break; + case (STATUS): + if ((layer->status = getSymbol(3, MS_ON, MS_OFF, MS_DEFAULT)) == -1) + return (-1); + break; + case (STYLEITEM): + if (getString(&layer->styleitem) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (SYMBOLSCALE): + case (SYMBOLSCALEDENOM): + if (getDouble(&(layer->symbolscaledenom), MS_NUM_CHECK_GTE, 1, -1) == -1) + return (-1); + break; + case (TEMPLATE): + if (getString(&layer->template) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (TILEINDEX): + if (getString(&layer->tileindex) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (TILEITEM): + if (getString(&layer->tileitem) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (TILESRS): + if (getString(&layer->tilesrs) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (TOLERANCE): + if (getDouble(&(layer->tolerance), MS_NUM_CHECK_GTE, 0, -1) == -1) + return (-1); + break; + case (TOLERANCEUNITS): + if ((layer->toleranceunits = getSymbol( + 8, MS_INCHES, MS_FEET, MS_MILES, MS_METERS, MS_KILOMETERS, + MS_NAUTICALMILES, MS_DD, MS_PIXELS)) == -1) + return (-1); + break; + case (TRANSFORM): + if ((layer->transform = + getSymbol(11, MS_TRUE, MS_FALSE, MS_UL, MS_UC, MS_UR, MS_CL, + MS_CC, MS_CR, MS_LL, MS_LC, MS_LR)) == -1) + return (-1); + break; + case (TYPE): + if ((type = + getSymbol(9, MS_LAYER_POINT, MS_LAYER_LINE, MS_LAYER_RASTER, + MS_LAYER_POLYGON, MS_LAYER_ANNOTATION, MS_LAYER_QUERY, + MS_LAYER_CIRCLE, MS_LAYER_CHART, TILEINDEX)) == -1) + return (-1); + if (type == TILEINDEX) + type = MS_LAYER_TILEINDEX; /* TILEINDEX is also a parameter */ + if (type == MS_LAYER_ANNOTATION) { + msSetError(MS_IDENTERR, + "Annotation Layers have been removed. To obtain same " + "functionality, use a layer with label->styles and no " + "class->styles", + "loadLayer()"); + return -1; + } + layer->type = type; + break; + case (UNITS): + if ((layer->units = getSymbol(9, MS_INCHES, MS_FEET, MS_MILES, MS_METERS, + MS_KILOMETERS, MS_NAUTICALMILES, MS_DD, + MS_PIXELS, MS_PERCENTAGES)) == -1) + return (-1); + break; + case (UTFDATA): + if (loadExpression(&(layer->utfdata)) == -1) + return (-1); /* loadExpression() cleans up previously allocated + expression */ + break; + case (UTFITEM): + if (getString(&layer->utfitem) == MS_FAILURE) + return (-1); + break; + case (VALIDATION): + if (loadHashTable(&(layer->validation)) != MS_SUCCESS) + return (-1); + break; + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadLayer()", msyystring_buffer, msyylineno); + return (-1); + } else { + return (0); /* end of a string, not an error */ + } } } /* next token */ } -int msUpdateLayerFromString(layerObj *layer, char *string) -{ +int msUpdateLayerFromString(layerObj *layer, char *string) { int i; - if(!layer || !string) return MS_FAILURE; + if (!layer || !string) + return MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_STRING; msyystring = string; @@ -4281,148 +4773,158 @@ int msUpdateLayerFromString(layerObj *layer, char *string) msyylineno = 1; /* start at line 1 */ - if(loadLayer(layer, layer->map) == -1) { - msReleaseLock( TLOCK_PARSER ); - return MS_FAILURE; /* parse error */; + if (loadLayer(layer, layer->map) == -1) { + msReleaseLock(TLOCK_PARSER); + return MS_FAILURE; /* parse error */ + ; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msyylex_destroy(); /* step through classes to resolve symbol names */ - for(i=0; inumclasses; i++) { - if(classResolveSymbolNames(layer->class[i]) != MS_SUCCESS) return MS_FAILURE; + for (i = 0; i < layer->numclasses; i++) { + if (classResolveSymbolNames(layer->class[i]) != MS_SUCCESS) + return MS_FAILURE; } return MS_SUCCESS; } -static void writeCompositingFilter(FILE *stream, int indent, CompositingFilter *filter) { - while(filter) { +static void writeCompositingFilter(FILE *stream, int indent, + CompositingFilter *filter) { + while (filter) { writeString(stream, indent, "COMPFILTER", "", filter->filter); filter = filter->next; } } -static void writeLayerCompositer(FILE *stream, int indent, LayerCompositer *compositor) { +static void writeLayerCompositer(FILE *stream, int indent, + LayerCompositer *compositor) { indent++; - while(compositor) { + while (compositor) { writeBlockBegin(stream, indent, "COMPOSITE"); writeCompositingFilter(stream, indent, compositor->filter); - if(compositor->comp_op != MS_COMPOP_SRC_OVER) { - switch(compositor->comp_op) { - case MS_COMPOP_CLEAR: - writeString(stream, indent, "COMPOP", NULL, "clear"); - break; - case MS_COMPOP_COLOR_BURN: - writeString(stream, indent, "COMPOP", NULL, "color-burn"); - break; - case MS_COMPOP_COLOR_DODGE: - writeString(stream, indent, "COMPOP", NULL, "color-dodge"); - break; - case MS_COMPOP_CONTRAST: - writeString(stream, indent, "COMPOP", NULL, "contrast"); - break; - case MS_COMPOP_DARKEN: - writeString(stream, indent, "COMPOP", NULL, "darken"); - break; - case MS_COMPOP_DIFFERENCE: - writeString(stream, indent, "COMPOP", NULL, "difference"); - break; - case MS_COMPOP_DST: - writeString(stream, indent, "COMPOP", NULL, "dst"); - break; - case MS_COMPOP_DST_ATOP: - writeString(stream, indent, "COMPOP", NULL, "dst-atop"); - break; - case MS_COMPOP_DST_IN: - writeString(stream, indent, "COMPOP", NULL, "dst-in"); - break; - case MS_COMPOP_DST_OUT: - writeString(stream, indent, "COMPOP", NULL, "dst-out"); - break; - case MS_COMPOP_DST_OVER: - writeString(stream, indent, "COMPOP", NULL, "dst-over"); - break; - case MS_COMPOP_EXCLUSION: - writeString(stream, indent, "COMPOP", NULL, "exclusion"); - break; - case MS_COMPOP_HARD_LIGHT: - writeString(stream, indent, "COMPOP", NULL, "hard-light"); - break; - case MS_COMPOP_INVERT: - writeString(stream, indent, "COMPOP", NULL, "invert"); - break; - case MS_COMPOP_INVERT_RGB: - writeString(stream, indent, "COMPOP", NULL, "invert-rgb"); - break; - case MS_COMPOP_LIGHTEN: - writeString(stream, indent, "COMPOP", NULL, "lighten"); - break; - case MS_COMPOP_MINUS: - writeString(stream, indent, "COMPOP", NULL, "minus"); - break; - case MS_COMPOP_MULTIPLY: - writeString(stream, indent, "COMPOP", NULL, "multiply"); - break; - case MS_COMPOP_OVERLAY: - writeString(stream, indent, "COMPOP", NULL, "overlay"); - break; - case MS_COMPOP_PLUS: - writeString(stream, indent, "COMPOP", NULL, "plus"); - break; - case MS_COMPOP_SCREEN: - writeString(stream, indent, "COMPOP", NULL, "screen"); - break; - case MS_COMPOP_SOFT_LIGHT: - writeString(stream, indent, "COMPOP", NULL, "soft-light"); - break; - case MS_COMPOP_SRC: - writeString(stream, indent, "COMPOP", NULL, "src"); - break; - case MS_COMPOP_SRC_ATOP: - writeString(stream, indent, "COMPOP", NULL, "src-atop"); - break; - case MS_COMPOP_SRC_IN: - writeString(stream, indent, "COMPOP", NULL, "src-in"); - break; - case MS_COMPOP_SRC_OUT: - writeString(stream, indent, "COMPOP", NULL, "src-out"); - break; - case MS_COMPOP_SRC_OVER: - writeString(stream, indent, "COMPOP", NULL, "src-over"); - break; - case MS_COMPOP_XOR: - writeString(stream, indent, "COMPOP", NULL, "xor"); - break; + if (compositor->comp_op != MS_COMPOP_SRC_OVER) { + switch (compositor->comp_op) { + case MS_COMPOP_CLEAR: + writeString(stream, indent, "COMPOP", NULL, "clear"); + break; + case MS_COMPOP_COLOR_BURN: + writeString(stream, indent, "COMPOP", NULL, "color-burn"); + break; + case MS_COMPOP_COLOR_DODGE: + writeString(stream, indent, "COMPOP", NULL, "color-dodge"); + break; + case MS_COMPOP_CONTRAST: + writeString(stream, indent, "COMPOP", NULL, "contrast"); + break; + case MS_COMPOP_DARKEN: + writeString(stream, indent, "COMPOP", NULL, "darken"); + break; + case MS_COMPOP_DIFFERENCE: + writeString(stream, indent, "COMPOP", NULL, "difference"); + break; + case MS_COMPOP_DST: + writeString(stream, indent, "COMPOP", NULL, "dst"); + break; + case MS_COMPOP_DST_ATOP: + writeString(stream, indent, "COMPOP", NULL, "dst-atop"); + break; + case MS_COMPOP_DST_IN: + writeString(stream, indent, "COMPOP", NULL, "dst-in"); + break; + case MS_COMPOP_DST_OUT: + writeString(stream, indent, "COMPOP", NULL, "dst-out"); + break; + case MS_COMPOP_DST_OVER: + writeString(stream, indent, "COMPOP", NULL, "dst-over"); + break; + case MS_COMPOP_EXCLUSION: + writeString(stream, indent, "COMPOP", NULL, "exclusion"); + break; + case MS_COMPOP_HARD_LIGHT: + writeString(stream, indent, "COMPOP", NULL, "hard-light"); + break; + case MS_COMPOP_INVERT: + writeString(stream, indent, "COMPOP", NULL, "invert"); + break; + case MS_COMPOP_INVERT_RGB: + writeString(stream, indent, "COMPOP", NULL, "invert-rgb"); + break; + case MS_COMPOP_LIGHTEN: + writeString(stream, indent, "COMPOP", NULL, "lighten"); + break; + case MS_COMPOP_MINUS: + writeString(stream, indent, "COMPOP", NULL, "minus"); + break; + case MS_COMPOP_MULTIPLY: + writeString(stream, indent, "COMPOP", NULL, "multiply"); + break; + case MS_COMPOP_OVERLAY: + writeString(stream, indent, "COMPOP", NULL, "overlay"); + break; + case MS_COMPOP_PLUS: + writeString(stream, indent, "COMPOP", NULL, "plus"); + break; + case MS_COMPOP_SCREEN: + writeString(stream, indent, "COMPOP", NULL, "screen"); + break; + case MS_COMPOP_SOFT_LIGHT: + writeString(stream, indent, "COMPOP", NULL, "soft-light"); + break; + case MS_COMPOP_SRC: + writeString(stream, indent, "COMPOP", NULL, "src"); + break; + case MS_COMPOP_SRC_ATOP: + writeString(stream, indent, "COMPOP", NULL, "src-atop"); + break; + case MS_COMPOP_SRC_IN: + writeString(stream, indent, "COMPOP", NULL, "src-in"); + break; + case MS_COMPOP_SRC_OUT: + writeString(stream, indent, "COMPOP", NULL, "src-out"); + break; + case MS_COMPOP_SRC_OVER: + writeString(stream, indent, "COMPOP", NULL, "src-over"); + break; + case MS_COMPOP_XOR: + writeString(stream, indent, "COMPOP", NULL, "xor"); + break; } } - writeNumber(stream,indent,"OPACITY",100,compositor->opacity); - writeBlockEnd(stream,indent,"COMPOSITE"); + writeNumber(stream, indent, "OPACITY", 100, compositor->opacity); + writeBlockEnd(stream, indent, "COMPOSITE"); compositor = compositor->next; } } -static void writeLayer(FILE *stream, int indent, layerObj *layer) -{ +static void writeLayer(FILE *stream, int indent, layerObj *layer) { int i; - featureListNodeObjPtr current=NULL; + featureListNodeObjPtr current = NULL; - if(layer->status == MS_DELETE) + if (layer->status == MS_DELETE) return; indent++; writeBlockBegin(stream, indent, "LAYER"); - /* bindvals */ + writeHashTable(stream, indent, "BINDVALS", &(layer->bindvals)); /* class - see below */ writeString(stream, indent, "CLASSGROUP", NULL, layer->classgroup); writeString(stream, indent, "CLASSITEM", NULL, layer->classitem); writeCluster(stream, indent, &(layer->cluster)); writeLayerCompositer(stream, indent, layer->compositer); writeString(stream, indent, "CONNECTION", NULL, layer->connection); - writeKeyword(stream, indent, "CONNECTIONTYPE", layer->connectiontype, 13, MS_OGR, "OGR", MS_POSTGIS, "POSTGIS", MS_WMS, "WMS", MS_ORACLESPATIAL, "ORACLESPATIAL", MS_WFS, "WFS", MS_PLUGIN, "PLUGIN", MS_UNION, "UNION", MS_UVRASTER, "UVRASTER", MS_CONTOUR, "CONTOUR", MS_KERNELDENSITY, "KERNELDENSITY", MS_IDW, "IDW", MS_FLATGEOBUF, "FLATGEOBUF"); - writeHashTableInline(stream, indent, "CONNECTIONOPTIONS", &(layer->connectionoptions)); + writeKeyword(stream, indent, "CONNECTIONTYPE", layer->connectiontype, 12, + MS_OGR, "OGR", MS_POSTGIS, "POSTGIS", MS_WMS, "WMS", + MS_ORACLESPATIAL, "ORACLESPATIAL", MS_WFS, "WFS", MS_PLUGIN, + "PLUGIN", MS_UNION, "UNION", MS_UVRASTER, "UVRASTER", MS_CONTOUR, + "CONTOUR", MS_KERNELDENSITY, "KERNELDENSITY", MS_IDW, "IDW", + MS_FLATGEOBUF, "FLATGEOBUF"); + writeHashTable(stream, indent, "CONNECTIONOPTIONS", + &(layer->connectionoptions)); writeString(stream, indent, "DATA", NULL, layer->data); - writeNumber(stream, indent, "DEBUG", 0, layer->debug); /* is this right? see loadLayer() */ + writeNumber(stream, indent, "DEBUG", 0, + layer->debug); /* is this right? see loadLayer() */ writeString(stream, indent, "ENCODING", NULL, layer->encoding); writeExtent(stream, indent, "EXTENT", layer->extent); writeExpression(stream, indent, "FILTER", &(layer->filter)); @@ -4430,17 +4932,20 @@ static void writeLayer(FILE *stream, int indent, layerObj *layer) writeString(stream, indent, "FOOTER", NULL, layer->footer); writeString(stream, indent, "GROUP", NULL, layer->group); - if(layer->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) { + if (layer->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) { writeIndent(stream, indent + 1); fprintf(stream, "GEOMTRANSFORM (%s)\n", layer->_geomtransform.string); } writeString(stream, indent, "HEADER", NULL, layer->header); /* join - see below */ - writeKeyword(stream, indent, "LABELCACHE", layer->labelcache, 1, MS_OFF, "OFF"); + writeKeyword(stream, indent, "LABELCACHE", layer->labelcache, 1, MS_OFF, + "OFF"); writeString(stream, indent, "LABELITEM", NULL, layer->labelitem); - writeNumber(stream, indent, "LABELMAXSCALEDENOM", -1, layer->labelmaxscaledenom); - writeNumber(stream, indent, "LABELMINSCALEDENOM", -1, layer->labelminscaledenom); + writeNumber(stream, indent, "LABELMAXSCALEDENOM", -1, + layer->labelmaxscaledenom); + writeNumber(stream, indent, "LABELMINSCALEDENOM", -1, + layer->labelminscaledenom); writeString(stream, indent, "LABELREQUIRES", NULL, layer->labelrequires); writeNumber(stream, indent, "MAXFEATURES", -1, layer->maxfeatures); writeNumber(stream, indent, "MAXGEOWIDTH", -1, layer->maxgeowidth); @@ -4453,13 +4958,18 @@ static void writeLayer(FILE *stream, int indent, layerObj *layer) writeString(stream, indent, "NAME", NULL, layer->name); writeColor(stream, indent, "OFFSITE", NULL, &(layer->offsite)); writeString(stream, indent, "PLUGIN", NULL, layer->plugin_library_original); - writeKeyword(stream, indent, "POSTLABELCACHE", layer->postlabelcache, 1, MS_TRUE, "TRUE"); - for(i=0; inumprocessing; i++) + writeKeyword(stream, indent, "POSTLABELCACHE", layer->postlabelcache, 1, + MS_TRUE, "TRUE"); + for (i = 0; i < layer->numprocessing; i++) writeString(stream, indent, "PROCESSING", NULL, layer->processing[i]); writeProjection(stream, indent, &(layer->projection)); writeString(stream, indent, "REQUIRES", NULL, layer->requires); - writeKeyword(stream, indent, "SIZEUNITS", layer->sizeunits, 7, MS_INCHES, "INCHES", MS_FEET ,"FEET", MS_MILES, "MILES", MS_METERS, "METERS", MS_KILOMETERS, "KILOMETERS", MS_NAUTICALMILES, "NAUTICALMILES", MS_DD, "DD"); - writeKeyword(stream, indent, "STATUS", layer->status, 3, MS_ON, "ON", MS_OFF, "OFF", MS_DEFAULT, "DEFAULT"); + writeKeyword(stream, indent, "SIZEUNITS", layer->sizeunits, 7, MS_INCHES, + "INCHES", MS_FEET, "FEET", MS_MILES, "MILES", MS_METERS, + "METERS", MS_KILOMETERS, "KILOMETERS", MS_NAUTICALMILES, + "NAUTICALMILES", MS_DD, "DD"); + writeKeyword(stream, indent, "STATUS", layer->status, 3, MS_ON, "ON", MS_OFF, + "OFF", MS_DEFAULT, "DEFAULT"); writeString(stream, indent, "STYLEITEM", NULL, layer->styleitem); writeNumber(stream, indent, "SYMBOLSCALEDENOM", -1, layer->symbolscaledenom); writeString(stream, indent, "TEMPLATE", NULL, layer->template); @@ -4467,22 +4977,40 @@ static void writeLayer(FILE *stream, int indent, layerObj *layer) writeString(stream, indent, "TILEITEM", NULL, layer->tileitem); writeString(stream, indent, "TILESRS", NULL, layer->tilesrs); writeNumber(stream, indent, "TOLERANCE", -1, layer->tolerance); - writeKeyword(stream, indent, "TOLERANCEUNITS", layer->toleranceunits, 7, MS_INCHES, "INCHES", MS_FEET ,"FEET", MS_MILES, "MILES", MS_METERS, "METERS", MS_KILOMETERS, "KILOMETERS", MS_NAUTICALMILES, "NAUTICALMILES", MS_DD, "DD"); - writeKeyword(stream, indent, "TRANSFORM", layer->transform, 10, MS_FALSE, "FALSE", MS_UL, "UL", MS_UC, "UC", MS_UR, "UR", MS_CL, "CL", MS_CC, "CC", MS_CR, "CR", MS_LL, "LL", MS_LC, "LC", MS_LR, "LR"); - writeKeyword(stream, indent, "TYPE", layer->type, 9, MS_LAYER_POINT, "POINT", MS_LAYER_LINE, "LINE", MS_LAYER_POLYGON, "POLYGON", MS_LAYER_RASTER, "RASTER", MS_LAYER_ANNOTATION, "ANNOTATION", MS_LAYER_QUERY, "QUERY", MS_LAYER_CIRCLE, "CIRCLE", MS_LAYER_TILEINDEX, "TILEINDEX", MS_LAYER_CHART, "CHART"); - writeKeyword(stream, indent, "UNITS", layer->units, 9, MS_INCHES, "INCHES", MS_FEET ,"FEET", MS_MILES, "MILES", MS_METERS, "METERS", MS_KILOMETERS, "KILOMETERS", MS_NAUTICALMILES, "NAUTICALMILES", MS_DD, "DD", MS_PIXELS, "PIXELS", MS_PERCENTAGES, "PERCENTATGES"); + writeKeyword(stream, indent, "TOLERANCEUNITS", layer->toleranceunits, 7, + MS_INCHES, "INCHES", MS_FEET, "FEET", MS_MILES, "MILES", + MS_METERS, "METERS", MS_KILOMETERS, "KILOMETERS", + MS_NAUTICALMILES, "NAUTICALMILES", MS_DD, "DD"); + writeKeyword(stream, indent, "TRANSFORM", layer->transform, 10, MS_FALSE, + "FALSE", MS_UL, "UL", MS_UC, "UC", MS_UR, "UR", MS_CL, "CL", + MS_CC, "CC", MS_CR, "CR", MS_LL, "LL", MS_LC, "LC", MS_LR, "LR"); + writeKeyword(stream, indent, "TYPE", layer->type, 9, MS_LAYER_POINT, "POINT", + MS_LAYER_LINE, "LINE", MS_LAYER_POLYGON, "POLYGON", + MS_LAYER_RASTER, "RASTER", MS_LAYER_ANNOTATION, "ANNOTATION", + MS_LAYER_QUERY, "QUERY", MS_LAYER_CIRCLE, "CIRCLE", + MS_LAYER_TILEINDEX, "TILEINDEX", MS_LAYER_CHART, "CHART"); + writeKeyword(stream, indent, "UNITS", layer->units, 9, MS_INCHES, "INCHES", + MS_FEET, "FEET", MS_MILES, "MILES", MS_METERS, "METERS", + MS_KILOMETERS, "KILOMETERS", MS_NAUTICALMILES, "NAUTICALMILES", + MS_DD, "DD", MS_PIXELS, "PIXELS", MS_PERCENTAGES, + "PERCENTATGES"); + writeExpression(stream, indent, "UTFDATA", &(layer->utfdata)); + writeString(stream, indent, "UTFITEM", NULL, layer->utfitem); writeHashTable(stream, indent, "VALIDATION", &(layer->validation)); /* write potentially multiply occuring objects last */ - for(i=0; inumscaletokens; i++) writeScaleToken(stream, indent, &(layer->scaletokens[i])); - for(i=0; inumjoins; i++) writeJoin(stream, indent, &(layer->joins[i])); - for(i=0; inumclasses; i++) writeClass(stream, indent, layer->class[i]); - - if( layer->grid && layer->connectiontype == MS_GRATICULE) + for (i = 0; i < layer->numscaletokens; i++) + writeScaleToken(stream, indent, &(layer->scaletokens[i])); + for (i = 0; i < layer->numjoins; i++) + writeJoin(stream, indent, &(layer->joins[i])); + for (i = 0; i < layer->numclasses; i++) + writeClass(stream, indent, layer->class[i]); + + if (layer->grid && layer->connectiontype == MS_GRATICULE) writeGrid(stream, indent, layer->grid); else { current = layer->features; - while(current != NULL) { + while (current != NULL) { writeFeature(stream, indent, &(current->shape)); current = current->next; } @@ -4492,9 +5020,8 @@ static void writeLayer(FILE *stream, int indent, layerObj *layer) writeLineFeed(stream); } -char* msWriteLayerToString(layerObj *layer) -{ - msIOContext context; +char *msWriteLayerToString(layerObj *layer) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -4505,23 +5032,23 @@ char* msWriteLayerToString(layerObj *layer) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeLayer(stdout, -1, layer); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } /* ** Initialize, load and free a referenceMapObj structure */ -void initReferenceMap(referenceMapObj *ref) -{ +void initReferenceMap(referenceMapObj *ref) { ref->height = ref->width = 0; - ref->extent.minx = ref->extent.miny = ref->extent.maxx = ref->extent.maxy = -1.0; + ref->extent.minx = ref->extent.miny = ref->extent.maxx = ref->extent.maxy = + -1.0; ref->image = NULL; MS_INIT_COLOR(ref->color, 255, 0, 0, 255); MS_INIT_COLOR(ref->outlinecolor, 0, 0, 0, 255); @@ -4534,103 +5061,124 @@ void initReferenceMap(referenceMapObj *ref) ref->map = NULL; } -void freeReferenceMap(referenceMapObj *ref) -{ +void freeReferenceMap(referenceMapObj *ref) { msFree(ref->image); msFree(ref->markername); } -int loadReferenceMap(referenceMapObj *ref, mapObj *map) -{ +int loadReferenceMap(referenceMapObj *ref, mapObj *map) { int state; ref->map = (mapObj *)map; - for(;;) { - switch(msyylex()) { - case(EOF): - msSetError(MS_EOFERR, NULL, "loadReferenceMap()"); - return(-1); - case(END): - if(!ref->image) { - msSetError(MS_MISCERR, "No image defined for the reference map.", "loadReferenceMap()"); - return(-1); - } - if(ref->width == 0 || ref->height == 0) { - msSetError(MS_MISCERR, "No image size defined for the reference map.", "loadReferenceMap()"); - return(-1); - } - return(0); - break; - case(COLOR): - if(loadColor(&(ref->color), NULL) != MS_SUCCESS) return(-1); - break; - case(EXTENT): - if(getDouble(&(ref->extent.minx), MS_NUM_CHECK_NONE, -1, -1) == -1) return(-1); - if(getDouble(&(ref->extent.miny), MS_NUM_CHECK_NONE, -1, -1) == -1) return(-1); - if(getDouble(&(ref->extent.maxx), MS_NUM_CHECK_NONE, -1, -1) == -1) return(-1); - if(getDouble(&(ref->extent.maxy), MS_NUM_CHECK_NONE, -1, -1) == -1) return(-1); - if (!MS_VALID_EXTENT(ref->extent)) { - msSetError(MS_MISCERR, "Given reference extent is invalid. Check that it " \ - "is in the form: minx, miny, maxx, maxy", "loadReferenceMap()"); - return(-1); - } - break; - case(IMAGE): - if(getString(&ref->image) == MS_FAILURE) return(-1); - break; - case(OUTLINECOLOR): - if(loadColor(&(ref->outlinecolor), NULL) != MS_SUCCESS) return(-1); - break; - case(SIZE): - if(getInteger(&(ref->width), MS_NUM_CHECK_RANGE, 5, ref->map->maxsize) == -1) return(-1); // is 5 reasonable? - if(getInteger(&(ref->height), MS_NUM_CHECK_RANGE, 5, ref->map->maxsize) == -1) return(-1); - break; - case(STATUS): - if((ref->status = getSymbol(2, MS_ON,MS_OFF)) == -1) return(-1); - break; - case(MARKER): - if((state = getSymbol(2, MS_NUMBER,MS_STRING)) == -1) return(-1); + for (;;) { + switch (msyylex()) { + case (EOF): + msSetError(MS_EOFERR, NULL, "loadReferenceMap()"); + return (-1); + case (END): + if (!ref->image) { + msSetError(MS_MISCERR, "No image defined for the reference map.", + "loadReferenceMap()"); + return (-1); + } + if (ref->width == 0 || ref->height == 0) { + msSetError(MS_MISCERR, "No image size defined for the reference map.", + "loadReferenceMap()"); + return (-1); + } + return (0); + break; + case (COLOR): + if (loadColor(&(ref->color), NULL) != MS_SUCCESS) + return (-1); + break; + case (EXTENT): + if (getDouble(&(ref->extent.minx), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (-1); + if (getDouble(&(ref->extent.miny), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (-1); + if (getDouble(&(ref->extent.maxx), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (-1); + if (getDouble(&(ref->extent.maxy), MS_NUM_CHECK_NONE, -1, -1) == -1) + return (-1); + if (!MS_VALID_EXTENT(ref->extent)) { + msSetError(MS_MISCERR, + "Given reference extent is invalid. Check that it " + "is in the form: minx, miny, maxx, maxy", + "loadReferenceMap()"); + return (-1); + } + break; + case (IMAGE): + if (getString(&ref->image) == MS_FAILURE) + return (-1); + break; + case (OUTLINECOLOR): + if (loadColor(&(ref->outlinecolor), NULL) != MS_SUCCESS) + return (-1); + break; + case (SIZE): + if (getInteger(&(ref->width), MS_NUM_CHECK_RANGE, 5, ref->map->maxsize) == + -1) + return (-1); // is 5 reasonable? + if (getInteger(&(ref->height), MS_NUM_CHECK_RANGE, 5, + ref->map->maxsize) == -1) + return (-1); + break; + case (STATUS): + if ((ref->status = getSymbol(2, MS_ON, MS_OFF)) == -1) + return (-1); + break; + case (MARKER): + if ((state = getSymbol(2, MS_NUMBER, MS_STRING)) == -1) + return (-1); - if(state == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_GTE, 0, -1) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid MARKER, must be greater than 0 (line %d)", "loadReferenceMap()", msyylineno); - return(-1); - } - ref->marker = (int) msyynumber; - } else { - if (ref->markername != NULL) - msFree(ref->markername); - ref->markername = msStrdup(msyystring_buffer); - } - break; - case(MARKERSIZE): - if(getInteger(&(ref->markersize), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(MINBOXSIZE): - if(getInteger(&(ref->minboxsize), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(MAXBOXSIZE): - if(getInteger(&(ref->maxboxsize), MS_NUM_CHECK_GT, 0, -1) == -1) return(-1); - break; - case(REFERENCE): - break; /* for string loads */ - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadReferenceMap()", msyystring_buffer, msyylineno); - return(-1); - } else { - return(0); /* end of a string, not an error */ + if (state == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_GTE, 0, -1) == MS_FAILURE) { + msSetError(MS_MISCERR, + "Invalid MARKER, must be greater than 0 (line %d)", + "loadReferenceMap()", msyylineno); + return (-1); } + ref->marker = (int)msyynumber; + } else { + if (ref->markername != NULL) + msFree(ref->markername); + ref->markername = msStrdup(msyystring_buffer); + } + break; + case (MARKERSIZE): + if (getInteger(&(ref->markersize), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (MINBOXSIZE): + if (getInteger(&(ref->minboxsize), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (MAXBOXSIZE): + if (getInteger(&(ref->maxboxsize), MS_NUM_CHECK_GT, 0, -1) == -1) + return (-1); + break; + case (REFERENCE): + break; /* for string loads */ + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadReferenceMap()", msyystring_buffer, msyylineno); + return (-1); + } else { + return (0); /* end of a string, not an error */ + } } } /* next token */ } -int msUpdateReferenceMapFromString(referenceMapObj *ref, char *string) -{ - if(!ref || !string) return MS_FAILURE; +int msUpdateReferenceMapFromString(referenceMapObj *ref, char *string) { + if (!ref || !string) + return MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_STRING; msyystring = string; @@ -4638,33 +5186,36 @@ int msUpdateReferenceMapFromString(referenceMapObj *ref, char *string) msyylineno = 1; /* start at line 1 */ - if(loadReferenceMap(ref, ref->map) == -1) { - msReleaseLock( TLOCK_PARSER ); - return MS_FAILURE; /* parse error */; + if (loadReferenceMap(ref, ref->map) == -1) { + msReleaseLock(TLOCK_PARSER); + return MS_FAILURE; /* parse error */ + ; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msyylex_destroy(); return MS_SUCCESS; } -static void writeReferenceMap(FILE *stream, int indent, referenceMapObj *ref) -{ +static void writeReferenceMap(FILE *stream, int indent, referenceMapObj *ref) { colorObj c; - if(!ref->image) return; + if (!ref->image) + return; indent++; writeBlockBegin(stream, indent, "REFERENCE"); - MS_INIT_COLOR(c,255,0,0,255); + MS_INIT_COLOR(c, 255, 0, 0, 255); writeColor(stream, indent, "COLOR", &c, &(ref->color)); writeExtent(stream, indent, "EXTENT", ref->extent); writeString(stream, indent, "IMAGE", NULL, ref->image); - MS_INIT_COLOR(c,0,0,0,255); + MS_INIT_COLOR(c, 0, 0, 0, 255); writeColor(stream, indent, "OUTLINECOLOR", &c, &(ref->outlinecolor)); writeDimension(stream, indent, "SIZE", ref->width, ref->height, NULL, NULL); - writeKeyword(stream, indent, "STATUS", ref->status, 2, MS_ON, "ON", MS_OFF, "OFF"); - writeNumberOrString(stream, indent, "MARKER", 0, ref->marker, ref->markername); + writeKeyword(stream, indent, "STATUS", ref->status, 2, MS_ON, "ON", MS_OFF, + "OFF"); + writeNumberOrString(stream, indent, "MARKER", 0, ref->marker, + ref->markername); writeNumber(stream, indent, "MARKERSIZE", -1, ref->markersize); writeNumber(stream, indent, "MAXBOXSIZE", -1, ref->maxboxsize); writeNumber(stream, indent, "MINBOXSIZE", -1, ref->minboxsize); @@ -4672,9 +5223,8 @@ static void writeReferenceMap(FILE *stream, int indent, referenceMapObj *ref) writeLineFeed(stream); } -char* msWriteReferenceMapToString(referenceMapObj *ref) -{ - msIOContext context; +char *msWriteReferenceMapToString(referenceMapObj *ref) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -4685,20 +5235,19 @@ char* msWriteReferenceMapToString(referenceMapObj *ref) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeReferenceMap(stdout, -1, ref); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } #define MAX_FORMATOPTIONS 100 -static int loadOutputFormat(mapObj *map) -{ +static int loadOutputFormat(mapObj *map) { char *name = NULL; char *mimetype = NULL; char *driver = NULL; @@ -4706,173 +5255,179 @@ static int loadOutputFormat(mapObj *map) int imagemode = MS_NOOVERRIDE; int transparent = MS_NOOVERRIDE; char *formatoptions[MAX_FORMATOPTIONS]; - int numformatoptions = 0; + int numformatoptions = 0; char *value = NULL; - for(;;) { - switch(msyylex()) { - case(EOF): - msSetError(MS_EOFERR, NULL, "loadOutputFormat()"); - goto load_output_error; + for (;;) { + switch (msyylex()) { + case (EOF): + msSetError(MS_EOFERR, NULL, "loadOutputFormat()"); + goto load_output_error; - case(END): { - outputFormatObj *format; + case (END): { + outputFormatObj *format; - if( driver == NULL ) { - msSetError(MS_MISCERR, - "OUTPUTFORMAT clause lacks DRIVER keyword near (%s):(%d)", - "loadOutputFormat()", - msyystring_buffer, msyylineno ); - goto load_output_error; - } + if (driver == NULL) { + msSetError(MS_MISCERR, + "OUTPUTFORMAT clause lacks DRIVER keyword near (%s):(%d)", + "loadOutputFormat()", msyystring_buffer, msyylineno); + goto load_output_error; + } - format = msCreateDefaultOutputFormat( map, driver, name, NULL ); - if( format == NULL ) { - msSetError(MS_MISCERR, - "OUTPUTFORMAT (%s) clause references driver (%s), but this driver isn't configured.", - "loadOutputFormat()", name, driver ); - goto load_output_error; - } - msFree( name ); - name = NULL; - msFree( driver ); - driver = NULL; - - if( transparent != MS_NOOVERRIDE ) - format->transparent = transparent; - if( extension != NULL ) { - msFree( format->extension ); - format->extension = extension; - extension = NULL; - } - if( mimetype != NULL ) { - msFree( format->mimetype ); - format->mimetype = mimetype; - mimetype = NULL; + format = msCreateDefaultOutputFormat(map, driver, name, NULL); + if (format == NULL) { + msSetError(MS_MISCERR, + "OUTPUTFORMAT (%s) clause references driver (%s), but this " + "driver isn't configured.", + "loadOutputFormat()", name, driver); + goto load_output_error; + } + msFree(name); + name = NULL; + msFree(driver); + driver = NULL; + + if (transparent != MS_NOOVERRIDE) + format->transparent = transparent; + if (extension != NULL) { + msFree(format->extension); + format->extension = extension; + extension = NULL; + } + if (mimetype != NULL) { + msFree(format->mimetype); + format->mimetype = mimetype; + mimetype = NULL; + } + if (imagemode != MS_NOOVERRIDE) { + if (format->renderer != MS_RENDER_WITH_AGG || + imagemode != MS_IMAGEMODE_PC256) { + /* don't force to PC256 with agg, this can happen when using mapfile + * defined GD outputformats that are now falling back to agg/png8 + */ + format->imagemode = imagemode; } - if( imagemode != MS_NOOVERRIDE ) { - if(format->renderer != MS_RENDER_WITH_AGG || imagemode != MS_IMAGEMODE_PC256) { - /* don't force to PC256 with agg, this can happen when using mapfile defined GD - * outputformats that are now falling back to agg/png8 - */ - format->imagemode = imagemode; - } - if( transparent == MS_NOOVERRIDE ) { - if( imagemode == MS_IMAGEMODE_RGB ) - format->transparent = MS_FALSE; - else if( imagemode == MS_IMAGEMODE_RGBA ) - format->transparent = MS_TRUE; - } - if( format->imagemode == MS_IMAGEMODE_INT16 - || format->imagemode == MS_IMAGEMODE_FLOAT32 - || format->imagemode == MS_IMAGEMODE_BYTE ) - format->renderer = MS_RENDER_WITH_RAWDATA; + if (transparent == MS_NOOVERRIDE) { + if (imagemode == MS_IMAGEMODE_RGB) + format->transparent = MS_FALSE; + else if (imagemode == MS_IMAGEMODE_RGBA) + format->transparent = MS_TRUE; } - while(numformatoptions--) { - char *key = strchr(formatoptions[numformatoptions],'='); - if(!key || !*(key+1)) { - msSetError(MS_MISCERR,"Failed to parse FORMATOPTION, expecting \"KEY=VALUE\" syntax.","loadOutputFormat()"); - goto load_output_error; - } - *key = 0; - key++; - msSetOutputFormatOption(format,formatoptions[numformatoptions],key); - free(formatoptions[numformatoptions]); + if (format->imagemode == MS_IMAGEMODE_INT16 || + format->imagemode == MS_IMAGEMODE_FLOAT32 || + format->imagemode == MS_IMAGEMODE_BYTE) + format->renderer = MS_RENDER_WITH_RAWDATA; + } + while (numformatoptions--) { + char *key = strchr(formatoptions[numformatoptions], '='); + if (!key || !*(key + 1)) { + msSetError( + MS_MISCERR, + "Failed to parse FORMATOPTION, expecting \"KEY=VALUE\" syntax.", + "loadOutputFormat()"); + goto load_output_error; } + *key = 0; + key++; + msSetOutputFormatOption(format, formatoptions[numformatoptions], key); + free(formatoptions[numformatoptions]); + } - format->inmapfile = MS_TRUE; + format->inmapfile = MS_TRUE; - msOutputFormatValidate( format, MS_FALSE ); - return(0); + msOutputFormatValidate(format, MS_FALSE); + return (0); + } + case (NAME): + msFree(name); + if ((name = getToken()) == NULL) + goto load_output_error; + break; + case (MIMETYPE): + if (getString(&mimetype) == MS_FAILURE) + goto load_output_error; + break; + case (DRIVER): { + int s; + if ((s = getSymbol(2, MS_STRING, TEMPLATE)) == + -1) /* allow the template to be quoted or not in the mapfile */ + goto load_output_error; + free(driver); + if (s == MS_STRING) + driver = msStrdup(msyystring_buffer); + else + driver = msStrdup("TEMPLATE"); + } break; + case (EXTENSION): + if (getString(&extension) == MS_FAILURE) + goto load_output_error; + if (extension[0] == '.') { + char *temp = msStrdup(extension + 1); + free(extension); + extension = temp; } - case(NAME): - msFree( name ); - if((name = getToken()) == NULL) - goto load_output_error; - break; - case(MIMETYPE): - if(getString(&mimetype) == MS_FAILURE) - goto load_output_error; - break; - case(DRIVER): { - int s; - if((s = getSymbol(2, MS_STRING, TEMPLATE)) == -1) /* allow the template to be quoted or not in the mapfile */ - goto load_output_error; - free(driver); - if(s == MS_STRING) - driver = msStrdup(msyystring_buffer); - else - driver = msStrdup("TEMPLATE"); + break; + case (FORMATOPTION): + if (getString(&value) == MS_FAILURE) + goto load_output_error; + if (numformatoptions < MAX_FORMATOPTIONS) + formatoptions[numformatoptions++] = value; + value = NULL; + break; + case (IMAGEMODE): + value = getToken(); + if (strcasecmp(value, "PC256") == 0) + imagemode = MS_IMAGEMODE_PC256; + else if (strcasecmp(value, "RGB") == 0) + imagemode = MS_IMAGEMODE_RGB; + else if (strcasecmp(value, "RGBA") == 0) + imagemode = MS_IMAGEMODE_RGBA; + else if (strcasecmp(value, "INT16") == 0) + imagemode = MS_IMAGEMODE_INT16; + else if (strcasecmp(value, "FLOAT32") == 0) + imagemode = MS_IMAGEMODE_FLOAT32; + else if (strcasecmp(value, "BYTE") == 0) + imagemode = MS_IMAGEMODE_BYTE; + else if (strcasecmp(value, "FEATURE") == 0) + imagemode = MS_IMAGEMODE_FEATURE; + else { + msSetError(MS_IDENTERR, + "Parsing error near (%s):(line %d), expected PC256, RGB, " + "RGBA, FEATURE, BYTE, INT16, or FLOAT32 for IMAGEMODE.", + "loadOutputFormat()", msyystring_buffer, msyylineno); + goto load_output_error; } + free(value); + value = NULL; break; - case(EXTENSION): - if(getString(&extension) == MS_FAILURE) - goto load_output_error; - if( extension[0] == '.' ) { - char *temp = msStrdup(extension+1); - free( extension ); - extension = temp; - } - break; - case(FORMATOPTION): - if(getString(&value) == MS_FAILURE) - goto load_output_error; - if( numformatoptions < MAX_FORMATOPTIONS ) - formatoptions[numformatoptions++] = value; - value=NULL; - break; - case(IMAGEMODE): - value = getToken(); - if( strcasecmp(value,"PC256") == 0 ) - imagemode = MS_IMAGEMODE_PC256; - else if( strcasecmp(value,"RGB") == 0 ) - imagemode = MS_IMAGEMODE_RGB; - else if( strcasecmp(value,"RGBA") == 0) - imagemode = MS_IMAGEMODE_RGBA; - else if( strcasecmp(value,"INT16") == 0) - imagemode = MS_IMAGEMODE_INT16; - else if( strcasecmp(value,"FLOAT32") == 0) - imagemode = MS_IMAGEMODE_FLOAT32; - else if( strcasecmp(value,"BYTE") == 0) - imagemode = MS_IMAGEMODE_BYTE; - else if( strcasecmp(value,"FEATURE") == 0) - imagemode = MS_IMAGEMODE_FEATURE; - else { - msSetError(MS_IDENTERR, - "Parsing error near (%s):(line %d), expected PC256, RGB, RGBA, FEATURE, BYTE, INT16, or FLOAT32 for IMAGEMODE.", "loadOutputFormat()", - msyystring_buffer, msyylineno); - goto load_output_error; - } - free(value); - value=NULL; - break; - case(TRANSPARENT): - if((transparent = getSymbol(2, MS_ON,MS_OFF)) == -1) - goto load_output_error; - break; - default: - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadOutputFormat()", - msyystring_buffer, msyylineno); + case (TRANSPARENT): + if ((transparent = getSymbol(2, MS_ON, MS_OFF)) == -1) goto load_output_error; + break; + default: + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadOutputFormat()", msyystring_buffer, msyylineno); + goto load_output_error; } } /* next token */ load_output_error: - msFree( driver ); - msFree( extension ); - msFree( mimetype ); - msFree( name ); - msFree( value ); + msFree(driver); + msFree(extension); + msFree(mimetype); + msFree(name); + msFree(value); return -1; } /* ** utility function to write an output format structure to file */ -static void writeOutputformatobject(FILE *stream, int indent, outputFormatObj *outputformat) -{ +static void writeOutputformatobject(FILE *stream, int indent, + outputFormatObj *outputformat) { int i = 0; - if(!outputformat) return; + if (!outputformat) + return; indent++; writeBlockBegin(stream, indent, "OUTPUTFORMAT"); @@ -4880,26 +5435,32 @@ static void writeOutputformatobject(FILE *stream, int indent, outputFormatObj *o writeString(stream, indent, "MIMETYPE", NULL, outputformat->mimetype); writeString(stream, indent, "DRIVER", NULL, outputformat->driver); writeString(stream, indent, "EXTENSION", NULL, outputformat->extension); - writeKeyword(stream, indent, "IMAGEMODE", outputformat->imagemode, 7, MS_IMAGEMODE_PC256, "PC256", MS_IMAGEMODE_RGB, "RGB", MS_IMAGEMODE_RGBA, "RGBA", MS_IMAGEMODE_INT16, "INT16", MS_IMAGEMODE_FLOAT32, "FLOAT32", MS_IMAGEMODE_BYTE, "BYTE", MS_IMAGEMODE_FEATURE, "FEATURE"); - writeKeyword(stream, indent, "TRANSPARENT", outputformat->transparent, 2, MS_TRUE, "TRUE", MS_FALSE, "FALSE"); - for (i=0; inumformatoptions; i++) - writeString(stream, indent, "FORMATOPTION", NULL, outputformat->formatoptions[i]); + writeKeyword(stream, indent, "IMAGEMODE", outputformat->imagemode, 7, + MS_IMAGEMODE_PC256, "PC256", MS_IMAGEMODE_RGB, "RGB", + MS_IMAGEMODE_RGBA, "RGBA", MS_IMAGEMODE_INT16, "INT16", + MS_IMAGEMODE_FLOAT32, "FLOAT32", MS_IMAGEMODE_BYTE, "BYTE", + MS_IMAGEMODE_FEATURE, "FEATURE"); + writeKeyword(stream, indent, "TRANSPARENT", outputformat->transparent, 2, + MS_TRUE, "TRUE", MS_FALSE, "FALSE"); + for (i = 0; i < outputformat->numformatoptions; i++) + writeString(stream, indent, "FORMATOPTION", NULL, + outputformat->formatoptions[i]); writeBlockEnd(stream, indent, "OUTPUTFORMAT"); writeLineFeed(stream); } - /* ** Write the output formats to file */ -static void writeOutputformat(FILE *stream, int indent, mapObj *map) -{ - int i=0; - if(!map->outputformat) return; +static void writeOutputformat(FILE *stream, int indent, mapObj *map) { + int i = 0; + if (!map->outputformat) + return; writeOutputformatobject(stream, indent, map->outputformat); - for(i=0; inumoutputformats; i++) { - if(map->outputformatlist[i]->inmapfile == MS_TRUE && strcmp(map->outputformatlist[i]->name, map->outputformat->name) != 0) + for (i = 0; i < map->numoutputformats; i++) { + if (map->outputformatlist[i]->inmapfile == MS_TRUE && + strcmp(map->outputformatlist[i]->name, map->outputformat->name) != 0) writeOutputformatobject(stream, indent, map->outputformatlist[i]); } } @@ -4907,11 +5468,10 @@ static void writeOutputformat(FILE *stream, int indent, mapObj *map) /* ** Initialize, load and free a legendObj structure */ -void initLegend(legendObj *legend) -{ +void initLegend(legendObj *legend) { legend->height = legend->width = 0; - MS_INIT_COLOR(legend->imagecolor, 255,255,255,255); /* white */ - MS_INIT_COLOR(legend->outlinecolor, -1,-1,-1,255); + MS_INIT_COLOR(legend->imagecolor, 255, 255, 255, 255); /* white */ + MS_INIT_COLOR(legend->outlinecolor, -1, -1, -1, 255); initLabel(&legend->label); legend->label.position = MS_XY; /* override */ legend->keysizex = 20; @@ -4926,77 +5486,93 @@ void initLegend(legendObj *legend) legend->map = NULL; } -void freeLegend(legendObj *legend) -{ +void freeLegend(legendObj *legend) { if (legend->template) free(legend->template); freeLabel(&(legend->label)); } -int loadLegend(legendObj *legend, mapObj *map) -{ +int loadLegend(legendObj *legend, mapObj *map) { legend->map = (mapObj *)map; - for(;;) { - switch(msyylex()) { - case(EOF): - msSetError(MS_EOFERR, NULL, "loadLegend()"); - return(-1); - case(END): - legend->label.position = MS_XY; /* overrides go here */ - return(0); - break; - case(IMAGECOLOR): - if(loadColor(&(legend->imagecolor), NULL) != MS_SUCCESS) return(-1); - break; - case(KEYSIZE): - if(getInteger(&(legend->keysizex), MS_NUM_CHECK_RANGE, MS_LEGEND_KEYSIZE_MIN, MS_LEGEND_KEYSIZE_MAX) == -1) return(-1); - if(getInteger(&(legend->keysizey), MS_NUM_CHECK_RANGE, MS_LEGEND_KEYSIZE_MIN, MS_LEGEND_KEYSIZE_MAX) == -1) return(-1); - break; - case(KEYSPACING): - if(getInteger(&(legend->keyspacingx), MS_NUM_CHECK_RANGE, MS_LEGEND_KEYSPACING_MIN, MS_LEGEND_KEYSPACING_MAX) == -1) return(-1); - if(getInteger(&(legend->keyspacingy), MS_NUM_CHECK_RANGE, MS_LEGEND_KEYSPACING_MIN, MS_LEGEND_KEYSPACING_MAX) == -1) return(-1); - break; - case(LABEL): - if(loadLabel(&(legend->label)) == -1) return(-1); - legend->label.angle = 0; /* force */ - break; - case(LEGEND): - break; /* for string loads */ - case(OUTLINECOLOR): - if(loadColor(&(legend->outlinecolor), NULL) != MS_SUCCESS) return(-1); - break; - case(POSITION): - if((legend->position = getSymbol(6, MS_UL,MS_UR,MS_LL,MS_LR,MS_UC,MS_LC)) == -1) return(-1); - break; - case(POSTLABELCACHE): - if((legend->postlabelcache = getSymbol(2, MS_TRUE,MS_FALSE)) == -1) return(-1); - break; - case(STATUS): - if((legend->status = getSymbol(3, MS_ON,MS_OFF,MS_EMBED)) == -1) return(-1); - break; - case(TRANSPARENT): - if((legend->transparent = getSymbol(2, MS_ON,MS_OFF)) == -1) return(-1); - break; - case(TEMPLATE): - if(getString(&legend->template) == MS_FAILURE) return(-1); - break; - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadLegend()", msyystring_buffer, msyylineno); - return(-1); - } else { - return(0); /* end of a string, not an error */ - } + for (;;) { + switch (msyylex()) { + case (EOF): + msSetError(MS_EOFERR, NULL, "loadLegend()"); + return (-1); + case (END): + legend->label.position = MS_XY; /* overrides go here */ + return (0); + break; + case (IMAGECOLOR): + if (loadColor(&(legend->imagecolor), NULL) != MS_SUCCESS) + return (-1); + break; + case (KEYSIZE): + if (getInteger(&(legend->keysizex), MS_NUM_CHECK_RANGE, + MS_LEGEND_KEYSIZE_MIN, MS_LEGEND_KEYSIZE_MAX) == -1) + return (-1); + if (getInteger(&(legend->keysizey), MS_NUM_CHECK_RANGE, + MS_LEGEND_KEYSIZE_MIN, MS_LEGEND_KEYSIZE_MAX) == -1) + return (-1); + break; + case (KEYSPACING): + if (getInteger(&(legend->keyspacingx), MS_NUM_CHECK_RANGE, + MS_LEGEND_KEYSPACING_MIN, MS_LEGEND_KEYSPACING_MAX) == -1) + return (-1); + if (getInteger(&(legend->keyspacingy), MS_NUM_CHECK_RANGE, + MS_LEGEND_KEYSPACING_MIN, MS_LEGEND_KEYSPACING_MAX) == -1) + return (-1); + break; + case (LABEL): + if (loadLabel(&(legend->label)) == -1) + return (-1); + legend->label.angle = 0; /* force */ + break; + case (LEGEND): + break; /* for string loads */ + case (OUTLINECOLOR): + if (loadColor(&(legend->outlinecolor), NULL) != MS_SUCCESS) + return (-1); + break; + case (POSITION): + if ((legend->position = + getSymbol(6, MS_UL, MS_UR, MS_LL, MS_LR, MS_UC, MS_LC)) == -1) + return (-1); + break; + case (POSTLABELCACHE): + if ((legend->postlabelcache = getSymbol(2, MS_TRUE, MS_FALSE)) == -1) + return (-1); + break; + case (STATUS): + if ((legend->status = getSymbol(3, MS_ON, MS_OFF, MS_EMBED)) == -1) + return (-1); + break; + case (TRANSPARENT): + if ((legend->transparent = getSymbol(2, MS_ON, MS_OFF)) == -1) + return (-1); + break; + case (TEMPLATE): + if (getString(&legend->template) == MS_FAILURE) + return (-1); + break; + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadLegend()", msyystring_buffer, msyylineno); + return (-1); + } else { + return (0); /* end of a string, not an error */ + } } } /* next token */ } -int msUpdateLegendFromString(legendObj *legend, char *string) -{ - if(!legend || !string) return MS_FAILURE; +int msUpdateLegendFromString(legendObj *legend, char *string) { + if (!legend || !string) + return MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_STRING; msyystring = string; @@ -5004,40 +5580,47 @@ int msUpdateLegendFromString(legendObj *legend, char *string) msyylineno = 1; /* start at line 1 */ - if(loadLegend(legend, legend->map) == -1) { - msReleaseLock( TLOCK_PARSER ); - return MS_FAILURE; /* parse error */; + if (loadLegend(legend, legend->map) == -1) { + msReleaseLock(TLOCK_PARSER); + return MS_FAILURE; /* parse error */ + ; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msyylex_destroy(); return MS_SUCCESS; } -static void writeLegend(FILE *stream, int indent, legendObj *legend) -{ +static void writeLegend(FILE *stream, int indent, legendObj *legend) { colorObj c; indent++; writeBlockBegin(stream, indent, "LEGEND"); - MS_INIT_COLOR(c,255,255,255,255); + MS_INIT_COLOR(c, 255, 255, 255, 255); writeColor(stream, indent, "IMAGECOLOR", &c, &(legend->imagecolor)); - writeDimension(stream, indent, "KEYSIZE", legend->keysizex, legend->keysizey, NULL, NULL); - writeDimension(stream, indent, "KEYSPACING", legend->keyspacingx, legend->keyspacingy, NULL, NULL); + writeDimension(stream, indent, "KEYSIZE", legend->keysizex, legend->keysizey, + NULL, NULL); + writeDimension(stream, indent, "KEYSPACING", legend->keyspacingx, + legend->keyspacingy, NULL, NULL); writeLabel(stream, indent, &(legend->label)); writeColor(stream, indent, "OUTLINECOLOR", NULL, &(legend->outlinecolor)); - if(legend->status == MS_EMBED) writeKeyword(stream, indent, "POSITION", legend->position, 6, MS_LL, "LL", MS_UL, "UL", MS_UR, "UR", MS_LR, "LR", MS_UC, "UC", MS_LC, "LC"); - writeKeyword(stream, indent, "POSTLABELCACHE", legend->postlabelcache, 1, MS_TRUE, "TRUE"); - writeKeyword(stream, indent, "STATUS", legend->status, 3, MS_ON, "ON", MS_OFF, "OFF", MS_EMBED, "EMBED"); - writeKeyword(stream, indent, "TRANSPARENT", legend->transparent, 2, MS_TRUE, "TRUE", MS_FALSE, "FALSE"); + if (legend->status == MS_EMBED) + writeKeyword(stream, indent, "POSITION", legend->position, 6, MS_LL, "LL", + MS_UL, "UL", MS_UR, "UR", MS_LR, "LR", MS_UC, "UC", MS_LC, + "LC"); + writeKeyword(stream, indent, "POSTLABELCACHE", legend->postlabelcache, 1, + MS_TRUE, "TRUE"); + writeKeyword(stream, indent, "STATUS", legend->status, 3, MS_ON, "ON", MS_OFF, + "OFF", MS_EMBED, "EMBED"); + writeKeyword(stream, indent, "TRANSPARENT", legend->transparent, 2, MS_TRUE, + "TRUE", MS_FALSE, "FALSE"); writeString(stream, indent, "TEMPLATE", NULL, legend->template); writeBlockEnd(stream, indent, "LEGEND"); writeLineFeed(stream); } -char* msWriteLegendToString(legendObj *legend) -{ - msIOContext context; +char *msWriteLegendToString(legendObj *legend) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -5048,123 +5631,147 @@ char* msWriteLegendToString(legendObj *legend) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeLegend(stdout, -1, legend); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } /* ** Initialize, load and free a scalebarObj structure */ -void initScalebar(scalebarObj *scalebar) -{ - MS_INIT_COLOR(scalebar->imagecolor, -1,-1,-1,255); +void initScalebar(scalebarObj *scalebar) { + MS_INIT_COLOR(scalebar->imagecolor, -1, -1, -1, 255); scalebar->width = 200; scalebar->height = 3; - scalebar->style = 0; /* only 2 styles at this point */ - scalebar->intervals = 4; - initLabel(&scalebar->label); - scalebar->label.position = MS_XY; /* override */ - MS_INIT_COLOR(scalebar->backgroundcolor, -1,-1,-1,255); /* if not set, scalebar creation needs to set this to match the background color */ - MS_INIT_COLOR(scalebar->color, 0,0,0,255); /* default to black */ - MS_INIT_COLOR(scalebar->outlinecolor, -1,-1,-1,255); - scalebar->units = MS_MILES; - scalebar->status = MS_OFF; - scalebar->position = MS_LL; - scalebar->transparent = MS_NOOVERRIDE; /* no transparency */ - scalebar->postlabelcache = MS_FALSE; /* draw with labels */ - scalebar->align = MS_ALIGN_CENTER; - scalebar->offsetx = 0; - scalebar->offsety = 0; -} - -void freeScalebar(scalebarObj *scalebar) -{ - freeLabel(&(scalebar->label)); -} - -int loadScalebar(scalebarObj *scalebar) -{ - for(;;) { - switch(msyylex()) { - case(ALIGN): - if((scalebar->align = getSymbol(3, MS_ALIGN_LEFT,MS_ALIGN_CENTER,MS_ALIGN_RIGHT)) == -1) return(-1); - break; - case(BACKGROUNDCOLOR): - if(loadColor(&(scalebar->backgroundcolor), NULL) != MS_SUCCESS) return(-1); - break; - case(COLOR): - if(loadColor(&(scalebar->color), NULL) != MS_SUCCESS) return(-1); - break; - case(EOF): - msSetError(MS_EOFERR, NULL, "loadScalebar()"); - return(-1); - case(END): - return(0); - break; - case(IMAGECOLOR): - if(loadColor(&(scalebar->imagecolor), NULL) != MS_SUCCESS) return(-1); - break; - case(INTERVALS): - if(getInteger(&(scalebar->intervals), MS_NUM_CHECK_RANGE, MS_SCALEBAR_INTERVALS_MIN, MS_SCALEBAR_INTERVALS_MAX) == -1) return(-1); - break; - case(LABEL): - if(loadLabel(&(scalebar->label)) == -1) return(-1); - scalebar->label.angle = 0; - break; - case(OUTLINECOLOR): - if(loadColor(&(scalebar->outlinecolor), NULL) != MS_SUCCESS) return(-1); - break; - case(POSITION): - if((scalebar->position = getSymbol(6, MS_UL,MS_UR,MS_LL,MS_LR,MS_UC,MS_LC)) == -1) - return(-1); - break; - case(POSTLABELCACHE): - if((scalebar->postlabelcache = getSymbol(2, MS_TRUE,MS_FALSE)) == -1) return(-1); - break; - case(SCALEBAR): - break; /* for string loads */ - case(SIZE): - if(getInteger(&(scalebar->width), MS_NUM_CHECK_RANGE, MS_SCALEBAR_WIDTH_MIN, MS_SCALEBAR_WIDTH_MAX) == -1) return(-1); - if(getInteger(&(scalebar->height), MS_NUM_CHECK_RANGE, MS_SCALEBAR_HEIGHT_MIN, MS_SCALEBAR_HEIGHT_MAX) == -1) return(-1); - break; - case(STATUS): - if((scalebar->status = getSymbol(3, MS_ON,MS_OFF,MS_EMBED)) == -1) return(-1); - break; - case(STYLE): - if(getInteger(&(scalebar->style), MS_NUM_CHECK_RANGE, 0, 1) == -1) return(-1); // only 2 styles: 0 and 1 - break; - case(TRANSPARENT): - if((scalebar->transparent = getSymbol(2, MS_ON,MS_OFF)) == -1) return(-1); - break; - case(UNITS): - if((scalebar->units = getSymbol(6, MS_INCHES,MS_FEET,MS_MILES,MS_METERS,MS_KILOMETERS,MS_NAUTICALMILES)) == -1) return(-1); - break; - case(OFFSET): - if(getInteger(&(scalebar->offsetx), MS_NUM_CHECK_RANGE, MS_SCALEBAR_OFFSET_MIN, MS_SCALEBAR_OFFSET_MAX) == -1) return(-1); - if(getInteger(&(scalebar->offsety), MS_NUM_CHECK_RANGE, MS_SCALEBAR_OFFSET_MIN, MS_SCALEBAR_OFFSET_MAX) == -1) return(-1); - break; - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadScalebar()", msyystring_buffer, msyylineno); - return(-1); - } else { - return(0); /* end of a string, not an error */ - } + scalebar->style = 0; /* only 2 styles at this point */ + scalebar->intervals = 4; + initLabel(&scalebar->label); + scalebar->label.position = MS_XY; /* override */ + MS_INIT_COLOR(scalebar->backgroundcolor, -1, -1, -1, + 255); /* if not set, scalebar creation needs to set this to + match the background color */ + MS_INIT_COLOR(scalebar->color, 0, 0, 0, 255); /* default to black */ + MS_INIT_COLOR(scalebar->outlinecolor, -1, -1, -1, 255); + scalebar->units = MS_MILES; + scalebar->status = MS_OFF; + scalebar->position = MS_LL; + scalebar->transparent = MS_NOOVERRIDE; /* no transparency */ + scalebar->postlabelcache = MS_FALSE; /* draw with labels */ + scalebar->align = MS_ALIGN_CENTER; + scalebar->offsetx = 0; + scalebar->offsety = 0; +} + +void freeScalebar(scalebarObj *scalebar) { freeLabel(&(scalebar->label)); } + +int loadScalebar(scalebarObj *scalebar) { + for (;;) { + switch (msyylex()) { + case (ALIGN): + if ((scalebar->align = getSymbol(3, MS_ALIGN_LEFT, MS_ALIGN_CENTER, + MS_ALIGN_RIGHT)) == -1) + return (-1); + break; + case (BACKGROUNDCOLOR): + if (loadColor(&(scalebar->backgroundcolor), NULL) != MS_SUCCESS) + return (-1); + break; + case (COLOR): + if (loadColor(&(scalebar->color), NULL) != MS_SUCCESS) + return (-1); + break; + case (EOF): + msSetError(MS_EOFERR, NULL, "loadScalebar()"); + return (-1); + case (END): + return (0); + break; + case (IMAGECOLOR): + if (loadColor(&(scalebar->imagecolor), NULL) != MS_SUCCESS) + return (-1); + break; + case (INTERVALS): + if (getInteger(&(scalebar->intervals), MS_NUM_CHECK_RANGE, + MS_SCALEBAR_INTERVALS_MIN, + MS_SCALEBAR_INTERVALS_MAX) == -1) + return (-1); + break; + case (LABEL): + if (loadLabel(&(scalebar->label)) == -1) + return (-1); + scalebar->label.angle = 0; + break; + case (OUTLINECOLOR): + if (loadColor(&(scalebar->outlinecolor), NULL) != MS_SUCCESS) + return (-1); + break; + case (POSITION): + if ((scalebar->position = + getSymbol(6, MS_UL, MS_UR, MS_LL, MS_LR, MS_UC, MS_LC)) == -1) + return (-1); + break; + case (POSTLABELCACHE): + if ((scalebar->postlabelcache = getSymbol(2, MS_TRUE, MS_FALSE)) == -1) + return (-1); + break; + case (SCALEBAR): + break; /* for string loads */ + case (SIZE): + if (getInteger(&(scalebar->width), MS_NUM_CHECK_RANGE, + MS_SCALEBAR_WIDTH_MIN, MS_SCALEBAR_WIDTH_MAX) == -1) + return (-1); + if (getInteger(&(scalebar->height), MS_NUM_CHECK_RANGE, + MS_SCALEBAR_HEIGHT_MIN, MS_SCALEBAR_HEIGHT_MAX) == -1) + return (-1); + break; + case (STATUS): + if ((scalebar->status = getSymbol(3, MS_ON, MS_OFF, MS_EMBED)) == -1) + return (-1); + break; + case (STYLE): + if (getInteger(&(scalebar->style), MS_NUM_CHECK_RANGE, 0, 1) == -1) + return (-1); // only 2 styles: 0 and 1 + break; + case (TRANSPARENT): + if ((scalebar->transparent = getSymbol(2, MS_ON, MS_OFF)) == -1) + return (-1); + break; + case (UNITS): + if ((scalebar->units = + getSymbol(6, MS_INCHES, MS_FEET, MS_MILES, MS_METERS, + MS_KILOMETERS, MS_NAUTICALMILES)) == -1) + return (-1); + break; + case (OFFSET): + if (getInteger(&(scalebar->offsetx), MS_NUM_CHECK_RANGE, + MS_SCALEBAR_OFFSET_MIN, MS_SCALEBAR_OFFSET_MAX) == -1) + return (-1); + if (getInteger(&(scalebar->offsety), MS_NUM_CHECK_RANGE, + MS_SCALEBAR_OFFSET_MIN, MS_SCALEBAR_OFFSET_MAX) == -1) + return (-1); + break; + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadScalebar()", msyystring_buffer, msyylineno); + return (-1); + } else { + return (0); /* end of a string, not an error */ + } } } /* next token */ } -int msUpdateScalebarFromString(scalebarObj *scalebar, char *string) -{ - if(!scalebar || !string) return MS_FAILURE; +int msUpdateScalebarFromString(scalebarObj *scalebar, char *string) { + if (!scalebar || !string) + return MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_STRING; msyystring = string; @@ -5172,44 +5779,54 @@ int msUpdateScalebarFromString(scalebarObj *scalebar, char *string) msyylineno = 1; /* start at line 1 */ - if(loadScalebar(scalebar) == -1) { - msReleaseLock( TLOCK_PARSER ); - return MS_FAILURE; /* parse error */; + if (loadScalebar(scalebar) == -1) { + msReleaseLock(TLOCK_PARSER); + return MS_FAILURE; /* parse error */ + ; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msyylex_destroy(); return MS_SUCCESS; } -static void writeScalebar(FILE *stream, int indent, scalebarObj *scalebar) -{ +static void writeScalebar(FILE *stream, int indent, scalebarObj *scalebar) { colorObj c; indent++; writeBlockBegin(stream, indent, "SCALEBAR"); - writeKeyword(stream, indent, "ALIGN", scalebar->align, 2, MS_ALIGN_LEFT, "LEFT", MS_ALIGN_RIGHT, "RIGHT"); - writeColor(stream, indent, "BACKGROUNDCOLOR", NULL, &(scalebar->backgroundcolor)); - MS_INIT_COLOR(c,0,0,0,255); + writeKeyword(stream, indent, "ALIGN", scalebar->align, 2, MS_ALIGN_LEFT, + "LEFT", MS_ALIGN_RIGHT, "RIGHT"); + writeColor(stream, indent, "BACKGROUNDCOLOR", NULL, + &(scalebar->backgroundcolor)); + MS_INIT_COLOR(c, 0, 0, 0, 255); writeColor(stream, indent, "COLOR", &c, &(scalebar->color)); writeColor(stream, indent, "IMAGECOLOR", NULL, &(scalebar->imagecolor)); writeNumber(stream, indent, "INTERVALS", -1, scalebar->intervals); writeLabel(stream, indent, &(scalebar->label)); writeColor(stream, indent, "OUTLINECOLOR", NULL, &(scalebar->outlinecolor)); - if(scalebar->status == MS_EMBED) writeKeyword(stream, indent, "POSITION", scalebar->position, 6, MS_LL, "LL", MS_UL, "UL", MS_UR, "UR", MS_LR, "LR", MS_UC, "UC", MS_LC, "LC"); - writeKeyword(stream, indent, "POSTLABELCACHE", scalebar->postlabelcache, 1, MS_TRUE, "TRUE"); - writeDimension(stream, indent, "SIZE", scalebar->width, scalebar->height, NULL, NULL); - writeKeyword(stream, indent, "STATUS", scalebar->status, 3, MS_ON, "ON", MS_OFF, "OFF", MS_EMBED, "EMBED"); + if (scalebar->status == MS_EMBED) + writeKeyword(stream, indent, "POSITION", scalebar->position, 6, MS_LL, "LL", + MS_UL, "UL", MS_UR, "UR", MS_LR, "LR", MS_UC, "UC", MS_LC, + "LC"); + writeKeyword(stream, indent, "POSTLABELCACHE", scalebar->postlabelcache, 1, + MS_TRUE, "TRUE"); + writeDimension(stream, indent, "SIZE", scalebar->width, scalebar->height, + NULL, NULL); + writeKeyword(stream, indent, "STATUS", scalebar->status, 3, MS_ON, "ON", + MS_OFF, "OFF", MS_EMBED, "EMBED"); writeNumber(stream, indent, "STYLE", 0, scalebar->style); - writeKeyword(stream, indent, "TRANSPARENT", scalebar->transparent, 2, MS_TRUE, "TRUE", MS_FALSE, "FALSE"); - writeKeyword(stream, indent, "UNITS", scalebar->units, 6, MS_INCHES, "INCHES", MS_FEET ,"FEET", MS_MILES, "MILES", MS_METERS, "METERS", MS_KILOMETERS, "KILOMETERS", MS_NAUTICALMILES, "NAUTICALMILES"); + writeKeyword(stream, indent, "TRANSPARENT", scalebar->transparent, 2, MS_TRUE, + "TRUE", MS_FALSE, "FALSE"); + writeKeyword(stream, indent, "UNITS", scalebar->units, 6, MS_INCHES, "INCHES", + MS_FEET, "FEET", MS_MILES, "MILES", MS_METERS, "METERS", + MS_KILOMETERS, "KILOMETERS", MS_NAUTICALMILES, "NAUTICALMILES"); writeBlockEnd(stream, indent, "SCALEBAR"); writeLineFeed(stream); } -char* msWriteScalebarToString(scalebarObj *scalebar) -{ - msIOContext context; +char *msWriteScalebarToString(scalebarObj *scalebar) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -5220,80 +5837,90 @@ char* msWriteScalebarToString(scalebarObj *scalebar) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeScalebar(stdout, -1, scalebar); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } /* ** Initialize a queryMapObj structure */ -void initQueryMap(queryMapObj *querymap) -{ +void initQueryMap(queryMapObj *querymap) { querymap->width = querymap->height = -1; querymap->style = MS_HILITE; querymap->status = MS_OFF; - MS_INIT_COLOR(querymap->color, 255,255,0,255); /* yellow */ + MS_INIT_COLOR(querymap->color, 255, 255, 0, 255); /* yellow */ } -int loadQueryMap(queryMapObj *querymap, mapObj *map) -{ +int loadQueryMap(queryMapObj *querymap, mapObj *map) { querymap->map = (mapObj *)map; - for(;;) { - switch(msyylex()) { - case(QUERYMAP): - break; /* for string loads */ - case(COLOR): - if(loadColor(&(querymap->color), NULL) != MS_SUCCESS) return MS_FAILURE; - break; - case(EOF): - msSetError(MS_EOFERR, NULL, "loadQueryMap()"); - return(-1); - case(END): - return(0); - break; - case(SIZE): - /* - ** we do -1 (and avoid 0) here to maintain backwards compatability as older versions write "SIZE -1 -1" when saving a mapfile - */ - if(getInteger(&(querymap->width), MS_NUM_CHECK_RANGE, -1, querymap->map->maxsize) == -1 || querymap->width == 0) { - msSetError(MS_MISCERR, "Invalid SIZE value (line %d)", "loadQueryMap()", msyylineno); - return(-1); - } - if(getInteger(&(querymap->height), MS_NUM_CHECK_RANGE, -1, querymap->map->maxsize) == -1 || querymap->height == 0) { - msSetError(MS_MISCERR, "Invalid SIZE value (line %d)", "loadQueryMap()", msyylineno); - return(-1); - } - break; - case(STATUS): - if((querymap->status = getSymbol(2, MS_ON,MS_OFF)) == -1) return(-1); - break; - case(STYLE): - case(TYPE): - if((querymap->style = getSymbol(3, MS_NORMAL,MS_HILITE,MS_SELECTED)) == -1) return(-1); - break; - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadQueryMap()", msyystring_buffer, msyylineno); - return(-1); - } else { - return(0); /* end of a string, not an error */ - } + for (;;) { + switch (msyylex()) { + case (QUERYMAP): + break; /* for string loads */ + case (COLOR): + if (loadColor(&(querymap->color), NULL) != MS_SUCCESS) + return MS_FAILURE; + break; + case (EOF): + msSetError(MS_EOFERR, NULL, "loadQueryMap()"); + return (-1); + case (END): + return (0); + break; + case (SIZE): + /* + ** we do -1 (and avoid 0) here to maintain backwards compatability as + *older versions write "SIZE -1 -1" when saving a mapfile + */ + if (getInteger(&(querymap->width), MS_NUM_CHECK_RANGE, -1, + querymap->map->maxsize) == -1 || + querymap->width == 0) { + msSetError(MS_MISCERR, "Invalid SIZE value (line %d)", "loadQueryMap()", + msyylineno); + return (-1); + } + if (getInteger(&(querymap->height), MS_NUM_CHECK_RANGE, -1, + querymap->map->maxsize) == -1 || + querymap->height == 0) { + msSetError(MS_MISCERR, "Invalid SIZE value (line %d)", "loadQueryMap()", + msyylineno); + return (-1); + } + break; + case (STATUS): + if ((querymap->status = getSymbol(2, MS_ON, MS_OFF)) == -1) + return (-1); + break; + case (STYLE): + case (TYPE): + if ((querymap->style = getSymbol(3, MS_NORMAL, MS_HILITE, MS_SELECTED)) == + -1) + return (-1); + break; + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadQueryMap()", msyystring_buffer, msyylineno); + return (-1); + } else { + return (0); /* end of a string, not an error */ + } } } } -int msUpdateQueryMapFromString(queryMapObj *querymap, char *string) -{ - if(!querymap || !string) return MS_FAILURE; +int msUpdateQueryMapFromString(queryMapObj *querymap, char *string) { + if (!querymap || !string) + return MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_STRING; msyystring = string; @@ -5301,35 +5928,38 @@ int msUpdateQueryMapFromString(queryMapObj *querymap, char *string) msyylineno = 1; /* start at line 1 */ - if(loadQueryMap(querymap, querymap->map) == -1) { - msReleaseLock( TLOCK_PARSER ); - return MS_FAILURE; /* parse error */; + if (loadQueryMap(querymap, querymap->map) == -1) { + msReleaseLock(TLOCK_PARSER); + return MS_FAILURE; /* parse error */ + ; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msyylex_destroy(); return MS_SUCCESS; } -static void writeQueryMap(FILE *stream, int indent, queryMapObj *querymap) -{ +static void writeQueryMap(FILE *stream, int indent, queryMapObj *querymap) { colorObj c; indent++; writeBlockBegin(stream, indent, "QUERYMAP"); - MS_INIT_COLOR(c,255,255,0,255); - writeColor(stream, indent, "COLOR", &c, &(querymap->color)); - if(querymap->width != -1 && querymap->height != -1) // don't write SIZE if not explicitly set - writeDimension(stream, indent, "SIZE", querymap->width, querymap->height, NULL, NULL); - writeKeyword(stream, indent, "STATUS", querymap->status, 2, MS_ON, "ON", MS_OFF, "OFF"); - writeKeyword(stream, indent, "STYLE", querymap->style, 3, MS_NORMAL, "NORMAL", MS_HILITE, "HILITE", MS_SELECTED, "SELECTED"); + MS_INIT_COLOR(c, 255, 255, 0, 255); + writeColor(stream, indent, "COLOR", &c, &(querymap->color)); + if (querymap->width != -1 && + querymap->height != -1) // don't write SIZE if not explicitly set + writeDimension(stream, indent, "SIZE", querymap->width, querymap->height, + NULL, NULL); + writeKeyword(stream, indent, "STATUS", querymap->status, 2, MS_ON, "ON", + MS_OFF, "OFF"); + writeKeyword(stream, indent, "STYLE", querymap->style, 3, MS_NORMAL, "NORMAL", + MS_HILITE, "HILITE", MS_SELECTED, "SELECTED"); writeBlockEnd(stream, indent, "QUERYMAP"); writeLineFeed(stream); } -char* msWriteQueryMapToString(queryMapObj *querymap) -{ - msIOContext context; +char *msWriteQueryMapToString(queryMapObj *querymap) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -5340,24 +5970,23 @@ char* msWriteQueryMapToString(queryMapObj *querymap) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeQueryMap(stdout, -1, querymap); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } /* ** Initialize a webObj structure */ -void initWeb(webObj *web) -{ +void initWeb(webObj *web) { web->template = NULL; web->header = web->footer = NULL; - web->error = web->empty = NULL; + web->error = web->empty = NULL; web->mintemplate = web->maxtemplate = NULL; web->minscaledenom = web->maxscaledenom = -1; web->imagepath = msStrdup(""); @@ -5373,8 +6002,7 @@ void initWeb(webObj *web) web->browseformat = msStrdup("text/html"); } -void freeWeb(webObj *web) -{ +void freeWeb(webObj *web) { msFree(web->template); msFree(web->header); msFree(web->footer); @@ -5388,12 +6016,13 @@ void freeWeb(webObj *web) msFree(web->queryformat); msFree(web->legendformat); msFree(web->browseformat); - if(&(web->metadata)) msFreeHashItems(&(web->metadata)); - if(&(web->validation)) msFreeHashItems(&(web->validation)); + if (&(web->metadata)) + msFreeHashItems(&(web->metadata)); + if (&(web->validation)) + msFreeHashItems(&(web->validation)); } -static void writeWeb(FILE *stream, int indent, webObj *web) -{ +static void writeWeb(FILE *stream, int indent, webObj *web) { indent++; writeBlockBegin(stream, indent, "WEB"); writeString(stream, indent, "BROWSEFORMAT", "text/html", web->browseformat); @@ -5417,9 +6046,8 @@ static void writeWeb(FILE *stream, int indent, webObj *web) writeLineFeed(stream); } -char* msWriteWebToString(webObj *web) -{ - msIOContext context; +char *msWriteWebToString(webObj *web) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -5430,103 +6058,120 @@ char* msWriteWebToString(webObj *web) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeWeb(stdout, -1, web); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } -int loadWeb(webObj *web, mapObj *map) -{ +int loadWeb(webObj *web, mapObj *map) { web->map = (mapObj *)map; - for(;;) { - switch(msyylex()) { - case(BROWSEFORMAT): /* change to use validation in 6.0 */ - free(web->browseformat); - web->browseformat = NULL; /* there is a default */ - if(getString(&web->browseformat) == MS_FAILURE) return(-1); - break; - case(EMPTY): - if(getString(&web->empty) == MS_FAILURE) return(-1); - break; - case(WEB): - break; /* for string loads */ - case(EOF): - msSetError(MS_EOFERR, NULL, "loadWeb()"); - return(-1); - case(END): - return(0); - break; - case(ERROR): - if(getString(&web->error) == MS_FAILURE) return(-1); - break; - case(FOOTER): - if(getString(&web->footer) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(HEADER): - if(getString(&web->header) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(IMAGEPATH): - if(getString(&web->imagepath) == MS_FAILURE) return(-1); - break; - case(TEMPPATH): - if(getString(&web->temppath) == MS_FAILURE) return(-1); - break; - case(IMAGEURL): - if(getString(&web->imageurl) == MS_FAILURE) return(-1); - break; - case(LEGENDFORMAT): /* change to use validation in 6.0 */ - free(web->legendformat); - web->legendformat = NULL; /* there is a default */ - if(getString(&web->legendformat) == MS_FAILURE) return(-1); - break; - case(MAXSCALEDENOM): - if(getDouble(&web->maxscaledenom, MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); - break; - case(MAXTEMPLATE): - if(getString(&web->maxtemplate) == MS_FAILURE) return(-1); - break; - case(METADATA): - if(loadHashTable(&(web->metadata)) != MS_SUCCESS) return(-1); - break; - case(MINSCALEDENOM): - if(getDouble(&web->minscaledenom, MS_NUM_CHECK_GTE, 0, -1) == -1) return(-1); - break; - case(MINTEMPLATE): - if(getString(&web->mintemplate) == MS_FAILURE) return(-1); - break; - case(QUERYFORMAT): /* change to use validation in 6.0 */ - free(web->queryformat); - web->queryformat = NULL; /* there is a default */ - if(getString(&web->queryformat) == MS_FAILURE) return(-1); - break; - case(TEMPLATE): - if(getString(&web->template) == MS_FAILURE) return(-1); /* getString() cleans up previously allocated string */ - break; - case(VALIDATION): - if(loadHashTable(&(web->validation)) != MS_SUCCESS) return(-1); - break; - default: - if(strlen(msyystring_buffer) > 0) { - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadWeb()", msyystring_buffer, msyylineno); - return(-1); - } else { - return(0); /* end of a string, not an error */ - } + for (;;) { + switch (msyylex()) { + case (BROWSEFORMAT): /* change to use validation in 6.0 */ + free(web->browseformat); + web->browseformat = NULL; /* there is a default */ + if (getString(&web->browseformat) == MS_FAILURE) + return (-1); + break; + case (EMPTY): + if (getString(&web->empty) == MS_FAILURE) + return (-1); + break; + case (WEB): + break; /* for string loads */ + case (EOF): + msSetError(MS_EOFERR, NULL, "loadWeb()"); + return (-1); + case (END): + return (0); + break; + case (ERROR): + if (getString(&web->error) == MS_FAILURE) + return (-1); + break; + case (FOOTER): + if (getString(&web->footer) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (HEADER): + if (getString(&web->header) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (IMAGEPATH): + if (getString(&web->imagepath) == MS_FAILURE) + return (-1); + break; + case (TEMPPATH): + if (getString(&web->temppath) == MS_FAILURE) + return (-1); + break; + case (IMAGEURL): + if (getString(&web->imageurl) == MS_FAILURE) + return (-1); + break; + case (LEGENDFORMAT): /* change to use validation in 6.0 */ + free(web->legendformat); + web->legendformat = NULL; /* there is a default */ + if (getString(&web->legendformat) == MS_FAILURE) + return (-1); + break; + case (MAXSCALEDENOM): + if (getDouble(&web->maxscaledenom, MS_NUM_CHECK_GTE, 0, -1) == -1) + return (-1); + break; + case (MAXTEMPLATE): + if (getString(&web->maxtemplate) == MS_FAILURE) + return (-1); + break; + case (METADATA): + if (loadHashTable(&(web->metadata)) != MS_SUCCESS) + return (-1); + break; + case (MINSCALEDENOM): + if (getDouble(&web->minscaledenom, MS_NUM_CHECK_GTE, 0, -1) == -1) + return (-1); + break; + case (MINTEMPLATE): + if (getString(&web->mintemplate) == MS_FAILURE) + return (-1); + break; + case (QUERYFORMAT): /* change to use validation in 6.0 */ + free(web->queryformat); + web->queryformat = NULL; /* there is a default */ + if (getString(&web->queryformat) == MS_FAILURE) + return (-1); + break; + case (TEMPLATE): + if (getString(&web->template) == MS_FAILURE) + return (-1); /* getString() cleans up previously allocated string */ + break; + case (VALIDATION): + if (loadHashTable(&(web->validation)) != MS_SUCCESS) + return (-1); + break; + default: + if (strlen(msyystring_buffer) > 0) { + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "loadWeb()", msyystring_buffer, msyylineno); + return (-1); + } else { + return (0); /* end of a string, not an error */ + } } } } -int msUpdateWebFromString(webObj *web, char *string) -{ - if(!web || !string) return MS_FAILURE; +int msUpdateWebFromString(webObj *web, char *string) { + if (!web || !string) + return MS_FAILURE; - msAcquireLock( TLOCK_PARSER ); + msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_STRING; msyystring = string; @@ -5534,11 +6179,12 @@ int msUpdateWebFromString(webObj *web, char *string) msyylineno = 1; /* start at line 1 */ - if(loadWeb(web, web->map) == -1) { - msReleaseLock( TLOCK_PARSER ); - return MS_FAILURE; /* parse error */; + if (loadWeb(web, web->map) == -1) { + msReleaseLock(TLOCK_PARSER); + return MS_FAILURE; /* parse error */ + ; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msyylex_destroy(); return MS_SUCCESS; @@ -5551,9 +6197,8 @@ int msUpdateWebFromString(webObj *web, char *string) ** lots of other init methods in this file. */ -int initMap(mapObj *map) -{ - int i=0; +int initMap(mapObj *map) { + int i = 0; MS_REFCNT_INIT(map); map->debug = (int)msGetGlobalDebugLevel(); @@ -5564,14 +6209,16 @@ int initMap(mapObj *map) map->numlayers = 0; map->maxlayers = 0; map->layers = NULL; - map->layerorder = NULL; /* used to modify the order in which the layers are drawn */ + map->layerorder = + NULL; /* used to modify the order in which the layers are drawn */ map->status = MS_ON; map->name = msStrdup("MS"); - map->extent.minx = map->extent.miny = map->extent.maxx = map->extent.maxy = -1.0; + map->extent.minx = map->extent.miny = map->extent.maxx = map->extent.maxy = + -1.0; map->scaledenom = -1.0; - map->resolution = MS_DEFAULT_RESOLUTION; /* pixels per inch */ + map->resolution = MS_DEFAULT_RESOLUTION; /* pixels per inch */ map->defresolution = MS_DEFAULT_RESOLUTION; /* pixels per inch */ map->height = map->width = -1; @@ -5586,7 +6233,7 @@ int initMap(mapObj *map) map->mappath = NULL; map->sldurl = NULL; - MS_INIT_COLOR(map->imagecolor, 255,255,255,255); /* white */ + MS_INIT_COLOR(map->imagecolor, 255, 255, 255, 255); /* white */ map->numoutputformats = 0; map->outputformatlist = NULL; @@ -5599,8 +6246,9 @@ int initMap(mapObj *map) map->palette.numcolors = 0; - for(i=0; ilabelcache.slots[i].labels = NULL; /* cache is initialize at draw time */ + for (i = 0; i < MS_MAX_LABEL_PRIORITY; i++) { + map->labelcache.slots[i].labels = + NULL; /* cache is initialize at draw time */ map->labelcache.slots[i].cachesize = 0; map->labelcache.slots[i].numlabels = 0; map->labelcache.slots[i].markers = NULL; @@ -5615,7 +6263,7 @@ int initMap(mapObj *map) initHashTable(&(map->fontset.fonts)); msInitSymbolSet(&map->symbolset); - map->symbolset.fontset = &(map->fontset); + map->symbolset.fontset = &(map->fontset); map->symbolset.map = map; initLegend(&map->legend); @@ -5626,10 +6274,10 @@ int initMap(mapObj *map) map->projContext = msProjectionContextGetFromPool(); - if(msInitProjection(&(map->projection)) == -1) - return(-1); - if(msInitProjection(&(map->latlon)) == -1) - return(-1); + if (msInitProjection(&(map->projection)) == -1) + return (-1); + if (msInitProjection(&(map->latlon)) == -1) + return (-1); msProjectionSetContext(&(map->projection), map->projContext); msProjectionSetContext(&(map->latlon), map->projContext); @@ -5637,8 +6285,10 @@ int initMap(mapObj *map) /* initialize a default "geographic" projection */ map->latlon.numargs = 2; map->latlon.args[0] = msStrdup("proj=latlong"); - map->latlon.args[1] = msStrdup("ellps=WGS84"); /* probably want a different ellipsoid */ - if(msProcessProjection(&(map->latlon)) == -1) return(-1); + map->latlon.args[1] = + msStrdup("ellps=WGS84"); /* probably want a different ellipsoid */ + if (msProcessProjection(&(map->latlon)) == -1) + return (-1); map->templatepattern = map->datapattern = NULL; @@ -5653,7 +6303,7 @@ int initMap(mapObj *map) map->config = NULL; - return(0); + return (0); } /* @@ -5668,8 +6318,7 @@ int initMap(mapObj *map) ** ** Returns a reference to the new layerObj on success, NULL on error. */ -layerObj *msGrowMapLayers( mapObj *map ) -{ +layerObj *msGrowMapLayers(mapObj *map) { /* Do we need to increase the size of layers/layerorder by * MS_LAYER_ALLOCSIZE? */ @@ -5681,50 +6330,47 @@ layerObj *msGrowMapLayers( mapObj *map ) newsize = map->maxlayers + MS_LAYER_ALLOCSIZE; /* Alloc/realloc layers */ - newLayersPtr = (layerObj**)realloc(map->layers, - newsize*sizeof(layerObj*)); - MS_CHECK_ALLOC(newLayersPtr, newsize*sizeof(layerObj*), NULL); + newLayersPtr = + (layerObj **)realloc(map->layers, newsize * sizeof(layerObj *)); + MS_CHECK_ALLOC(newLayersPtr, newsize * sizeof(layerObj *), NULL); map->layers = newLayersPtr; /* Alloc/realloc layerorder */ - newLayerorderPtr = (int *)realloc(map->layerorder, - newsize*sizeof(int)); - MS_CHECK_ALLOC(newLayerorderPtr, newsize*sizeof(int), NULL); + newLayerorderPtr = (int *)realloc(map->layerorder, newsize * sizeof(int)); + MS_CHECK_ALLOC(newLayerorderPtr, newsize * sizeof(int), NULL); map->layerorder = newLayerorderPtr; map->maxlayers = newsize; - for(i=map->numlayers; imaxlayers; i++) { + for (i = map->numlayers; i < map->maxlayers; i++) { map->layers[i] = NULL; map->layerorder[i] = 0; } } - if (map->layers[map->numlayers]==NULL) { - map->layers[map->numlayers]=(layerObj*)calloc(1,sizeof(layerObj)); + if (map->layers[map->numlayers] == NULL) { + map->layers[map->numlayers] = (layerObj *)calloc(1, sizeof(layerObj)); MS_CHECK_ALLOC(map->layers[map->numlayers], sizeof(layerObj), NULL); } return map->layers[map->numlayers]; } - -int msFreeLabelCacheSlot(labelCacheSlotObj *cacheslot) -{ +int msFreeLabelCacheSlot(labelCacheSlotObj *cacheslot) { int i, j; /* free the labels */ if (cacheslot->labels) { - for(i=0; inumlabels; i++) { + for (i = 0; i < cacheslot->numlabels; i++) { - for(j=0; jlabels[i].numtextsymbols; j++) { + for (j = 0; j < cacheslot->labels[i].numtextsymbols; j++) { freeTextSymbol(cacheslot->labels[i].textsymbols[j]); free(cacheslot->labels[i].textsymbols[j]); } msFree(cacheslot->labels[i].textsymbols); - if(cacheslot->labels[i].leaderline) { + if (cacheslot->labels[i].leaderline) { msFree(cacheslot->labels[i].leaderline->point); msFree(cacheslot->labels[i].leaderline); msFree(cacheslot->labels[i].leaderbbox); @@ -5741,14 +6387,13 @@ int msFreeLabelCacheSlot(labelCacheSlotObj *cacheslot) cacheslot->markercachesize = 0; cacheslot->nummarkers = 0; - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msFreeLabelCache(labelCacheObj *cache) -{ +int msFreeLabelCache(labelCacheObj *cache) { int p; - for(p=0; pslots[p])) != MS_SUCCESS) return MS_FAILURE; } @@ -5759,32 +6404,36 @@ int msFreeLabelCache(labelCacheObj *cache) return MS_SUCCESS; } -int msInitLabelCacheSlot(labelCacheSlotObj *cacheslot) -{ +int msInitLabelCacheSlot(labelCacheSlotObj *cacheslot) { - if(cacheslot->labels || cacheslot->markers) + if (cacheslot->labels || cacheslot->markers) msFreeLabelCacheSlot(cacheslot); - cacheslot->labels = (labelCacheMemberObj *)malloc(sizeof(labelCacheMemberObj)*MS_LABELCACHEINITSIZE); - MS_CHECK_ALLOC(cacheslot->labels, sizeof(labelCacheMemberObj)*MS_LABELCACHEINITSIZE, MS_FAILURE); + cacheslot->labels = (labelCacheMemberObj *)malloc( + sizeof(labelCacheMemberObj) * MS_LABELCACHEINITSIZE); + MS_CHECK_ALLOC(cacheslot->labels, + sizeof(labelCacheMemberObj) * MS_LABELCACHEINITSIZE, + MS_FAILURE); cacheslot->cachesize = MS_LABELCACHEINITSIZE; cacheslot->numlabels = 0; - cacheslot->markers = (markerCacheMemberObj *)malloc(sizeof(markerCacheMemberObj)*MS_LABELCACHEINITSIZE); - MS_CHECK_ALLOC(cacheslot->markers, sizeof(markerCacheMemberObj)*MS_LABELCACHEINITSIZE, MS_FAILURE); + cacheslot->markers = (markerCacheMemberObj *)malloc( + sizeof(markerCacheMemberObj) * MS_LABELCACHEINITSIZE); + MS_CHECK_ALLOC(cacheslot->markers, + sizeof(markerCacheMemberObj) * MS_LABELCACHEINITSIZE, + MS_FAILURE); cacheslot->markercachesize = MS_LABELCACHEINITSIZE; cacheslot->nummarkers = 0; - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msInitLabelCache(labelCacheObj *cache) -{ +int msInitLabelCache(labelCacheObj *cache) { int p; - for(p=0; pslots[p])) != MS_SUCCESS) return MS_FAILURE; } @@ -5795,8 +6444,7 @@ int msInitLabelCache(labelCacheObj *cache) return MS_SUCCESS; } -static void writeMap(FILE *stream, int indent, mapObj *map) -{ +static void writeMap(FILE *stream, int indent, mapObj *map) { int i; colorObj c; @@ -5807,7 +6455,7 @@ static void writeMap(FILE *stream, int indent, mapObj *map) writeNumber(stream, indent, "DEFRESOLUTION", 72.0, map->defresolution); writeExtent(stream, indent, "EXTENT", map->extent); writeString(stream, indent, "FONTSET", NULL, map->fontset.filename); - MS_INIT_COLOR(c,255,255,255,255); + MS_INIT_COLOR(c, 255, 255, 255, 255); writeColor(stream, indent, "IMAGECOLOR", &c, &(map->imagecolor)); writeString(stream, indent, "IMAGETYPE", NULL, map->imagetype); writeNumber(stream, indent, "MAXSIZE", MS_MAXIMAGESIZE_DEFAULT, map->maxsize); @@ -5815,16 +6463,21 @@ static void writeMap(FILE *stream, int indent, mapObj *map) writeNumber(stream, indent, "RESOLUTION", 72.0, map->resolution); writeString(stream, indent, "SHAPEPATH", NULL, map->shapepath); writeDimension(stream, indent, "SIZE", map->width, map->height, NULL, NULL); - writeKeyword(stream, indent, "STATUS", map->status, 2, MS_ON, "ON", MS_OFF, "OFF"); + writeKeyword(stream, indent, "STATUS", map->status, 2, MS_ON, "ON", MS_OFF, + "OFF"); writeString(stream, indent, "SYMBOLSET", NULL, map->symbolset.filename); - writeKeyword(stream, indent, "UNITS", map->units, 7, MS_INCHES, "INCHES", MS_FEET ,"FEET", MS_MILES, "MILES", MS_METERS, "METERS", MS_KILOMETERS, "KILOMETERS", MS_NAUTICALMILES, "NAUTICALMILES", MS_DD, "DD"); + writeKeyword(stream, indent, "UNITS", map->units, 7, MS_INCHES, "INCHES", + MS_FEET, "FEET", MS_MILES, "MILES", MS_METERS, "METERS", + MS_KILOMETERS, "KILOMETERS", MS_NAUTICALMILES, "NAUTICALMILES", + MS_DD, "DD"); writeLineFeed(stream); writeOutputformat(stream, indent, map); /* write symbol with INLINE tag in mapfile */ - for(i=0; isymbolset.numsymbols; i++) { - if(map->symbolset.symbol[i]->inmapfile) writeSymbol(map->symbolset.symbol[i], stream); + for (i = 0; i < map->symbolset.numsymbols; i++) { + if (map->symbolset.symbol[i]->inmapfile) + writeSymbol(map->symbolset.symbol[i], stream); } writeProjection(stream, indent, &(map->projection)); @@ -5835,15 +6488,14 @@ static void writeMap(FILE *stream, int indent, mapObj *map) writeScalebar(stream, indent, &(map->scalebar)); writeWeb(stream, indent, &(map->web)); - for(i=0; inumlayers; i++) + for (i = 0; i < map->numlayers; i++) writeLayer(stream, indent, GET_LAYER(map, map->layerorder[i])); writeBlockEnd(stream, indent, "MAP"); } -char* msWriteMapToString(mapObj *map) -{ - msIOContext context; +char *msWriteMapToString(mapObj *map) { + msIOContext context; msIOBuffer buffer; context.label = NULL; @@ -5854,282 +6506,349 @@ char* msWriteMapToString(mapObj *map) buffer.data_len = 0; buffer.data_offset = 0; - msIO_installHandlers( NULL, &context, NULL ); + msIO_installHandlers(NULL, &context, NULL); writeMap(stdout, 0, map); - msIO_bufferWrite( &buffer, "", 1 ); + msIO_bufferWrite(&buffer, "", 1); - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); - return (char*)buffer.data; + return (char *)buffer.data; } -int msSaveMap(mapObj *map, char *filename) -{ +int msSaveMap(mapObj *map, char *filename) { FILE *stream; char szPath[MS_MAXPATHLEN]; - if(!map) { + if (!map) { msSetError(MS_MISCERR, "Map is undefined.", "msSaveMap()"); - return(-1); + return (-1); } - if(!filename) { + if (!filename) { msSetError(MS_MISCERR, "Filename is undefined.", "msSaveMap()"); - return(-1); + return (-1); } stream = fopen(msBuildPath(szPath, map->mappath, filename), "w"); - if(!stream) { + if (!stream) { msSetError(MS_IOERR, "(%s)", "msSaveMap()", filename); - return(-1); + return (-1); } writeMap(stream, 0, map); fclose(stream); - return(0); + return (0); } -static void writeConfig(FILE *stream, int indent, configObj *config) -{ +static void writeConfig(FILE *stream, int indent, configObj *config) { writeBlockBegin(stream, indent, "CONFIG"); writeHashTable(stream, indent, "ENV", &(config->env)); writeHashTable(stream, indent, "MAPS", &(config->maps)); writeBlockEnd(stream, indent, "CONFIG"); } -int msSaveConfig(configObj *config, const char *filename) -{ +int msSaveConfig(configObj *config, const char *filename) { FILE *stream; - if(!config) { + if (!config) { msSetError(MS_MISCERR, "Config is undefined.", "msSaveConfigMap()"); - return(-1); + return (-1); } - if(!filename) { + if (!filename) { msSetError(MS_MISCERR, "Filename is undefined.", "msSaveConfigMap()"); - return(-1); + return (-1); } stream = fopen(filename, "w"); - if(!stream) { + if (!stream) { msSetError(MS_IOERR, "(%s)", "msSaveConfig()", filename); - return(-1); + return (-1); } - writeConfig(stream,0,config); + writeConfig(stream, 0, config); fclose(stream); - return(0); + return (0); } -static int loadMapInternal(mapObj *map) -{ - int foundMapToken=MS_FALSE; +static int loadMapInternal(mapObj *map) { + int foundMapToken = MS_FALSE; int foundBomToken = MS_FALSE; int token; - for(;;) { + for (;;) { token = msyylex(); - if(!foundBomToken && token == BOM) { + if (!foundBomToken && token == BOM) { foundBomToken = MS_TRUE; - if(!foundMapToken) { + if (!foundMapToken) { continue; /*skip a leading bom*/ } } - if(!foundMapToken && token != MAP) { - msSetError(MS_IDENTERR, "First token must be MAP, this doesn't look like a mapfile.", "msLoadMap()"); - return(MS_FAILURE); + if (!foundMapToken && token != MAP) { + msSetError(MS_IDENTERR, + "First token must be MAP, this doesn't look like a mapfile.", + "msLoadMap()"); + return (MS_FAILURE); } - switch(token) { + switch (token) { - case(CONFIG): { - char *key=NULL, *value=NULL; + case (CONFIG): { + char *key = NULL, *value = NULL; - if( getString(&key) == MS_FAILURE ) - return MS_FAILURE; + if (getString(&key) == MS_FAILURE) + return MS_FAILURE; - if( getString(&value) == MS_FAILURE ) { - free(key); - return MS_FAILURE; - } + if (getString(&value) == MS_FAILURE) { + free(key); + return MS_FAILURE; + } - if (msSetConfigOption( map, key, value ) == MS_FAILURE) { - free(key); - free(value); - return MS_FAILURE; - } + if (msSetConfigOption(map, key, value) == MS_FAILURE) { + free(key); + free(value); + return MS_FAILURE; + } - free( key ); - free( value ); + free(key); + free(value); + } break; + case (DEBUG): + if ((map->debug = getSymbol(3, MS_ON, MS_OFF, MS_NUMBER)) == -1) + return MS_FAILURE; + if (map->debug == MS_NUMBER) { + if (msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, 0, 5) == MS_FAILURE) { + msSetError(MS_MISCERR, + "Invalid DEBUG level, must be between 0 and 5 (line %d)", + "msLoadMap()", msyylineno); + return (-1); + } + map->debug = (int)msyynumber; } break; - case(DEBUG): - if((map->debug = getSymbol(3, MS_ON,MS_OFF, MS_NUMBER)) == -1) return MS_FAILURE; - if(map->debug == MS_NUMBER) { - if(msCheckNumber(msyynumber, MS_NUM_CHECK_RANGE, 0, 5) == MS_FAILURE) { - msSetError(MS_MISCERR, "Invalid DEBUG level, must be between 0 and 5 (line %d)", "msLoadMap()", msyylineno); - return(-1); - } - map->debug = (int) msyynumber; - } - break; - case(END): - if(msyyin) { - fclose(msyyin); - msyyin = NULL; - } - - /*** Make config options current ***/ - msApplyMapConfigOptions( map ); + case (END): + if (msyyin) { + fclose(msyyin); + msyyin = NULL; + } - /*** Compute rotated extent info if applicable ***/ - msMapComputeGeotransform( map ); + /*** Make config options current ***/ + msApplyMapConfigOptions(map); - /*** OUTPUTFORMAT related setup ***/ - if( msPostMapParseOutputFormatSetup( map ) == MS_FAILURE ) - return MS_FAILURE; + /*** Compute rotated extent info if applicable ***/ + msMapComputeGeotransform(map); - if(loadSymbolSet(&(map->symbolset), map) == -1) return MS_FAILURE; + /*** OUTPUTFORMAT related setup ***/ + if (msPostMapParseOutputFormatSetup(map) == MS_FAILURE) + return MS_FAILURE; - if (resolveSymbolNames(map) == MS_FAILURE) return MS_FAILURE; + if (loadSymbolSet(&(map->symbolset), map) == -1) + return MS_FAILURE; + if (resolveSymbolNames(map) == MS_FAILURE) + return MS_FAILURE; - if(msLoadFontSet(&(map->fontset), map) == -1) return MS_FAILURE; + if (msLoadFontSet(&(map->fontset), map) == -1) + return MS_FAILURE; - return MS_SUCCESS; - break; - case(EOF): - msSetError(MS_EOFERR, NULL, "msLoadMap()"); + return MS_SUCCESS; + break; + case (EOF): + msSetError(MS_EOFERR, NULL, "msLoadMap()"); + return MS_FAILURE; + case (EXTENT): { + if (getDouble(&(map->extent.minx), MS_NUM_CHECK_NONE, -1, -1) == -1) + return MS_FAILURE; + if (getDouble(&(map->extent.miny), MS_NUM_CHECK_NONE, -1, -1) == -1) + return MS_FAILURE; + if (getDouble(&(map->extent.maxx), MS_NUM_CHECK_NONE, -1, -1) == -1) + return MS_FAILURE; + if (getDouble(&(map->extent.maxy), MS_NUM_CHECK_NONE, -1, -1) == -1) + return MS_FAILURE; + if (!MS_VALID_EXTENT(map->extent)) { + msSetError(MS_MISCERR, + "Given map extent is invalid. Check that it " + "is in the form: minx, miny, maxx, maxy", + "loadMapInternal()"); return MS_FAILURE; - case(EXTENT): { - if(getDouble(&(map->extent.minx), MS_NUM_CHECK_NONE, -1, -1) == -1) return MS_FAILURE; - if(getDouble(&(map->extent.miny), MS_NUM_CHECK_NONE, -1, -1) == -1) return MS_FAILURE; - if(getDouble(&(map->extent.maxx), MS_NUM_CHECK_NONE, -1, -1) == -1) return MS_FAILURE; - if(getDouble(&(map->extent.maxy), MS_NUM_CHECK_NONE, -1, -1) == -1) return MS_FAILURE; - if (!MS_VALID_EXTENT(map->extent)) { - msSetError(MS_MISCERR, "Given map extent is invalid. Check that it " \ - "is in the form: minx, miny, maxx, maxy", "loadMapInternal()"); - return MS_FAILURE; - } } + } break; + case (ANGLE): { + double rotation_angle; + if (getDouble(&(rotation_angle), MS_NUM_CHECK_RANGE, -360, 360) == -1) + return MS_FAILURE; + msMapSetRotation(map, rotation_angle); + } break; + case (FONTSET): + if (getString(&map->fontset.filename) == MS_FAILURE) + return MS_FAILURE; + break; + case (IMAGECOLOR): + if (loadColor(&(map->imagecolor), NULL) != MS_SUCCESS) + return MS_FAILURE; + break; + case (IMAGETYPE): + msFree(map->imagetype); + map->imagetype = getToken(); + break; + case (LATLON): + if (loadProjection(&map->latlon) == -1) + return MS_FAILURE; + break; + case (LAYER): + if (msGrowMapLayers(map) == NULL) + return MS_FAILURE; + if (initLayer((GET_LAYER(map, map->numlayers)), map) == -1) + return MS_FAILURE; + if (loadLayer((GET_LAYER(map, map->numlayers)), map) == -1) + return MS_FAILURE; + GET_LAYER(map, map->numlayers)->index = + map->numlayers; /* save the index */ + /* Update the layer order list with the layer's index. */ + map->layerorder[map->numlayers] = map->numlayers; + map->numlayers++; + break; + case (OUTPUTFORMAT): + if (loadOutputFormat(map) == -1) + return MS_FAILURE; + break; + case (LEGEND): + if (loadLegend(&(map->legend), map) == -1) + return MS_FAILURE; + break; + case (MAP): + foundMapToken = MS_TRUE; + break; + case (MAXSIZE): + if (getInteger(&(map->maxsize), MS_NUM_CHECK_GT, 0, -1) == -1) + return MS_FAILURE; + break; + case (NAME): + free(map->name); + map->name = NULL; /* erase default */ + if (getString(&map->name) == MS_FAILURE) + return MS_FAILURE; + break; + case (PROJECTION): + if (loadProjection(&map->projection) == -1) + return MS_FAILURE; + break; + case (QUERYMAP): + if (loadQueryMap(&(map->querymap), map) == -1) + return MS_FAILURE; break; - case(ANGLE): { - double rotation_angle; - if(getDouble(&(rotation_angle), MS_NUM_CHECK_RANGE, -360, 360) == -1) return MS_FAILURE; - msMapSetRotation( map, rotation_angle ); + case (REFERENCE): + if (loadReferenceMap(&(map->reference), map) == -1) + return MS_FAILURE; + break; + case (RESOLUTION): + if (getDouble(&(map->resolution), MS_NUM_CHECK_RANGE, MS_RESOLUTION_MIN, + MS_RESOLUTION_MAX) == -1) + return MS_FAILURE; + break; + case (DEFRESOLUTION): + if (getDouble(&(map->defresolution), MS_NUM_CHECK_RANGE, + MS_RESOLUTION_MIN, MS_RESOLUTION_MAX) == -1) + return MS_FAILURE; + break; + case (SCALE): + case (SCALEDENOM): + if (getDouble(&(map->scaledenom), MS_NUM_CHECK_GTE, 1, -1) == -1) + return MS_FAILURE; + break; + case (SCALEBAR): + if (loadScalebar(&(map->scalebar)) == -1) + return MS_FAILURE; + break; + case (SHAPEPATH): + if (getString(&map->shapepath) == MS_FAILURE) + return MS_FAILURE; + break; + case (SIZE): + if (getInteger(&(map->width), MS_NUM_CHECK_RANGE, 1, map->maxsize) == -1) + return MS_FAILURE; + if (getInteger(&(map->height), MS_NUM_CHECK_RANGE, 1, map->maxsize) == -1) + return MS_FAILURE; + break; + case (STATUS): + if ((map->status = getSymbol(2, MS_ON, MS_OFF)) == -1) + return MS_FAILURE; + break; + case (SYMBOL): + if (msGrowSymbolSet(&(map->symbolset)) == NULL) + return MS_FAILURE; + if ((loadSymbol(map->symbolset.symbol[map->symbolset.numsymbols], + map->mappath) == -1)) { + msFreeSymbol(map->symbolset.symbol[map->symbolset.numsymbols]); + free(map->symbolset.symbol[map->symbolset.numsymbols]); + map->symbolset.symbol[map->symbolset.numsymbols] = NULL; + return MS_FAILURE; } + map->symbolset.symbol[map->symbolset.numsymbols]->inmapfile = MS_TRUE; + map->symbolset.numsymbols++; break; - case(FONTSET): - if(getString(&map->fontset.filename) == MS_FAILURE) return MS_FAILURE; - break; - case(IMAGECOLOR): - if(loadColor(&(map->imagecolor), NULL) != MS_SUCCESS) return MS_FAILURE; - break; - case(IMAGETYPE): - msFree(map->imagetype); - map->imagetype = getToken(); - break; - case(LATLON): - msFreeProjectionExceptContext(&map->latlon); - if(loadProjection(&map->latlon) == -1) return MS_FAILURE; - break; - case(LAYER): - if(msGrowMapLayers(map) == NULL) - return MS_FAILURE; - if(initLayer((GET_LAYER(map, map->numlayers)), map) == -1) return MS_FAILURE; - if(loadLayer((GET_LAYER(map, map->numlayers)), map) == -1) return MS_FAILURE; - GET_LAYER(map, map->numlayers)->index = map->numlayers; /* save the index */ - /* Update the layer order list with the layer's index. */ - map->layerorder[map->numlayers] = map->numlayers; - map->numlayers++; - break; - case(OUTPUTFORMAT): - if(loadOutputFormat(map) == -1) return MS_FAILURE; - break; - case(LEGEND): - if(loadLegend(&(map->legend), map) == -1) return MS_FAILURE; - break; - case(MAP): - foundMapToken = MS_TRUE; - break; - case(MAXSIZE): - if(getInteger(&(map->maxsize), MS_NUM_CHECK_GT, 0, -1) == -1) return MS_FAILURE; - break; - case(NAME): - free(map->name); - map->name = NULL; /* erase default */ - if(getString(&map->name) == MS_FAILURE) return MS_FAILURE; - break; - case(PROJECTION): - if(loadProjection(&map->projection) == -1) return MS_FAILURE; - break; - case(QUERYMAP): - if(loadQueryMap(&(map->querymap), map) == -1) return MS_FAILURE; - break; - case(REFERENCE): - if(loadReferenceMap(&(map->reference), map) == -1) return MS_FAILURE; - break; - case(RESOLUTION): - if(getDouble(&(map->resolution), MS_NUM_CHECK_RANGE, MS_RESOLUTION_MIN, MS_RESOLUTION_MAX) == -1) return MS_FAILURE; - break; - case(DEFRESOLUTION): - if(getDouble(&(map->defresolution), MS_NUM_CHECK_RANGE, MS_RESOLUTION_MIN, MS_RESOLUTION_MAX) == -1) return MS_FAILURE; - break; - case(SCALE): - case(SCALEDENOM): - if(getDouble(&(map->scaledenom), MS_NUM_CHECK_GTE, 1, -1) == -1) return MS_FAILURE; - break; - case(SCALEBAR): - if(loadScalebar(&(map->scalebar)) == -1) return MS_FAILURE; - break; - case(SHAPEPATH): - if(getString(&map->shapepath) == MS_FAILURE) return MS_FAILURE; - break; - case(SIZE): - if(getInteger(&(map->width), MS_NUM_CHECK_RANGE, 1, map->maxsize) == -1) return MS_FAILURE; - if(getInteger(&(map->height), MS_NUM_CHECK_RANGE, 1, map->maxsize) == -1) return MS_FAILURE; - break; - case(STATUS): - if((map->status = getSymbol(2, MS_ON,MS_OFF)) == -1) return MS_FAILURE; - break; - case(SYMBOL): - if(msGrowSymbolSet(&(map->symbolset)) == NULL) - return MS_FAILURE; - if((loadSymbol(map->symbolset.symbol[map->symbolset.numsymbols], map->mappath) == -1)) return MS_FAILURE; - map->symbolset.symbol[map->symbolset.numsymbols]->inmapfile = MS_TRUE; - map->symbolset.numsymbols++; - break; - case(SYMBOLSET): - if(getString(&map->symbolset.filename) == MS_FAILURE) return MS_FAILURE; - break; - case(UNITS): - if((int)(map->units = getSymbol(7, MS_INCHES,MS_FEET,MS_MILES,MS_METERS,MS_KILOMETERS,MS_NAUTICALMILES,MS_DD)) == -1) return MS_FAILURE; - break; - case(WEB): - if(loadWeb(&(map->web), map) == -1) return MS_FAILURE; - break; - default: - msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "msLoadMap()", msyystring_buffer, msyylineno); + case (SYMBOLSET): + if (getString(&map->symbolset.filename) == MS_FAILURE) + return MS_FAILURE; + break; + case (UNITS): + if ((int)(map->units = + getSymbol(7, MS_INCHES, MS_FEET, MS_MILES, MS_METERS, + MS_KILOMETERS, MS_NAUTICALMILES, MS_DD)) == -1) return MS_FAILURE; + break; + case (WEB): + if (loadWeb(&(map->web), map) == -1) + return MS_FAILURE; + break; + default: + msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", + "msLoadMap()", msyystring_buffer, msyylineno); + return MS_FAILURE; } } /* next token */ } +static bool msGetCWD(char *szBuffer, size_t nBufferSize, + const char *pszFunctionName) { + if (NULL == getcwd(szBuffer, nBufferSize)) { +#ifndef _WIN32 + if (errno == EACCES) + msSetError(MS_MISCERR, + "getcwd() failed with EACCES: you may need to force the " + "current directory in the mapserver launcher " + "(e.g -d option of spawn-fcgi)", + pszFunctionName); + else if (errno == ENAMETOOLONG) + msSetError(MS_MISCERR, "getcwd() returned a too long path", + pszFunctionName); + else + msSetError(MS_MISCERR, "getcwd() failed with errno code %d", + pszFunctionName, errno); +#else + msSetError(MS_MISCERR, "getcwd() returned a too long path", + pszFunctionName); +#endif + return FALSE; + } + return TRUE; +} + /* -** Sets up string-based mapfile loading and calls loadMapInternal to do the work. +** Sets up string-based mapfile loading and calls loadMapInternal to do the +*work. */ -mapObj *msLoadMapFromString(char *buffer, char *new_mappath) -{ +mapObj *msLoadMapFromString(char *buffer, char *new_mappath, + const configObj *config) { mapObj *map; struct mstimeval starttime = {0}, endtime = {0}; char szPath[MS_MAXPATHLEN], szCWDPath[MS_MAXPATHLEN]; - char *mappath=NULL; + char *mappath = NULL; int debuglevel; debuglevel = (int)msGetGlobalDebugLevel(); @@ -6139,23 +6858,26 @@ mapObj *msLoadMapFromString(char *buffer, char *new_mappath) msGettimeofday(&starttime, NULL); } - if(!buffer) { + if (!buffer) { msSetError(MS_MISCERR, "No buffer to load.", "msLoadMapFromString()"); - return(NULL); + return (NULL); } /* ** Allocate mapObj structure */ - map = (mapObj *)calloc(sizeof(mapObj),1); + map = (mapObj *)calloc(sizeof(mapObj), 1); MS_CHECK_ALLOC(map, sizeof(mapObj), NULL); - if(initMap(map) == -1) { /* initialize this map */ + if (initMap(map) == -1) { /* initialize this map */ msFreeMap(map); - return(NULL); + return (NULL); } - msAcquireLock( TLOCK_PARSER ); /* might need to move this lock a bit higher, yup (bug 2108) */ + map->config = config; // create a read-only reference + + msAcquireLock(TLOCK_PARSER); /* might need to move this lock a bit higher, yup + (bug 2108) */ msyystate = MS_TOKENIZE_STRING; msyystring = buffer; @@ -6164,10 +6886,9 @@ mapObj *msLoadMapFromString(char *buffer, char *new_mappath) msyylineno = 1; /* start at line 1 (do lines mean anything here?) */ /* If new_mappath is provided then use it, otherwise use the CWD */ - if(NULL == getcwd(szCWDPath, MS_MAXPATHLEN)) { - msSetError(MS_MISCERR, "getcwd() returned a too long path", "msLoadMapFromString()"); + if (!msGetCWD(szCWDPath, MS_MAXPATHLEN, "msLoadMapFromString()")) { msFreeMap(map); - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); } if (new_mappath) { mappath = msStrdup(new_mappath); @@ -6177,27 +6898,30 @@ mapObj *msLoadMapFromString(char *buffer, char *new_mappath) msyybasepath = map->mappath; /* for INCLUDEs */ - if(loadMapInternal(map) != MS_SUCCESS) { + if (loadMapInternal(map) != MS_SUCCESS) { msFreeMap(map); - msReleaseLock( TLOCK_PARSER ); - if(mappath != NULL) free(mappath); + msReleaseLock(TLOCK_PARSER); + if (mappath != NULL) + free(mappath); return NULL; } - if (mappath != NULL) free(mappath); + if (mappath != NULL) + free(mappath); msyylex_destroy(); - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); if (debuglevel >= MS_DEBUGLEVEL_TUNING) { /* In debug mode, report time spent loading/parsing mapfile. */ msGettimeofday(&endtime, NULL); msDebug("msLoadMap(): %.3fs\n", - (endtime.tv_sec+endtime.tv_usec/1.0e6)- - (starttime.tv_sec+starttime.tv_usec/1.0e6) ); + (endtime.tv_sec + endtime.tv_usec / 1.0e6) - + (starttime.tv_sec + starttime.tv_usec / 1.0e6)); } - if (resolveSymbolNames(map) == MS_FAILURE) return NULL; + if (resolveSymbolNames(map) == MS_FAILURE) + return NULL; return map; } @@ -6205,10 +6929,10 @@ mapObj *msLoadMapFromString(char *buffer, char *new_mappath) /* ** Sets up file-based mapfile loading and calls loadMapInternal to do the work. */ -mapObj *msLoadMap(const char *filename, const char *new_mappath, const configObj *config) -{ +mapObj *msLoadMap(const char *filename, const char *new_mappath, + const configObj *config) { mapObj *map; - struct mstimeval starttime={0}, endtime={0}; + struct mstimeval starttime = {0}, endtime = {0}; char szPath[MS_MAXPATHLEN], szCWDPath[MS_MAXPATHLEN]; int debuglevel; @@ -6219,57 +6943,62 @@ mapObj *msLoadMap(const char *filename, const char *new_mappath, const configObj msGettimeofday(&starttime, NULL); } - if(!filename) { + if (!filename) { msSetError(MS_MISCERR, "Filename is undefined.", "msLoadMap()"); - return(NULL); + return (NULL); } - const char *ms_mapfile_pattern = CPLGetConfigOption("MS_MAPFILE_PATTERN", MS_DEFAULT_MAPFILE_PATTERN); - if(msEvalRegex(ms_mapfile_pattern, filename) != MS_TRUE) { - msSetError(MS_REGEXERR, "Filename validation failed." , "msLoadMap()"); - return(NULL); + const char *ms_mapfile_pattern = + CPLGetConfigOption("MS_MAPFILE_PATTERN", MS_DEFAULT_MAPFILE_PATTERN); + if (msEvalRegex(ms_mapfile_pattern, filename) != MS_TRUE) { + msSetError(MS_REGEXERR, "Filename validation failed.", "msLoadMap()"); + return (NULL); } /* ** Allocate mapObj structure */ - map = (mapObj *)calloc(sizeof(mapObj),1); + map = (mapObj *)calloc(sizeof(mapObj), 1); MS_CHECK_ALLOC(map, sizeof(mapObj), NULL); - if(initMap(map) == -1) { /* initialize this map */ + if (initMap(map) == -1) { /* initialize this map */ msFreeMap(map); - return(NULL); + return (NULL); } map->config = config; // create a read-only reference - msAcquireLock( TLOCK_PARSER ); /* Steve: might need to move this lock a bit higher; Umberto: done */ + msAcquireLock(TLOCK_PARSER); /* Steve: might need to move this lock a bit + higher; Umberto: done */ #ifdef USE_XMLMAPFILE /* If the mapfile is an xml mapfile, transform it */ - const char *ms_xmlmapfile_xslt = CPLGetConfigOption("MS_XMLMAPFILE_XSLT", NULL); + const char *ms_xmlmapfile_xslt = + CPLGetConfigOption("MS_XMLMAPFILE_XSLT", NULL); if (ms_xmlmapfile_xslt && (msEvalRegex(MS_DEFAULT_XMLMAPFILE_PATTERN, filename) == MS_TRUE)) { msyyin = tmpfile(); if (msyyin == NULL) { - msSetError(MS_IOERR, "tmpfile() failed to create temporary file", "msLoadMap()"); - msReleaseLock( TLOCK_PARSER ); + msSetError(MS_IOERR, "tmpfile() failed to create temporary file", + "msLoadMap()"); + msReleaseLock(TLOCK_PARSER); msFreeMap(map); return NULL; } - if (msTransformXmlMapfile(ms_xmlmapfile_xslt, filename, msyyin) != MS_SUCCESS) { + if (msTransformXmlMapfile(ms_xmlmapfile_xslt, filename, msyyin) != + MS_SUCCESS) { fclose(msyyin); msFreeMap(map); return NULL; } - fseek ( msyyin , 0 , SEEK_SET ); + fseek(msyyin, 0, SEEK_SET); } else { #endif - if((msyyin = fopen(filename,"r")) == NULL) { + if ((msyyin = fopen(filename, "r")) == NULL) { msSetError(MS_IOERR, "(%s)", "msLoadMap()", filename); - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); msFreeMap(map); return NULL; } @@ -6285,9 +7014,8 @@ mapObj *msLoadMap(const char *filename, const char *new_mappath, const configObj /* If new_mappath is provided then use it, otherwise use the location */ /* of the mapfile as the default path */ - if(NULL == getcwd(szCWDPath, MS_MAXPATHLEN)) { - msSetError(MS_MISCERR, "getcwd() returned a too long path", "msLoadMap()"); - msReleaseLock( TLOCK_PARSER ); + if (!msGetCWD(szCWDPath, MS_MAXPATHLEN, "msLoadMap()")) { + msReleaseLock(TLOCK_PARSER); msFreeMap(map); return NULL; } @@ -6297,41 +7025,42 @@ mapObj *msLoadMap(const char *filename, const char *new_mappath, const configObj else { char *path = msGetPath(filename); map->mappath = msStrdup(msBuildPath(szPath, szCWDPath, path)); - free( path ); + free(path); } msyybasepath = map->mappath; /* for INCLUDEs */ - if(loadMapInternal(map) != MS_SUCCESS) { + if (loadMapInternal(map) != MS_SUCCESS) { msFreeMap(map); - msReleaseLock( TLOCK_PARSER ); - if( msyyin ) { + msReleaseLock(TLOCK_PARSER); + if (msyyin) { msyycleanup_includes(); fclose(msyyin); msyyin = NULL; } return NULL; } - msReleaseLock( TLOCK_PARSER ); + msReleaseLock(TLOCK_PARSER); if (debuglevel >= MS_DEBUGLEVEL_TUNING) { /* In debug mode, report time spent loading/parsing mapfile. */ msGettimeofday(&endtime, NULL); msDebug("msLoadMap(): %.3fs\n", - (endtime.tv_sec+endtime.tv_usec/1.0e6)- - (starttime.tv_sec+starttime.tv_usec/1.0e6) ); + (endtime.tv_sec + endtime.tv_usec / 1.0e6) - + (starttime.tv_sec + starttime.tv_usec / 1.0e6)); } return map; } -static void hashTableSubstituteString(hashTableObj *hash, const char *from, const char *to) { +static void hashTableSubstituteString(hashTableObj *hash, const char *from, + const char *to) { const char *key, *val; char *new_val; key = msFirstKeyFromHashTable(hash); - while(key != NULL) { + while (key != NULL) { val = msLookupHashTable(hash, key); - if(strcasestr(val, from)) { + if (strcasestr(val, from)) { new_val = msCaseReplaceSubstring(msStrdup(val), from, to); msInsertHashTable(hash, key, new_val); msFree(new_val); @@ -6340,64 +7069,81 @@ static void hashTableSubstituteString(hashTableObj *hash, const char *from, cons } } -static void classSubstituteString(classObj *class, const char *from, const char *to) { - if(class->expression.string) class->expression.string = msCaseReplaceSubstring(class->expression.string, from, to); - if(class->text.string) class->text.string = msCaseReplaceSubstring(class->text.string, from, to); - if(class->title) class->title = msCaseReplaceSubstring(class->title, from, to); +static void classSubstituteString(classObj *class, const char *from, + const char *to) { + if (class->expression.string) + class->expression.string = + msCaseReplaceSubstring(class->expression.string, from, to); + if (class->text.string) + class->text.string = msCaseReplaceSubstring(class->text.string, from, to); + if (class->title) + class->title = msCaseReplaceSubstring(class->title, from, to); } - -static void layerSubstituteString(layerObj *layer, const char *from, const char *to) -{ +static void layerSubstituteString(layerObj *layer, const char *from, + const char *to) { int c; - if(layer->data) layer->data = msCaseReplaceSubstring(layer->data, from, to); - if(layer->tileindex) layer->tileindex = msCaseReplaceSubstring(layer->tileindex, from, to); - if(layer->connection) layer->connection = msCaseReplaceSubstring(layer->connection, from, to); - if(layer->filter.string) layer->filter.string = msCaseReplaceSubstring(layer->filter.string, from, to); - if(layer->mask) layer->mask = msCaseReplaceSubstring(layer->mask, from, to); // new for 8.0 - - /* The bindvalues are most useful when able to substitute values from the URL */ + if (layer->data) + layer->data = msCaseReplaceSubstring(layer->data, from, to); + if (layer->tileindex) + layer->tileindex = msCaseReplaceSubstring(layer->tileindex, from, to); + if (layer->connection) + layer->connection = msCaseReplaceSubstring(layer->connection, from, to); + if (layer->filter.string) + layer->filter.string = + msCaseReplaceSubstring(layer->filter.string, from, to); + if (layer->mask) + layer->mask = msCaseReplaceSubstring(layer->mask, from, to); // new for 8.0 + + /* The bindvalues are most useful when able to substitute values from the URL + */ hashTableSubstituteString(&layer->bindvals, from, to); hashTableSubstituteString(&layer->metadata, from, to); - msLayerSubstituteProcessing( layer, from, to ); - for(c=0; cnumclasses;c++) { + msLayerSubstituteProcessing(layer, from, to); + for (c = 0; c < layer->numclasses; c++) { classSubstituteString(layer->class[c], from, to); } } static void mapSubstituteString(mapObj *map, const char *from, const char *to) { int l; - for(l=0;lnumlayers; l++) { - layerSubstituteString(GET_LAYER(map,l), from, to); + for (l = 0; l < map->numlayers; l++) { + layerSubstituteString(GET_LAYER(map, l), from, to); } /* output formats (#3751) */ - for(l=0; lnumoutputformats; l++) { + for (l = 0; l < map->numoutputformats; l++) { int o; - for(o=0; ooutputformatlist[l]->numformatoptions; o++) { - map->outputformatlist[l]->formatoptions[o] = msCaseReplaceSubstring(map->outputformatlist[l]->formatoptions[o], from, to); + for (o = 0; o < map->outputformatlist[l]->numformatoptions; o++) { + map->outputformatlist[l]->formatoptions[o] = msCaseReplaceSubstring( + map->outputformatlist[l]->formatoptions[o], from, to); } } + hashTableSubstituteString(&map->web.metadata, from, to); + if (map->web.template) + map->web.template = msCaseReplaceSubstring(map->web.template, from, to); } -static void applyOutputFormatDefaultSubstitutions(outputFormatObj *format, const char *option, hashTableObj *table) -{ +static void applyOutputFormatDefaultSubstitutions(outputFormatObj *format, + const char *option, + hashTableObj *table) { const char *filename; filename = msGetOutputFormatOption(format, option, NULL); - if(filename && strlen(filename)>0) { + if (filename && strlen(filename) > 0) { char *tmpfilename = msStrdup(filename); const char *default_key = msFirstKeyFromHashTable(table); - while(default_key) { - if(!strncasecmp(default_key,"default_",8)) { + while (default_key) { + if (!strncasecmp(default_key, "default_", 8)) { char *new_filename = NULL; - size_t buffer_size = (strlen(default_key)-5); + size_t buffer_size = (strlen(default_key) - 5); char *tag = (char *)msSmallMalloc(buffer_size); snprintf(tag, buffer_size, "%%%s%%", &(default_key[8])); new_filename = msStrdup(tmpfilename); - new_filename = msCaseReplaceSubstring(new_filename, tag, msLookupHashTable(table, default_key)); + new_filename = msCaseReplaceSubstring( + new_filename, tag, msLookupHashTable(table, default_key)); free(tag); msSetOutputFormatOption(format, option, new_filename); @@ -6410,12 +7156,12 @@ static void applyOutputFormatDefaultSubstitutions(outputFormatObj *format, const return; } -static void applyClassDefaultSubstitutions(classObj *class, hashTableObj *table) -{ +static void applyClassDefaultSubstitutions(classObj *class, + hashTableObj *table) { const char *default_key = msFirstKeyFromHashTable(table); - while(default_key) { - if(!strncasecmp(default_key,"default_",8)) { - size_t buffer_size = (strlen(default_key)-5); + while (default_key) { + if (!strncasecmp(default_key, "default_", 8)) { + size_t buffer_size = (strlen(default_key) - 5); char *tag = (char *)msSmallMalloc(buffer_size); snprintf(tag, buffer_size, "%%%s%%", &(default_key[8])); @@ -6427,18 +7173,18 @@ static void applyClassDefaultSubstitutions(classObj *class, hashTableObj *table) return; } -static void applyLayerDefaultSubstitutions(layerObj *layer, hashTableObj *table) -{ +static void applyLayerDefaultSubstitutions(layerObj *layer, + hashTableObj *table) { int i; const char *default_key = msFirstKeyFromHashTable(table); - while(default_key) { - if(!strncasecmp(default_key,"default_",8)) { - size_t buffer_size = (strlen(default_key)-5); + while (default_key) { + if (!strncasecmp(default_key, "default_", 8)) { + size_t buffer_size = (strlen(default_key) - 5); const char *to = msLookupHashTable(table, default_key); char *tag = (char *)msSmallMalloc(buffer_size); snprintf(tag, buffer_size, "%%%s%%", &(default_key[8])); - for(i=0; inumclasses; i++) { + for (i = 0; i < layer->numclasses; i++) { classSubstituteString(layer->class[i], tag, to); } layerSubstituteString(layer, tag, to); @@ -6449,8 +7195,8 @@ static void applyLayerDefaultSubstitutions(layerObj *layer, hashTableObj *table) return; } -static void applyHashTableDefaultSubstitutions(hashTableObj *hashTab, hashTableObj *table) -{ +static void applyHashTableDefaultSubstitutions(hashTableObj *hashTab, + hashTableObj *table) { const char *default_key = msFirstKeyFromHashTable(table); while (default_key) { if (!strncasecmp(default_key, "default_", 8)) { @@ -6468,117 +7214,134 @@ static void applyHashTableDefaultSubstitutions(hashTableObj *hashTab, hashTableO } /* -** Loop through layer metadata for keys that have a default_%key% pattern to replace +** Loop through layer metadata for keys that have a default_%key% pattern to +*replace ** remaining %key% entries by their default value. */ -void msApplyDefaultSubstitutions(mapObj *map) -{ - int i,j; +void msApplyDefaultSubstitutions(mapObj *map) { + int i, j; /* output formats (#3751) */ - for(i=0; inumoutputformats; i++) { - applyOutputFormatDefaultSubstitutions(map->outputformatlist[i], "filename", &(map->web.validation)); - applyOutputFormatDefaultSubstitutions(map->outputformatlist[i], "JSONP", &(map->web.validation)); + for (i = 0; i < map->numoutputformats; i++) { + applyOutputFormatDefaultSubstitutions(map->outputformatlist[i], "filename", + &(map->web.validation)); + applyOutputFormatDefaultSubstitutions(map->outputformatlist[i], "JSONP", + &(map->web.validation)); } - for(i=0; inumlayers; i++) { + for (i = 0; i < map->numlayers; i++) { layerObj *layer = GET_LAYER(map, i); - for(j=0; jnumclasses; j++) { /* class settings take precedence... */ + for (j = 0; j < layer->numclasses; + j++) { /* class settings take precedence... */ classObj *class = GET_CLASS(map, i, j); applyClassDefaultSubstitutions(class, &(class->validation)); } - applyLayerDefaultSubstitutions(layer, &(layer->validation)); /* ...then layer settings... */ - applyLayerDefaultSubstitutions(layer, &(map->web.validation)); /* ...and finally web settings */ + applyLayerDefaultSubstitutions( + layer, &(layer->validation)); /* ...then layer settings... */ + applyLayerDefaultSubstitutions( + layer, &(map->web.validation)); /* ...and finally web settings */ } - applyHashTableDefaultSubstitutions(&map->web.metadata, &(map->web.validation)); + applyHashTableDefaultSubstitutions(&map->web.metadata, + &(map->web.validation)); } -char *_get_param_value(const char *key, char **names, char **values, int npairs) -{ - if(npairs <= 0) return NULL; // bail, no point searching +char *_get_param_value(const char *key, char **names, char **values, + int npairs) { + if (npairs <= 0) + return NULL; // bail, no point searching - if(getenv(key)) { /* envirronment override */ + if (getenv(key)) { /* envirronment override */ return getenv(key); } - while(npairs) { + while (npairs) { npairs--; - if(strcasecmp(key, names[npairs]) == 0) { + if (strcasecmp(key, names[npairs]) == 0) { return values[npairs]; } } return NULL; } -void msApplySubstitutions(mapObj *map, char **names, char **values, int npairs) -{ +void msApplySubstitutions(mapObj *map, char **names, char **values, + int npairs) { int l; const char *key, *value, *validation; char *tag; - for(l=0; lnumlayers; l++) { + for (l = 0; l < map->numlayers; l++) { int c; - layerObj *lp = GET_LAYER(map,l); - for(c=0; cnumclasses; c++) { + layerObj *lp = GET_LAYER(map, l); + for (c = 0; c < lp->numclasses; c++) { classObj *cp = lp->class[c]; key = NULL; - while( (key = msNextKeyFromHashTable(&cp->validation, key)) ) { - value = _get_param_value(key,names,values,npairs); - if(!value) continue; /*parameter was not in url*/ + while ((key = msNextKeyFromHashTable(&cp->validation, key))) { + value = _get_param_value(key, names, values, npairs); + if (!value) + continue; /*parameter was not in url*/ validation = msLookupHashTable(&cp->validation, key); - if(msEvalRegex(validation, value)) { - /* we've found a substitution and it validates correctly, now let's apply it */ - tag = msSmallMalloc(strlen(key)+3); - sprintf(tag,"%%%s%%",key); - classSubstituteString(cp,tag,value); + if (msEvalRegex(validation, value)) { + /* we've found a substitution and it validates correctly, now let's + * apply it */ + tag = msSmallMalloc(strlen(key) + 3); + sprintf(tag, "%%%s%%", key); + classSubstituteString(cp, tag, value); free(tag); } else { - msSetError(MS_REGEXERR, "Parameter pattern validation failed." , "msApplySubstitutions()"); - if(map->debug || lp->debug) { - msDebug("layer (%s), class %d: failed to validate (%s=%s) for regex (%s)\n", lp->name, c, key, value, validation); + msSetError(MS_REGEXERR, "Parameter pattern validation failed.", + "msApplySubstitutions()"); + if (map->debug || lp->debug) { + msDebug("layer (%s), class %d: failed to validate (%s=%s) for " + "regex (%s)\n", + lp->name, c, key, value, validation); } } - } } key = NULL; - while( (key = msNextKeyFromHashTable(&lp->validation, key)) ) { - value = _get_param_value(key,names,values,npairs); - if(!value) continue; /*parameter was not in url*/ + while ((key = msNextKeyFromHashTable(&lp->validation, key))) { + value = _get_param_value(key, names, values, npairs); + if (!value) + continue; /*parameter was not in url*/ validation = msLookupHashTable(&lp->validation, key); - if(msEvalRegex(validation, value)) { - /* we've found a substitution and it validates correctly, now let's apply it */ - tag = msSmallMalloc(strlen(key)+3); - sprintf(tag,"%%%s%%",key); - layerSubstituteString(lp,tag,value); + if (msEvalRegex(validation, value)) { + /* we've found a substitution and it validates correctly, now let's + * apply it */ + tag = msSmallMalloc(strlen(key) + 3); + sprintf(tag, "%%%s%%", key); + layerSubstituteString(lp, tag, value); free(tag); } else { - msSetError(MS_REGEXERR, "Parameter pattern validation failed." , "msApplySubstitutions()"); - if(map->debug || lp->debug) { - msDebug("layer (%s): failed to validate (%s=%s) for regex (%s)\n", lp->name, key, value, validation); + msSetError(MS_REGEXERR, "Parameter pattern validation failed.", + "msApplySubstitutions()"); + if (map->debug || lp->debug) { + msDebug("layer (%s): failed to validate (%s=%s) for regex (%s)\n", + lp->name, key, value, validation); } } - } } key = NULL; - while( (key = msNextKeyFromHashTable(&map->web.validation, key)) ) { - value = _get_param_value(key,names,values,npairs); - if(!value) continue; /*parameter was not in url*/ + while ((key = msNextKeyFromHashTable(&map->web.validation, key))) { + value = _get_param_value(key, names, values, npairs); + if (!value) + continue; /*parameter was not in url*/ validation = msLookupHashTable(&map->web.validation, key); - if(msEvalRegex(validation, value)) { - /* we've found a substitution and it validates correctly, now let's apply it */ - tag = msSmallMalloc(strlen(key)+3); - sprintf(tag,"%%%s%%",key); - mapSubstituteString(map,tag,value); + if (msEvalRegex(validation, value)) { + /* we've found a substitution and it validates correctly, now let's apply + * it */ + tag = msSmallMalloc(strlen(key) + 3); + sprintf(tag, "%%%s%%", key); + mapSubstituteString(map, tag, value); free(tag); } else { - msSetError(MS_REGEXERR, "Parameter pattern validation failed." , "msApplySubstitutions()"); - if(map->debug) { - msDebug("failed to validate (%s=%s) for regex (%s)\n", key, value, validation); + msSetError(MS_REGEXERR, "Parameter pattern validation failed.", + "msApplySubstitutions()"); + if (map->debug) { + msDebug("failed to validate (%s=%s) for regex (%s)\n", key, value, + validation); } } - } } @@ -6588,15 +7351,14 @@ void msApplySubstitutions(mapObj *map, char **names, char **values, int npairs) ** ** The returned array should be freed using msFreeCharArray(). */ -static char **tokenizeMapInternal(char *filename, int *ret_numtokens) -{ +static char **tokenizeMapInternal(char *filename, int *ret_numtokens) { char **tokens = NULL; - int numtokens=0, numtokens_allocated=0; + int numtokens = 0, numtokens_allocated = 0; size_t buffer_size = 0; *ret_numtokens = 0; - if(!filename) { + if (!filename) { msSetError(MS_MISCERR, "Filename is undefined.", "msTokenizeMap()"); return NULL; } @@ -6604,18 +7366,20 @@ static char **tokenizeMapInternal(char *filename, int *ret_numtokens) /* ** Check map filename to make sure it's legal */ - const char *ms_mapfile_pattern = CPLGetConfigOption("MS_MAPFILE_PATTERN", MS_DEFAULT_MAPFILE_PATTERN); - if(msEvalRegex(ms_mapfile_pattern, filename) != MS_TRUE) { - msSetError(MS_REGEXERR, "Filename validation failed." , "msLoadMap()"); - return(NULL); + const char *ms_mapfile_pattern = + CPLGetConfigOption("MS_MAPFILE_PATTERN", MS_DEFAULT_MAPFILE_PATTERN); + if (msEvalRegex(ms_mapfile_pattern, filename) != MS_TRUE) { + msSetError(MS_REGEXERR, "Filename validation failed.", "msLoadMap()"); + return (NULL); } - if((msyyin = fopen(filename,"r")) == NULL) { + if ((msyyin = fopen(filename, "r")) == NULL) { msSetError(MS_IOERR, "(%s)", "msTokenizeMap()", filename); return NULL; } - msyystate = MS_TOKENIZE_FILE; /* restore lexer state to INITIAL, and do return comments */ + msyystate = MS_TOKENIZE_FILE; /* restore lexer state to INITIAL, and do return + comments */ msyylex(); msyyreturncomments = 1; /* want all tokens, including comments */ @@ -6624,60 +7388,62 @@ static char **tokenizeMapInternal(char *filename, int *ret_numtokens) numtokens = 0; numtokens_allocated = 256; - tokens = (char **) malloc(numtokens_allocated*sizeof(char*)); - if(tokens == NULL) { + tokens = (char **)malloc(numtokens_allocated * sizeof(char *)); + if (tokens == NULL) { msSetError(MS_MEMERR, NULL, "msTokenizeMap()"); fclose(msyyin); return NULL; } - for(;;) { + for (;;) { - if(numtokens_allocated <= numtokens) { - numtokens_allocated *= 2; /* double size of the array every time we reach the limit */ - char** tokensNew = (char **)realloc(tokens, numtokens_allocated*sizeof(char*)); - if(tokensNew == NULL) { + if (numtokens_allocated <= numtokens) { + numtokens_allocated *= + 2; /* double size of the array every time we reach the limit */ + char **tokensNew = + (char **)realloc(tokens, numtokens_allocated * sizeof(char *)); + if (tokensNew == NULL) { msSetError(MS_MEMERR, "Realloc() error.", "msTokenizeMap()"); fclose(msyyin); - for(int i=0; inumlayers; i++) { + for (i = 0; i < map->numlayers; i++) { lp = (GET_LAYER(map, i)); - /* If the vtable is null, then the layer is never accessed or used -> skip it + /* If the vtable is null, then the layer is never accessed or used -> skip + * it */ if (lp->vtable) { lp->vtable->LayerCloseConnection(lp); @@ -6719,47 +7484,42 @@ void msCloseConnections(mapObj *map) } } -void initResultCache(resultCacheObj *resultcache) -{ +void initResultCache(resultCacheObj *resultcache) { if (resultcache) { resultcache->results = NULL; resultcache->numresults = 0; resultcache->cachesize = 0; - resultcache->bounds.minx = resultcache->bounds.miny = resultcache->bounds.maxx = resultcache->bounds.maxy = -1; + resultcache->bounds.minx = resultcache->bounds.miny = + resultcache->bounds.maxx = resultcache->bounds.maxy = -1; resultcache->previousBounds = resultcache->bounds; } } -void cleanupResultCache(resultCacheObj *resultcache) -{ - if(resultcache) { - if(resultcache->results) - { - int i; - for( i = 0; i < resultcache->numresults; i++ ) - { - if( resultcache->results[i].shape ) - { - msFreeShape( resultcache->results[i].shape ); - msFree( resultcache->results[i].shape ); - } +void cleanupResultCache(resultCacheObj *resultcache) { + if (resultcache) { + if (resultcache->results) { + int i; + for (i = 0; i < resultcache->numresults; i++) { + if (resultcache->results[i].shape) { + msFreeShape(resultcache->results[i].shape); + msFree(resultcache->results[i].shape); } - free(resultcache->results); + } + free(resultcache->results); } resultcache->results = NULL; initResultCache(resultcache); } } - -static int resolveSymbolNames(mapObj* map) -{ +static int resolveSymbolNames(mapObj *map) { int i, j; /* step through layers and classes to resolve symbol names */ - for(i=0; inumlayers; i++) { - for(j=0; jnumclasses; j++) { - if(classResolveSymbolNames(GET_LAYER(map, i)->class[j]) != MS_SUCCESS) return MS_FAILURE; + for (i = 0; i < map->numlayers; i++) { + for (j = 0; j < GET_LAYER(map, i)->numclasses; j++) { + if (classResolveSymbolNames(GET_LAYER(map, i)->class[j]) != MS_SUCCESS) + return MS_FAILURE; } } diff --git a/mapfile.h b/mapfile.h index a527691486..d2a8990cea 100644 --- a/mapfile.h +++ b/mapfile.h @@ -27,12 +27,19 @@ * DEALINGS IN THE SOFTWARE. ****************************************************************************/ - #ifndef MAPFILE_H #define MAPFILE_H -enum MS_LEXER_STATES {MS_TOKENIZE_DEFAULT=0, MS_TOKENIZE_FILE, MS_TOKENIZE_STRING, MS_TOKENIZE_EXPRESSION, MS_TOKENIZE_VALUE, MS_TOKENIZE_NAME, MS_TOKENIZE_CONFIG}; -enum MS_TOKEN_SOURCES {MS_FILE_TOKENS=0, MS_STRING_TOKENS}; +enum MS_LEXER_STATES { + MS_TOKENIZE_DEFAULT = 0, + MS_TOKENIZE_FILE, + MS_TOKENIZE_STRING, + MS_TOKENIZE_EXPRESSION, + MS_TOKENIZE_VALUE, + MS_TOKENIZE_NAME, + MS_TOKENIZE_CONFIG +}; +enum MS_TOKEN_SOURCES { MS_FILE_TOKENS = 0, MS_STRING_TOKENS }; /* ** Keyword definitions for the mapfiles and symbolfiles (used by lexer) @@ -81,7 +88,6 @@ enum MS_TOKEN_SOURCES {MS_FILE_TOKENS=0, MS_STRING_TOKENS}; #define LOG 1043 #define MAP 1044 - #define MAXFEATURES 1047 #define MAXSCALE 1048 #define MAXSIZE 1049 @@ -190,10 +196,10 @@ enum MS_TOKEN_SOURCES {MS_FILE_TOKENS=0, MS_STRING_TOKENS}; #define MAXINTERVAL 1144 #define MININTERVAL 1145 #define MAXSUBDIVIDE 1146 -#define MINSUBDIVIDE 1147 -#define LABELFORMAT 1148 +#define MINSUBDIVIDE 1147 +#define LABELFORMAT 1148 -#define PROCESSING 1153 +#define PROCESSING 1153 /* The DEBUG macro is also used to request debugging output. Redefine for keyword purposes. */ @@ -308,7 +314,6 @@ enum MS_TOKEN_SOURCES {MS_FILE_TOKENS=0, MS_STRING_TOKENS}; #define COMPOP 1291 #define COMPFILTER 1292 - #define BOM 1300 /* rfc59 bindvals objects */ diff --git a/mapflatgeobuf.c b/mapflatgeobuf.c index 1dbc1c49b3..3b73df1de5 100644 --- a/mapflatgeobuf.c +++ b/mapflatgeobuf.c @@ -39,66 +39,66 @@ #include #include -static void msFGBPassThroughFieldDefinitions(layerObj *layer, flatgeobuf_ctx *ctx) -{ +static void msFGBPassThroughFieldDefinitions(layerObj *layer, + flatgeobuf_ctx *ctx) { for (int i = 0; i < ctx->columns_len; i++) { - char item[16]; - //int nWidth=0, nPrecision=0; + char item[255]; char gml_width[32], gml_precision[32]; const char *gml_type = NULL; - flatgeobuf_column column = ctx->columns[i]; + const flatgeobuf_column *column = &(ctx->columns[i]); + strncpy(item, column->name, 255 - 1); gml_width[0] = '\0'; gml_precision[0] = '\0'; - switch( column.type ) { - case flatgeobuf_column_type_byte: - case flatgeobuf_column_type_ubyte: - case flatgeobuf_column_type_bool: - case flatgeobuf_column_type_short: - case flatgeobuf_column_type_ushort: - case flatgeobuf_column_type_int: - case flatgeobuf_column_type_uint: - gml_type = "Integer"; - //sprintf( gml_width, "%d", nWidth ); - break; - case flatgeobuf_column_type_long: - case flatgeobuf_column_type_ulong: - gml_type = "Long"; - //sprintf( gml_width, "%d", nWidth ); - break; - case flatgeobuf_column_type_float: - case flatgeobuf_column_type_double: - gml_type = "Real"; - //sprintf( gml_width, "%d", nWidth ); - //sprintf( gml_precision, "%d", nPrecision ); - break; - case flatgeobuf_column_type_string: - case flatgeobuf_column_type_json: - case flatgeobuf_column_type_datetime: - default: - gml_type = "Character"; - //sprintf( gml_width, "%d", nWidth ); - break; + switch (column->type) { + case flatgeobuf_column_type_byte: + case flatgeobuf_column_type_ubyte: + case flatgeobuf_column_type_bool: + case flatgeobuf_column_type_short: + case flatgeobuf_column_type_ushort: + case flatgeobuf_column_type_int: + case flatgeobuf_column_type_uint: + gml_type = "Integer"; + sprintf(gml_width, "%d", 4); + break; + case flatgeobuf_column_type_long: + case flatgeobuf_column_type_ulong: + gml_type = "Long"; + sprintf(gml_width, "%d", 8); + break; + case flatgeobuf_column_type_float: + case flatgeobuf_column_type_double: + gml_type = "Real"; + sprintf(gml_width, "%d", 8); + sprintf(gml_precision, "%d", 15); + break; + case flatgeobuf_column_type_string: + case flatgeobuf_column_type_json: + case flatgeobuf_column_type_datetime: + default: + gml_type = "Character"; + sprintf(gml_width, "%d", 4096); + break; } - msUpdateGMLFieldMetadata(layer, item, gml_type, gml_width, gml_precision, 0); + msUpdateGMLFieldMetadata(layer, item, gml_type, gml_width, gml_precision, + 0); } } -void msFlatGeobufLayerFreeItemInfo(layerObj *layer) -{ +void msFlatGeobufLayerFreeItemInfo(layerObj *layer) { if (layer->iteminfo) { free(layer->iteminfo); layer->iteminfo = NULL; } } -int msFlatGeobufLayerInitItemInfo(layerObj *layer) -{ - if(!layer->layerinfo) { - msSetError(MS_FGBERR, "FlatGeobuf layer has not been opened.", "msFlatGeobufLayerInitItemInfo()"); +int msFlatGeobufLayerInitItemInfo(layerObj *layer) { + if (!layer->layerinfo) { + msSetError(MS_FGBERR, "FlatGeobuf layer has not been opened.", + "msFlatGeobufLayerInitItemInfo()"); return MS_FAILURE; } @@ -109,31 +109,38 @@ int msFlatGeobufLayerInitItemInfo(layerObj *layer) if (!ctx) return MS_FAILURE; - for (int i = 0; i < layer->numitems; i++) - for (int j = 0; j < ctx->columns_len; j++) - if (strcasecmp(layer->items[i], ctx->columns[j].name) == 0) + for (int j = 0; j < ctx->columns_len; j++) { + ctx->columns[j].itemindex = -1; + for (int i = 0; i < layer->numitems; i++) { + if (strcasecmp(layer->items[i], ctx->columns[j].name) == 0) { ctx->columns[j].itemindex = i; + break; + } + } + } return MS_SUCCESS; } -int msFlatGeobufLayerOpen(layerObj *layer) -{ +int msFlatGeobufLayerOpen(layerObj *layer) { char szPath[MS_MAXPATHLEN]; int ret; - if(layer->layerinfo) + if (layer->layerinfo) return MS_SUCCESS; - if (msCheckParentPointer(layer->map,"map") == MS_FAILURE) + if (msCheckParentPointer(layer->map, "map") == MS_FAILURE) return MS_FAILURE; flatgeobuf_ctx *ctx = flatgeobuf_init_ctx(); layer->layerinfo = ctx; - ctx->file = VSIFOpenL(msBuildPath(szPath, layer->map->mappath, layer->data), "rb"); + ctx->file = + VSIFOpenL(msBuildPath(szPath, layer->map->mappath, layer->data), "rb"); if (!ctx->file) - ctx->file = VSIFOpenL(msBuildPath3(szPath, layer->map->mappath, layer->map->shapepath, layer->data), "rb"); + ctx->file = VSIFOpenL(msBuildPath3(szPath, layer->map->mappath, + layer->map->shapepath, layer->data), + "rb"); if (!ctx->file) { layer->layerinfo = NULL; flatgeobuf_free_ctx(ctx); @@ -155,36 +162,48 @@ int msFlatGeobufLayerOpen(layerObj *layer) } if (layer->projection.numargs > 0 && - EQUAL(layer->projection.args[0], "auto")) - { - OGRSpatialReferenceH hSRS = OSRNewSpatialReference( NULL ); - if (ctx->srid) - if (!(OSRImportFromEPSG(hSRS, ctx->srid) != OGRERR_NONE)) - return -1; + EQUAL(layer->projection.args[0], "auto")) { + OGRSpatialReferenceH hSRS = OSRNewSpatialReference(NULL); char *pszWKT = NULL; + if (ctx->srid > 0) { + if (OSRImportFromEPSG(hSRS, ctx->srid) != OGRERR_NONE) { + OSRDestroySpatialReference(hSRS); + flatgeobuf_free_ctx(ctx); + return MS_FAILURE; + } + if (OSRExportToWkt(hSRS, &pszWKT) != OGRERR_NONE) { + OSRDestroySpatialReference(hSRS); + flatgeobuf_free_ctx(ctx); + return MS_FAILURE; + } + } else if (ctx->wkt == NULL) { + OSRDestroySpatialReference(hSRS); + return MS_SUCCESS; + } int bOK = MS_FALSE; - if (msOGCWKT2ProjectionObj(pszWKT, &(layer->projection), layer->debug) == MS_SUCCESS) + if (msOGCWKT2ProjectionObj(ctx->wkt ? ctx->wkt : pszWKT, + &(layer->projection), + layer->debug) == MS_SUCCESS) bOK = MS_TRUE; CPLFree(pszWKT); OSRDestroySpatialReference(hSRS); - if( bOK != MS_TRUE ) - if( layer->debug || layer->map->debug ) - msDebug( "Unable to get SRS from FlatGeobuf '%s' for layer '%s'.\n", szPath, layer->name ); + if (bOK != MS_TRUE) + if (layer->debug || layer->map->debug) + msDebug("Unable to get SRS from FlatGeobuf '%s' for layer '%s'.\n", + szPath, layer->name); } return MS_SUCCESS; } -int msFlatGeobufLayerIsOpen(layerObj *layer) -{ - if(layer->layerinfo) +int msFlatGeobufLayerIsOpen(layerObj *layer) { + if (layer->layerinfo) return MS_TRUE; else return MS_FALSE; } -int msFlatGeobufLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) -{ +int msFlatGeobufLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) { (void)isQuery; flatgeobuf_ctx *ctx; ctx = layer->layerinfo; @@ -194,47 +213,62 @@ int msFlatGeobufLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) if (!ctx->has_extent || !ctx->index_node_size) return MS_SUCCESS; - if(msRectOverlap(&ctx->bounds, &rect) != MS_TRUE) + if (msRectOverlap(&ctx->bounds, &rect) != MS_TRUE) return MS_DONE; - if (msRectContained(&ctx->bounds, &rect) == MS_FALSE && ctx->index_node_size > 0) + if (msRectContained(&ctx->bounds, &rect) == MS_FALSE && + ctx->index_node_size > 0) { flatgeobuf_index_search(ctx, &rect); - else + if (ctx->search_result_len == 0) + return MS_DONE; + } else { flatgeobuf_index_skip(ctx); + } return MS_SUCCESS; } -int msFlatGeobufLayerNextShape(layerObj *layer, shapeObj *shape) -{ +int msFlatGeobufLayerNextShape(layerObj *layer, shapeObj *shape) { flatgeobuf_ctx *ctx; ctx = layer->layerinfo; if (!ctx) return MS_FAILURE; - if (ctx->search_result) { - if (ctx->search_index >= ctx->search_result_len - 1) - return MS_DONE; - flatgeobuf_search_item item = ctx->search_result[ctx->search_index]; - if (VSIFSeekL(ctx->file, ctx->feature_offset + item.offset, SEEK_SET) == -1) { - msSetError(MS_FGBERR, "Unable to seek in file", "msFlatGeobufLayerNextShape"); + do { + if (ctx->search_result) { + if (ctx->search_index >= ctx->search_result_len) + return MS_DONE; + flatgeobuf_search_item item = ctx->search_result[ctx->search_index]; + if (VSIFSeekL(ctx->file, ctx->feature_offset + item.offset, SEEK_SET) == + -1) { + msSetError(MS_FGBERR, "Unable to seek in file", + "msFlatGeobufLayerNextShape"); return MS_FAILURE; + } + ctx->offset = ctx->feature_offset + item.offset; + ctx->search_index++; + ctx->feature_index = item.index; } - ctx->offset = ctx->feature_offset + item.offset; - ctx->search_index++; - } - - int ret = flatgeobuf_decode_feature(ctx, layer, shape); - if (ret == -1) - return MS_FAILURE; - if (ctx->done) - return MS_DONE; + int ret = flatgeobuf_decode_feature(ctx, layer, shape); + if (ret == -1) + return MS_FAILURE; + shape->index = ctx->feature_index; + if (!ctx->search_result) + ctx->feature_index++; + if (ctx->done) + return MS_DONE; + if (ctx->is_null_geom) { + msFreeCharArray(shape->values, shape->numvalues); + shape->values = NULL; + } + } while (ctx->is_null_geom); return MS_SUCCESS; } -int msFlatGeobufLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) -{ +int msFlatGeobufLayerGetShape(layerObj *layer, shapeObj *shape, + resultObj *record) { + (void)shape; (void)record; flatgeobuf_ctx *ctx; @@ -242,11 +276,16 @@ int msFlatGeobufLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *recor if (!ctx) return MS_FAILURE; long i = record->shapeindex; + if (i < 0 || (uint64_t)i >= ctx->features_count) { + msSetError(MS_MISCERR, "Invalid feature id", "msFlatGeobufLayerGetShape"); + return MS_FAILURE; + } uint64_t offset; flatgeobuf_read_feature_offset(ctx, i, &offset); if (VSIFSeekL(ctx->file, ctx->feature_offset + offset, SEEK_SET) == -1) { - msSetError(MS_FGBERR, "Unable to seek in file", "msFlatGeobufLayerGetShape"); - return MS_FAILURE; + msSetError(MS_FGBERR, "Unable to seek in file", + "msFlatGeobufLayerGetShape"); + return MS_FAILURE; } int ret = flatgeobuf_decode_feature(ctx, layer, shape); if (ret == -1) @@ -254,8 +293,7 @@ int msFlatGeobufLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *recor return MS_SUCCESS; } -int msFlatGeobufLayerClose(layerObj *layer) -{ +int msFlatGeobufLayerClose(layerObj *layer) { flatgeobuf_ctx *ctx; ctx = layer->layerinfo; if (!ctx) @@ -266,8 +304,7 @@ int msFlatGeobufLayerClose(layerObj *layer) return MS_SUCCESS; } -int msFlatGeobufLayerGetItems(layerObj *layer) -{ +int msFlatGeobufLayerGetItems(layerObj *layer) { const char *value; flatgeobuf_ctx *ctx; ctx = layer->layerinfo; @@ -275,20 +312,19 @@ int msFlatGeobufLayerGetItems(layerObj *layer) return MS_FAILURE; layer->numitems = ctx->columns_len; - char **items = (char **) malloc(sizeof(char *) * ctx->columns_len); + char **items = (char **)malloc(sizeof(char *) * ctx->columns_len); for (int i = 0; i < ctx->columns_len; i++) items[i] = msStrdup(ctx->columns[i].name); layer->items = items; - if((value = msOWSLookupMetadata(&(layer->metadata), "G", "types")) != NULL - && strcasecmp(value,"auto") == 0 ) + if ((value = msOWSLookupMetadata(&(layer->metadata), "G", "types")) != NULL && + strcasecmp(value, "auto") == 0) msFGBPassThroughFieldDefinitions(layer, ctx); return msLayerInitItemInfo(layer); } -int msFlatGeobufLayerGetExtent(layerObj *layer, rectObj *extent) -{ +int msFlatGeobufLayerGetExtent(layerObj *layer, rectObj *extent) { flatgeobuf_ctx *ctx; ctx = layer->layerinfo; extent->minx = ctx->xmin; @@ -298,18 +334,17 @@ int msFlatGeobufLayerGetExtent(layerObj *layer, rectObj *extent) return MS_SUCCESS; } -int msFlatGeobufLayerSupportsCommonFilters(layerObj *layer) -{ +int msFlatGeobufLayerSupportsCommonFilters(layerObj *layer) { (void)layer; return MS_TRUE; } -int msFlatGeobufLayerInitializeVirtualTable(layerObj *layer) -{ +int msFlatGeobufLayerInitializeVirtualTable(layerObj *layer) { assert(layer != NULL); assert(layer->vtable != NULL); - layer->vtable->LayerSupportsCommonFilters = msFlatGeobufLayerSupportsCommonFilters; + layer->vtable->LayerSupportsCommonFilters = + msFlatGeobufLayerSupportsCommonFilters; layer->vtable->LayerInitItemInfo = msFlatGeobufLayerInitItemInfo; layer->vtable->LayerFreeItemInfo = msFlatGeobufLayerFreeItemInfo; layer->vtable->LayerOpen = msFlatGeobufLayerOpen; diff --git a/mapgdal.cpp b/mapgdal.cpp index b61fb7b7fc..b4544f36d2 100644 --- a/mapgdal.cpp +++ b/mapgdal.cpp @@ -32,28 +32,27 @@ #include "mapgdal.h" #include - #include "cpl_conv.h" #include "cpl_string.h" #include "ogr_srs_api.h" #include "gdal.h" -static int bGDALInitialized = 0; +static int bGDALInitialized = 0; /************************************************************************/ /* msGDALInitialize() */ /************************************************************************/ -void msGDALInitialize( void ) +void msGDALInitialize(void) { - if( !bGDALInitialized ) { - msAcquireLock( TLOCK_GDAL ); + if (!bGDALInitialized) { + msAcquireLock(TLOCK_GDAL); GDALAllRegister(); - CPLPushErrorHandler( CPLQuietErrorHandler ); - msReleaseLock( TLOCK_GDAL ); + CPLPushErrorHandler(CPLQuietErrorHandler); + msReleaseLock(TLOCK_GDAL); bGDALInitialized = 1; } @@ -63,42 +62,42 @@ void msGDALInitialize( void ) /* msGDALCleanup() */ /************************************************************************/ -void msGDALCleanup( void ) +void msGDALCleanup(void) { - if( bGDALInitialized ) { + if (bGDALInitialized) { int iRepeat = 5; - /* - ** Cleanup any unreferenced but open datasets as will tend - ** to exist due to deferred close requests. We are careful - ** to only close one file at a time before refecting the - ** list as closing some datasets may cause others to be - ** closed (subdatasets in a VRT for instance). - */ + /* + ** Cleanup any unreferenced but open datasets as will tend + ** to exist due to deferred close requests. We are careful + ** to only close one file at a time before refecting the + ** list as closing some datasets may cause others to be + ** closed (subdatasets in a VRT for instance). + */ GDALDatasetH *pahDSList = NULL; int nDSCount = 0; int bDidSomething; - msAcquireLock( TLOCK_GDAL ); + msAcquireLock(TLOCK_GDAL); do { - int i; - GDALGetOpenDatasets( &pahDSList, &nDSCount ); - bDidSomething = FALSE; - for( i = 0; i < nDSCount && !bDidSomething; i++ ) { - if( GDALReferenceDataset( pahDSList[i] ) == 1 ) { - GDALClose( pahDSList[i] ); - bDidSomething = TRUE; - } else - GDALDereferenceDataset( pahDSList[i] ); - } - } while( bDidSomething ); + int i; + GDALGetOpenDatasets(&pahDSList, &nDSCount); + bDidSomething = FALSE; + for (i = 0; i < nDSCount && !bDidSomething; i++) { + if (GDALReferenceDataset(pahDSList[i]) == 1) { + GDALClose(pahDSList[i]); + bDidSomething = TRUE; + } else + GDALDereferenceDataset(pahDSList[i]); + } + } while (bDidSomething); - while( iRepeat-- ) + while (iRepeat--) CPLPopErrorHandler(); - msReleaseLock( TLOCK_GDAL ); + msReleaseLock(TLOCK_GDAL); bGDALInitialized = 0; } @@ -111,62 +110,61 @@ void msGDALCleanup( void ) /* things are clean before we start, and after we are done. */ /************************************************************************/ -void msCleanVSIDir( const char *pszDir ) +void msCleanVSIDir(const char *pszDir) { - char **papszFiles = CPLReadDir( pszDir ); - int i, nFileCount = CSLCount( papszFiles ); + char **papszFiles = CPLReadDir(pszDir); + int i, nFileCount = CSLCount(papszFiles); - for( i = 0; i < nFileCount; i++ ) { - if( strcasecmp(papszFiles[i],".") == 0 - || strcasecmp(papszFiles[i],"..") == 0 ) + for (i = 0; i < nFileCount; i++) { + if (strcasecmp(papszFiles[i], ".") == 0 || + strcasecmp(papszFiles[i], "..") == 0) continue; - VSIUnlink( CPLFormFilename(pszDir, papszFiles[i], NULL) ); + VSIUnlink(CPLFormFilename(pszDir, papszFiles[i], NULL)); } - CSLDestroy( papszFiles ); + CSLDestroy(papszFiles); } /************************************************************************/ /* msSaveImageGDAL() */ /************************************************************************/ -int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filenameIn ) +int msSaveImageGDAL(mapObj *map, imageObj *image, const char *filenameIn) { - int bFileIsTemporary = MS_FALSE; + int bFileIsTemporary = MS_FALSE; GDALDatasetH hMemDS, hOutputDS; - GDALDriverH hMemDriver, hOutputDriver; - int nBands = 1; - int iLine; + GDALDriverH hMemDriver, hOutputDriver; + int nBands = 1; + int iLine; outputFormatObj *format = image->format; rasterBufferObj rb; GDALDataType eDataType = GDT_Byte; int bUseXmp = MS_FALSE; - const char *filename = NULL; - char *filenameToFree = NULL; - const char *gdal_driver_shortname = format->driver+5; + const char *filename = NULL; + char *filenameToFree = NULL; + const char *gdal_driver_shortname = format->driver + 5; msGDALInitialize(); - memset(&rb,0,sizeof(rasterBufferObj)); + memset(&rb, 0, sizeof(rasterBufferObj)); #ifdef USE_EXEMPI - if( map != NULL ) { + if (map != NULL) { bUseXmp = msXmpPresent(map); } #endif - /* -------------------------------------------------------------------- */ /* Identify the proposed output driver. */ /* -------------------------------------------------------------------- */ - msAcquireLock( TLOCK_GDAL ); - hOutputDriver = GDALGetDriverByName( gdal_driver_shortname ); - if( hOutputDriver == NULL ) { - msReleaseLock( TLOCK_GDAL ); - msSetError( MS_MISCERR, "Failed to find %s driver.", - "msSaveImageGDAL()", gdal_driver_shortname ); + msAcquireLock(TLOCK_GDAL); + hOutputDriver = GDALGetDriverByName(gdal_driver_shortname); + if (hOutputDriver == NULL) { + msReleaseLock(TLOCK_GDAL); + msSetError(MS_MISCERR, "Failed to find %s driver.", "msSaveImageGDAL()", + gdal_driver_shortname); return MS_FAILURE; } @@ -177,27 +175,26 @@ int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filenameIn ) /* memory, otherwise we try to put it in a reasonable temporary */ /* file location. */ /* -------------------------------------------------------------------- */ - if( filenameIn == NULL ) { + if (filenameIn == NULL) { const char *pszExtension = format->extension; - if( pszExtension == NULL ) + if (pszExtension == NULL) pszExtension = "img.tmp"; - if( bUseXmp == MS_FALSE && - msGDALDriverSupportsVirtualIOOutput(hOutputDriver) ) { - msCleanVSIDir( "/vsimem/msout" ); - filenameToFree = msTmpFile(map, NULL, "/vsimem/msout/", pszExtension ); + if (bUseXmp == MS_FALSE && + msGDALDriverSupportsVirtualIOOutput(hOutputDriver)) { + msCleanVSIDir("/vsimem/msout"); + filenameToFree = msTmpFile(map, NULL, "/vsimem/msout/", pszExtension); } - if( filenameToFree == NULL && map != NULL) - filenameToFree = msTmpFile(map, map->mappath,NULL,pszExtension); - else if( filenameToFree == NULL ) { - filenameToFree = msTmpFile(map, NULL, NULL, pszExtension ); + if (filenameToFree == NULL && map != NULL) + filenameToFree = msTmpFile(map, map->mappath, NULL, pszExtension); + else if (filenameToFree == NULL) { + filenameToFree = msTmpFile(map, NULL, NULL, pszExtension); } filename = filenameToFree; bFileIsTemporary = MS_TRUE; - } - else { + } else { filename = filenameIn; } @@ -206,32 +203,38 @@ int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filenameIn ) /* dataset. */ /* -------------------------------------------------------------------- */ - if( format->imagemode == MS_IMAGEMODE_RGB ) { + if (format->imagemode == MS_IMAGEMODE_RGB) { nBands = 3; - assert( MS_RENDERER_PLUGIN(format) && format->vtable->supports_pixel_buffer ); - if(MS_UNLIKELY(MS_FAILURE == format->vtable->getRasterBufferHandle(image,&rb))) { - msReleaseLock( TLOCK_GDAL ); + assert(MS_RENDERER_PLUGIN(format) && format->vtable->supports_pixel_buffer); + if (MS_UNLIKELY(MS_FAILURE == + format->vtable->getRasterBufferHandle(image, &rb))) { + msReleaseLock(TLOCK_GDAL); + msFree(filenameToFree); return MS_FAILURE; } - } else if( format->imagemode == MS_IMAGEMODE_RGBA ) { + } else if (format->imagemode == MS_IMAGEMODE_RGBA) { nBands = 4; - assert( MS_RENDERER_PLUGIN(format) && format->vtable->supports_pixel_buffer ); - if(MS_UNLIKELY(MS_FAILURE == format->vtable->getRasterBufferHandle(image,&rb))) { - msReleaseLock( TLOCK_GDAL ); + assert(MS_RENDERER_PLUGIN(format) && format->vtable->supports_pixel_buffer); + if (MS_UNLIKELY(MS_FAILURE == + format->vtable->getRasterBufferHandle(image, &rb))) { + msReleaseLock(TLOCK_GDAL); + msFree(filenameToFree); return MS_FAILURE; } - } else if( format->imagemode == MS_IMAGEMODE_INT16 ) { + } else if (format->imagemode == MS_IMAGEMODE_INT16) { nBands = format->bands; eDataType = GDT_Int16; - } else if( format->imagemode == MS_IMAGEMODE_FLOAT32 ) { + } else if (format->imagemode == MS_IMAGEMODE_FLOAT32) { nBands = format->bands; eDataType = GDT_Float32; - } else if( format->imagemode == MS_IMAGEMODE_BYTE ) { + } else if (format->imagemode == MS_IMAGEMODE_BYTE) { nBands = format->bands; eDataType = GDT_Byte; } else { - msReleaseLock( TLOCK_GDAL ); - msSetError( MS_MEMERR, "Unknown format. This is a bug.", "msSaveImageGDAL()"); + msReleaseLock(TLOCK_GDAL); + msSetError(MS_MEMERR, "Unknown format. This is a bug.", + "msSaveImageGDAL()"); + msFree(filenameToFree); return MS_FAILURE; } @@ -239,114 +242,117 @@ int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filenameIn ) /* Create a memory dataset which we can use as a source for a */ /* CreateCopy(). */ /* -------------------------------------------------------------------- */ - hMemDriver = GDALGetDriverByName( "MEM" ); - if( hMemDriver == NULL ) { - msReleaseLock( TLOCK_GDAL ); - msSetError( MS_MISCERR, "Failed to find MEM driver.", - "msSaveImageGDAL()" ); + hMemDriver = GDALGetDriverByName("MEM"); + if (hMemDriver == NULL) { + msReleaseLock(TLOCK_GDAL); + msSetError(MS_MISCERR, "Failed to find MEM driver.", "msSaveImageGDAL()"); + msFree(filenameToFree); return MS_FAILURE; } - hMemDS = GDALCreate( hMemDriver, "msSaveImageGDAL_temp", - image->width, image->height, nBands, - eDataType, NULL ); - if( hMemDS == NULL ) { - msReleaseLock( TLOCK_GDAL ); - msSetError( MS_MISCERR, "Failed to create MEM dataset.", - "msSaveImageGDAL()" ); + hMemDS = GDALCreate(hMemDriver, "msSaveImageGDAL_temp", image->width, + image->height, nBands, eDataType, NULL); + if (hMemDS == NULL) { + msReleaseLock(TLOCK_GDAL); + msSetError(MS_MISCERR, "Failed to create MEM dataset.", + "msSaveImageGDAL()"); + msFree(filenameToFree); return MS_FAILURE; } /* -------------------------------------------------------------------- */ /* Copy the gd image into the memory dataset. */ /* -------------------------------------------------------------------- */ - for( iLine = 0; iLine < image->height; iLine++ ) { + for (iLine = 0; iLine < image->height; iLine++) { int iBand; - for( iBand = 0; iBand < nBands; iBand++ ) { + for (iBand = 0; iBand < nBands; iBand++) { CPLErr eErr; - GDALRasterBandH hBand = GDALGetRasterBand( hMemDS, iBand+1 ); - - if( format->imagemode == MS_IMAGEMODE_INT16 ) { - eErr = GDALRasterIO( hBand, GF_Write, 0, iLine, image->width, 1, - image->img.raw_16bit + iLine * image->width - + iBand * image->width * image->height, - image->width, 1, GDT_Int16, 2, 0 ); - - } else if( format->imagemode == MS_IMAGEMODE_FLOAT32 ) { - eErr = GDALRasterIO( hBand, GF_Write, 0, iLine, image->width, 1, - image->img.raw_float + iLine * image->width - + iBand * image->width * image->height, - image->width, 1, GDT_Float32, 4, 0 ); - } else if( format->imagemode == MS_IMAGEMODE_BYTE ) { - eErr = GDALRasterIO( hBand, GF_Write, 0, iLine, image->width, 1, - image->img.raw_byte + iLine * image->width - + iBand * image->width * image->height, - image->width, 1, GDT_Byte, 1, 0 ); + GDALRasterBandH hBand = GDALGetRasterBand(hMemDS, iBand + 1); + + if (format->imagemode == MS_IMAGEMODE_INT16) { + eErr = GDALRasterIO(hBand, GF_Write, 0, iLine, image->width, 1, + image->img.raw_16bit + iLine * image->width + + iBand * image->width * image->height, + image->width, 1, GDT_Int16, 2, 0); + + } else if (format->imagemode == MS_IMAGEMODE_FLOAT32) { + eErr = GDALRasterIO(hBand, GF_Write, 0, iLine, image->width, 1, + image->img.raw_float + iLine * image->width + + iBand * image->width * image->height, + image->width, 1, GDT_Float32, 4, 0); + } else if (format->imagemode == MS_IMAGEMODE_BYTE) { + eErr = GDALRasterIO(hBand, GF_Write, 0, iLine, image->width, 1, + image->img.raw_byte + iLine * image->width + + iBand * image->width * image->height, + image->width, 1, GDT_Byte, 1, 0); } else { GByte *pabyData; unsigned char *pixptr = NULL; - assert( rb.type == MS_BUFFER_BYTE_RGBA ); - switch(iBand) { - case 0: - pixptr = rb.data.rgba.r; - break; - case 1: - pixptr = rb.data.rgba.g; - break; - case 2: - pixptr = rb.data.rgba.b; - break; - case 3: - pixptr = rb.data.rgba.a; - break; + assert(rb.type == MS_BUFFER_BYTE_RGBA); + switch (iBand) { + case 0: + pixptr = rb.data.rgba.r; + break; + case 1: + pixptr = rb.data.rgba.g; + break; + case 2: + pixptr = rb.data.rgba.b; + break; + case 3: + pixptr = rb.data.rgba.a; + break; } assert(pixptr); - if( pixptr == NULL ) { - msReleaseLock( TLOCK_GDAL ); - msSetError( MS_MISCERR, "Missing RGB or A buffer.\n", - "msSaveImageGDAL()" ); + if (pixptr == NULL) { + msReleaseLock(TLOCK_GDAL); + msSetError(MS_MISCERR, "Missing RGB or A buffer.\n", + "msSaveImageGDAL()"); GDALClose(hMemDS); + msFree(filenameToFree); return MS_FAILURE; } - pabyData = (GByte *)(pixptr + iLine*rb.data.rgba.row_step); + pabyData = (GByte *)(pixptr + iLine * rb.data.rgba.row_step); - if( rb.data.rgba.a == NULL || iBand == 3 ) { - eErr = GDALRasterIO( hBand, GF_Write, 0, iLine, image->width, 1, - pabyData, image->width, 1, GDT_Byte, - rb.data.rgba.pixel_step, 0 ); + if (rb.data.rgba.a == NULL || iBand == 3) { + eErr = GDALRasterIO(hBand, GF_Write, 0, iLine, image->width, 1, + pabyData, image->width, 1, GDT_Byte, + rb.data.rgba.pixel_step, 0); } else { /* We need to un-pre-multiple RGB by alpha. */ - GByte *pabyUPM = (GByte*) malloc(image->width); - GByte *pabyAlpha= (GByte *)(rb.data.rgba.a + iLine*rb.data.rgba.row_step); + GByte *pabyUPM = (GByte *)malloc(image->width); + GByte *pabyAlpha = + (GByte *)(rb.data.rgba.a + iLine * rb.data.rgba.row_step); int i; - for( i = 0; i < image->width; i++ ) { - int alpha = pabyAlpha[i*rb.data.rgba.pixel_step]; + for (i = 0; i < image->width; i++) { + int alpha = pabyAlpha[i * rb.data.rgba.pixel_step]; - if( alpha == 0 ) + if (alpha == 0) pabyUPM[i] = 0; else { - int result = (pabyData[i*rb.data.rgba.pixel_step] * 255) / alpha; + int result = + (pabyData[i * rb.data.rgba.pixel_step] * 255) / alpha; - if( result > 255 ) + if (result > 255) result = 255; pabyUPM[i] = result; } } - eErr = GDALRasterIO( hBand, GF_Write, 0, iLine, image->width, 1, - pabyUPM, image->width, 1, GDT_Byte, 1, 0 ); - free( pabyUPM ); + eErr = GDALRasterIO(hBand, GF_Write, 0, iLine, image->width, 1, + pabyUPM, image->width, 1, GDT_Byte, 1, 0); + free(pabyUPM); } } - if( eErr != CE_None ) { - msReleaseLock( TLOCK_GDAL ); - msSetError( MS_MISCERR, "GDALRasterIO() failed.\n", - "msSaveImageGDAL()" ); - GDALClose(hMemDS); - return MS_FAILURE; + if (eErr != CE_None) { + msReleaseLock(TLOCK_GDAL); + msSetError(MS_MISCERR, "GDALRasterIO() failed.\n", "msSaveImageGDAL()"); + GDALClose(hMemDS); + msFree(filenameToFree); + return MS_FAILURE; } } } @@ -354,118 +360,107 @@ int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filenameIn ) /* -------------------------------------------------------------------- */ /* Attach the palette if appropriate. */ /* -------------------------------------------------------------------- */ - if( format->imagemode == MS_IMAGEMODE_RGB ) { - GDALSetRasterColorInterpretation( - GDALGetRasterBand( hMemDS, 1 ), GCI_RedBand ); - GDALSetRasterColorInterpretation( - GDALGetRasterBand( hMemDS, 2 ), GCI_GreenBand ); - GDALSetRasterColorInterpretation( - GDALGetRasterBand( hMemDS, 3 ), GCI_BlueBand ); - } else if( format->imagemode == MS_IMAGEMODE_RGBA ) { - GDALSetRasterColorInterpretation( - GDALGetRasterBand( hMemDS, 1 ), GCI_RedBand ); - GDALSetRasterColorInterpretation( - GDALGetRasterBand( hMemDS, 2 ), GCI_GreenBand ); - GDALSetRasterColorInterpretation( - GDALGetRasterBand( hMemDS, 3 ), GCI_BlueBand ); - GDALSetRasterColorInterpretation( - GDALGetRasterBand( hMemDS, 4 ), GCI_AlphaBand ); - } + if (format->imagemode == MS_IMAGEMODE_RGB) { + GDALSetRasterColorInterpretation(GDALGetRasterBand(hMemDS, 1), GCI_RedBand); + GDALSetRasterColorInterpretation(GDALGetRasterBand(hMemDS, 2), + GCI_GreenBand); + GDALSetRasterColorInterpretation(GDALGetRasterBand(hMemDS, 3), + GCI_BlueBand); + } else if (format->imagemode == MS_IMAGEMODE_RGBA) { + GDALSetRasterColorInterpretation(GDALGetRasterBand(hMemDS, 1), GCI_RedBand); + GDALSetRasterColorInterpretation(GDALGetRasterBand(hMemDS, 2), + GCI_GreenBand); + GDALSetRasterColorInterpretation(GDALGetRasterBand(hMemDS, 3), + GCI_BlueBand); + GDALSetRasterColorInterpretation(GDALGetRasterBand(hMemDS, 4), + GCI_AlphaBand); + } /* -------------------------------------------------------------------- */ /* Assign the projection and coordinate system to the memory */ /* dataset. */ /* -------------------------------------------------------------------- */ - if( map != NULL ) { + if (map != NULL) { char *pszWKT; - GDALSetGeoTransform( hMemDS, map->gt.geotransform ); + GDALSetGeoTransform(hMemDS, map->gt.geotransform); - pszWKT = msProjectionObj2OGCWKT( &(map->projection) ); - if( pszWKT != NULL ) { - GDALSetProjection( hMemDS, pszWKT ); - msFree( pszWKT ); + pszWKT = msProjectionObj2OGCWKT(&(map->projection)); + if (pszWKT != NULL) { + GDALSetProjection(hMemDS, pszWKT); + msFree(pszWKT); } } /* -------------------------------------------------------------------- */ /* Possibly assign a nodata value. */ /* -------------------------------------------------------------------- */ - const char *nullvalue = msGetOutputFormatOption(format,"NULLVALUE",NULL); - if( nullvalue != NULL ) { + const char *nullvalue = msGetOutputFormatOption(format, "NULLVALUE", NULL); + if (nullvalue != NULL) { const double dfNullValue = atof(nullvalue); - for( int iBand = 0; iBand < nBands; iBand++ ) { - GDALRasterBandH hBand = GDALGetRasterBand( hMemDS, iBand+1 ); - GDALSetRasterNoDataValue( hBand, dfNullValue ); + for (int iBand = 0; iBand < nBands; iBand++) { + GDALRasterBandH hBand = GDALGetRasterBand(hMemDS, iBand + 1); + GDALSetRasterNoDataValue(hBand, dfNullValue); } } /* -------------------------------------------------------------------- */ /* Try to save resolution in the output file. */ /* -------------------------------------------------------------------- */ - if( image->resolution > 0 ) { + if (image->resolution > 0) { char res[30]; - sprintf( res, "%lf", image->resolution ); - GDALSetMetadataItem( hMemDS, "TIFFTAG_XRESOLUTION", res, NULL ); - GDALSetMetadataItem( hMemDS, "TIFFTAG_YRESOLUTION", res, NULL ); - GDALSetMetadataItem( hMemDS, "TIFFTAG_RESOLUTIONUNIT", "2", NULL ); + sprintf(res, "%lf", image->resolution); + GDALSetMetadataItem(hMemDS, "TIFFTAG_XRESOLUTION", res, NULL); + GDALSetMetadataItem(hMemDS, "TIFFTAG_YRESOLUTION", res, NULL); + GDALSetMetadataItem(hMemDS, "TIFFTAG_RESOLUTIONUNIT", "2", NULL); } /* -------------------------------------------------------------------- */ /* Separate creation options from metadata items. */ /* -------------------------------------------------------------------- */ - std::vector apszCreationOptions; - for( int i = 0; i < format->numformatoptions; i++ ) - { - char* option = format->formatoptions[i]; + std::vector apszCreationOptions; + for (int i = 0; i < format->numformatoptions; i++) { + char *option = format->formatoptions[i]; // MDI stands for MetaDataItem - if( STARTS_WITH(option, "mdi_") ) - { - const char* option_without_band = option + strlen("mdi_"); + if (STARTS_WITH(option, "mdi_")) { + const char *option_without_band = option + strlen("mdi_"); GDALMajorObjectH hObject = (GDALMajorObjectH)hMemDS; - if( STARTS_WITH(option_without_band, "BAND_") ) - { + if (STARTS_WITH(option_without_band, "BAND_")) { int nBandNumber = atoi(option_without_band + strlen("BAND_")); - if( nBandNumber > 0 && nBandNumber <= nBands ) - { - const char* pszAfterBand = strchr(option_without_band + strlen("BAND_"), '_'); - if( pszAfterBand != NULL ) - { - hObject = (GDALMajorObjectH)GDALGetRasterBand(hMemDS, nBandNumber); - option_without_band = pszAfterBand + 1; + if (nBandNumber > 0 && nBandNumber <= nBands) { + const char *pszAfterBand = + strchr(option_without_band + strlen("BAND_"), '_'); + if (pszAfterBand != NULL) { + hObject = (GDALMajorObjectH)GDALGetRasterBand(hMemDS, nBandNumber); + option_without_band = pszAfterBand + 1; } - } - else { - msDebug("Invalid band number %d in metadata item option %s", nBandNumber, option); + } else { + msDebug("Invalid band number %d in metadata item option %s", + nBandNumber, option); } } - if( hObject ) { + if (hObject) { std::string osDomain(option_without_band); size_t nUnderscorePos = osDomain.find('_'); - if( nUnderscorePos != std::string::npos ) { + if (nUnderscorePos != std::string::npos) { std::string osKeyValue = osDomain.substr(nUnderscorePos + 1); osDomain.resize(nUnderscorePos); - if( osDomain == "default" ) - osDomain.clear(); + if (osDomain == "default") + osDomain.clear(); size_t nEqualPos = osKeyValue.find('='); - if( nEqualPos != std::string::npos ) - { - GDALSetMetadataItem(hObject, - osKeyValue.substr(0, nEqualPos).c_str(), - osKeyValue.substr(nEqualPos + 1).c_str(), - osDomain.c_str()); + if (nEqualPos != std::string::npos) { + GDALSetMetadataItem( + hObject, osKeyValue.substr(0, nEqualPos).c_str(), + osKeyValue.substr(nEqualPos + 1).c_str(), osDomain.c_str()); } - } - else { + } else { msDebug("Invalid format in metadata item option %s", option); } } - } - else - { + } else { apszCreationOptions.emplace_back(option); } } @@ -475,36 +470,35 @@ int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filenameIn ) /* Create a disk image in the selected output format from the */ /* memory image. */ /* -------------------------------------------------------------------- */ - hOutputDS = GDALCreateCopy( hOutputDriver, filename, hMemDS, FALSE, - &apszCreationOptions[0], NULL, NULL ); - + hOutputDS = GDALCreateCopy(hOutputDriver, filename, hMemDS, FALSE, + &apszCreationOptions[0], NULL, NULL); - if( hOutputDS == NULL ) { - GDALClose( hMemDS ); - msReleaseLock( TLOCK_GDAL ); - msSetError( MS_MISCERR, "Failed to create output %s file.\n%s", - "msSaveImageGDAL()", format->driver+5, - CPLGetLastErrorMsg() ); + if (hOutputDS == NULL) { + GDALClose(hMemDS); + msReleaseLock(TLOCK_GDAL); + msSetError(MS_MISCERR, "Failed to create output %s file.\n%s", + "msSaveImageGDAL()", format->driver + 5, CPLGetLastErrorMsg()); + msFree(filenameToFree); return MS_FAILURE; } /* closing the memory DS also frees all associated resources. */ - GDALClose( hMemDS ); - - GDALClose( hOutputDS ); - msReleaseLock( TLOCK_GDAL ); + GDALClose(hMemDS); + GDALClose(hOutputDS); + msReleaseLock(TLOCK_GDAL); /* -------------------------------------------------------------------- */ /* Are we writing license info into the image? */ /* If so, add it to the temp file on disk now. */ /* -------------------------------------------------------------------- */ #ifdef USE_EXEMPI - if ( bUseXmp == MS_TRUE ) { - if( msXmpWrite(map, filename) == MS_FAILURE ) { + if (bUseXmp == MS_TRUE) { + if (msXmpWrite(map, filename) == MS_FAILURE) { /* Something bad happened. */ - msSetError( MS_MISCERR, "XMP write to %s failed.\n", - "msSaveImageGDAL()", filename); + msSetError(MS_MISCERR, "XMP write to %s failed.\n", "msSaveImageGDAL()", + filename); + msFree(filenameToFree); return MS_FAILURE; } } @@ -514,35 +508,36 @@ int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filenameIn ) /* Is this supposed to be a temporary file? If so, stream to */ /* stdout and delete the file. */ /* -------------------------------------------------------------------- */ - if( bFileIsTemporary ) { - FILE *fp; + if (bFileIsTemporary) { + VSILFILE *fp; unsigned char block[4000]; int bytes_read; - if( msIO_needBinaryStdout() == MS_FAILURE ) + if (msIO_needBinaryStdout() == MS_FAILURE) { + msFree(filenameToFree); return MS_FAILURE; + } /* We aren't sure how far back GDAL exports the VSI*L API, so we only use it if we suspect we need it. But we do need it if holding temporary file in memory. */ - fp = VSIFOpenL( filename, "rb" ); - if( fp == NULL ) { - msSetError( MS_MISCERR, - "Failed to open %s for streaming to stdout.", - "msSaveImageGDAL()", filename ); + fp = VSIFOpenL(filename, "rb"); + if (fp == NULL) { + msSetError(MS_MISCERR, "Failed to open %s for streaming to stdout.", + "msSaveImageGDAL()", filename); + msFree(filenameToFree); return MS_FAILURE; } - while( (bytes_read = VSIFReadL(block, 1, sizeof(block), fp)) > 0 ) - msIO_fwrite( block, 1, bytes_read, stdout ); - - VSIFCloseL( fp ); + while ((bytes_read = VSIFReadL(block, 1, sizeof(block), fp)) > 0) + msIO_fwrite(block, 1, bytes_read, stdout); - VSIUnlink( filename ); - msCleanVSIDir( "/vsimem/msout" ); + VSIFCloseL(fp); - msFree( filenameToFree ); + VSIUnlink(filename); + msCleanVSIDir("/vsimem/msout"); } + msFree(filenameToFree); return MS_SUCCESS; } @@ -551,7 +546,7 @@ int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filenameIn ) /* msInitGDALOutputFormat() */ /************************************************************************/ -int msInitDefaultGDALOutputFormat( outputFormatObj *format ) +int msInitDefaultGDALOutputFormat(outputFormatObj *format) { GDALDriverH hDriver; @@ -563,17 +558,17 @@ int msInitDefaultGDALOutputFormat( outputFormatObj *format ) /* be pretty threadsafe so don't bother acquiring the GDAL */ /* lock. */ /* -------------------------------------------------------------------- */ - hDriver = GDALGetDriverByName( format->driver+5 ); - if( hDriver == NULL ) { - msSetError( MS_MISCERR, "No GDAL driver named `%s' available.", - "msInitGDALOutputFormat()", format->driver+5 ); + hDriver = GDALGetDriverByName(format->driver + 5); + if (hDriver == NULL) { + msSetError(MS_MISCERR, "No GDAL driver named `%s' available.", + "msInitGDALOutputFormat()", format->driver + 5); return MS_FAILURE; } - if( GDALGetMetadataItem( hDriver, GDAL_DCAP_CREATE, NULL ) == NULL - && GDALGetMetadataItem( hDriver, GDAL_DCAP_CREATECOPY, NULL ) == NULL ) { - msSetError( MS_MISCERR, "GDAL `%s' driver does not support output.", - "msInitGDALOutputFormat()", format->driver+5 ); + if (GDALGetMetadataItem(hDriver, GDAL_DCAP_CREATE, NULL) == NULL && + GDALGetMetadataItem(hDriver, GDAL_DCAP_CREATECOPY, NULL) == NULL) { + msSetError(MS_MISCERR, "GDAL `%s' driver does not support output.", + "msInitGDALOutputFormat()", format->driver + 5); return MS_FAILURE; } @@ -583,28 +578,29 @@ int msInitDefaultGDALOutputFormat( outputFormatObj *format ) format->imagemode = MS_IMAGEMODE_RGB; format->renderer = MS_RENDER_WITH_AGG; - if( GDALGetMetadataItem( hDriver, GDAL_DMD_MIMETYPE, NULL ) != NULL ) + if (GDALGetMetadataItem(hDriver, GDAL_DMD_MIMETYPE, NULL) != NULL) format->mimetype = - msStrdup(GDALGetMetadataItem(hDriver,GDAL_DMD_MIMETYPE,NULL)); - if( GDALGetMetadataItem( hDriver, GDAL_DMD_EXTENSION, NULL ) != NULL ) + msStrdup(GDALGetMetadataItem(hDriver, GDAL_DMD_MIMETYPE, NULL)); + if (GDALGetMetadataItem(hDriver, GDAL_DMD_EXTENSION, NULL) != NULL) format->extension = - msStrdup(GDALGetMetadataItem(hDriver,GDAL_DMD_EXTENSION,NULL)); + msStrdup(GDALGetMetadataItem(hDriver, GDAL_DMD_EXTENSION, NULL)); return MS_SUCCESS; } -char** msGetStringListFromHashTable(hashTableObj* table) -{ +char **msGetStringListFromHashTable(hashTableObj *table) { struct hashObj *tp = NULL; int i; - char** papszRet = NULL; + char **papszRet = NULL; - if(!table) return NULL; - if(msHashIsEmpty(table)) return NULL; + if (!table) + return NULL; + if (msHashIsEmpty(table)) + return NULL; - for (i=0; iitems[i] != NULL) { - for (tp=table->items[i]; tp!=NULL; tp=tp->next) { + for (tp = table->items[i]; tp != NULL; tp = tp->next) { papszRet = CSLSetNameValue(papszRet, tp->key, tp->data); } } @@ -612,7 +608,6 @@ char** msGetStringListFromHashTable(hashTableObj* table) return papszRet; } - /************************************************************************/ /* msProjectionObj2OGCWKT() */ /* */ @@ -624,59 +619,59 @@ char** msGetStringListFromHashTable(hashTableObj* table) /* returned string should be freed with msFree(). */ /************************************************************************/ -char *msProjectionObj2OGCWKT( projectionObj *projection ) +char *msProjectionObj2OGCWKT(projectionObj *projection) { OGRSpatialReferenceH hSRS; - char *pszWKT=NULL, *pszProj4, *pszInitEpsg=NULL; - int nLength = 0, i; + char *pszWKT = NULL, *pszProj4, *pszInitEpsg = NULL; + int nLength = 0, i; OGRErr eErr; - if( projection->proj == NULL ) + if (projection->proj == NULL) return NULL; - hSRS = OSRNewSpatialReference( NULL ); + hSRS = OSRNewSpatialReference(NULL); /* -------------------------------------------------------------------- */ /* Look for an EPSG-like projection argument */ /* -------------------------------------------------------------------- */ - if( projection->numargs == 1 && - (pszInitEpsg = strcasestr(projection->args[0],"init=epsg:"))) { - int nEpsgCode = atoi(pszInitEpsg + strlen("init=epsg:")); - eErr = OSRImportFromEPSG(hSRS, nEpsgCode); + if (projection->numargs == 1 && + (pszInitEpsg = strcasestr(projection->args[0], "init=epsg:"))) { + int nEpsgCode = atoi(pszInitEpsg + strlen("init=epsg:")); + eErr = OSRImportFromEPSG(hSRS, nEpsgCode); } else { /* -------------------------------------------------------------------- */ /* Form arguments into a full Proj.4 definition string. */ /* -------------------------------------------------------------------- */ - for( i = 0; i < projection->numargs; i++ ) + for (i = 0; i < projection->numargs; i++) nLength += strlen(projection->args[i]) + 2; - pszProj4 = (char *) CPLMalloc(nLength+2); + pszProj4 = (char *)CPLMalloc(nLength + 2); pszProj4[0] = '\0'; - for( i = 0; i < projection->numargs; i++ ) { - strcat( pszProj4, "+" ); - strcat( pszProj4, projection->args[i] ); - strcat( pszProj4, " " ); + for (i = 0; i < projection->numargs; i++) { + strcat(pszProj4, "+"); + strcat(pszProj4, projection->args[i]); + strcat(pszProj4, " "); } /* -------------------------------------------------------------------- */ /* Ingest the string into OGRSpatialReference. */ /* -------------------------------------------------------------------- */ - eErr = OSRImportFromProj4( hSRS, pszProj4 ); - CPLFree( pszProj4 ); + eErr = OSRImportFromProj4(hSRS, pszProj4); + CPLFree(pszProj4); } /* -------------------------------------------------------------------- */ /* Export as a WKT string. */ /* -------------------------------------------------------------------- */ - if( eErr == OGRERR_NONE ) - OSRExportToWkt( hSRS, &pszWKT ); + if (eErr == OGRERR_NONE) + OSRExportToWkt(hSRS, &pszWKT); - OSRDestroySpatialReference( hSRS ); + OSRDestroySpatialReference(hSRS); - if( pszWKT ) { + if (pszWKT) { char *pszWKT2 = msStrdup(pszWKT); - CPLFree( pszWKT ); + CPLFree(pszWKT); return pszWKT2; } else @@ -687,11 +682,10 @@ char *msProjectionObj2OGCWKT( projectionObj *projection ) /* msGDALDriverSupportsVirtualIOOutput() */ /************************************************************************/ -int msGDALDriverSupportsVirtualIOOutput( GDALDriverH hDriver ) -{ - /* We need special testing here for the netCDF driver, since recent */ - /* GDAL versions advertize VirtualIO support, but this is only for the */ - /* read-side of the driver, not the write-side. */ - return GDALGetMetadataItem( hDriver, GDAL_DCAP_VIRTUALIO, NULL ) != NULL && - !EQUAL(GDALGetDescription(hDriver), "netCDF"); +int msGDALDriverSupportsVirtualIOOutput(GDALDriverH hDriver) { + /* We need special testing here for the netCDF driver, since recent */ + /* GDAL versions advertize VirtualIO support, but this is only for the */ + /* read-side of the driver, not the write-side. */ + return GDALGetMetadataItem(hDriver, GDAL_DCAP_VIRTUALIO, NULL) != NULL && + !EQUAL(GDALGetDescription(hDriver), "netCDF"); } diff --git a/mapgdal.h b/mapgdal.h index 45ec7eb26b..211b90c2ff 100644 --- a/mapgdal.h +++ b/mapgdal.h @@ -37,7 +37,7 @@ extern "C" { #endif -int msGDALDriverSupportsVirtualIOOutput( GDALDriverH hDriver ); +int msGDALDriverSupportsVirtualIOOutput(GDALDriverH hDriver); #ifdef __cplusplus } diff --git a/mapgeomtransform.c b/mapgeomtransform.c index 03b3199095..f64d5d5943 100644 --- a/mapgeomtransform.c +++ b/mapgeomtransform.c @@ -32,8 +32,7 @@ extern int yyparse(parseObj *p); -void msStyleSetGeomTransform(styleObj *s, char *transform) -{ +void msStyleSetGeomTransform(styleObj *s, char *transform) { msFree(s->_geomtransform.string); if (!transform) { s->_geomtransform.type = MS_GEOMTRANSFORM_NONE; @@ -41,71 +40,65 @@ void msStyleSetGeomTransform(styleObj *s, char *transform) return; } s->_geomtransform.string = msStrdup(transform); - if(!strncasecmp("start",transform,5)) { + if (!strncasecmp("start", transform, 5)) { s->_geomtransform.type = MS_GEOMTRANSFORM_START; - } else if(!strncasecmp("end",transform,3)) { + } else if (!strncasecmp("end", transform, 3)) { s->_geomtransform.type = MS_GEOMTRANSFORM_END; - } else if(!strncasecmp("vertices",transform,8)) { + } else if (!strncasecmp("vertices", transform, 8)) { s->_geomtransform.type = MS_GEOMTRANSFORM_VERTICES; - } else if(!strncasecmp("bbox",transform,4)) { + } else if (!strncasecmp("bbox", transform, 4)) { s->_geomtransform.type = MS_GEOMTRANSFORM_BBOX; - } else if(!strncasecmp("labelpnt",transform,8)) { + } else if (!strncasecmp("labelpnt", transform, 8)) { s->_geomtransform.type = MS_GEOMTRANSFORM_LABELPOINT; - } else if(!strncasecmp("labelpoly",transform,9)) { + } else if (!strncasecmp("labelpoly", transform, 9)) { s->_geomtransform.type = MS_GEOMTRANSFORM_LABELPOLY; - } else if(!strncasecmp("labelcenter",transform,11)) { + } else if (!strncasecmp("labelcenter", transform, 11)) { s->_geomtransform.type = MS_GEOMTRANSFORM_LABELCENTER; - } else if(!strncasecmp("centroid",transform,8)) { + } else if (!strncasecmp("centroid", transform, 8)) { s->_geomtransform.type = MS_GEOMTRANSFORM_CENTROID; } else { s->_geomtransform.type = MS_GEOMTRANSFORM_NONE; - msSetError(MS_MISCERR,"unknown transform expression","msStyleSetGeomTransform()"); + msSetError(MS_MISCERR, "unknown transform expression", + "msStyleSetGeomTransform()"); msFree(s->_geomtransform.string); s->_geomtransform.string = NULL; } } - /* * return a copy of the geometry transform expression * returned char* must be freed by the caller */ -char *msStyleGetGeomTransform(styleObj *s) -{ +char *msStyleGetGeomTransform(styleObj *s) { return msStrdup(s->_geomtransform.string); } - -double calcOrientation(pointObj *p1, pointObj *p2) -{ +double calcOrientation(pointObj *p1, pointObj *p2) { double theta; - theta = atan2(p2->x - p1->x,p2->y - p1->y); - return MS_RAD_TO_DEG*(theta-MS_PI2); + theta = atan2(p2->x - p1->x, p2->y - p1->y); + return MS_RAD_TO_DEG * (theta - MS_PI2); } -double calcMidAngle(pointObj *p1, pointObj *p2, pointObj *p3) -{ +double calcMidAngle(pointObj *p1, pointObj *p2, pointObj *p3) { pointObj p1n; double dx12, dy12, dx23, dy23, l12, l23; - /* We treat both segments as vector 1-2 and vector 2-3 and - * compute their dx,dy and length + /* We treat both segments as vector 1-2 and vector 2-3 and + * compute their dx,dy and length */ dx12 = p2->x - p1->x; dy12 = p2->y - p1->y; - l12 = sqrt(dx12*dx12 + dy12*dy12); + l12 = sqrt(dx12 * dx12 + dy12 * dy12); dx23 = p3->x - p2->x; dy23 = p3->y - p2->y; - l23 = sqrt(dx23*dx23 + dy23*dy23); + l23 = sqrt(dx23 * dx23 + dy23 * dy23); /* Normalize length of vector 1-2 to same as length of vector 2-3 */ - if (l12 > 0.0) - { - p1n.x = p2->x - dx12*(l23/l12); - p1n.y = p2->y - dy12*(l23/l12); - } - else - p1n = *p2; /* segment 1-2 is 0-length, use segment 2-3 for orientation */ + if (l12 > 0.0) { + p1n.x = p2->x - dx12 * (l23 / l12); + p1n.y = p2->y - dy12 * (l23 / l12); + } else + p1n = *p2; /* segment 1-2 is 0-length, use segment 2-3 for orientation */ /* Return the orientation defined by the sum of the normalized vectors */ return calcOrientation(&p1n, p3); @@ -116,133 +109,139 @@ double calcMidAngle(pointObj *p1, pointObj *p2, pointObj *p3) * - transform the original shapeobj * - use the styleObj to render the transformed shapeobj */ -int msDrawTransformedShape(mapObj *map, imageObj *image, shapeObj *shape, styleObj *style, double scalefactor) -{ +int msDrawTransformedShape(mapObj *map, imageObj *image, shapeObj *shape, + styleObj *style, double scalefactor) { int type = style->_geomtransform.type; - int i,j,status = MS_SUCCESS; - switch(type) { - case MS_GEOMTRANSFORM_END: /*render point on last vertex only*/ - for(j=0; jnumlines; j++) { - lineObj *line = &(shape->line[j]); - pointObj *p = &(line->point[line->numpoints-1]); - if(p->x<0||p->x>image->width||p->y<0||p->y>image->height) - continue; - if(style->autoangle==MS_TRUE && line->numpoints>1) { - style->angle = calcOrientation(&(line->point[line->numpoints-2]),p); - } - status = msDrawMarkerSymbol(map,image,p,style,scalefactor); - } - break; - case MS_GEOMTRANSFORM_START: /*render point on first vertex only*/ - for(j=0; jnumlines; j++) { - lineObj *line = &(shape->line[j]); - pointObj *p = &(line->point[0]); - /*skip if outside image*/ - if(p->x<0||p->x>image->width||p->y<0||p->y>image->height) - continue; - if(style->autoangle==MS_TRUE && line->numpoints>1) { - style->angle = calcOrientation(p,&(line->point[1])); - } - status = msDrawMarkerSymbol(map,image,p,style,scalefactor); + int i, j, status = MS_SUCCESS; + switch (type) { + case MS_GEOMTRANSFORM_END: /*render point on last vertex only*/ + for (j = 0; j < shape->numlines; j++) { + lineObj *line = &(shape->line[j]); + pointObj *p = &(line->point[line->numpoints - 1]); + if (p->x < 0 || p->x > image->width || p->y < 0 || p->y > image->height) + continue; + if (style->autoangle == MS_TRUE && line->numpoints > 1) { + style->angle = calcOrientation(&(line->point[line->numpoints - 2]), p); } - break; - case MS_GEOMTRANSFORM_VERTICES: - for(j=0; jnumlines; j++) { - lineObj *line = &(shape->line[j]); - for(i=1; inumpoints-1; i++) { - pointObj *p = &(line->point[i]); - /*skip points outside image*/ - if(p->x<0||p->x>image->width||p->y<0||p->y>image->height) - continue; - if(style->autoangle==MS_TRUE) { - style->angle = calcMidAngle(&(line->point[i-1]),&(line->point[i]),&(line->point[i+1])); - } - status = msDrawMarkerSymbol(map,image,p,style,scalefactor); - } + status = msDrawMarkerSymbol(map, image, p, style, scalefactor); + } + break; + case MS_GEOMTRANSFORM_START: /*render point on first vertex only*/ + for (j = 0; j < shape->numlines; j++) { + lineObj *line = &(shape->line[j]); + pointObj *p = &(line->point[0]); + /*skip if outside image*/ + if (p->x < 0 || p->x > image->width || p->y < 0 || p->y > image->height) + continue; + if (style->autoangle == MS_TRUE && line->numpoints > 1) { + style->angle = calcOrientation(p, &(line->point[1])); } - break; - case MS_GEOMTRANSFORM_BBOX: { - shapeObj bbox; - lineObj bbox_line; - pointObj bbox_points[5]; - int padding = MS_MAX(style->width,style->size)+3; /* so clipped shape does not extent into image */ - - /*create a shapeObj representing the bounding box (clipped by the image size)*/ - bbox.numlines = 1; - bbox.line = &bbox_line; - bbox.line->numpoints = 5; - bbox.line->point = bbox_points; - - msComputeBounds(shape); - bbox_points[0].x=bbox_points[4].x=bbox_points[1].x = - (shape->bounds.minx < -padding) ? -padding : shape->bounds.minx; - /* cppcheck-suppress unreadVariable */ - bbox_points[2].x=bbox_points[3].x = - (shape->bounds.maxx > image->width+padding) ? image->width+padding : shape->bounds.maxx; - bbox_points[0].y=bbox_points[4].y=bbox_points[3].y = - (shape->bounds.miny < -padding) ? -padding : shape->bounds.miny; - /* cppcheck-suppress unreadVariable */ - bbox_points[1].y=bbox_points[2].y = - (shape->bounds.maxy > image->height+padding) ? image->height+padding : shape->bounds.maxy; - status = msDrawShadeSymbol(map, image, &bbox, style, scalefactor); + status = msDrawMarkerSymbol(map, image, p, style, scalefactor); } break; - case MS_GEOMTRANSFORM_CENTROID: { - double unused; /*used by centroid function*/ - pointObj centroid; - if(MS_SUCCESS == msGetPolygonCentroid(shape,¢roid,&unused,&unused)) { - status = msDrawMarkerSymbol(map,image,¢roid,style,scalefactor); + case MS_GEOMTRANSFORM_VERTICES: + for (j = 0; j < shape->numlines; j++) { + lineObj *line = &(shape->line[j]); + for (i = 1; i < line->numpoints - 1; i++) { + pointObj *p = &(line->point[i]); + /*skip points outside image*/ + if (p->x < 0 || p->x > image->width || p->y < 0 || p->y > image->height) + continue; + if (style->autoangle == MS_TRUE) { + style->angle = calcMidAngle(&(line->point[i - 1]), &(line->point[i]), + &(line->point[i + 1])); + } + status = msDrawMarkerSymbol(map, image, p, style, scalefactor); } } break; - case MS_GEOMTRANSFORM_EXPRESSION: { - int status; - shapeObj *tmpshp; - parseObj p; + case MS_GEOMTRANSFORM_BBOX: { + shapeObj bbox; + lineObj bbox_line; + pointObj bbox_points[5]; + int padding = MS_MAX(style->width, style->size) + + 3; /* so clipped shape does not extent into image */ - p.shape = shape; /* set a few parser globals (hence the lock) */ - p.expr = &(style->_geomtransform); + /*create a shapeObj representing the bounding box (clipped by the image + * size)*/ + bbox.numlines = 1; + bbox.line = &bbox_line; + bbox.line->numpoints = 5; + bbox.line->point = bbox_points; - if(p.expr->tokens == NULL) { /* this could happen if drawing originates from legend code (#5193) */ - status = msTokenizeExpression(p.expr, NULL, NULL); - if(status != MS_SUCCESS) { - msSetError(MS_MISCERR, "Unable to tokenize expression.", "msDrawTransformedShape()"); - return MS_FAILURE; - } - } + msComputeBounds(shape); + bbox_points[0].x = bbox_points[4].x = bbox_points[1].x = + (shape->bounds.minx < -padding) ? -padding : shape->bounds.minx; + /* cppcheck-suppress unreadVariable */ + bbox_points[2].x = bbox_points[3].x = + (shape->bounds.maxx > image->width + padding) ? image->width + padding + : shape->bounds.maxx; + bbox_points[0].y = bbox_points[4].y = bbox_points[3].y = + (shape->bounds.miny < -padding) ? -padding : shape->bounds.miny; + /* cppcheck-suppress unreadVariable */ + bbox_points[1].y = bbox_points[2].y = + (shape->bounds.maxy > image->height + padding) ? image->height + padding + : shape->bounds.maxy; + status = msDrawShadeSymbol(map, image, &bbox, style, scalefactor); + } break; + case MS_GEOMTRANSFORM_CENTROID: { + double unused; /*used by centroid function*/ + pointObj centroid; + if (MS_SUCCESS == + msGetPolygonCentroid(shape, ¢roid, &unused, &unused)) { + status = msDrawMarkerSymbol(map, image, ¢roid, style, scalefactor); + } + } break; + case MS_GEOMTRANSFORM_EXPRESSION: { + int status; + shapeObj *tmpshp; + parseObj p; - p.expr->curtoken = p.expr->tokens; /* reset */ - p.type = MS_PARSE_TYPE_SHAPE; + p.shape = shape; /* set a few parser globals (hence the lock) */ + p.expr = &(style->_geomtransform); - status = yyparse(&p); - if (status != 0) { - msSetError(MS_PARSEERR, "Failed to process shape expression: %s", "msDrawTransformedShape", style->_geomtransform.string); + if (p.expr->tokens == NULL) { /* this could happen if drawing originates + from legend code (#5193) */ + status = msTokenizeExpression(p.expr, NULL, NULL); + if (status != MS_SUCCESS) { + msSetError(MS_MISCERR, "Unable to tokenize expression.", + "msDrawTransformedShape()"); return MS_FAILURE; } - tmpshp = p.result.shpval; + } - switch (tmpshp->type) { - case MS_SHAPE_POINT: - case MS_SHAPE_POLYGON: - /* cppcheck-suppress unreadVariable */ - status = msDrawShadeSymbol(map, image, tmpshp, style, scalefactor); - break; - case MS_SHAPE_LINE: - /* cppcheck-suppress unreadVariable */ - status = msDrawLineSymbol(map, image, tmpshp, style, scalefactor); - break; - } + p.expr->curtoken = p.expr->tokens; /* reset */ + p.type = MS_PARSE_TYPE_SHAPE; - msFreeShape(tmpshp); - msFree(tmpshp); + status = yyparse(&p); + if (status != 0) { + msSetError(MS_PARSEERR, "Failed to process shape expression: %s", + "msDrawTransformedShape", style->_geomtransform.string); + return MS_FAILURE; } - break; - case MS_GEOMTRANSFORM_LABELPOINT: - case MS_GEOMTRANSFORM_LABELPOLY: + tmpshp = p.result.shpval; + + switch (tmpshp->type) { + case MS_SHAPE_POINT: + case MS_SHAPE_POLYGON: + /* cppcheck-suppress unreadVariable */ + status = msDrawShadeSymbol(map, image, tmpshp, style, scalefactor); break; - default: - msSetError(MS_MISCERR, "unknown geomtransform", "msDrawTransformedShape()"); - return MS_FAILURE; + case MS_SHAPE_LINE: + /* cppcheck-suppress unreadVariable */ + status = msDrawLineSymbol(map, image, tmpshp, style, scalefactor); + break; + } + + msFreeShape(tmpshp); + msFree(tmpshp); + } break; + case MS_GEOMTRANSFORM_LABELPOINT: + case MS_GEOMTRANSFORM_LABELPOLY: + break; + default: + msSetError(MS_MISCERR, "unknown geomtransform", "msDrawTransformedShape()"); + return MS_FAILURE; } return status; } @@ -251,70 +250,71 @@ int msDrawTransformedShape(mapObj *map, imageObj *image, shapeObj *shape, styleO * RFC89 implementation: * - transform directly the shapeobj */ -int msGeomTransformShape(mapObj *map, layerObj *layer, shapeObj *shape) -{ +int msGeomTransformShape(mapObj *map, layerObj *layer, shapeObj *shape) { int i; - expressionObj *e = &layer->_geomtransform; + expressionObj *e = &layer->_geomtransform; #ifdef USE_V8_MAPSCRIPT if (!map->v8context) { msV8CreateContext(map); - if (!map->v8context) - { - msSetError(MS_V8ERR, "Unable to create v8 context.", "msGeomTransformShape()"); + if (!map->v8context) { + msSetError(MS_V8ERR, "Unable to create v8 context.", + "msGeomTransformShape()"); return MS_FAILURE; } } msV8ContextSetLayer(map, layer); #endif - - switch(e->type) { - case MS_GEOMTRANSFORM_EXPRESSION: { - int status; - shapeObj *tmpshp; - parseObj p; - - p.shape = shape; /* set a few parser globals (hence the lock) */ - p.expr = e; - p.expr->curtoken = p.expr->tokens; /* reset */ - p.type = MS_PARSE_TYPE_SHAPE; - p.dblval = map->cellsize * (msInchesPerUnit(map->units,0)/msInchesPerUnit(layer->units,0)); - p.dblval2 = 0; - /* data_cellsize is only set with contour layer */ - if (layer->connectiontype == MS_CONTOUR) - { - const char *value = msLookupHashTable(&layer->metadata, "__data_cellsize__"); - if (value) - p.dblval2 = atof(value); - } - - status = yyparse(&p); - if (status != 0) { - msSetError(MS_PARSEERR, "Failed to process shape expression: %s", "msGeomTransformShape()", e->string); - return MS_FAILURE; - } - - tmpshp = p.result.shpval; - for (i= 0; i < shape->numlines; i++) - free(shape->line[i].point); - shape->numlines = 0; - if (shape->line) free(shape->line); - shape->line = NULL; - shape->type = tmpshp->type; /* might have been a change (e.g. centerline) */ + switch (e->type) { + case MS_GEOMTRANSFORM_EXPRESSION: { + int status; + shapeObj *tmpshp; + parseObj p; - for(i=0; inumlines; i++) - msAddLine(shape, &(tmpshp->line[i])); /* copy each line */ - - msFreeShape(tmpshp); - msFree(tmpshp); + p.shape = shape; /* set a few parser globals (hence the lock) */ + p.expr = e; + p.expr->curtoken = p.expr->tokens; /* reset */ + p.type = MS_PARSE_TYPE_SHAPE; + p.dblval = map->cellsize * (msInchesPerUnit(map->units, 0) / + msInchesPerUnit(layer->units, 0)); + p.dblval2 = 0; + /* data_cellsize is only set with contour layer */ + if (layer->connectiontype == MS_CONTOUR) { + const char *value = + msLookupHashTable(&layer->metadata, "__data_cellsize__"); + if (value) + p.dblval2 = atof(value); } - break; - default: - msSetError(MS_MISCERR, "unknown geomtransform", "msGeomTransformShape()"); + + status = yyparse(&p); + if (status != 0) { + msSetError(MS_PARSEERR, "Failed to process shape expression: %s", + "msGeomTransformShape()", e->string); return MS_FAILURE; + } + + tmpshp = p.result.shpval; + + for (i = 0; i < shape->numlines; i++) + free(shape->line[i].point); + shape->numlines = 0; + if (shape->line) + free(shape->line); + shape->line = NULL; + shape->type = tmpshp->type; /* might have been a change (e.g. centerline) */ + + for (i = 0; i < tmpshp->numlines; i++) + msAddLine(shape, &(tmpshp->line[i])); /* copy each line */ + + msFreeShape(tmpshp); + msFree(tmpshp); + } break; + default: + msSetError(MS_MISCERR, "unknown geomtransform", "msGeomTransformShape()"); + return MS_FAILURE; } - + return MS_SUCCESS; } diff --git a/mapgeomutil.cpp b/mapgeomutil.cpp index 7792599f03..b4f0bfa014 100644 --- a/mapgeomutil.cpp +++ b/mapgeomutil.cpp @@ -31,31 +31,32 @@ #include "renderers/agg/include/agg_arc.h" #include "renderers/agg/include/agg_basics.h" - - -shapeObj *msRasterizeArc(double x0, double y0, double radius, double startAngle, double endAngle, int isSlice) -{ - static int allocated_size=100; - shapeObj *shape = (shapeObj*)calloc(1,sizeof(shapeObj)); +shapeObj *msRasterizeArc(double x0, double y0, double radius, double startAngle, + double endAngle, int isSlice) { + static int allocated_size = 100; + shapeObj *shape = (shapeObj *)calloc(1, sizeof(shapeObj)); MS_CHECK_ALLOC(shape, sizeof(shapeObj), NULL); - mapserver::arc arc ( x0, y0,radius,radius, startAngle*MS_DEG_TO_RAD, endAngle*MS_DEG_TO_RAD,true ); - arc.approximation_scale ( 1 ); + mapserver::arc arc(x0, y0, radius, radius, startAngle * MS_DEG_TO_RAD, + endAngle * MS_DEG_TO_RAD, true); + arc.approximation_scale(1); arc.rewind(1); msInitShape(shape); - lineObj *line = (lineObj*)calloc(1,sizeof(lineObj)); + lineObj *line = (lineObj *)calloc(1, sizeof(lineObj)); if (!line) { - msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" , - __FILE__, __LINE__, (unsigned int)sizeof(lineObj)); + msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", + "msRasterizeArc()", __FILE__, __LINE__, + (unsigned int)sizeof(lineObj)); free(shape); return NULL; } shape->line = line; shape->numlines = 1; - line->point = (pointObj*)calloc(allocated_size,sizeof(pointObj)); + line->point = (pointObj *)calloc(allocated_size, sizeof(pointObj)); if (!line->point) { - msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" , - __FILE__, __LINE__, (unsigned int)(allocated_size*sizeof(pointObj))); + msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", + "msRasterizeArc()", __FILE__, __LINE__, + (unsigned int)(allocated_size * sizeof(pointObj))); free(line); free(shape); return NULL; @@ -63,21 +64,23 @@ shapeObj *msRasterizeArc(double x0, double y0, double radius, double startAngle, line->numpoints = 0; - double x,y; + double x, y; - //first segment from center to first point of arc - if(isSlice) { + // first segment from center to first point of arc + if (isSlice) { line->point[0].x = x0; line->point[0].y = y0; line->numpoints = 1; } - while(arc.vertex(&x,&y) != mapserver::path_cmd_stop) { - if(line->numpoints == allocated_size) { + while (arc.vertex(&x, &y) != mapserver::path_cmd_stop) { + if (line->numpoints == allocated_size) { allocated_size *= 2; - line->point = (pointObj*)realloc(line->point, allocated_size * sizeof(pointObj)); + line->point = + (pointObj *)realloc(line->point, allocated_size * sizeof(pointObj)); if (!line->point) { - msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" , - __FILE__, __LINE__, (unsigned int)(allocated_size * sizeof(pointObj))); + msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", + "msRasterizeArc()", __FILE__, __LINE__, + (unsigned int)(allocated_size * sizeof(pointObj))); free(line); free(shape); return NULL; @@ -88,12 +91,13 @@ shapeObj *msRasterizeArc(double x0, double y0, double radius, double startAngle, line->numpoints++; } - //make sure the shape is closed - if(line->point[line->numpoints-1].x != line->point[0].x || - line->point[line->numpoints-1].y != line->point[0].y) { - if(line->numpoints == allocated_size) { + // make sure the shape is closed + if (line->point[line->numpoints - 1].x != line->point[0].x || + line->point[line->numpoints - 1].y != line->point[0].y) { + if (line->numpoints == allocated_size) { allocated_size *= 2; - line->point = (pointObj*)msSmallRealloc(line->point, allocated_size * sizeof(pointObj)); + line->point = (pointObj *)msSmallRealloc( + line->point, allocated_size * sizeof(pointObj)); } line->point[line->numpoints].x = line->point[0].x; line->point[line->numpoints].y = line->point[0].y; @@ -102,6 +106,3 @@ shapeObj *msRasterizeArc(double x0, double y0, double radius, double startAngle, return shape; } - - - diff --git a/mapgeos.c b/mapgeos.c index 29146f25c0..14b33aa84e 100644 --- a/mapgeos.c +++ b/mapgeos.c @@ -41,27 +41,25 @@ /* ** Error handling... */ -static void msGEOSError(const char *format, ...) -{ +static void msGEOSError(const char *format, ...) { va_list args; - va_start (args, format); - msSetError(MS_GEOSERR, format, "msGEOSError()", args); /* just pass along to MapServer error handling */ + va_start(args, format); + msSetError(MS_GEOSERR, format, "msGEOSError()", + args); /* just pass along to MapServer error handling */ va_end(args); return; } -static void msGEOSNotice(const char *fmt, ...) -{ +static void msGEOSNotice(const char *fmt, ...) { (void)fmt; /* do nothing with notices at this point */ } #ifndef USE_THREAD static GEOSContextHandle_t geos_handle; -static inline GEOSContextHandle_t msGetGeosContextHandle() -{ +static inline GEOSContextHandle_t msGetGeosContextHandle() { return geos_handle; } @@ -69,37 +67,37 @@ static inline GEOSContextHandle_t msGetGeosContextHandle() #include "mapthread.h" typedef struct geos_thread_info { struct geos_thread_info *next; - void* thread_id; - GEOSContextHandle_t geos_handle; + void *thread_id; + GEOSContextHandle_t geos_handle; } geos_thread_info_t; static geos_thread_info_t *geos_list = NULL; -static GEOSContextHandle_t msGetGeosContextHandle() -{ +static GEOSContextHandle_t msGetGeosContextHandle() { geos_thread_info_t *link; GEOSContextHandle_t ret_obj; - void* thread_id; + void *thread_id; - msAcquireLock( TLOCK_GEOS ); + msAcquireLock(TLOCK_GEOS); thread_id = msGetThreadId(); /* find link for this thread */ - for( link = geos_list; - link != NULL && link->thread_id != thread_id - && link->next != NULL && link->next->thread_id != thread_id; - link = link->next ) {} + for (link = geos_list; + link != NULL && link->thread_id != thread_id && link->next != NULL && + link->next->thread_id != thread_id; + link = link->next) { + } /* If the target thread link is already at the head of the list were ok */ - if( geos_list != NULL && geos_list->thread_id == thread_id ) { + if (geos_list != NULL && geos_list->thread_id == thread_id) { } /* We don't have one ... initialize one. */ - else if( link == NULL || link->next == NULL ) { + else if (link == NULL || link->next == NULL) { geos_thread_info_t *new_link; - new_link = (geos_thread_info_t *) malloc(sizeof(geos_thread_info_t)); + new_link = (geos_thread_info_t *)malloc(sizeof(geos_thread_info_t)); new_link->next = geos_list; new_link->thread_id = thread_id; new_link->geos_handle = initGEOS_r(msGEOSNotice, msGEOSError); @@ -118,7 +116,7 @@ static GEOSContextHandle_t msGetGeosContextHandle() ret_obj = geos_list->geos_handle; - msReleaseLock( TLOCK_GEOS ); + msReleaseLock(TLOCK_GEOS); return ret_obj; } @@ -127,214 +125,231 @@ static GEOSContextHandle_t msGetGeosContextHandle() /* ** Setup/Cleanup wrappers */ -void msGEOSSetup() -{ +void msGEOSSetup() { #ifndef USE_THREAD geos_handle = initGEOS_r(msGEOSNotice, msGEOSError); #endif } -void msGEOSCleanup() -{ +void msGEOSCleanup() { #ifndef USE_THREAD finishGEOS_r(geos_handle); geos_handle = NULL; #else geos_thread_info_t *link; - msAcquireLock( TLOCK_GEOS ); - for( link = geos_list; link != NULL;) { + msAcquireLock(TLOCK_GEOS); + for (link = geos_list; link != NULL;) { geos_thread_info_t *cur = link; link = link->next; finishGEOS_r(cur->geos_handle); free(cur); } geos_list = NULL; - msReleaseLock( TLOCK_GEOS ); + msReleaseLock(TLOCK_GEOS); #endif } /* ** Translation functions */ -static GEOSGeom msGEOSShape2Geometry_point(pointObj *point) -{ +static GEOSGeom msGEOSShape2Geometry_point(pointObj *point) { GEOSCoordSeq coords; GEOSGeom g; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!point) return NULL; + if (!point) + return NULL; - coords = GEOSCoordSeq_create_r(handle,1, 2); /* todo handle z's */ - if(!coords) return NULL; + coords = GEOSCoordSeq_create_r(handle, 1, 2); /* todo handle z's */ + if (!coords) + return NULL; - GEOSCoordSeq_setX_r(handle,coords, 0, point->x); - GEOSCoordSeq_setY_r(handle,coords, 0, point->y); + GEOSCoordSeq_setX_r(handle, coords, 0, point->x); + GEOSCoordSeq_setY_r(handle, coords, 0, point->y); /* GEOSCoordSeq_setY(coords, 0, point->z); */ - g = GEOSGeom_createPoint_r(handle,coords); /* g owns the coordinate in coords */ + g = GEOSGeom_createPoint_r(handle, + coords); /* g owns the coordinate in coords */ return g; } -static GEOSGeom msGEOSShape2Geometry_multipoint(lineObj *multipoint) -{ +static GEOSGeom msGEOSShape2Geometry_multipoint(lineObj *multipoint) { int i; GEOSGeom g; GEOSGeom *points; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!multipoint) return NULL; + if (!multipoint) + return NULL; - points = malloc(multipoint->numpoints*sizeof(GEOSGeom)); - if(!points) return NULL; + points = malloc(multipoint->numpoints * sizeof(GEOSGeom)); + if (!points) + return NULL; - for(i=0; inumpoints; i++) + for (i = 0; i < multipoint->numpoints; i++) points[i] = msGEOSShape2Geometry_point(&(multipoint->point[i])); - g = GEOSGeom_createCollection_r(handle,GEOS_MULTIPOINT, points, multipoint->numpoints); + g = GEOSGeom_createCollection_r(handle, GEOS_MULTIPOINT, points, + multipoint->numpoints); free(points); return g; } -static GEOSGeom msGEOSShape2Geometry_line(lineObj *line) -{ +static GEOSGeom msGEOSShape2Geometry_line(lineObj *line) { int i; GEOSGeom g; GEOSCoordSeq coords; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!line) return NULL; + if (!line) + return NULL; - coords = GEOSCoordSeq_create_r(handle,line->numpoints, 2); /* todo handle z's */ - if(!coords) return NULL; + coords = + GEOSCoordSeq_create_r(handle, line->numpoints, 2); /* todo handle z's */ + if (!coords) + return NULL; - for(i=0; inumpoints; i++) { - GEOSCoordSeq_setX_r(handle,coords, i, line->point[i].x); - GEOSCoordSeq_setY_r(handle,coords, i, line->point[i].y); + for (i = 0; i < line->numpoints; i++) { + GEOSCoordSeq_setX_r(handle, coords, i, line->point[i].x); + GEOSCoordSeq_setY_r(handle, coords, i, line->point[i].y); /* GEOSCoordSeq_setZ(coords, i, line->point[i].z); */ } - g = GEOSGeom_createLineString_r(handle,coords); /* g owns the coordinates in coords */ + g = GEOSGeom_createLineString_r( + handle, coords); /* g owns the coordinates in coords */ return g; } -static GEOSGeom msGEOSShape2Geometry_multiline(shapeObj *multiline) -{ +static GEOSGeom msGEOSShape2Geometry_multiline(shapeObj *multiline) { int i; GEOSGeom g; GEOSGeom *lines; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!multiline) return NULL; + if (!multiline) + return NULL; - lines = malloc(multiline->numlines*sizeof(GEOSGeom)); - if(!lines) return NULL; + lines = malloc(multiline->numlines * sizeof(GEOSGeom)); + if (!lines) + return NULL; - for(i=0; inumlines; i++) + for (i = 0; i < multiline->numlines; i++) lines[i] = msGEOSShape2Geometry_line(&(multiline->line[i])); - g = GEOSGeom_createCollection_r(handle,GEOS_MULTILINESTRING, lines, multiline->numlines); + g = GEOSGeom_createCollection_r(handle, GEOS_MULTILINESTRING, lines, + multiline->numlines); free(lines); return g; } -static GEOSGeom msGEOSShape2Geometry_simplepolygon(shapeObj *shape, int r, int *outerList) -{ +static GEOSGeom msGEOSShape2Geometry_simplepolygon(shapeObj *shape, int r, + int *outerList) { int i, j, k; GEOSCoordSeq coords; GEOSGeom g; GEOSGeom outerRing; - GEOSGeom *innerRings=NULL; - int numInnerRings=0, *innerList; + GEOSGeom *innerRings = NULL; + int numInnerRings = 0, *innerList; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape || !outerList) return NULL; + if (!shape || !outerList) + return NULL; /* build the outer shell */ - coords = GEOSCoordSeq_create_r(handle,shape->line[r].numpoints, 2); /* todo handle z's */ - if(!coords) return NULL; + coords = GEOSCoordSeq_create_r(handle, shape->line[r].numpoints, + 2); /* todo handle z's */ + if (!coords) + return NULL; - for(i=0; iline[r].numpoints; i++) { - GEOSCoordSeq_setX_r(handle,coords, i, shape->line[r].point[i].x); - GEOSCoordSeq_setY_r(handle,coords, i, shape->line[r].point[i].y); + for (i = 0; i < shape->line[r].numpoints; i++) { + GEOSCoordSeq_setX_r(handle, coords, i, shape->line[r].point[i].x); + GEOSCoordSeq_setY_r(handle, coords, i, shape->line[r].point[i].y); /* GEOSCoordSeq_setZ(coords, i, shape->line[r].point[i].z); */ } - outerRing = GEOSGeom_createLinearRing_r(handle,coords); /* outerRing owns the coordinates in coords */ + outerRing = GEOSGeom_createLinearRing_r( + handle, coords); /* outerRing owns the coordinates in coords */ /* build the holes */ innerList = msGetInnerList(shape, r, outerList); - for(j=0; jnumlines; j++) - if(innerList[j] == MS_TRUE) numInnerRings++; + for (j = 0; j < shape->numlines; j++) + if (innerList[j] == MS_TRUE) + numInnerRings++; - if(numInnerRings > 0) { + if (numInnerRings > 0) { k = 0; /* inner ring counter */ - innerRings = msSmallMalloc(numInnerRings*sizeof(GEOSGeom)); + innerRings = msSmallMalloc(numInnerRings * sizeof(GEOSGeom)); - for(j=0; jnumlines; j++) { - if(innerList[j] == MS_FALSE) continue; + for (j = 0; j < shape->numlines; j++) { + if (innerList[j] == MS_FALSE) + continue; - coords = GEOSCoordSeq_create_r(handle,shape->line[j].numpoints, 2); /* todo handle z's */ - if(!coords) { + coords = GEOSCoordSeq_create_r(handle, shape->line[j].numpoints, + 2); /* todo handle z's */ + if (!coords) { free(innerRings); free(innerList); return NULL; /* todo, this will leak memory (shell + allocated holes) */ } - for(i=0; iline[j].numpoints; i++) { - GEOSCoordSeq_setX_r(handle,coords, i, shape->line[j].point[i].x); - GEOSCoordSeq_setY_r(handle,coords, i, shape->line[j].point[i].y); + for (i = 0; i < shape->line[j].numpoints; i++) { + GEOSCoordSeq_setX_r(handle, coords, i, shape->line[j].point[i].x); + GEOSCoordSeq_setY_r(handle, coords, i, shape->line[j].point[i].y); /* GEOSCoordSeq_setZ(coords, i, shape->line[j].point[i].z); */ } - innerRings[k] = GEOSGeom_createLinearRing_r(handle,coords); /* innerRings[k] owns the coordinates in coords */ + innerRings[k] = GEOSGeom_createLinearRing_r( + handle, coords); /* innerRings[k] owns the coordinates in coords */ k++; } } - g = GEOSGeom_createPolygon_r(handle,outerRing, innerRings, numInnerRings); + g = GEOSGeom_createPolygon_r(handle, outerRing, innerRings, numInnerRings); - free(innerList); /* clean up */ + free(innerList); /* clean up */ free(innerRings); /* clean up */ return g; } -static GEOSGeom msGEOSShape2Geometry_polygon(shapeObj *shape) -{ +static GEOSGeom msGEOSShape2Geometry_polygon(shapeObj *shape) { int i, j; GEOSGeom *polygons; - int *outerList, numOuterRings=0, lastOuterRing=0; + int *outerList, numOuterRings = 0, lastOuterRing = 0; GEOSGeom g; GEOSContextHandle_t handle = msGetGeosContextHandle(); outerList = msGetOuterList(shape); - for(i=0; inumlines; i++) { - if(outerList[i] == MS_TRUE) { + for (i = 0; i < shape->numlines; i++) { + if (outerList[i] == MS_TRUE) { numOuterRings++; lastOuterRing = i; /* save for the simple case */ } } - if(numOuterRings == 1) { + if (numOuterRings == 1) { g = msGEOSShape2Geometry_simplepolygon(shape, lastOuterRing, outerList); } else { /* a true multipolygon */ - polygons = msSmallMalloc(numOuterRings*sizeof(GEOSGeom)); + polygons = msSmallMalloc(numOuterRings * sizeof(GEOSGeom)); j = 0; /* part counter */ - for(i=0; inumlines; i++) { - if(outerList[i] == MS_FALSE) continue; - polygons[j] = msGEOSShape2Geometry_simplepolygon(shape, i, outerList); /* TODO: account for NULL return values */ + for (i = 0; i < shape->numlines; i++) { + if (outerList[i] == MS_FALSE) + continue; + polygons[j] = msGEOSShape2Geometry_simplepolygon( + shape, i, outerList); /* TODO: account for NULL return values */ j++; } - g = GEOSGeom_createCollection_r(handle,GEOS_MULTIPOLYGON, polygons, numOuterRings); + g = GEOSGeom_createCollection_r(handle, GEOS_MULTIPOLYGON, polygons, + numOuterRings); free(polygons); } @@ -342,65 +357,69 @@ static GEOSGeom msGEOSShape2Geometry_polygon(shapeObj *shape) return g; } -GEOSGeom msGEOSShape2Geometry(shapeObj *shape) -{ - if(!shape) +GEOSGeom msGEOSShape2Geometry(shapeObj *shape) { + if (!shape) return NULL; /* a NULL shape generates a NULL geometry */ - switch(shape->type) { - case MS_SHAPE_POINT: - if(shape->numlines == 0 || shape->line[0].numpoints == 0) /* not enough info for a point */ - return NULL; - - if(shape->line[0].numpoints == 1) /* simple point */ - return msGEOSShape2Geometry_point(&(shape->line[0].point[0])); - else /* multi-point */ - return msGEOSShape2Geometry_multipoint(&(shape->line[0])); - break; - case MS_SHAPE_LINE: - if(shape->numlines == 0 || shape->line[0].numpoints < 2) /* not enough info for a line */ - return NULL; - - if(shape->numlines == 1) /* simple line */ - return msGEOSShape2Geometry_line(&(shape->line[0])); - else /* multi-line */ - return msGEOSShape2Geometry_multiline(shape); - break; - case MS_SHAPE_POLYGON: - if(shape->numlines == 0 || shape->line[0].numpoints < 4) /* not enough info for a polygon (first=last) */ - return NULL; - - return msGEOSShape2Geometry_polygon(shape); /* simple and multipolygon cases are addressed */ - break; - default: - break; + switch (shape->type) { + case MS_SHAPE_POINT: + if (shape->numlines == 0 || + shape->line[0].numpoints == 0) /* not enough info for a point */ + return NULL; + + if (shape->line[0].numpoints == 1) /* simple point */ + return msGEOSShape2Geometry_point(&(shape->line[0].point[0])); + else /* multi-point */ + return msGEOSShape2Geometry_multipoint(&(shape->line[0])); + break; + case MS_SHAPE_LINE: + if (shape->numlines == 0 || + shape->line[0].numpoints < 2) /* not enough info for a line */ + return NULL; + + if (shape->numlines == 1) /* simple line */ + return msGEOSShape2Geometry_line(&(shape->line[0])); + else /* multi-line */ + return msGEOSShape2Geometry_multiline(shape); + break; + case MS_SHAPE_POLYGON: + if (shape->numlines == 0 || + shape->line[0].numpoints < + 4) /* not enough info for a polygon (first=last) */ + return NULL; + + return msGEOSShape2Geometry_polygon( + shape); /* simple and multipolygon cases are addressed */ + break; + default: + break; } return NULL; /* should not get here */ } -static shapeObj *msGEOSGeometry2Shape_point(GEOSGeom g) -{ +static shapeObj *msGEOSGeometry2Shape_point(GEOSGeom g) { GEOSCoordSeq coords; - shapeObj *shape=NULL; + shapeObj *shape = NULL; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!g) return NULL; + if (!g) + return NULL; - shape = (shapeObj *) malloc(sizeof(shapeObj)); + shape = (shapeObj *)malloc(sizeof(shapeObj)); msInitShape(shape); shape->type = MS_SHAPE_POINT; - shape->line = (lineObj *) malloc(sizeof(lineObj)); + shape->line = (lineObj *)malloc(sizeof(lineObj)); shape->numlines = 1; - shape->line[0].point = (pointObj *) malloc(sizeof(pointObj)); + shape->line[0].point = (pointObj *)malloc(sizeof(pointObj)); shape->line[0].numpoints = 1; - shape->geometry = (GEOSGeom) g; + shape->geometry = (GEOSGeom)g; - coords = (GEOSCoordSeq) GEOSGeom_getCoordSeq_r(handle,g); + coords = (GEOSCoordSeq)GEOSGeom_getCoordSeq_r(handle, g); - GEOSCoordSeq_getX_r(handle,coords, 0, &(shape->line[0].point[0].x)); - GEOSCoordSeq_getY_r(handle,coords, 0, &(shape->line[0].point[0].y)); + GEOSCoordSeq_getX_r(handle, coords, 0, &(shape->line[0].point[0].x)); + GEOSCoordSeq_getY_r(handle, coords, 0, &(shape->line[0].point[0].y)); /* GEOSCoordSeq_getZ(coords, 0, &(shape->line[0].point[0].z)); */ shape->bounds.minx = shape->bounds.maxx = shape->line[0].point[0].x; @@ -409,35 +428,35 @@ static shapeObj *msGEOSGeometry2Shape_point(GEOSGeom g) return shape; } -static shapeObj *msGEOSGeometry2Shape_multipoint(GEOSGeom g) -{ +static shapeObj *msGEOSGeometry2Shape_multipoint(GEOSGeom g) { int i; int numPoints; GEOSCoordSeq coords; GEOSGeom point; - shapeObj *shape=NULL; + shapeObj *shape = NULL; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!g) return NULL; - numPoints = GEOSGetNumGeometries_r(handle,g); /* each geometry has 1 point */ + if (!g) + return NULL; + numPoints = GEOSGetNumGeometries_r(handle, g); /* each geometry has 1 point */ - shape = (shapeObj *) malloc(sizeof(shapeObj)); + shape = (shapeObj *)malloc(sizeof(shapeObj)); msInitShape(shape); shape->type = MS_SHAPE_POINT; - shape->line = (lineObj *) malloc(sizeof(lineObj)); + shape->line = (lineObj *)malloc(sizeof(lineObj)); shape->numlines = 1; - shape->line[0].point = (pointObj *) malloc(sizeof(pointObj)*numPoints); + shape->line[0].point = (pointObj *)malloc(sizeof(pointObj) * numPoints); shape->line[0].numpoints = numPoints; - shape->geometry = (GEOSGeom) g; + shape->geometry = (GEOSGeom)g; - for(i=0; iline[0].point[i].x)); - GEOSCoordSeq_getY_r(handle,coords, 0, &(shape->line[0].point[i].y)); + GEOSCoordSeq_getX_r(handle, coords, 0, &(shape->line[0].point[i].x)); + GEOSCoordSeq_getY_r(handle, coords, 0, &(shape->line[0].point[i].y)); /* GEOSCoordSeq_getZ(coords, 0, &(shape->line[0].point[i].z)); */ } @@ -446,32 +465,32 @@ static shapeObj *msGEOSGeometry2Shape_multipoint(GEOSGeom g) return shape; } -static shapeObj *msGEOSGeometry2Shape_line(GEOSGeom g) -{ - shapeObj *shape=NULL; +static shapeObj *msGEOSGeometry2Shape_line(GEOSGeom g) { + shapeObj *shape = NULL; GEOSContextHandle_t handle = msGetGeosContextHandle(); int i; int numPoints; GEOSCoordSeq coords; - if(!g) return NULL; - numPoints = GEOSGetNumCoordinates_r(handle,g); - coords = (GEOSCoordSeq) GEOSGeom_getCoordSeq_r(handle,g); + if (!g) + return NULL; + numPoints = GEOSGetNumCoordinates_r(handle, g); + coords = (GEOSCoordSeq)GEOSGeom_getCoordSeq_r(handle, g); - shape = (shapeObj *) malloc(sizeof(shapeObj)); + shape = (shapeObj *)malloc(sizeof(shapeObj)); msInitShape(shape); shape->type = MS_SHAPE_LINE; - shape->line = (lineObj *) malloc(sizeof(lineObj)); + shape->line = (lineObj *)malloc(sizeof(lineObj)); shape->numlines = 1; - shape->line[0].point = (pointObj *) malloc(sizeof(pointObj)*numPoints); + shape->line[0].point = (pointObj *)malloc(sizeof(pointObj) * numPoints); shape->line[0].numpoints = numPoints; - shape->geometry = (GEOSGeom) g; + shape->geometry = (GEOSGeom)g; - for(i=0; iline[0].point[i].x)); - GEOSCoordSeq_getY_r(handle,coords, i, &(shape->line[0].point[i].y)); + for (i = 0; i < numPoints; i++) { + GEOSCoordSeq_getX_r(handle, coords, i, &(shape->line[0].point[i].x)); + GEOSCoordSeq_getY_r(handle, coords, i, &(shape->line[0].point[i].y)); /* GEOSCoordSeq_getZ(coords, i, &(shape->line[0].point[i].z)); */ } @@ -480,29 +499,31 @@ static shapeObj *msGEOSGeometry2Shape_line(GEOSGeom g) return shape; } -static void msGEOSGeometry2Shape_multiline_part(GEOSContextHandle_t handle, GEOSGeom part, shapeObj *shape) { +static void msGEOSGeometry2Shape_multiline_part(GEOSContextHandle_t handle, + GEOSGeom part, + shapeObj *shape) { int i; int type, numGeometries, numPoints; GEOSCoordSeq coords; lineObj line; - - type = GEOSGeomTypeId_r(handle,part); + + type = GEOSGeomTypeId_r(handle, part); if (type == GEOS_MULTILINESTRING) { - numGeometries = GEOSGetNumGeometries_r(handle,part); + numGeometries = GEOSGetNumGeometries_r(handle, part); - for(i=0; itype = MS_SHAPE_LINE; - shape->geometry = (GEOSGeom) g; + shape->geometry = (GEOSGeom)g; - for(i=0; itype = MS_SHAPE_POLYGON; - shape->geometry = (GEOSGeom) g; + shape->geometry = (GEOSGeom)g; /* exterior ring */ - ring = (GEOSGeom) GEOSGetExteriorRing_r(handle,g); - numPoints = GEOSGetNumCoordinates_r(handle,ring); - coords = (GEOSCoordSeq) GEOSGeom_getCoordSeq_r(handle,ring); + ring = (GEOSGeom)GEOSGetExteriorRing_r(handle, g); + numPoints = GEOSGetNumCoordinates_r(handle, ring); + coords = (GEOSCoordSeq)GEOSGeom_getCoordSeq_r(handle, ring); - line.point = (pointObj *) malloc(sizeof(pointObj)*numPoints); + line.point = (pointObj *)malloc(sizeof(pointObj) * numPoints); line.numpoints = numPoints; - for(i=0; itype = MS_SHAPE_POLYGON; - shape->geometry = (GEOSGeom) g; + shape->geometry = (GEOSGeom)g; - for(k=0; ktype = MS_SHAPE_LINE; - shape->geometry = (GEOSGeom) g; - - const int numGeoms = GEOSGetNumGeometries_r(handle,g); - for(int i = 0; i < numGeoms; i++) { /* for each geometry */ - shapeObj* shape2 = msGEOSGeometry2Shape((GEOSGeom)GEOSGetGeometryN_r(handle,g, i)); - if (shape2) { - for (int j = 0; j < shape2->numlines; j++) - msAddLineDirectly(shape, &shape2->line[j]); - shape2->numlines = 0; - shape2->geometry = NULL; /* not owned */ - msFreeShape(shape2); - } + type = GEOSGeomTypeId_r(handle, g); + switch (type) { + case GEOS_POINT: + return msGEOSGeometry2Shape_point(g); + break; + case GEOS_MULTIPOINT: + return msGEOSGeometry2Shape_multipoint(g); + break; + case GEOS_LINESTRING: + return msGEOSGeometry2Shape_line(g); + break; + case GEOS_MULTILINESTRING: + return msGEOSGeometry2Shape_multiline(g); + break; + case GEOS_POLYGON: + return msGEOSGeometry2Shape_polygon(g); + break; + case GEOS_MULTIPOLYGON: + return msGEOSGeometry2Shape_multipolygon(g); + break; + case GEOS_GEOMETRYCOLLECTION: + if (!GEOSisEmpty_r(handle, g)) { + shapeObj *shape = (shapeObj *)malloc(sizeof(shapeObj)); + msInitShape(shape); + shape->type = MS_SHAPE_LINE; + shape->geometry = (GEOSGeom)g; + + const int numGeoms = GEOSGetNumGeometries_r(handle, g); + for (int i = 0; i < numGeoms; i++) { /* for each geometry */ + shapeObj *shape2 = + msGEOSGeometry2Shape((GEOSGeom)GEOSGetGeometryN_r(handle, g, i)); + if (shape2) { + for (int j = 0; j < shape2->numlines; j++) + msAddLineDirectly(shape, &shape2->line[j]); + shape2->numlines = 0; + shape2->geometry = NULL; /* not owned */ + msFreeShape(shape2); } - msComputeBounds(shape); - return shape; } - break; - default: - msSetError(MS_GEOSERR, "Unsupported GEOS geometry type (%d).", "msGEOSGeometry2Shape()", type); + msComputeBounds(shape); + return shape; + } + break; + default: + msSetError(MS_GEOSERR, "Unsupported GEOS geometry type (%d).", + "msGEOSGeometry2Shape()", type); } return NULL; } @@ -722,20 +745,20 @@ shapeObj *msGEOSGeometry2Shape(GEOSGeom g) ** Maintenence functions exposed to MapServer/MapScript. */ -void msGEOSFreeGeometry(shapeObj *shape) -{ +void msGEOSFreeGeometry(shapeObj *shape) { #ifdef USE_GEOS - GEOSGeom g=NULL; + GEOSGeom g = NULL; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape || !shape->geometry) + if (!shape || !shape->geometry) return; - g = (GEOSGeom) shape->geometry; - GEOSGeom_destroy_r(handle,g); + g = (GEOSGeom)shape->geometry; + GEOSGeom_destroy_r(handle, g); shape->geometry = NULL; #else - msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSFreeGEOSGeom()"); + msSetError(MS_GEOSERR, "GEOS support is not available.", + "msGEOSFreeGEOSGeom()"); return; #endif } @@ -743,59 +766,61 @@ void msGEOSFreeGeometry(shapeObj *shape) /* ** WKT input and output functions */ -shapeObj *msGEOSShapeFromWKT(const char *wkt) -{ +shapeObj *msGEOSShapeFromWKT(const char *wkt) { #ifdef USE_GEOS GEOSGeom g; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!wkt) + if (!wkt) return NULL; - g = GEOSGeomFromWKT_r(handle,wkt); - if(!g) { - msSetError(MS_GEOSERR, "Error reading WKT geometry \"%s\".", "msGEOSShapeFromWKT()", wkt); + g = GEOSGeomFromWKT_r(handle, wkt); + if (!g) { + msSetError(MS_GEOSERR, "Error reading WKT geometry \"%s\".", + "msGEOSShapeFromWKT()", wkt); return NULL; } else { return msGEOSGeometry2Shape(g); } #else - msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSShapeFromWKT()"); + msSetError(MS_GEOSERR, "GEOS support is not available.", + "msGEOSShapeFromWKT()"); return NULL; #endif } /* Return should be freed with msGEOSFreeWKT */ -char *msGEOSShapeToWKT(shapeObj *shape) -{ +char *msGEOSShapeToWKT(shapeObj *shape) { #ifdef USE_GEOS GEOSGeom g; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) + if (!shape) return NULL; /* if we have a geometry, we should update it*/ msGEOSFreeGeometry(shape); - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); - g = (GEOSGeom) shape->geometry; - if(!g) return NULL; + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); + g = (GEOSGeom)shape->geometry; + if (!g) + return NULL; - return GEOSGeomToWKT_r(handle,g); + return GEOSGeomToWKT_r(handle, g); #else - msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSShapeToWKT()"); + msSetError(MS_GEOSERR, "GEOS support is not available.", + "msGEOSShapeToWKT()"); return NULL; #endif } -void msGEOSFreeWKT(char* pszGEOSWKT) -{ +void msGEOSFreeWKT(char *pszGEOSWKT) { #ifdef USE_GEOS GEOSContextHandle_t handle = msGetGeosContextHandle(); -#if GEOS_VERSION_MAJOR > 3 || (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 2) - GEOSFree_r(handle,pszGEOSWKT); +#if GEOS_VERSION_MAJOR > 3 || \ + (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 2) + GEOSFree_r(handle, pszGEOSWKT); #endif #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSFreeWKT()"); @@ -803,12 +828,13 @@ void msGEOSFreeWKT(char* pszGEOSWKT) } shapeObj *msGEOSOffsetCurve(shapeObj *p, double offset) { -#if defined USE_GEOS && (GEOS_VERSION_MAJOR > 3 || (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 3)) +#if defined USE_GEOS && (GEOS_VERSION_MAJOR > 3 || \ + (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 3)) int typeChanged = 0; GEOSGeom g1, g2 = NULL; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!p) + if (!p) return NULL; /* @@ -816,40 +842,41 @@ shapeObj *msGEOSOffsetCurve(shapeObj *p, double offset) { * works with lines, naturally. In order to allow offsets for a MapServer * polygonObj, it has to be processed as line and afterwards reverted. */ - if(p->type == MS_SHAPE_POLYGON) { + if (p->type == MS_SHAPE_POLYGON) { p->type = MS_SHAPE_LINE; typeChanged = 1; msGEOSFreeGeometry(p); } - if(typeChanged || !p->geometry) - p->geometry = (GEOSGeom) msGEOSShape2Geometry(p); - - g1 = (GEOSGeom) p->geometry; - if(!g1) return NULL; - - if (GEOSGeomTypeId_r(handle,g1) == GEOS_MULTILINESTRING) - { - GEOSGeom *lines = malloc(p->numlines*sizeof(GEOSGeom)); - if (!lines) return NULL; - for(int i=0; inumlines; i++) - { - lines[i] = GEOSOffsetCurve_r(handle, GEOSGetGeometryN_r(handle,g1,i), - offset, 4, GEOSBUF_JOIN_MITRE, fabs(offset*1.5)); + if (typeChanged || !p->geometry) + p->geometry = (GEOSGeom)msGEOSShape2Geometry(p); + + g1 = (GEOSGeom)p->geometry; + if (!g1) + return NULL; + + if (GEOSGeomTypeId_r(handle, g1) == GEOS_MULTILINESTRING) { + GEOSGeom *lines = malloc(p->numlines * sizeof(GEOSGeom)); + if (!lines) + return NULL; + for (int i = 0; i < p->numlines; i++) { + lines[i] = + GEOSOffsetCurve_r(handle, GEOSGetGeometryN_r(handle, g1, i), offset, + 4, GEOSBUF_JOIN_MITRE, fabs(offset * 1.5)); } - g2 = GEOSGeom_createCollection_r(handle,GEOS_MULTILINESTRING, lines, p->numlines); + g2 = GEOSGeom_createCollection_r(handle, GEOS_MULTILINESTRING, lines, + p->numlines); free(lines); - } - else - { - g2 = GEOSOffsetCurve_r(handle,g1, offset, 4, GEOSBUF_JOIN_MITRE, fabs(offset*1.5)); + } else { + g2 = GEOSOffsetCurve_r(handle, g1, offset, 4, GEOSBUF_JOIN_MITRE, + fabs(offset * 1.5)); } /* * Undo change of geometry type. We won't re-create the geos gemotry here, * it's up to each geos function to create it. */ - if(typeChanged) { + if (typeChanged) { msGEOSFreeGeometry(p); p->type = MS_SHAPE_POLYGON; } @@ -859,7 +886,8 @@ shapeObj *msGEOSOffsetCurve(shapeObj *p, double offset) { return NULL; #else - msSetError(MS_GEOSERR, "GEOS Offset Curve support is not available.", "msGEOSingleSidedBuffer()"); + msSetError(MS_GEOSERR, "GEOS Offset Curve support is not available.", + "msGEOSingleSidedBuffer()"); return NULL; #endif } @@ -868,22 +896,22 @@ shapeObj *msGEOSOffsetCurve(shapeObj *p, double offset) { ** Analytical functions exposed to MapServer/MapScript. */ -shapeObj *msGEOSBuffer(shapeObj *shape, double width) -{ +shapeObj *msGEOSBuffer(shapeObj *shape, double width) { #ifdef USE_GEOS GEOSGeom g1, g2; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) + if (!shape) return NULL; - if(!shape->geometry) /* if no geometry for the shape then build one */ - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); + if (!shape->geometry) /* if no geometry for the shape then build one */ + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); - g1 = (GEOSGeom) shape->geometry; - if(!g1) return NULL; + g1 = (GEOSGeom)shape->geometry; + if (!g1) + return NULL; - g2 = GEOSBuffer_r(handle,g1, width, 30); + g2 = GEOSBuffer_r(handle, g1, width, 30); return msGEOSGeometry2Shape(g2); #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSBuffer()"); @@ -891,87 +919,92 @@ shapeObj *msGEOSBuffer(shapeObj *shape, double width) #endif } -shapeObj *msGEOSSimplify(shapeObj *shape, double tolerance) -{ +shapeObj *msGEOSSimplify(shapeObj *shape, double tolerance) { #ifdef USE_GEOS GEOSGeom g1, g2; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) + if (!shape) return NULL; - if(!shape->geometry) /* if no geometry for the shape then build one */ - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); + if (!shape->geometry) /* if no geometry for the shape then build one */ + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); - g1 = (GEOSGeom) shape->geometry; - if(!g1) return NULL; + g1 = (GEOSGeom)shape->geometry; + if (!g1) + return NULL; - g2 = GEOSSimplify_r(handle,g1, tolerance); + g2 = GEOSSimplify_r(handle, g1, tolerance); return msGEOSGeometry2Shape(g2); #else - msSetError(MS_GEOSERR, "GEOS Simplify support is not available.", "msGEOSSimplify()"); + msSetError(MS_GEOSERR, "GEOS Simplify support is not available.", + "msGEOSSimplify()"); return NULL; #endif } -shapeObj *msGEOSTopologyPreservingSimplify(shapeObj *shape, double tolerance) -{ +shapeObj *msGEOSTopologyPreservingSimplify(shapeObj *shape, double tolerance) { #ifdef USE_GEOS GEOSGeom g1, g2; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) + if (!shape) return NULL; - if(!shape->geometry) /* if no geometry for the shape then build one */ - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); + if (!shape->geometry) /* if no geometry for the shape then build one */ + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); - g1 = (GEOSGeom) shape->geometry; - if(!g1) return NULL; + g1 = (GEOSGeom)shape->geometry; + if (!g1) + return NULL; - g2 = GEOSTopologyPreserveSimplify_r(handle,g1, tolerance); + g2 = GEOSTopologyPreserveSimplify_r(handle, g1, tolerance); return msGEOSGeometry2Shape(g2); #else - msSetError(MS_GEOSERR, "GEOS Simplify support is not available.", "msGEOSTopologyPreservingSimplify()"); + msSetError(MS_GEOSERR, "GEOS Simplify support is not available.", + "msGEOSTopologyPreservingSimplify()"); return NULL; #endif } -shapeObj *msGEOSConvexHull(shapeObj *shape) -{ +shapeObj *msGEOSConvexHull(shapeObj *shape) { #ifdef USE_GEOS GEOSGeom g1, g2; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) return NULL; + if (!shape) + return NULL; - if(!shape->geometry) /* if no geometry for the shape then build one */ - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); - g1 = (GEOSGeom) shape->geometry; - if(!g1) return NULL; + if (!shape->geometry) /* if no geometry for the shape then build one */ + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); + g1 = (GEOSGeom)shape->geometry; + if (!g1) + return NULL; - g2 = GEOSConvexHull_r(handle,g1); + g2 = GEOSConvexHull_r(handle, g1); return msGEOSGeometry2Shape(g2); #else - msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSConvexHull()"); + msSetError(MS_GEOSERR, "GEOS support is not available.", + "msGEOSConvexHull()"); return NULL; #endif } -shapeObj *msGEOSBoundary(shapeObj *shape) -{ +shapeObj *msGEOSBoundary(shapeObj *shape) { #ifdef USE_GEOS GEOSGeom g1, g2; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) return NULL; + if (!shape) + return NULL; - if(!shape->geometry) /* if no geometry for the shape then build one */ - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); - g1 = (GEOSGeom) shape->geometry; - if(!g1) return NULL; + if (!shape->geometry) /* if no geometry for the shape then build one */ + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); + g1 = (GEOSGeom)shape->geometry; + if (!g1) + return NULL; - g2 = GEOSBoundary_r(handle,g1); + g2 = GEOSBoundary_r(handle, g1); return msGEOSGeometry2Shape(g2); #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSBoundary()"); @@ -979,61 +1012,65 @@ shapeObj *msGEOSBoundary(shapeObj *shape) #endif } -pointObj *msGEOSGetCentroid(shapeObj *shape) -{ +pointObj *msGEOSGetCentroid(shapeObj *shape) { #ifdef USE_GEOS GEOSGeom g1, g2; GEOSCoordSeq coords; pointObj *point; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) return NULL; + if (!shape) + return NULL; - if(!shape->geometry) /* if no geometry for the shape then build one */ - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); - g1 = (GEOSGeom) shape->geometry; - if(!g1) return NULL; + if (!shape->geometry) /* if no geometry for the shape then build one */ + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); + g1 = (GEOSGeom)shape->geometry; + if (!g1) + return NULL; - g2 = GEOSGetCentroid_r(handle,g1); - if (!g2) return NULL; + g2 = GEOSGetCentroid_r(handle, g1); + if (!g2) + return NULL; - point = (pointObj *) malloc(sizeof(pointObj)); + point = (pointObj *)malloc(sizeof(pointObj)); - coords = (GEOSCoordSeq) GEOSGeom_getCoordSeq_r(handle,g2); + coords = (GEOSCoordSeq)GEOSGeom_getCoordSeq_r(handle, g2); - GEOSCoordSeq_getX_r(handle,coords, 0, &(point->x)); - GEOSCoordSeq_getY_r(handle,coords, 0, &(point->y)); + GEOSCoordSeq_getX_r(handle, coords, 0, &(point->x)); + GEOSCoordSeq_getY_r(handle, coords, 0, &(point->y)); /* GEOSCoordSeq_getZ(coords, 0, &(point->z)); */ GEOSGeom_destroy_r(handle, g2); return point; #else - msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSGetCentroid()"); + msSetError(MS_GEOSERR, "GEOS support is not available.", + "msGEOSGetCentroid()"); return NULL; #endif } -shapeObj *msGEOSUnion(shapeObj *shape1, shapeObj *shape2) -{ +shapeObj *msGEOSUnion(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2, g3; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return NULL; - if(!shape1->geometry) /* if no geometry for the shape then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); - g1 = (GEOSGeom) shape1->geometry; - if(!g1) return NULL; + if (!shape1->geometry) /* if no geometry for the shape then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); + g1 = (GEOSGeom)shape1->geometry; + if (!g1) + return NULL; - if(!shape2->geometry) /* if no geometry for the shape then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); - g2 = (GEOSGeom) shape2->geometry; - if(!g2) return NULL; + if (!shape2->geometry) /* if no geometry for the shape then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); + g2 = (GEOSGeom)shape2->geometry; + if (!g2) + return NULL; - g3 = GEOSUnion_r(handle,g1, g2); + g3 = GEOSUnion_r(handle, g1, g2); return msGEOSGeometry2Shape(g3); #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSUnion()"); @@ -1041,100 +1078,108 @@ shapeObj *msGEOSUnion(shapeObj *shape1, shapeObj *shape2) #endif } -shapeObj *msGEOSIntersection(shapeObj *shape1, shapeObj *shape2) -{ +shapeObj *msGEOSIntersection(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2, g3; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return NULL; - if(!shape1->geometry) /* if no geometry for the shape then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); - g1 = (GEOSGeom) shape1->geometry; - if(!g1) return NULL; + if (!shape1->geometry) /* if no geometry for the shape then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); + g1 = (GEOSGeom)shape1->geometry; + if (!g1) + return NULL; - if(!shape2->geometry) /* if no geometry for the shape then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); - g2 = (GEOSGeom) shape2->geometry; - if(!g2) return NULL; + if (!shape2->geometry) /* if no geometry for the shape then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); + g2 = (GEOSGeom)shape2->geometry; + if (!g2) + return NULL; - g3 = GEOSIntersection_r(handle,g1, g2); + g3 = GEOSIntersection_r(handle, g1, g2); return msGEOSGeometry2Shape(g3); #else - msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSIntersection()"); + msSetError(MS_GEOSERR, "GEOS support is not available.", + "msGEOSIntersection()"); return NULL; #endif } -shapeObj *msGEOSDifference(shapeObj *shape1, shapeObj *shape2) -{ +shapeObj *msGEOSDifference(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2, g3; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return NULL; - if(!shape1->geometry) /* if no geometry for the shape then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); - g1 = (GEOSGeom) shape1->geometry; - if(!g1) return NULL; + if (!shape1->geometry) /* if no geometry for the shape then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); + g1 = (GEOSGeom)shape1->geometry; + if (!g1) + return NULL; - if(!shape2->geometry) /* if no geometry for the shape then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); - g2 = (GEOSGeom) shape2->geometry; - if(!g2) return NULL; + if (!shape2->geometry) /* if no geometry for the shape then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); + g2 = (GEOSGeom)shape2->geometry; + if (!g2) + return NULL; - g3 = GEOSDifference_r(handle,g1, g2); + g3 = GEOSDifference_r(handle, g1, g2); return msGEOSGeometry2Shape(g3); #else - msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSDifference()"); + msSetError(MS_GEOSERR, "GEOS support is not available.", + "msGEOSDifference()"); return NULL; #endif } -shapeObj *msGEOSSymDifference(shapeObj *shape1, shapeObj *shape2) -{ +shapeObj *msGEOSSymDifference(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2, g3; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return NULL; - if(!shape1->geometry) /* if no geometry for the shape then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); - g1 = (GEOSGeom) shape1->geometry; - if(!g1) return NULL; + if (!shape1->geometry) /* if no geometry for the shape then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); + g1 = (GEOSGeom)shape1->geometry; + if (!g1) + return NULL; - if(!shape2->geometry) /* if no geometry for the shape then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); - g2 = (GEOSGeom) shape2->geometry; - if(!g2) return NULL; + if (!shape2->geometry) /* if no geometry for the shape then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); + g2 = (GEOSGeom)shape2->geometry; + if (!g2) + return NULL; - g3 = GEOSSymDifference_r(handle,g1, g2); + g3 = GEOSSymDifference_r(handle, g1, g2); return msGEOSGeometry2Shape(g3); #else - msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSSymDifference()"); + msSetError(MS_GEOSERR, "GEOS support is not available.", + "msGEOSSymDifference()"); return NULL; #endif } -shapeObj *msGEOSLineMerge(shapeObj *shape) -{ +shapeObj *msGEOSLineMerge(shapeObj *shape) { #ifdef USE_GEOS GEOSGeom g1, g2; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) return NULL; - if(shape->type != MS_SHAPE_LINE) return NULL; + if (!shape) + return NULL; + if (shape->type != MS_SHAPE_LINE) + return NULL; - if(!shape->geometry) /* if no geometry for the shape then build one */ - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); - g1 = (GEOSGeom) shape->geometry; - if(!g1) return NULL; + if (!shape->geometry) /* if no geometry for the shape then build one */ + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); + g1 = (GEOSGeom)shape->geometry; + if (!g1) + return NULL; g2 = GEOSLineMerge_r(handle, g1); return msGEOSGeometry2Shape(g2); @@ -1144,52 +1189,64 @@ shapeObj *msGEOSLineMerge(shapeObj *shape) #endif } -shapeObj *msGEOSVoronoiDiagram(shapeObj *shape, double tolerance, int onlyEdges) -{ -#if defined(USE_GEOS) && (GEOS_VERSION_MAJOR > 3 || (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 5)) +shapeObj *msGEOSVoronoiDiagram(shapeObj *shape, double tolerance, + int onlyEdges) { +#if defined(USE_GEOS) && \ + (GEOS_VERSION_MAJOR > 3 || \ + (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 5)) GEOSGeom g1, g2; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) return NULL; + if (!shape) + return NULL; - if(!shape->geometry) /* if no geometry for the shape then build one */ - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); - g1 = (GEOSGeom) shape->geometry; - if(!g1) return NULL; + if (!shape->geometry) /* if no geometry for the shape then build one */ + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); + g1 = (GEOSGeom)shape->geometry; + if (!g1) + return NULL; g2 = GEOSVoronoiDiagram_r(handle, g1, NULL, tolerance, onlyEdges); return msGEOSGeometry2Shape(g2); #else - msSetError(MS_GEOSERR, "GEOS support is not available or GEOS version is not 3.5 or higher.", "msGEOSVoronoiDiagram()"); + msSetError( + MS_GEOSERR, + "GEOS support is not available or GEOS version is not 3.5 or higher.", + "msGEOSVoronoiDiagram()"); return NULL; #endif } -static int keepEdge(lineObj *segment, shapeObj *polygon) -{ - int i,j; - - if(segment->numpoints<2) return MS_FALSE; - if(msIntersectPointPolygon(&segment->point[0], polygon) != MS_TRUE) return MS_FALSE; - if(msIntersectPointPolygon(&segment->point[1], polygon) != MS_TRUE) return MS_FALSE; - - for(i=0; inumlines; i++) - for(j=1; jline[i].numpoints; j++) - if(msIntersectSegments(&(segment->point[0]), &(segment->point[1]), &(polygon->line[i].point[j-1]), &(polygon->line[i].point[j])) == MS_TRUE) - return(MS_FALSE); +static int keepEdge(lineObj *segment, shapeObj *polygon) { + int i, j; - return(MS_TRUE); + if (segment->numpoints < 2) + return MS_FALSE; + if (msIntersectPointPolygon(&segment->point[0], polygon) != MS_TRUE) + return MS_FALSE; + if (msIntersectPointPolygon(&segment->point[1], polygon) != MS_TRUE) + return MS_FALSE; + + for (i = 0; i < polygon->numlines; i++) + for (j = 1; j < polygon->line[i].numpoints; j++) + if (msIntersectSegments(&(segment->point[0]), &(segment->point[1]), + &(polygon->line[i].point[j - 1]), + &(polygon->line[i].point[j])) == MS_TRUE) + return (MS_FALSE); + + return (MS_TRUE); } -#define ARE_SAME_POINTS(a,b) (((a).x!=(b).x || (a).y!=(b).y)?MS_FALSE:MS_TRUE) +#define ARE_SAME_POINTS(a, b) \ + (((a).x != (b).x || (a).y != (b).y) ? MS_FALSE : MS_TRUE) -// returns the index of the node, we use z to store a count of points at the same coordinate -static int buildNodes(multipointObj *nodes, pointObj *point) -{ +// returns the index of the node, we use z to store a count of points at the +// same coordinate +static int buildNodes(multipointObj *nodes, pointObj *point) { int i; - for(i=0; inumpoints; i++) { - if(ARE_SAME_POINTS(nodes->point[i], *point)) { // found it + for (i = 0; i < nodes->numpoints; i++) { + if (ARE_SAME_POINTS(nodes->point[i], *point)) { // found it nodes->point[i].z++; return i; } @@ -1204,60 +1261,70 @@ static int buildNodes(multipointObj *nodes, pointObj *point) return i; } -shapeObj *msGEOSCenterline(shapeObj *shape) -{ -#if defined(USE_GEOS) && (GEOS_VERSION_MAJOR > 3 || (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 5)) +shapeObj *msGEOSCenterline(shapeObj *shape) { +#if defined(USE_GEOS) && \ + (GEOS_VERSION_MAJOR > 3 || \ + (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 5)) int i; - shapeObj *shape2=NULL; + shapeObj *shape2 = NULL; multipointObj nodes; graphObj *graph; - int *path=NULL; // array of node indexes - int path_size=0; - double path_dist=-1, max_path_dist=-1; + int *path = NULL; // array of node indexes + int path_size = 0; + double path_dist = -1, max_path_dist = -1; - if(!shape) return NULL; - if(shape->type != MS_SHAPE_POLYGON) { - msSetError(MS_GEOSERR, "Centerlines can only be computed for polygon shapes.", "msGEOSCenterline()"); + if (!shape) + return NULL; + if (shape->type != MS_SHAPE_POLYGON) { + msSetError(MS_GEOSERR, + "Centerlines can only be computed for polygon shapes.", + "msGEOSCenterline()"); return NULL; } shape2 = msGEOSVoronoiDiagram(shape, 0.0, MS_TRUE); - if(!shape2) { - msSetError(MS_GEOSERR, "Voronoi diagram generation failed.", "msGEOSCenterline()"); + if (!shape2) { + msSetError(MS_GEOSERR, "Voronoi diagram generation failed.", + "msGEOSCenterline()"); return NULL; } // process the edges and build a graph representation - nodes.point = (pointObj *) malloc(shape2->numlines*sizeof(pointObj)*2); + nodes.point = (pointObj *)malloc(shape2->numlines * sizeof(pointObj) * 2); nodes.numpoints = 0; - if(!nodes.point) { + if (!nodes.point) { msFreeShape(shape2); free(shape2); return NULL; } - graph = msCreateGraph(shape2->numlines*2); - if(!graph) { + graph = msCreateGraph(shape2->numlines * 2); + if (!graph) { msFreeShape(shape2); free(shape2); free(nodes.point); return NULL; } - for(i=0; inumlines; i++) { - if(keepEdge(&shape2->line[i], shape) == MS_TRUE) { + for (i = 0; i < shape2->numlines; i++) { + if (keepEdge(&shape2->line[i], shape) == MS_TRUE) { int src = buildNodes(&nodes, &shape2->line[i].point[0]); int dest = buildNodes(&nodes, &shape2->line[i].point[1]); - msGraphAddEdge(graph, src, dest, msDistancePointToPoint(&shape2->line[i].point[0], &shape2->line[i].point[1])); + msGraphAddEdge(graph, src, dest, + msDistancePointToPoint(&shape2->line[i].point[0], + &shape2->line[i].point[1])); } } - msFreeShape(shape2); // done with voronoi geometry, shape2 is still allocated though, just empty + msFreeShape(shape2); // done with voronoi geometry, shape2 is still allocated + // though, just empty shape2->type = MS_SHAPE_LINE; // will fill with centerline - if(nodes.numpoints == 0) { - msSetError(MS_GEOSERR, "Centerline generation failed, try densifying the shapes.", "msGEOSCenterline()"); + if (nodes.numpoints == 0) { + msSetError(MS_GEOSERR, + "Centerline generation failed, try densifying the shapes.", + "msGEOSCenterline()"); free(shape2); msFreeGraph(graph); free(nodes.point); @@ -1265,20 +1332,23 @@ shapeObj *msGEOSCenterline(shapeObj *shape) } // step through edge nodes (z=1) - for(i=0; i max_path_dist) { + int *tmp_path = NULL; + int tmp_path_size = 0; + double tmp_path_dist = -1; + + if (i == path[path_size - 1]) + continue; // skip, graph is bi-directional so it can't be any longer + tmp_path = msGraphGetLongestShortestPath(graph, i, &tmp_path_size, + &tmp_path_dist); + if (tmp_path_dist > max_path_dist) { free(path); path = tmp_path; path_size = tmp_path_size; @@ -1292,15 +1362,16 @@ shapeObj *msGEOSCenterline(shapeObj *shape) msFreeGraph(graph); // done with graph // transform the path into a shape - if(!path) { - msSetError(MS_GEOSERR, "Centerline generation failed.", "msGEOSCenterline()"); + if (!path) { + msSetError(MS_GEOSERR, "Centerline generation failed.", + "msGEOSCenterline()"); free(shape2); free(nodes.point); return NULL; } else { lineObj line; - line.point = (pointObj *) malloc(path_size*sizeof(pointObj)); - if(!line.point) { + line.point = (pointObj *)malloc(path_size * sizeof(pointObj)); + if (!line.point) { free(shape2); free(path); free(nodes.point); @@ -1308,7 +1379,7 @@ shapeObj *msGEOSCenterline(shapeObj *shape) } line.numpoints = path_size; - for(i=0; igeometry) /* if no geometry for shape1 then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); + if (!shape1->geometry) /* if no geometry for shape1 then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); g1 = shape1->geometry; - if(!g1) return -1; + if (!g1) + return -1; - if(!shape2->geometry) /* if no geometry for shape2 then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); + if (!shape2->geometry) /* if no geometry for shape2 then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); g2 = shape2->geometry; - if(!g2) return -1; + if (!g2) + return -1; - result = GEOSContains_r(handle,g1, g2); - return ((result==2) ? -1 : result); + result = GEOSContains_r(handle, g1, g2); + return ((result == 2) ? -1 : result); #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSContains()"); return -1; @@ -1363,28 +1438,29 @@ int msGEOSContains(shapeObj *shape1, shapeObj *shape2) /* ** Does shape1 overlap shape2, returns MS_TRUE/MS_FALSE or -1 for an error. */ -int msGEOSOverlaps(shapeObj *shape1, shapeObj *shape2) -{ +int msGEOSOverlaps(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2; int result; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return -1; - if(!shape1->geometry) /* if no geometry for shape1 then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); + if (!shape1->geometry) /* if no geometry for shape1 then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); g1 = shape1->geometry; - if(!g1) return -1; + if (!g1) + return -1; - if(!shape2->geometry) /* if no geometry for shape2 then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); + if (!shape2->geometry) /* if no geometry for shape2 then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); g2 = shape2->geometry; - if(!g2) return -1; + if (!g2) + return -1; - result = GEOSOverlaps_r(handle,g1, g2); - return ((result==2) ? -1 : result); + result = GEOSOverlaps_r(handle, g1, g2); + return ((result == 2) ? -1 : result); #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSOverlaps()"); return -1; @@ -1394,28 +1470,29 @@ int msGEOSOverlaps(shapeObj *shape1, shapeObj *shape2) /* ** Is shape1 within shape2, returns MS_TRUE/MS_FALSE or -1 for an error. */ -int msGEOSWithin(shapeObj *shape1, shapeObj *shape2) -{ +int msGEOSWithin(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2; int result; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return -1; - if(!shape1->geometry) /* if no geometry for shape1 then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); + if (!shape1->geometry) /* if no geometry for shape1 then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); g1 = shape1->geometry; - if(!g1) return -1; + if (!g1) + return -1; - if(!shape2->geometry) /* if no geometry for shape2 then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); + if (!shape2->geometry) /* if no geometry for shape2 then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); g2 = shape2->geometry; - if(!g2) return -1; + if (!g2) + return -1; - result = GEOSWithin_r(handle,g1, g2); - return ((result==2) ? -1 : result); + result = GEOSWithin_r(handle, g1, g2); + return ((result == 2) ? -1 : result); #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSWithin()"); return -1; @@ -1425,28 +1502,29 @@ int msGEOSWithin(shapeObj *shape1, shapeObj *shape2) /* ** Does shape1 cross shape2, returns MS_TRUE/MS_FALSE or -1 for an error. */ -int msGEOSCrosses(shapeObj *shape1, shapeObj *shape2) -{ +int msGEOSCrosses(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2; int result; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return -1; - if(!shape1->geometry) /* if no geometry for shape1 then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); + if (!shape1->geometry) /* if no geometry for shape1 then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); g1 = shape1->geometry; - if(!g1) return -1; + if (!g1) + return -1; - if(!shape2->geometry) /* if no geometry for shape2 then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); + if (!shape2->geometry) /* if no geometry for shape2 then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); g2 = shape2->geometry; - if(!g2) return -1; + if (!g2) + return -1; - result = GEOSCrosses_r(handle,g1, g2); - return ((result==2) ? -1 : result); + result = GEOSCrosses_r(handle, g1, g2); + return ((result == 2) ? -1 : result); #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSCrosses()"); return -1; @@ -1456,49 +1534,50 @@ int msGEOSCrosses(shapeObj *shape1, shapeObj *shape2) /* ** Does shape1 intersect shape2, returns MS_TRUE/MS_FALSE or -1 for an error. */ -int msGEOSIntersects(shapeObj *shape1, shapeObj *shape2) -{ +int msGEOSIntersects(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2; int result; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return -1; - if(!shape1->geometry) /* if no geometry for shape1 then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); - g1 = (GEOSGeom) shape1->geometry; - if(!g1) return -1; + if (!shape1->geometry) /* if no geometry for shape1 then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); + g1 = (GEOSGeom)shape1->geometry; + if (!g1) + return -1; - if(!shape2->geometry) /* if no geometry for shape2 then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); - g2 = (GEOSGeom) shape2->geometry; - if(!g2) return -1; + if (!shape2->geometry) /* if no geometry for shape2 then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); + g2 = (GEOSGeom)shape2->geometry; + if (!g2) + return -1; - result = GEOSIntersects_r(handle,g1, g2); - return ((result==2) ? -1 : result); + result = GEOSIntersects_r(handle, g1, g2); + return ((result == 2) ? -1 : result); #else - if(!shape1 || !shape2) + if (!shape1 || !shape2) return -1; - switch(shape1->type) { /* todo: deal with point shapes */ - case(MS_SHAPE_LINE): - switch(shape2->type) { - case(MS_SHAPE_LINE): - return msIntersectPolylines(shape1, shape2); - case(MS_SHAPE_POLYGON): - return msIntersectPolylinePolygon(shape1, shape2); - } - break; - case(MS_SHAPE_POLYGON): - switch(shape2->type) { - case(MS_SHAPE_LINE): - return msIntersectPolylinePolygon(shape2, shape1); - case(MS_SHAPE_POLYGON): - return msIntersectPolygons(shape1, shape2); - } - break; + switch (shape1->type) { /* todo: deal with point shapes */ + case (MS_SHAPE_LINE): + switch (shape2->type) { + case (MS_SHAPE_LINE): + return msIntersectPolylines(shape1, shape2); + case (MS_SHAPE_POLYGON): + return msIntersectPolylinePolygon(shape1, shape2); + } + break; + case (MS_SHAPE_POLYGON): + switch (shape2->type) { + case (MS_SHAPE_LINE): + return msIntersectPolylinePolygon(shape2, shape1); + case (MS_SHAPE_POLYGON): + return msIntersectPolygons(shape1, shape2); + } + break; } return -1; @@ -1508,28 +1587,29 @@ int msGEOSIntersects(shapeObj *shape1, shapeObj *shape2) /* ** Does shape1 touch shape2, returns MS_TRUE/MS_FALSE or -1 for an error. */ -int msGEOSTouches(shapeObj *shape1, shapeObj *shape2) -{ +int msGEOSTouches(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2; int result; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return -1; - if(!shape1->geometry) /* if no geometry for shape1 then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); - g1 = (GEOSGeom) shape1->geometry; - if(!g1) return -1; + if (!shape1->geometry) /* if no geometry for shape1 then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); + g1 = (GEOSGeom)shape1->geometry; + if (!g1) + return -1; - if(!shape2->geometry) /* if no geometry for shape2 then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); - g2 = (GEOSGeom) shape2->geometry; - if(!g2) return -1; + if (!shape2->geometry) /* if no geometry for shape2 then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); + g2 = (GEOSGeom)shape2->geometry; + if (!g2) + return -1; - result = GEOSTouches_r(handle,g1, g2); - return ((result==2) ? -1 : result); + result = GEOSTouches_r(handle, g1, g2); + return ((result == 2) ? -1 : result); #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSTouches()"); return -1; @@ -1539,28 +1619,29 @@ int msGEOSTouches(shapeObj *shape1, shapeObj *shape2) /* ** Does shape1 equal shape2, returns MS_TRUE/MS_FALSE or -1 for an error. */ -int msGEOSEquals(shapeObj *shape1, shapeObj *shape2) -{ +int msGEOSEquals(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2; int result; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return -1; - if(!shape1->geometry) /* if no geometry for shape1 then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); - g1 = (GEOSGeom) shape1->geometry; - if(!g1) return -1; + if (!shape1->geometry) /* if no geometry for shape1 then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); + g1 = (GEOSGeom)shape1->geometry; + if (!g1) + return -1; - if(!shape2->geometry) /* if no geometry for shape2 then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); - g2 = (GEOSGeom) shape2->geometry; - if(!g2) return -1; + if (!shape2->geometry) /* if no geometry for shape2 then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); + g2 = (GEOSGeom)shape2->geometry; + if (!g2) + return -1; - result = GEOSEquals_r(handle,g1, g2); - return ((result==2) ? -1 : result); + result = GEOSEquals_r(handle, g1, g2); + return ((result == 2) ? -1 : result); #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSEquals()"); return -1; @@ -1570,28 +1651,29 @@ int msGEOSEquals(shapeObj *shape1, shapeObj *shape2) /* ** Are shape1 and shape2 disjoint, returns MS_TRUE/MS_FALSE or -1 for an error. */ -int msGEOSDisjoint(shapeObj *shape1, shapeObj *shape2) -{ +int msGEOSDisjoint(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2; int result; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return -1; - if(!shape1->geometry) /* if no geometry for shape1 then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); - g1 = (GEOSGeom) shape1->geometry; - if(!g1) return -1; + if (!shape1->geometry) /* if no geometry for shape1 then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); + g1 = (GEOSGeom)shape1->geometry; + if (!g1) + return -1; - if(!shape2->geometry) /* if no geometry for shape2 then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); - g2 = (GEOSGeom) shape2->geometry; - if(!g2) return -1; + if (!shape2->geometry) /* if no geometry for shape2 then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); + g2 = (GEOSGeom)shape2->geometry; + if (!g2) + return -1; - result = GEOSDisjoint_r(handle,g1, g2); - return ((result==2) ? -1 : result); + result = GEOSDisjoint_r(handle, g1, g2); + return ((result == 2) ? -1 : result); #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSDisjoint()"); return -1; @@ -1601,25 +1683,30 @@ int msGEOSDisjoint(shapeObj *shape1, shapeObj *shape2) /* ** Useful misc. functions that return -1 on failure. */ -double msGEOSArea(shapeObj *shape) -{ -#if defined(USE_GEOS) && defined(GEOS_CAPI_VERSION_MAJOR) && defined(GEOS_CAPI_VERSION_MINOR) && (GEOS_CAPI_VERSION_MAJOR > 1 || GEOS_CAPI_VERSION_MINOR >= 1) +double msGEOSArea(shapeObj *shape) { +#if defined(USE_GEOS) && defined(GEOS_CAPI_VERSION_MAJOR) && \ + defined(GEOS_CAPI_VERSION_MINOR) && \ + (GEOS_CAPI_VERSION_MAJOR > 1 || GEOS_CAPI_VERSION_MINOR >= 1) GEOSGeom g; double area; int result; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) return -1; + if (!shape) + return -1; - if(!shape->geometry) /* if no geometry for the shape then build one */ - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); - g = (GEOSGeom) shape->geometry; - if(!g) return -1; + if (!shape->geometry) /* if no geometry for the shape then build one */ + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); + g = (GEOSGeom)shape->geometry; + if (!g) + return -1; - result = GEOSArea_r(handle,g, &area); - return ((result==0) ? -1 : area); + result = GEOSArea_r(handle, g, &area); + return ((result == 0) ? -1 : area); #elif defined(USE_GEOS) - msSetError(MS_GEOSERR, "GEOS support enabled, but old version lacks GEOSArea().", "msGEOSArea()"); + msSetError(MS_GEOSERR, + "GEOS support enabled, but old version lacks GEOSArea().", + "msGEOSArea()"); return -1; #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSArea()"); @@ -1627,26 +1714,31 @@ double msGEOSArea(shapeObj *shape) #endif } -double msGEOSLength(shapeObj *shape) -{ -#if defined(USE_GEOS) && defined(GEOS_CAPI_VERSION_MAJOR) && defined(GEOS_CAPI_VERSION_MINOR) && (GEOS_CAPI_VERSION_MAJOR > 1 || GEOS_CAPI_VERSION_MINOR >= 1) +double msGEOSLength(shapeObj *shape) { +#if defined(USE_GEOS) && defined(GEOS_CAPI_VERSION_MAJOR) && \ + defined(GEOS_CAPI_VERSION_MINOR) && \ + (GEOS_CAPI_VERSION_MAJOR > 1 || GEOS_CAPI_VERSION_MINOR >= 1) GEOSGeom g; double length; int result; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape) return -1; + if (!shape) + return -1; - if(!shape->geometry) /* if no geometry for the shape then build one */ - shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); - g = (GEOSGeom) shape->geometry; - if(!g) return -1; + if (!shape->geometry) /* if no geometry for the shape then build one */ + shape->geometry = (GEOSGeom)msGEOSShape2Geometry(shape); + g = (GEOSGeom)shape->geometry; + if (!g) + return -1; - result = GEOSLength_r(handle,g, &length); - return ((result==0) ? -1 : length); + result = GEOSLength_r(handle, g, &length); + return ((result == 0) ? -1 : length); #elif defined(USE_GEOS) - msSetError(MS_GEOSERR, "GEOS support enabled, but old version lacks GEOSLength().", "msGEOSLength()"); + msSetError(MS_GEOSERR, + "GEOS support enabled, but old version lacks GEOSLength().", + "msGEOSLength()"); return -1; #else msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSLength()"); @@ -1654,30 +1746,32 @@ double msGEOSLength(shapeObj *shape) #endif } -double msGEOSDistance(shapeObj *shape1, shapeObj *shape2) -{ +double msGEOSDistance(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2; double distance; int result; GEOSContextHandle_t handle = msGetGeosContextHandle(); - if(!shape1 || !shape2) + if (!shape1 || !shape2) return -1; - if(!shape1->geometry) /* if no geometry for shape1 then build one */ - shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); - g1 = (GEOSGeom) shape1->geometry; - if(!g1) return -1; + if (!shape1->geometry) /* if no geometry for shape1 then build one */ + shape1->geometry = (GEOSGeom)msGEOSShape2Geometry(shape1); + g1 = (GEOSGeom)shape1->geometry; + if (!g1) + return -1; - if(!shape2->geometry) /* if no geometry for shape2 then build one */ - shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); - g2 = (GEOSGeom) shape2->geometry; - if(!g2) return -1; + if (!shape2->geometry) /* if no geometry for shape2 then build one */ + shape2->geometry = (GEOSGeom)msGEOSShape2Geometry(shape2); + g2 = (GEOSGeom)shape2->geometry; + if (!g2) + return -1; - result = GEOSDistance_r(handle,g1, g2, &distance); - return ((result==0) ? -1 : distance); + result = GEOSDistance_r(handle, g1, g2, &distance); + return ((result == 0) ? -1 : distance); #else - return msDistanceShapeToShape(shape1, shape2); /* fall back on brute force method (for MapScript) */ + return msDistanceShapeToShape( + shape1, shape2); /* fall back on brute force method (for MapScript) */ #endif } diff --git a/mapgml.c b/mapgml.c index 3b9739f6c9..a0828cd339 100644 --- a/mapgml.c +++ b/mapgml.c @@ -33,38 +33,42 @@ #include "mapgml.h" #include "maptime.h" +/* Use only mapgml.c if WMS or WFS is available (with minor exceptions at end) + */ -/* Use only mapgml.c if WMS or WFS is available (with minor exceptions at end) */ - -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) -static int msGMLGeometryLookup(gmlGeometryListObj *geometryList, const char *type); +static int msGMLGeometryLookup(gmlGeometryListObj *geometryList, + const char *type); /* ** Functions that write the feature boundary geometry (i.e. a rectObj). */ /* GML 2.1.2 */ -static int gmlWriteBounds_GML2(FILE *stream, rectObj *rect, - const char *srsname, const char *tab, - const char *pszTopPrefix) -{ +static int gmlWriteBounds_GML2(FILE *stream, rectObj *rect, const char *srsname, + const char *tab, const char *pszTopPrefix) { char *srsname_encoded; - if(!stream) return(MS_FAILURE); - if(!rect) return(MS_FAILURE); - if(!tab) return(MS_FAILURE); + if (!stream) + return (MS_FAILURE); + if (!rect) + return (MS_FAILURE); + if (!tab) + return (MS_FAILURE); msIO_fprintf(stream, "%s<%s:boundedBy>\n", tab, pszTopPrefix); - if(srsname) { + if (srsname) { srsname_encoded = msEncodeHTMLEntities(srsname); - msIO_fprintf(stream, "%s\t\n", tab, srsname_encoded); + msIO_fprintf(stream, "%s\t\n", tab, + srsname_encoded); msFree(srsname_encoded); } else msIO_fprintf(stream, "%s\t\n", tab); msIO_fprintf(stream, "%s\t\t", tab); - msIO_fprintf(stream, "%.6f,%.6f %.6f,%.6f", rect->minx, rect->miny, rect->maxx, rect->maxy ); + msIO_fprintf(stream, "%.6f,%.6f %.6f,%.6f", rect->minx, rect->miny, + rect->maxx, rect->maxy); msIO_fprintf(stream, "\n"); msIO_fprintf(stream, "%s\t\n", tab); msIO_fprintf(stream, "%s\n", tab, pszTopPrefix); @@ -73,26 +77,30 @@ static int gmlWriteBounds_GML2(FILE *stream, rectObj *rect, } /* GML 3.1 or GML 3.2 (MapServer limits GML encoding to the level 0 profile) */ -static int gmlWriteBounds_GML3(FILE *stream, rectObj *rect, - const char *srsname, const char *tab, - const char *pszTopPrefix) -{ +static int gmlWriteBounds_GML3(FILE *stream, rectObj *rect, const char *srsname, + const char *tab, const char *pszTopPrefix) { char *srsname_encoded; - if(!stream) return(MS_FAILURE); - if(!rect) return(MS_FAILURE); - if(!tab) return(MS_FAILURE); + if (!stream) + return (MS_FAILURE); + if (!rect) + return (MS_FAILURE); + if (!tab) + return (MS_FAILURE); msIO_fprintf(stream, "%s<%s:boundedBy>\n", tab, pszTopPrefix); - if(srsname) { + if (srsname) { srsname_encoded = msEncodeHTMLEntities(srsname); - msIO_fprintf(stream, "%s\t\n", tab, srsname_encoded); + msIO_fprintf(stream, "%s\t\n", tab, + srsname_encoded); msFree(srsname_encoded); } else msIO_fprintf(stream, "%s\t\n", tab); - msIO_fprintf(stream, "%s\t\t%.6f %.6f\n", tab, rect->minx, rect->miny); - msIO_fprintf(stream, "%s\t\t%.6f %.6f\n", tab, rect->maxx, rect->maxy); + msIO_fprintf(stream, "%s\t\t%.6f %.6f\n", + tab, rect->minx, rect->miny); + msIO_fprintf(stream, "%s\t\t%.6f %.6f\n", + tab, rect->maxx, rect->maxy); msIO_fprintf(stream, "%s\t\n", tab); msIO_fprintf(stream, "%s\n", tab, pszTopPrefix); @@ -101,26 +109,26 @@ static int gmlWriteBounds_GML3(FILE *stream, rectObj *rect, } static void gmlStartGeometryContainer(FILE *stream, const char *name, - const char *namespace, const char *tab) -{ - const char *tag_name=OWS_GML_DEFAULT_GEOMETRY_NAME; + const char *namespace, const char *tab) { + const char *tag_name = OWS_GML_DEFAULT_GEOMETRY_NAME; - if(name) tag_name = name; + if (name) + tag_name = name; - if(namespace) + if (namespace) msIO_fprintf(stream, "%s<%s:%s>\n", tab, namespace, tag_name); else msIO_fprintf(stream, "%s<%s>\n", tab, tag_name); } static void gmlEndGeometryContainer(FILE *stream, const char *name, - const char *namespace, const char *tab) -{ - const char *tag_name=OWS_GML_DEFAULT_GEOMETRY_NAME; + const char *namespace, const char *tab) { + const char *tag_name = OWS_GML_DEFAULT_GEOMETRY_NAME; - if(name) tag_name = name; + if (name) + tag_name = name; - if(namespace) + if (namespace) msIO_fprintf(stream, "%s\n", tab, namespace, tag_name); else msIO_fprintf(stream, "%s\n", tab, tag_name); @@ -130,677 +138,840 @@ static void gmlEndGeometryContainer(FILE *stream, const char *name, static int gmlWriteGeometry_GML2(FILE *stream, gmlGeometryListObj *geometryList, shapeObj *shape, const char *srsname, const char *namespace, const char *tab, - int nSRSDimension, int geometry_precision) -{ + int nSRSDimension, int geometry_precision) { int i, j, k; - int *innerlist, *outerlist=NULL, numouters; + int *innerlist, *outerlist = NULL, numouters; char *srsname_encoded = NULL; int geometry_aggregate_index, geometry_simple_index; char *geometry_aggregate_name = NULL, *geometry_simple_name = NULL; - if(!stream) return(MS_FAILURE); - if(!shape) return(MS_FAILURE); - if(!tab) return(MS_FAILURE); - if(!geometryList) return(MS_FAILURE); + if (!stream) + return (MS_FAILURE); + if (!shape) + return (MS_FAILURE); + if (!tab) + return (MS_FAILURE); + if (!geometryList) + return (MS_FAILURE); - if(shape->numlines <= 0) return(MS_SUCCESS); /* empty shape, nothing to output */ + if (shape->numlines <= 0) + return (MS_SUCCESS); /* empty shape, nothing to output */ - if(srsname) + if (srsname) srsname_encoded = msEncodeHTMLEntities(srsname); /* feature geometry */ - switch(shape->type) { - case(MS_SHAPE_POINT): - geometry_simple_index = msGMLGeometryLookup(geometryList, "point"); - geometry_aggregate_index = msGMLGeometryLookup(geometryList, "multipoint"); - if(geometry_simple_index >= 0) geometry_simple_name = geometryList->geometries[geometry_simple_index].name; - if(geometry_aggregate_index >= 0) geometry_aggregate_name = geometryList->geometries[geometry_aggregate_index].name; - - if((geometry_simple_index != -1 && shape->line[0].numpoints == 1 && shape->numlines == 1) || - (geometry_simple_index != -1 && geometry_aggregate_index == -1) || - (geometryList->numgeometries == 0 && shape->line[0].numpoints == 1 && shape->numlines == 1)) { /* write a Point(s) */ - - for(i=0; inumlines; i++) { - for(j=0; jline[i].numpoints; j++) { - gmlStartGeometryContainer(stream, geometry_simple_name, namespace, tab); - - /* Point */ - if(srsname_encoded) - msIO_fprintf(stream, "%s\n", tab, srsname_encoded); - else - msIO_fprintf(stream, "%s\n", tab); - - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%s %.*f,%.*f,%.*f\n", - tab, geometry_precision,shape->line[i].point[j].x, geometry_precision,shape->line[i].point[j].y, geometry_precision,shape->line[i].point[j].z); - else - /* fall-through */ + switch (shape->type) { + case (MS_SHAPE_POINT): + geometry_simple_index = msGMLGeometryLookup(geometryList, "point"); + geometry_aggregate_index = msGMLGeometryLookup(geometryList, "multipoint"); + if (geometry_simple_index >= 0) + geometry_simple_name = + geometryList->geometries[geometry_simple_index].name; + if (geometry_aggregate_index >= 0) + geometry_aggregate_name = + geometryList->geometries[geometry_aggregate_index].name; + + if ((geometry_simple_index != -1 && shape->line[0].numpoints == 1 && + shape->numlines == 1) || + (geometry_simple_index != -1 && geometry_aggregate_index == -1) || + (geometryList->numgeometries == 0 && shape->line[0].numpoints == 1 && + shape->numlines == 1)) { /* write a Point(s) */ + + for (i = 0; i < shape->numlines; i++) { + for (j = 0; j < shape->line[i].numpoints; j++) { + gmlStartGeometryContainer(stream, geometry_simple_name, namespace, + tab); + + /* Point */ + if (srsname_encoded) + msIO_fprintf(stream, "%s\n", tab, + srsname_encoded); + else + msIO_fprintf(stream, "%s\n", tab); + + if (nSRSDimension == 3) + msIO_fprintf( + stream, + "%s %.*f,%.*f,%.*f\n", tab, + geometry_precision, shape->line[i].point[j].x, + geometry_precision, shape->line[i].point[j].y, + geometry_precision, shape->line[i].point[j].z); + else + /* fall-through */ - msIO_fprintf(stream, "%s %.*f,%.*f\n", tab, geometry_precision,shape->line[i].point[j].x, geometry_precision,shape->line[i].point[j].y); + msIO_fprintf(stream, + "%s %.*f,%.*f\n", + tab, geometry_precision, shape->line[i].point[j].x, + geometry_precision, shape->line[i].point[j].y); - msIO_fprintf(stream, "%s\n", tab); + msIO_fprintf(stream, "%s\n", tab); - gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); - } + gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); + } + } + } else if ((geometry_aggregate_index != -1) || + (geometryList->numgeometries == 0)) { /* write a MultiPoint */ + gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, + tab); + + /* MultiPoint */ + if (srsname_encoded) + msIO_fprintf(stream, "%s\n", tab, + srsname_encoded); + else + msIO_fprintf(stream, "%s\n", tab); + + for (i = 0; i < shape->numlines; i++) { + for (j = 0; j < shape->line[i].numpoints; j++) { + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + if (nSRSDimension == 3) + msIO_fprintf( + stream, + "%s %.*f,%.*f,%.*f\n", + tab, geometry_precision, shape->line[i].point[j].x, + geometry_precision, shape->line[i].point[j].y, + geometry_precision, shape->line[i].point[j].z); + else + /* fall-through */ + msIO_fprintf( + stream, "%s %f,%f\n", + tab, shape->line[i].point[j].x, shape->line[i].point[j].y); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); } - } else if((geometry_aggregate_index != -1) || (geometryList->numgeometries == 0)) { /* write a MultiPoint */ - gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, tab); + } - /* MultiPoint */ - if(srsname_encoded) - msIO_fprintf(stream, "%s\n", tab, srsname_encoded); + msIO_fprintf(stream, "%s\n", tab); + + gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); + } else { + msIO_fprintf(stream, "\n"); + } + + break; + case (MS_SHAPE_LINE): + geometry_simple_index = msGMLGeometryLookup(geometryList, "line"); + geometry_aggregate_index = msGMLGeometryLookup(geometryList, "multiline"); + if (geometry_simple_index >= 0) + geometry_simple_name = + geometryList->geometries[geometry_simple_index].name; + if (geometry_aggregate_index >= 0) + geometry_aggregate_name = + geometryList->geometries[geometry_aggregate_index].name; + + if ((geometry_simple_index != -1 && shape->numlines == 1) || + (geometry_simple_index != -1 && geometry_aggregate_index == -1) || + (geometryList->numgeometries == 0 && + shape->numlines == 1)) { /* write a LineStrings(s) */ + for (i = 0; i < shape->numlines; i++) { + gmlStartGeometryContainer(stream, geometry_simple_name, namespace, tab); + + /* LineString */ + if (srsname_encoded) + msIO_fprintf(stream, "%s\n", tab, + srsname_encoded); else - msIO_fprintf(stream, "%s\n", tab); - - for(i=0; inumlines; i++) { - for(j=0; jline[i].numpoints; j++) { - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%s %.*f,%.*f,%.*f\n", - tab, geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y, - geometry_precision, shape->line[i].point[j].z); - else - /* fall-through */ - msIO_fprintf(stream, "%s %f,%f\n", tab, shape->line[i].point[j].x, shape->line[i].point[j].y); - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - } + msIO_fprintf(stream, "%s\n", tab); + + msIO_fprintf(stream, "%s ", tab); + for (j = 0; j < shape->line[i].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y, geometry_precision, + shape->line[i].point[j].z); + else + /* fall-through */ + msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y); } + msIO_fprintf(stream, "\n"); - msIO_fprintf(stream, "%s\n", tab); + msIO_fprintf(stream, "%s\n", tab); - gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); - } else { - msIO_fprintf(stream, "\n"); + gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); } - - break; - case(MS_SHAPE_LINE): - geometry_simple_index = msGMLGeometryLookup(geometryList, "line"); - geometry_aggregate_index = msGMLGeometryLookup(geometryList, "multiline"); - if(geometry_simple_index >= 0) geometry_simple_name = geometryList->geometries[geometry_simple_index].name; - if(geometry_aggregate_index >= 0) geometry_aggregate_name = geometryList->geometries[geometry_aggregate_index].name; - - if((geometry_simple_index != -1 && shape->numlines == 1) || - (geometry_simple_index != -1 && geometry_aggregate_index == -1) || - (geometryList->numgeometries == 0 && shape->numlines == 1)) { /* write a LineStrings(s) */ - for(i=0; inumlines; i++) { - gmlStartGeometryContainer(stream, geometry_simple_name, namespace, tab); - - /* LineString */ - if(srsname_encoded) - msIO_fprintf(stream, "%s\n", tab, srsname_encoded); + } else if (geometry_aggregate_index != -1 || + (geometryList->numgeometries == 0)) { /* write a MultiCurve */ + gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, + tab); + + /* MultiLineString */ + if (srsname_encoded) + msIO_fprintf(stream, "%s\n", tab, + srsname_encoded); + else + msIO_fprintf(stream, "%s\n", tab); + + for (j = 0; j < shape->numlines; j++) { + msIO_fprintf(stream, "%s \n", + tab); /* no srsname at this point */ + msIO_fprintf(stream, "%s \n", + tab); /* no srsname at this point */ + + msIO_fprintf(stream, "%s ", tab); + for (i = 0; i < shape->line[j].numpoints; i++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision, + shape->line[j].point[i].x, geometry_precision, + shape->line[j].point[i].y, geometry_precision, + shape->line[j].point[i].z); else - msIO_fprintf(stream, "%s\n", tab); - - msIO_fprintf(stream, "%s ", tab); - for(j=0; jline[i].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision,shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y, - geometry_precision, shape->line[i].point[j].z); - else - /* fall-through */ - msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y); - } - msIO_fprintf(stream, "\n"); + /* fall-through */ + msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision, + shape->line[j].point[i].x, geometry_precision, + shape->line[j].point[i].y); + } + msIO_fprintf(stream, "\n"); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + } - msIO_fprintf(stream, "%s\n", tab); + msIO_fprintf(stream, "%s\n", tab); - gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); - } - } else if(geometry_aggregate_index != -1 || (geometryList->numgeometries == 0)) { /* write a MultiCurve */ - gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, tab); + gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); + } else { + msIO_fprintf(stream, "\n"); + } - /* MultiLineString */ - if(srsname_encoded) - msIO_fprintf(stream, "%s\n", tab, srsname_encoded); + break; + case ( + MS_SHAPE_POLYGON): /* this gets nasty, since our shapes are so flexible */ + geometry_simple_index = msGMLGeometryLookup(geometryList, "polygon"); + geometry_aggregate_index = + msGMLGeometryLookup(geometryList, "multipolygon"); + if (geometry_simple_index >= 0) + geometry_simple_name = + geometryList->geometries[geometry_simple_index].name; + if (geometry_aggregate_index >= 0) + geometry_aggregate_name = + geometryList->geometries[geometry_aggregate_index].name; + + /* get a list of outter rings for this polygon */ + outerlist = msGetOuterList(shape); + + numouters = 0; + for (i = 0; i < shape->numlines; i++) + if (outerlist[i] == MS_TRUE) + numouters++; + + if ((geometry_simple_index != -1 && numouters == 1) || + (geometry_simple_index != -1 && geometry_aggregate_index == -1) || + (geometryList->numgeometries == 0 && + shape->numlines == 1)) { /* write a Polygon(s) */ + for (i = 0; i < shape->numlines; i++) { + if (outerlist[i] == MS_FALSE) + break; /* skip non-outer rings, each outer ring is a new polygon */ + + /* get a list of inner rings for this polygon */ + innerlist = msGetInnerList(shape, i, outerlist); + + gmlStartGeometryContainer(stream, geometry_simple_name, namespace, tab); + + /* Polygon */ + if (srsname_encoded) + msIO_fprintf(stream, "%s\n", tab, + srsname_encoded); else - msIO_fprintf(stream, "%s\n", tab); - - for(j=0; jnumlines; j++) { - msIO_fprintf(stream, "%s \n", tab); /* no srsname at this point */ - msIO_fprintf(stream, "%s \n", tab); /* no srsname at this point */ - - msIO_fprintf(stream, "%s ", tab); - for(i=0; iline[j].numpoints; i++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision, shape->line[j].point[i].x, geometry_precision, shape->line[j].point[i].y, - geometry_precision, shape->line[j].point[i].z); - else + msIO_fprintf(stream, "%s\n", tab); + + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + + msIO_fprintf(stream, "%s ", tab); + for (j = 0; j < shape->line[i].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y, geometry_precision, + shape->line[i].point[j].z); + else + /* fall-through */ + msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y); + } + msIO_fprintf(stream, "\n"); + + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + + for (k = 0; k < shape->numlines; + k++) { /* now step through all the inner rings */ + if (innerlist[k] == MS_TRUE) { + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + + msIO_fprintf(stream, "%s ", tab); + for (j = 0; j < shape->line[k].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision, + shape->line[k].point[j].x, geometry_precision, + shape->line[k].point[j].y, geometry_precision, + shape->line[k].point[j].z); + else /* fall-through */ - msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision, shape->line[j].point[i].x, geometry_precision, shape->line[j].point[i].y); + msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision, + shape->line[k].point[j].x, geometry_precision, + shape->line[k].point[j].y); + } + msIO_fprintf(stream, "\n"); + + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); } - msIO_fprintf(stream, "\n"); - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); } - msIO_fprintf(stream, "%s\n", tab); + msIO_fprintf(stream, "%s\n", tab); + free(innerlist); - gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); - } else { - msIO_fprintf(stream, "\n"); + gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); } + free(outerlist); + outerlist = NULL; + } else if (geometry_aggregate_index != -1 || + (geometryList->numgeometries == 0)) { /* write a MultiPolygon */ + gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, + tab); + + /* MultiPolygon */ + if (srsname_encoded) + msIO_fprintf(stream, "%s\n", tab, + srsname_encoded); + else + msIO_fprintf(stream, "%s\n", tab); - break; - case(MS_SHAPE_POLYGON): /* this gets nasty, since our shapes are so flexible */ - geometry_simple_index = msGMLGeometryLookup(geometryList, "polygon"); - geometry_aggregate_index = msGMLGeometryLookup(geometryList, "multipolygon"); - if(geometry_simple_index >= 0) geometry_simple_name = geometryList->geometries[geometry_simple_index].name; - if(geometry_aggregate_index >= 0) geometry_aggregate_name = geometryList->geometries[geometry_aggregate_index].name; - - /* get a list of outter rings for this polygon */ - outerlist = msGetOuterList(shape); - - numouters = 0; - for(i=0; inumlines; i++) - if(outerlist[i] == MS_TRUE) numouters++; - - if((geometry_simple_index != -1 && numouters == 1) || - (geometry_simple_index != -1 && geometry_aggregate_index == -1) || - (geometryList->numgeometries == 0 && shape->numlines == 1)) { /* write a Polygon(s) */ - for(i=0; inumlines; i++) { - if(outerlist[i] == MS_FALSE) break; /* skip non-outer rings, each outer ring is a new polygon */ - - /* get a list of inner rings for this polygon */ + for (i = 0; i < shape->numlines; i++) { /* step through the outer rings */ + if (outerlist[i] == MS_TRUE) { innerlist = msGetInnerList(shape, i, outerlist); - gmlStartGeometryContainer(stream, geometry_simple_name, namespace, tab); - - /* Polygon */ - if(srsname_encoded) - msIO_fprintf(stream, "%s\n", tab, srsname_encoded); - else - msIO_fprintf(stream, "%s\n", tab); + msIO_fprintf(stream, "%s\n", tab); + msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s ", tab); - for(j=0; jline[i].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y, - geometry_precision, shape->line[i].point[j].z); + msIO_fprintf(stream, "%s ", tab); + for (j = 0; j < shape->line[i].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y, geometry_precision, + shape->line[i].point[j].z); else - /* fall-through */ - msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y); + /* fall-through */ + msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y); } msIO_fprintf(stream, "\n"); - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); - for(k=0; knumlines; k++) { /* now step through all the inner rings */ - if(innerlist[k] == MS_TRUE) { - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); + for (k = 0; k < shape->numlines; + k++) { /* now step through all the inner rings */ + if (innerlist[k] == MS_TRUE) { + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s ", tab); - for(j=0; jline[k].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision,shape->line[k].point[j].x, geometry_precision,shape->line[k].point[j].y, - geometry_precision,shape->line[k].point[j].z); + msIO_fprintf(stream, "%s ", tab); + for (j = 0; j < shape->line[k].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision, + shape->line[k].point[j].x, geometry_precision, + shape->line[k].point[j].y, geometry_precision, + shape->line[k].point[j].z); else /* fall-through */ - msIO_fprintf(stream, "%.*f,%.*f ",geometry_precision, shape->line[k].point[j].x, geometry_precision,shape->line[k].point[j].y); + msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision, + shape->line[k].point[j].x, geometry_precision, + shape->line[k].point[j].y); } msIO_fprintf(stream, "\n"); - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); } } - msIO_fprintf(stream, "%s\n", tab); - free(innerlist); - - gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); - } - free(outerlist); - outerlist = NULL; - } else if(geometry_aggregate_index != -1 || (geometryList->numgeometries == 0)) { /* write a MultiPolygon */ - gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, tab); - - /* MultiPolygon */ - if(srsname_encoded) - msIO_fprintf(stream, "%s\n", tab, srsname_encoded); - else - msIO_fprintf(stream, "%s\n", tab); - - for(i=0; inumlines; i++) { /* step through the outer rings */ - if(outerlist[i] == MS_TRUE) { - innerlist = msGetInnerList(shape, i, outerlist); - - msIO_fprintf(stream, "%s\n", tab); - msIO_fprintf(stream, "%s \n", tab); - - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - - msIO_fprintf(stream, "%s ", tab); - for(j=0; jline[i].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y, - geometry_precision, shape->line[i].point[j].z); - else - /* fall-through */ - msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y); - } - msIO_fprintf(stream, "\n"); - - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - - for(k=0; knumlines; k++) { /* now step through all the inner rings */ - if(innerlist[k] == MS_TRUE) { - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - - msIO_fprintf(stream, "%s ", tab); - for(j=0; jline[k].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f,%.*f,%.*f ", geometry_precision,shape->line[k].point[j].x, geometry_precision,shape->line[k].point[j].y, - geometry_precision,shape->line[k].point[j].z); - else - /* fall-through */ - msIO_fprintf(stream, "%.*f,%.*f ", geometry_precision,shape->line[k].point[j].x, geometry_precision,shape->line[k].point[j].y); - } - msIO_fprintf(stream, "\n"); - - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - } - } - - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s\n", tab); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s\n", tab); - free(innerlist); - } + free(innerlist); } - msIO_fprintf(stream, "%s\n", tab); + } + msIO_fprintf(stream, "%s\n", tab); - free(outerlist); - outerlist = NULL; + free(outerlist); + outerlist = NULL; - gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); - } else { - msIO_fprintf(stream, "\n"); - } + gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); + } else { + msIO_fprintf(stream, "\n"); + } - break; - default: - break; + break; + default: + break; } /* clean-up */ msFree(srsname_encoded); msFree(outerlist); - return(MS_SUCCESS); + return (MS_SUCCESS); } -static char* gmlCreateGeomId(OWSGMLVersion nGMLVersion, const char* pszFID, int* p_id) -{ - char* pszGMLId; - if( nGMLVersion == OWS_GML32 ) - { - pszGMLId = (char*) msSmallMalloc( strlen(pszFID) + 1 + strlen(" gml:id=\"\"") + 10 ); - sprintf(pszGMLId, " gml:id=\"%s.%d\"", pszFID, *p_id); - (*p_id) ++; - } - else - pszGMLId = msStrdup(""); - return pszGMLId; +static char *gmlCreateGeomId(OWSGMLVersion nGMLVersion, const char *pszFID, + int *p_id) { + char *pszGMLId; + if (nGMLVersion == OWS_GML32) { + pszGMLId = + (char *)msSmallMalloc(strlen(pszFID) + 1 + strlen(" gml:id=\"\"") + 10); + sprintf(pszGMLId, " gml:id=\"%s.%d\"", pszFID, *p_id); + (*p_id)++; + } else + pszGMLId = msStrdup(""); + return pszGMLId; } /* GML 3.1 or GML 3.2 (MapServer limits GML encoding to the level 0 profile) */ -static int gmlWriteGeometry_GML3(FILE *stream, gmlGeometryListObj *geometryList, shapeObj *shape, - const char *srsname, const char *namespace, const char *tab, +static int gmlWriteGeometry_GML3(FILE *stream, gmlGeometryListObj *geometryList, + shapeObj *shape, const char *srsname, + const char *namespace, const char *tab, const char *pszFID, OWSGMLVersion nGMLVersion, - int nSRSDimension, int geometry_precision) -{ + int nSRSDimension, int geometry_precision) { int i, j, k, id = 1; - int *innerlist, *outerlist=NULL, numouters; + int *innerlist, *outerlist = NULL, numouters; char *srsname_encoded = NULL; - char* pszGMLId; + char *pszGMLId; int geometry_aggregate_index, geometry_simple_index; char *geometry_aggregate_name = NULL, *geometry_simple_name = NULL; - if(!stream) return(MS_FAILURE); - if(!shape) return(MS_FAILURE); - if(!tab) return(MS_FAILURE); - if(!geometryList) return(MS_FAILURE); + if (!stream) + return (MS_FAILURE); + if (!shape) + return (MS_FAILURE); + if (!tab) + return (MS_FAILURE); + if (!geometryList) + return (MS_FAILURE); - if(shape->numlines <= 0) return(MS_SUCCESS); /* empty shape, nothing to output */ + if (shape->numlines <= 0) + return (MS_SUCCESS); /* empty shape, nothing to output */ - if(srsname) + if (srsname) srsname_encoded = msEncodeHTMLEntities(srsname); /* feature geometry */ - switch(shape->type) { - case(MS_SHAPE_POINT): - geometry_simple_index = msGMLGeometryLookup(geometryList, "point"); - geometry_aggregate_index = msGMLGeometryLookup(geometryList, "multipoint"); - if(geometry_simple_index >= 0) geometry_simple_name = geometryList->geometries[geometry_simple_index].name; - if(geometry_aggregate_index >= 0) geometry_aggregate_name = geometryList->geometries[geometry_aggregate_index].name; - - if((geometry_simple_index != -1 && shape->line[0].numpoints == 1 && shape->numlines == 1) || - (geometry_simple_index != -1 && geometry_aggregate_index == -1) || - (geometryList->numgeometries == 0 && shape->line[0].numpoints == 1 && shape->numlines == 1)) { /* write a Point(s) */ - - for(i=0; inumlines; i++) { - for(j=0; jline[i].numpoints; j++) { - gmlStartGeometryContainer(stream, geometry_simple_name, namespace, tab); - - /* Point */ - pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); - if(srsname_encoded) - msIO_fprintf(stream, "%s \n", tab, pszGMLId, srsname_encoded); - else - msIO_fprintf(stream, "%s \n", tab, pszGMLId); + switch (shape->type) { + case (MS_SHAPE_POINT): + geometry_simple_index = msGMLGeometryLookup(geometryList, "point"); + geometry_aggregate_index = msGMLGeometryLookup(geometryList, "multipoint"); + if (geometry_simple_index >= 0) + geometry_simple_name = + geometryList->geometries[geometry_simple_index].name; + if (geometry_aggregate_index >= 0) + geometry_aggregate_name = + geometryList->geometries[geometry_aggregate_index].name; + + if ((geometry_simple_index != -1 && shape->line[0].numpoints == 1 && + shape->numlines == 1) || + (geometry_simple_index != -1 && geometry_aggregate_index == -1) || + (geometryList->numgeometries == 0 && shape->line[0].numpoints == 1 && + shape->numlines == 1)) { /* write a Point(s) */ + + for (i = 0; i < shape->numlines; i++) { + for (j = 0; j < shape->line[i].numpoints; j++) { + gmlStartGeometryContainer(stream, geometry_simple_name, namespace, + tab); + + /* Point */ + pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); + if (srsname_encoded) + msIO_fprintf(stream, "%s \n", tab, + pszGMLId, srsname_encoded); + else + msIO_fprintf(stream, "%s \n", tab, pszGMLId); + + if (nSRSDimension == 3) + msIO_fprintf( + stream, + "%s %.*f %.*f %.*f\n", + tab, geometry_precision, shape->line[i].point[j].x, + geometry_precision, shape->line[i].point[j].y, + geometry_precision, shape->line[i].point[j].z); + else + /* fall-through */ + msIO_fprintf(stream, "%s %.*f %.*f\n", tab, + geometry_precision, shape->line[i].point[j].x, + geometry_precision, shape->line[i].point[j].y); - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%s %.*f %.*f %.*f\n", tab, geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y, geometry_precision, shape->line[i].point[j].z); - else - /* fall-through */ - msIO_fprintf(stream, "%s %.*f %.*f\n", tab, geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y); + msIO_fprintf(stream, "%s \n", tab); + + gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); + msFree(pszGMLId); + } + } + } else if ((geometry_aggregate_index != -1) || + (geometryList->numgeometries == 0)) { /* write a MultiPoint */ + pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); + gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, + tab); + + /* MultiPoint */ + if (srsname_encoded) + msIO_fprintf(stream, "%s \n", tab, + pszGMLId, srsname_encoded); + else + msIO_fprintf(stream, "%s \n", tab, pszGMLId); - msIO_fprintf(stream, "%s \n", tab); + msFree(pszGMLId); - gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); - msFree(pszGMLId); - } + for (i = 0; i < shape->numlines; i++) { + for (j = 0; j < shape->line[i].numpoints; j++) { + msIO_fprintf(stream, "%s \n", tab); + pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); + msIO_fprintf(stream, "%s \n", tab, pszGMLId); + if (nSRSDimension == 3) + msIO_fprintf(stream, + "%s %.*f %.*f " + "%.*f\n", + tab, geometry_precision, shape->line[i].point[j].x, + geometry_precision, shape->line[i].point[j].y, + geometry_precision, shape->line[i].point[j].z); + else + /* fall-through */ + msIO_fprintf(stream, "%s %.*f %.*f\n", + tab, geometry_precision, shape->line[i].point[j].x, + geometry_precision, shape->line[i].point[j].y); + msIO_fprintf(stream, "%s \n", tab); + msFree(pszGMLId); + msIO_fprintf(stream, "%s \n", tab); } - } else if((geometry_aggregate_index != -1) || (geometryList->numgeometries == 0)) { /* write a MultiPoint */ - pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); - gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, tab); + } - /* MultiPoint */ - if(srsname_encoded) - msIO_fprintf(stream, "%s \n", tab, pszGMLId, srsname_encoded); - else - msIO_fprintf(stream, "%s \n", tab, pszGMLId); + msIO_fprintf(stream, "%s \n", tab); + + gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); + } else { + msIO_fprintf(stream, "\n"); + } + break; + case (MS_SHAPE_LINE): + geometry_simple_index = msGMLGeometryLookup(geometryList, "line"); + geometry_aggregate_index = msGMLGeometryLookup(geometryList, "multiline"); + if (geometry_simple_index >= 0) + geometry_simple_name = + geometryList->geometries[geometry_simple_index].name; + if (geometry_aggregate_index >= 0) + geometry_aggregate_name = + geometryList->geometries[geometry_aggregate_index].name; + + if ((geometry_simple_index != -1 && shape->numlines == 1) || + (geometry_simple_index != -1 && geometry_aggregate_index == -1) || + (geometryList->numgeometries == 0 && + shape->numlines == 1)) { /* write a LineStrings(s) */ + for (i = 0; i < shape->numlines; i++) { + gmlStartGeometryContainer(stream, geometry_simple_name, namespace, tab); + + /* LineString (should be Curve?) */ + pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); + if (srsname_encoded) + msIO_fprintf(stream, "%s \n", tab, + pszGMLId, srsname_encoded); + else + msIO_fprintf(stream, "%s \n", tab, pszGMLId); msFree(pszGMLId); - for(i=0; inumlines; i++) { - for(j=0; jline[i].numpoints; j++) { - msIO_fprintf(stream, "%s \n", tab); - pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); - msIO_fprintf(stream, "%s \n", tab, pszGMLId); - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%s %.*f %.*f %.*f\n", tab, geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y, geometry_precision, shape->line[i].point[j].z); - else - /* fall-through */ - msIO_fprintf(stream, "%s %.*f %.*f\n", tab, geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y); - msIO_fprintf(stream, "%s \n", tab); - msFree(pszGMLId); - msIO_fprintf(stream, "%s \n", tab); - } + msIO_fprintf(stream, "%s ", tab, + nSRSDimension); + for (j = 0; j < shape->line[i].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y, geometry_precision, + shape->line[i].point[j].z); + else + /* fall-through */ + msIO_fprintf(stream, "%.*f %.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y); } + msIO_fprintf(stream, "\n"); - msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); - gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); - } else { - msIO_fprintf(stream, "\n"); + gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); } + } else if (geometry_aggregate_index != -1 || + (geometryList->numgeometries == 0)) { /* write a MultiCurve */ + gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, + tab); + + /* MultiCurve */ + pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); + if (srsname_encoded) + msIO_fprintf(stream, "%s \n", tab, + pszGMLId, srsname_encoded); + else + msIO_fprintf(stream, "%s \n", tab, pszGMLId); + msFree(pszGMLId); - break; - case(MS_SHAPE_LINE): - geometry_simple_index = msGMLGeometryLookup(geometryList, "line"); - geometry_aggregate_index = msGMLGeometryLookup(geometryList, "multiline"); - if(geometry_simple_index >= 0) geometry_simple_name = geometryList->geometries[geometry_simple_index].name; - if(geometry_aggregate_index >= 0) geometry_aggregate_name = geometryList->geometries[geometry_aggregate_index].name; - - if((geometry_simple_index != -1 && shape->numlines == 1) || - (geometry_simple_index != -1 && geometry_aggregate_index == -1) || - (geometryList->numgeometries == 0 && shape->numlines == 1)) { /* write a LineStrings(s) */ - for(i=0; inumlines; i++) { - gmlStartGeometryContainer(stream, geometry_simple_name, namespace, tab); + for (i = 0; i < shape->numlines; i++) { + msIO_fprintf(stream, "%s \n", tab); + pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); + msIO_fprintf(stream, "%s \n", tab, + pszGMLId); /* no srsname at this point */ + msFree(pszGMLId); - /* LineString (should be Curve?) */ - pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); - if(srsname_encoded) - msIO_fprintf(stream, "%s \n", tab, pszGMLId, srsname_encoded); + msIO_fprintf(stream, "%s ", tab, + nSRSDimension); + for (j = 0; j < shape->line[i].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y, geometry_precision, + shape->line[i].point[j].z); else - msIO_fprintf(stream, "%s \n", tab, pszGMLId); - msFree(pszGMLId); + /* fall-through */ + msIO_fprintf(stream, "%.*f %.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y); + } - msIO_fprintf(stream, "%s ", tab, nSRSDimension); - for(j=0; jline[i].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y, geometry_precision, shape->line[i].point[j].z); - else - /* fall-through */ - msIO_fprintf(stream, "%.*f %.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y); - } - msIO_fprintf(stream, "\n"); + msIO_fprintf(stream, "\n"); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + } - msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); - gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); - } - } else if(geometry_aggregate_index != -1 || (geometryList->numgeometries == 0)) { /* write a MultiCurve */ - gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, tab); + gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); + } else { + msIO_fprintf(stream, "\n"); + } + + break; + case ( + MS_SHAPE_POLYGON): /* this gets nasty, since our shapes are so flexible */ + geometry_simple_index = msGMLGeometryLookup(geometryList, "polygon"); + geometry_aggregate_index = + msGMLGeometryLookup(geometryList, "multipolygon"); + if (geometry_simple_index >= 0) + geometry_simple_name = + geometryList->geometries[geometry_simple_index].name; + if (geometry_aggregate_index >= 0) + geometry_aggregate_name = + geometryList->geometries[geometry_aggregate_index].name; + + /* get a list of outter rings for this polygon */ + outerlist = msGetOuterList(shape); + + numouters = 0; + for (i = 0; i < shape->numlines; i++) + if (outerlist[i] == MS_TRUE) + numouters++; + + if ((geometry_simple_index != -1 && numouters == 1) || + (geometry_simple_index != -1 && geometry_aggregate_index == -1) || + (geometryList->numgeometries == 0 && + shape->numlines == 1)) { /* write a Polygon(s) */ + for (i = 0; i < shape->numlines; i++) { + if (outerlist[i] == MS_FALSE) + break; /* skip non-outer rings, each outer ring is a new polygon */ + + /* get a list of inner rings for this polygon */ + innerlist = msGetInnerList(shape, i, outerlist); + + gmlStartGeometryContainer(stream, geometry_simple_name, namespace, tab); - /* MultiCurve */ pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); - if(srsname_encoded) - msIO_fprintf(stream, "%s \n", tab, pszGMLId, srsname_encoded); + + /* Polygon (should be Surface?) */ + if (srsname_encoded) + msIO_fprintf(stream, "%s \n", tab, + pszGMLId, srsname_encoded); else - msIO_fprintf(stream, "%s \n", tab, pszGMLId); + msIO_fprintf(stream, "%s \n", tab, pszGMLId); msFree(pszGMLId); - for(i=0; inumlines; i++) { - msIO_fprintf(stream, "%s \n", tab); - pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); - msIO_fprintf(stream, "%s \n", tab, pszGMLId); /* no srsname at this point */ - msFree(pszGMLId); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + + msIO_fprintf(stream, "%s ", tab, + nSRSDimension); + for (j = 0; j < shape->line[i].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y, geometry_precision, + shape->line[i].point[j].z); + else + /* fall-through */ + msIO_fprintf(stream, "%.*f %.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y); + } - msIO_fprintf(stream, "%s ", tab, nSRSDimension); - for(j=0; jline[i].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y, geometry_precision, shape->line[i].point[j].z); - else - /* fall-through */ - msIO_fprintf(stream, "%.*f %.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y); - } + msIO_fprintf(stream, "\n"); - msIO_fprintf(stream, "\n"); - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - } + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); + for (k = 0; k < shape->numlines; + k++) { /* now step through all the inner rings */ + if (innerlist[k] == MS_TRUE) { + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); - gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); - } else { - msIO_fprintf(stream, "\n"); - } + msIO_fprintf(stream, "%s ", + tab, nSRSDimension); + for (j = 0; j < shape->line[k].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision, + shape->line[k].point[j].x, geometry_precision, + shape->line[k].point[j].y, geometry_precision, + shape->line[k].point[j].z); + else + /* fall-through */ + msIO_fprintf(stream, "%.*f %.*f ", geometry_precision, + shape->line[k].point[j].x, geometry_precision, + shape->line[k].point[j].y); + } + + msIO_fprintf(stream, "\n"); - break; - case(MS_SHAPE_POLYGON): /* this gets nasty, since our shapes are so flexible */ - geometry_simple_index = msGMLGeometryLookup(geometryList, "polygon"); - geometry_aggregate_index = msGMLGeometryLookup(geometryList, "multipolygon"); - if(geometry_simple_index >= 0) geometry_simple_name = geometryList->geometries[geometry_simple_index].name; - if(geometry_aggregate_index >= 0) geometry_aggregate_name = geometryList->geometries[geometry_aggregate_index].name; + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + } + } - /* get a list of outter rings for this polygon */ - outerlist = msGetOuterList(shape); + msIO_fprintf(stream, "%s \n", tab); + free(innerlist); - numouters = 0; - for(i=0; inumlines; i++) - if(outerlist[i] == MS_TRUE) numouters++; + gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); + } + free(outerlist); + outerlist = NULL; + } else if (geometry_aggregate_index != -1 || + (geometryList->numgeometries == 0)) { /* write a MultiSurface */ + gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, + tab); + + pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); + + /* MultiSurface */ + if (srsname_encoded) + msIO_fprintf(stream, "%s \n", tab, + pszGMLId, srsname_encoded); + else + msIO_fprintf(stream, "%s \n", tab, pszGMLId); + msFree(pszGMLId); - if((geometry_simple_index != -1 && numouters == 1) || - (geometry_simple_index != -1 && geometry_aggregate_index == -1) || - (geometryList->numgeometries == 0 && shape->numlines == 1)) { /* write a Polygon(s) */ - for(i=0; inumlines; i++) { - if(outerlist[i] == MS_FALSE) break; /* skip non-outer rings, each outer ring is a new polygon */ + for (i = 0; i < shape->numlines; i++) { /* step through the outer rings */ + if (outerlist[i] == MS_TRUE) { + msIO_fprintf(stream, "%s \n", tab); /* get a list of inner rings for this polygon */ innerlist = msGetInnerList(shape, i, outerlist); - gmlStartGeometryContainer(stream, geometry_simple_name, namespace, tab); - pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); - /* Polygon (should be Surface?) */ - if(srsname_encoded) - msIO_fprintf(stream, "%s \n", tab, pszGMLId, srsname_encoded); - else - msIO_fprintf(stream, "%s \n", tab, pszGMLId); + msIO_fprintf(stream, "%s \n", tab, pszGMLId); msFree(pszGMLId); - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - - msIO_fprintf(stream, "%s ", tab, nSRSDimension); - for(j=0; jline[i].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y, geometry_precision, shape->line[i].point[j].z); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + + msIO_fprintf(stream, + "%s ", tab, + nSRSDimension); + for (j = 0; j < shape->line[i].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y, geometry_precision, + shape->line[i].point[j].z); else - /* fall-through */ - msIO_fprintf(stream, "%.*f %.*f ", geometry_precision, shape->line[i].point[j].x, geometry_precision, shape->line[i].point[j].y); + /* fall-through */ + msIO_fprintf(stream, "%.*f %.*f ", geometry_precision, + shape->line[i].point[j].x, geometry_precision, + shape->line[i].point[j].y); } msIO_fprintf(stream, "\n"); - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - - for(k=0; knumlines; k++) { /* now step through all the inner rings */ - if(innerlist[k] == MS_TRUE) { - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - - msIO_fprintf(stream, "%s ", tab, nSRSDimension); - for(j=0; jline[k].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision,shape->line[k].point[j].x, geometry_precision,shape->line[k].point[j].y, geometry_precision,shape->line[k].point[j].z); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + + for (k = 0; k < shape->numlines; + k++) { /* now step through all the inner rings */ + if (innerlist[k] == MS_TRUE) { + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + + msIO_fprintf(stream, + "%s ", + tab, nSRSDimension); + for (j = 0; j < shape->line[k].numpoints; j++) { + if (nSRSDimension == 3) + msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision, + shape->line[k].point[j].x, geometry_precision, + shape->line[k].point[j].y, geometry_precision, + shape->line[k].point[j].z); else - /* fall-through */ - msIO_fprintf(stream, "%.*f %.*f ", geometry_precision,shape->line[k].point[j].x, geometry_precision,shape->line[k].point[j].y); + /* fall-through */ + msIO_fprintf(stream, "%.*f %.*f ", geometry_precision, + shape->line[k].point[j].x, geometry_precision, + shape->line[k].point[j].y); } - msIO_fprintf(stream, "\n"); - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); } } - msIO_fprintf(stream, "%s \n", tab); - free(innerlist); - - gmlEndGeometryContainer(stream, geometry_simple_name, namespace, tab); - } - free(outerlist); - outerlist = NULL; - } else if(geometry_aggregate_index != -1 || (geometryList->numgeometries == 0)) { /* write a MultiSurface */ - gmlStartGeometryContainer(stream, geometry_aggregate_name, namespace, tab); - - pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); - - /* MultiSurface */ - if(srsname_encoded) - msIO_fprintf(stream, "%s \n", tab, pszGMLId, srsname_encoded); - else - msIO_fprintf(stream, "%s \n", tab, pszGMLId); - msFree(pszGMLId); - - for(i=0; inumlines; i++) { /* step through the outer rings */ - if(outerlist[i] == MS_TRUE) { - msIO_fprintf(stream, "%s \n", tab); + msIO_fprintf(stream, "%s \n", tab); - /* get a list of inner rings for this polygon */ - innerlist = msGetInnerList(shape, i, outerlist); - - pszGMLId = gmlCreateGeomId(nGMLVersion, pszFID, &id); - - msIO_fprintf(stream, "%s \n", tab, pszGMLId); - msFree(pszGMLId); - - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - - msIO_fprintf(stream, "%s ", tab, nSRSDimension); - for(j=0; jline[i].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision,shape->line[i].point[j].x, geometry_precision,shape->line[i].point[j].y, geometry_precision,shape->line[i].point[j].z); - else - /* fall-through */ - msIO_fprintf(stream, "%.*f %.*f ", geometry_precision,shape->line[i].point[j].x, geometry_precision,shape->line[i].point[j].y); - } - - msIO_fprintf(stream, "\n"); - - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - - for(k=0; knumlines; k++) { /* now step through all the inner rings */ - if(innerlist[k] == MS_TRUE) { - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - - msIO_fprintf(stream, "%s ", tab, nSRSDimension); - for(j=0; jline[k].numpoints; j++) - { - if( nSRSDimension == 3 ) - msIO_fprintf(stream, "%.*f %.*f %.*f ", geometry_precision, shape->line[k].point[j].x, geometry_precision,shape->line[k].point[j].y, geometry_precision,shape->line[k].point[j].z); - else - /* fall-through */ - msIO_fprintf(stream, "%.*f %.*f ", geometry_precision,shape->line[k].point[j].x, geometry_precision,shape->line[k].point[j].y); - } - msIO_fprintf(stream, "\n"); - - msIO_fprintf(stream, "%s \n", tab); - msIO_fprintf(stream, "%s \n", tab); - } - } - - msIO_fprintf(stream, "%s \n", tab); - - free(innerlist); - msIO_fprintf(stream, "%s \n", tab); - } + free(innerlist); + msIO_fprintf(stream, "%s \n", tab); } - msIO_fprintf(stream, "%s \n", tab); + } + msIO_fprintf(stream, "%s \n", tab); - free(outerlist); - outerlist = NULL; + free(outerlist); + outerlist = NULL; - gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); - } else { - msIO_fprintf(stream, "\n"); - } + gmlEndGeometryContainer(stream, geometry_aggregate_name, namespace, tab); + } else { + msIO_fprintf(stream, "\n"); + } - break; - default: - break; + break; + default: + break; } /* clean-up */ msFree(outerlist); msFree(srsname_encoded); - return(MS_SUCCESS); + return (MS_SUCCESS); } /* @@ -808,113 +979,125 @@ static int gmlWriteGeometry_GML3(FILE *stream, gmlGeometryListObj *geometryList, */ static int gmlWriteBounds(FILE *stream, OWSGMLVersion format, rectObj *rect, const char *srsname, const char *tab, - const char *pszTopPrefix) -{ - switch(format) { - case(OWS_GML2): - return gmlWriteBounds_GML2(stream, rect, srsname, tab, pszTopPrefix); - break; - case(OWS_GML3): - case(OWS_GML32): - return gmlWriteBounds_GML3(stream, rect, srsname, tab, pszTopPrefix); - break; - default: - msSetError(MS_IOERR, "Unsupported GML format.", "gmlWriteBounds()"); + const char *pszTopPrefix) { + switch (format) { + case (OWS_GML2): + return gmlWriteBounds_GML2(stream, rect, srsname, tab, pszTopPrefix); + break; + case (OWS_GML3): + case (OWS_GML32): + return gmlWriteBounds_GML3(stream, rect, srsname, tab, pszTopPrefix); + break; + default: + msSetError(MS_IOERR, "Unsupported GML format.", "gmlWriteBounds()"); } - return(MS_FAILURE); + return (MS_FAILURE); } static int gmlWriteGeometry(FILE *stream, gmlGeometryListObj *geometryList, OWSGMLVersion format, shapeObj *shape, const char *srsname, const char *namespace, - const char *tab, const char* pszFID, int nSRSDimension, int geometry_precision) -{ - switch(format) { - case(OWS_GML2): - return gmlWriteGeometry_GML2(stream, geometryList, shape, srsname, namespace, tab, nSRSDimension, geometry_precision); - break; - case(OWS_GML3): - case(OWS_GML32): - return gmlWriteGeometry_GML3(stream, geometryList, shape, srsname, namespace, tab, pszFID, format, nSRSDimension, geometry_precision); - break; - default: - msSetError(MS_IOERR, "Unsupported GML format.", "gmlWriteGeometry()"); + const char *tab, const char *pszFID, + int nSRSDimension, int geometry_precision) { + switch (format) { + case (OWS_GML2): + return gmlWriteGeometry_GML2(stream, geometryList, shape, srsname, + namespace, tab, nSRSDimension, + geometry_precision); + break; + case (OWS_GML3): + case (OWS_GML32): + return gmlWriteGeometry_GML3(stream, geometryList, shape, srsname, + namespace, tab, pszFID, format, nSRSDimension, + geometry_precision); + break; + default: + msSetError(MS_IOERR, "Unsupported GML format.", "gmlWriteGeometry()"); } - return(MS_FAILURE); + return (MS_FAILURE); } /* ** GML specific metadata handling functions. */ -int msItemInGroups(const char *name, gmlGroupListObj *groupList) -{ +int msItemInGroups(const char *name, gmlGroupListObj *groupList) { int i, j; gmlGroupObj *group; - if(!groupList) return MS_FALSE; /* no groups */ + if (!groupList) + return MS_FALSE; /* no groups */ - for(i=0; inumgroups; i++) { + for (i = 0; i < groupList->numgroups; i++) { group = &(groupList->groups[i]); - for(j=0; jnumitems; j++) { - if(strcasecmp(name, group->items[j]) == 0) return MS_TRUE; + for (j = 0; j < group->numitems; j++) { + if (strcasecmp(name, group->items[j]) == 0) + return MS_TRUE; } } return MS_FALSE; } -static int msGMLGeometryLookup(gmlGeometryListObj *geometryList, const char *type) -{ +static int msGMLGeometryLookup(gmlGeometryListObj *geometryList, + const char *type) { int i; - if(!geometryList || !type) return -1; /* nothing to look for */ + if (!geometryList || !type) + return -1; /* nothing to look for */ - for(i=0; inumgeometries; i++) - if(geometryList->geometries[i].type && (strcasecmp(geometryList->geometries[i].type, type) == 0)) + for (i = 0; i < geometryList->numgeometries; i++) + if (geometryList->geometries[i].type && + (strcasecmp(geometryList->geometries[i].type, type) == 0)) return i; - if( geometryList->numgeometries == 1 && geometryList->geometries[0].type == NULL ) + if (geometryList->numgeometries == 1 && + geometryList->geometries[0].type == NULL) return 0; return -1; /* not found */ } -gmlGeometryListObj *msGMLGetGeometries(layerObj *layer, const char *metadata_namespaces, int bWithDefaultGeom) -{ +gmlGeometryListObj *msGMLGetGeometries(layerObj *layer, + const char *metadata_namespaces, + int bWithDefaultGeom) { int i; - const char *value=NULL; + const char *value = NULL; char tag[64]; - char **names=NULL; - int numnames=0; + char **names = NULL; + int numnames = 0; - gmlGeometryListObj *geometryList=NULL; - gmlGeometryObj *geometry=NULL; + gmlGeometryListObj *geometryList = NULL; + gmlGeometryObj *geometry = NULL; /* allocate memory and initialize the item collection */ - geometryList = (gmlGeometryListObj *) malloc(sizeof(gmlGeometryListObj)); - MS_CHECK_ALLOC(geometryList, sizeof(gmlGeometryListObj), NULL) ; + geometryList = (gmlGeometryListObj *)malloc(sizeof(gmlGeometryListObj)); + MS_CHECK_ALLOC(geometryList, sizeof(gmlGeometryListObj), NULL); geometryList->geometries = NULL; geometryList->numgeometries = 0; - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "geometries")) != NULL) { + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + "geometries")) != NULL) { names = msStringSplit(value, ',', &numnames); /* allocation an array of gmlGeometryObj's */ geometryList->numgeometries = numnames; - geometryList->geometries = (gmlGeometryObj *) malloc(sizeof(gmlGeometryObj)*geometryList->numgeometries); - if (geometryList->geometries == NULL) { - msSetError(MS_MEMERR, "Out of memory allocating %u bytes.\n", "msGMLGetGeometries()", - (unsigned int)(sizeof(gmlGeometryObj)*geometryList->numgeometries)); + geometryList->geometries = (gmlGeometryObj *)malloc( + sizeof(gmlGeometryObj) * geometryList->numgeometries); + if (geometryList->geometries == NULL) { + msSetError( + MS_MEMERR, "Out of memory allocating %u bytes.\n", + "msGMLGetGeometries()", + (unsigned int)(sizeof(gmlGeometryObj) * geometryList->numgeometries)); free(geometryList); return NULL; } - for(i=0; inumgeometries; i++) { + for (i = 0; i < geometryList->numgeometries; i++) { geometry = &(geometryList->geometries[i]); geometry->name = msStrdup(names[i]); /* initialize a few things */ @@ -923,31 +1106,33 @@ gmlGeometryListObj *msGMLGetGeometries(layerObj *layer, const char *metadata_nam geometry->occurmax = 1; snprintf(tag, 64, "%s_type", names[i]); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) geometry->type = msStrdup(value); /* TODO: validate input value */ snprintf(tag, 64, "%s_occurances", names[i]); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) { + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) { char **occur; int numoccur; occur = msStringSplit(value, ',', &numoccur); - if(numoccur == 2) { /* continue (TODO: throw an error if != 2) */ + if (numoccur == 2) { /* continue (TODO: throw an error if != 2) */ geometry->occurmin = atof(occur[0]); - if(strcasecmp(occur[1], "UNBOUNDED") == 0) + if (strcasecmp(occur[1], "UNBOUNDED") == 0) geometry->occurmax = OWS_GML_OCCUR_UNBOUNDED; else geometry->occurmax = atof(occur[1]); } - msFreeCharArray(occur,numoccur); + msFreeCharArray(occur, numoccur); } } msFreeCharArray(names, numnames); - } - else if( bWithDefaultGeom ) { + } else if (bWithDefaultGeom) { geometryList->numgeometries = 1; - geometryList->geometries = (gmlGeometryObj *) calloc(1, sizeof(gmlGeometryObj)); + geometryList->geometries = + (gmlGeometryObj *)calloc(1, sizeof(gmlGeometryObj)); geometryList->geometries[0].name = msStrdup(OWS_GML_DEFAULT_GEOMETRY_NAME); geometryList->geometries[0].type = NULL; geometryList->geometries[0].occurmin = 0; @@ -957,13 +1142,13 @@ gmlGeometryListObj *msGMLGetGeometries(layerObj *layer, const char *metadata_nam return geometryList; } -void msGMLFreeGeometries(gmlGeometryListObj *geometryList) -{ +void msGMLFreeGeometries(gmlGeometryListObj *geometryList) { int i; - if(!geometryList) return; + if (!geometryList) + return; - for(i=0; inumgeometries; i++) { + for (i = 0; i < geometryList->numgeometries; i++) { msFree(geometryList->geometries[i].name); msFree(geometryList->geometries[i].type); } @@ -972,143 +1157,143 @@ void msGMLFreeGeometries(gmlGeometryListObj *geometryList) free(geometryList); } -static void msGMLWriteItem(FILE *stream, gmlItemObj *item, - const char *value, const char *namespace, - const char *tab, - OWSGMLVersion outputformat, - const char *pszFID) -{ +static void msGMLWriteItem(FILE *stream, gmlItemObj *item, const char *value, + const char *namespace, const char *tab, + OWSGMLVersion outputformat, const char *pszFID) { char *encoded_value = NULL, *tag_name; int add_namespace = MS_TRUE; char gmlid[256]; gmlid[0] = 0; - if(!stream || !item) return; - if(!item->visible) return; + if (!stream || !item) + return; + if (!item->visible) + return; - if(!namespace) add_namespace = MS_FALSE; + if (!namespace) + add_namespace = MS_FALSE; - if(item->alias) + if (item->alias) tag_name = item->alias; else tag_name = item->name; - if(strchr(tag_name, ':') != NULL) add_namespace = MS_FALSE; - - if( item->type && (EQUAL(item->type, "Date") || - EQUAL(item->type, "DateTime") || - EQUAL(item->type, "Time")) ) { - struct tm tm; - if( msParseTime(value, &tm) == MS_TRUE ) { - const char* pszStartTag = ""; - const char* pszEndTag = ""; - - encoded_value = (char*) msSmallMalloc(256); - if( outputformat == OWS_GML32 ) { - if( pszFID != NULL ) - snprintf(gmlid, 256, " gml:id=\"%s.%s\"", pszFID, tag_name); - pszStartTag = ""; - pszEndTag = ""; - } + if (strchr(tag_name, ':') != NULL) + add_namespace = MS_FALSE; + + if (item->type && + (EQUAL(item->type, "Date") || EQUAL(item->type, "DateTime") || + EQUAL(item->type, "Time"))) { + struct tm tm; + if (msParseTime(value, &tm) == MS_TRUE) { + const char *pszStartTag = ""; + const char *pszEndTag = ""; + + encoded_value = (char *)msSmallMalloc(256); + if (outputformat == OWS_GML32) { + if (pszFID != NULL) + snprintf(gmlid, 256, " gml:id=\"%s.%s\"", pszFID, tag_name); + pszStartTag = ""; + pszEndTag = ""; + } - if( EQUAL(item->type, "Date") ) - snprintf(encoded_value, 256, "%s%04d-%02d-%02d%s", - pszStartTag, - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - pszEndTag); - else if( EQUAL(item->type, "Time") ) - snprintf(encoded_value, 256, "%s%02d:%02d:%02dZ%s", - pszStartTag, - tm.tm_hour, tm.tm_min, tm.tm_sec, - pszEndTag); - else - { - // Detected date time already formatted as YYYY-MM-DDTHH:mm:SS+ab:cd - // because msParseTime() can't handle time zones. - if( strlen(value) == 4+1+2+1+2+1+2+1+2+1+2+1+2+1+2 && - value[4] == '-' && value[7] == '-' && value[10] == 'T' && - value[13] == ':' && value[16] == ':' && - (value[19] == '+' || value[19] == '-') && - value[22] == ':' ) - { - snprintf(encoded_value, 256, "%s%s%s", - pszStartTag, value, pszEndTag); - } - else - { - snprintf(encoded_value, 256, "%s%04d-%02d-%02dT%02d:%02d:%02dZ%s", - pszStartTag, - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, pszEndTag); - } - } + if (EQUAL(item->type, "Date")) + snprintf(encoded_value, 256, "%s%04d-%02d-%02d%s", pszStartTag, + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, pszEndTag); + else if (EQUAL(item->type, "Time")) + snprintf(encoded_value, 256, "%s%02d:%02d:%02dZ%s", pszStartTag, + tm.tm_hour, tm.tm_min, tm.tm_sec, pszEndTag); + else { + // Detected date time already formatted as YYYY-MM-DDTHH:mm:SS+ab:cd + // because msParseTime() can't handle time zones. + if (strlen(value) == + 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 && + value[4] == '-' && value[7] == '-' && value[10] == 'T' && + value[13] == ':' && value[16] == ':' && + (value[19] == '+' || value[19] == '-') && value[22] == ':') { + snprintf(encoded_value, 256, "%s%s%s", pszStartTag, value, pszEndTag); + } else { + snprintf(encoded_value, 256, "%s%04d-%02d-%02dT%02d:%02d:%02dZ%s", + pszStartTag, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, pszEndTag); + } } + } } - if( encoded_value == NULL ) - { - if(item->encode == MS_TRUE) + if (encoded_value == NULL) { + if (item->encode == MS_TRUE) encoded_value = msEncodeHTMLEntities(value); else encoded_value = msStrdup(value); } - if(!item->template) { /* build the tag from pieces */ + if (!item->template) { /* build the tag from pieces */ - if(add_namespace == MS_TRUE && msIsXMLTagValid(tag_name) == MS_FALSE) - msIO_fprintf(stream, "\n", tag_name); + if (add_namespace == MS_TRUE && msIsXMLTagValid(tag_name) == MS_FALSE) + msIO_fprintf(stream, + "\n", + tag_name); - if(add_namespace == MS_TRUE) - msIO_fprintf(stream, "%s<%s:%s%s>%s\n", tab, namespace, tag_name, gmlid, encoded_value, namespace, tag_name); + if (add_namespace == MS_TRUE) + msIO_fprintf(stream, "%s<%s:%s%s>%s\n", tab, namespace, tag_name, + gmlid, encoded_value, namespace, tag_name); else - msIO_fprintf(stream, "%s<%s%s>%s\n", tab, tag_name, gmlid, encoded_value, tag_name); + msIO_fprintf(stream, "%s<%s%s>%s\n", tab, tag_name, gmlid, + encoded_value, tag_name); } else { char *tag = NULL; tag = msStrdup(item->template); tag = msReplaceSubstring(tag, "$value", encoded_value); - if(namespace) tag = msReplaceSubstring(tag, "$namespace", namespace); + if (namespace) + tag = msReplaceSubstring(tag, "$namespace", namespace); msIO_fprintf(stream, "%s%s\n", tab, tag); free(tag); } - free( encoded_value ); + free(encoded_value); return; } -gmlNamespaceListObj *msGMLGetNamespaces(webObj *web, const char *metadata_namespaces) -{ +gmlNamespaceListObj *msGMLGetNamespaces(webObj *web, + const char *metadata_namespaces) { int i; - const char *value=NULL; + const char *value = NULL; char tag[64]; - char **prefixes=NULL; - int numprefixes=0; + char **prefixes = NULL; + int numprefixes = 0; - gmlNamespaceListObj *namespaceList=NULL; - gmlNamespaceObj *namespace=NULL; + gmlNamespaceListObj *namespaceList = NULL; + gmlNamespaceObj *namespace = NULL; /* allocate the collection */ - namespaceList = (gmlNamespaceListObj *) malloc(sizeof(gmlNamespaceListObj)); - MS_CHECK_ALLOC(namespaceList, sizeof(gmlNamespaceListObj), NULL) ; + namespaceList = (gmlNamespaceListObj *)malloc(sizeof(gmlNamespaceListObj)); + MS_CHECK_ALLOC(namespaceList, sizeof(gmlNamespaceListObj), NULL); namespaceList->namespaces = NULL; namespaceList->numnamespaces = 0; /* list of namespaces (TODO: make this automatic by parsing metadata) */ - if((value = msOWSLookupMetadata(&(web->metadata), metadata_namespaces, "external_namespace_prefixes")) != NULL) { + if ((value = msOWSLookupMetadata(&(web->metadata), metadata_namespaces, + "external_namespace_prefixes")) != NULL) { prefixes = msStringSplit(value, ',', &numprefixes); /* allocation an array of gmlNamespaceObj's */ namespaceList->numnamespaces = numprefixes; - namespaceList->namespaces = (gmlNamespaceObj *) malloc(sizeof(gmlNamespaceObj)*namespaceList->numnamespaces); + namespaceList->namespaces = (gmlNamespaceObj *)malloc( + sizeof(gmlNamespaceObj) * namespaceList->numnamespaces); if (namespaceList->namespaces == NULL) { - msSetError(MS_MEMERR, "Out of memory allocating %u bytes.\n", "msGMLGetNamespaces()", - (unsigned int)(sizeof(gmlNamespaceObj)*namespaceList->numnamespaces)); + msSetError(MS_MEMERR, "Out of memory allocating %u bytes.\n", + "msGMLGetNamespaces()", + (unsigned int)(sizeof(gmlNamespaceObj) * + namespaceList->numnamespaces)); free(namespaceList); return NULL; } - for(i=0; inumnamespaces; i++) { + for (i = 0; i < namespaceList->numnamespaces; i++) { namespace = &(namespaceList->namespaces[i]); namespace->prefix = msStrdup(prefixes[i]); /* initialize a few things */ @@ -1116,12 +1301,14 @@ gmlNamespaceListObj *msGMLGetNamespaces(webObj *web, const char *metadata_namesp namespace->schemalocation = NULL; snprintf(tag, 64, "%s_uri", namespace->prefix); - if((value = msOWSLookupMetadata(&(web->metadata), metadata_namespaces, tag)) != NULL) - namespace->uri = msStrdup(value); + if ((value = msOWSLookupMetadata(&(web->metadata), metadata_namespaces, + tag)) != NULL) + namespace->uri = msStrdup(value); snprintf(tag, 64, "%s_schema_location", namespace->prefix); - if((value = msOWSLookupMetadata(&(web->metadata), metadata_namespaces, tag)) != NULL) - namespace->schemalocation = msStrdup(value); + if ((value = msOWSLookupMetadata(&(web->metadata), metadata_namespaces, + tag)) != NULL) + namespace->schemalocation = msStrdup(value); } msFreeCharArray(prefixes, numprefixes); @@ -1130,13 +1317,13 @@ gmlNamespaceListObj *msGMLGetNamespaces(webObj *web, const char *metadata_namesp return namespaceList; } -void msGMLFreeNamespaces(gmlNamespaceListObj *namespaceList) -{ +void msGMLFreeNamespaces(gmlNamespaceListObj *namespaceList) { int i; - if(!namespaceList) return; + if (!namespaceList) + return; - for(i=0; inumnamespaces; i++) { + for (i = 0; i < namespaceList->numnamespaces; i++) { msFree(namespaceList->namespaces[i].prefix); msFree(namespaceList->namespaces[i].uri); msFree(namespaceList->namespaces[i].schemalocation); @@ -1145,40 +1332,43 @@ void msGMLFreeNamespaces(gmlNamespaceListObj *namespaceList) free(namespaceList); } -gmlConstantListObj *msGMLGetConstants(layerObj *layer, const char *metadata_namespaces) -{ +gmlConstantListObj *msGMLGetConstants(layerObj *layer, + const char *metadata_namespaces) { int i; - const char *value=NULL; + const char *value = NULL; char tag[64]; - char **names=NULL; - int numnames=0; + char **names = NULL; + int numnames = 0; - gmlConstantListObj *constantList=NULL; - gmlConstantObj *constant=NULL; + gmlConstantListObj *constantList = NULL; + gmlConstantObj *constant = NULL; /* allocate the collection */ - constantList = (gmlConstantListObj *) malloc(sizeof(gmlConstantListObj)); + constantList = (gmlConstantListObj *)malloc(sizeof(gmlConstantListObj)); MS_CHECK_ALLOC(constantList, sizeof(gmlConstantListObj), NULL); constantList->constants = NULL; constantList->numconstants = 0; /* list of constants (TODO: make this automatic by parsing metadata) */ - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "constants")) != NULL) { + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + "constants")) != NULL) { names = msStringSplit(value, ',', &numnames); /* allocation an array of gmlConstantObj's */ constantList->numconstants = numnames; - constantList->constants = (gmlConstantObj *) malloc(sizeof(gmlConstantObj)*constantList->numconstants); + constantList->constants = (gmlConstantObj *)malloc( + sizeof(gmlConstantObj) * constantList->numconstants); if (constantList->constants == NULL) { - msSetError(MS_MEMERR, "Out of memory allocating %u bytes.\n", "msGMLGetConstants()", - (unsigned int)(sizeof(gmlConstantObj)*constantList->numconstants)); + msSetError( + MS_MEMERR, "Out of memory allocating %u bytes.\n", + "msGMLGetConstants()", + (unsigned int)(sizeof(gmlConstantObj) * constantList->numconstants)); free(constantList); return NULL; } - - for(i=0; inumconstants; i++) { + for (i = 0; i < constantList->numconstants; i++) { constant = &(constantList->constants[i]); constant->name = msStrdup(names[i]); /* initialize a few things */ @@ -1186,11 +1376,13 @@ gmlConstantListObj *msGMLGetConstants(layerObj *layer, const char *metadata_name constant->type = NULL; snprintf(tag, 64, "%s_value", constant->name); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) constant->value = msStrdup(value); snprintf(tag, 64, "%s_type", constant->name); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) constant->type = msStrdup(value); } @@ -1200,13 +1392,13 @@ gmlConstantListObj *msGMLGetConstants(layerObj *layer, const char *metadata_name return constantList; } -void msGMLFreeConstants(gmlConstantListObj *constantList) -{ +void msGMLFreeConstants(gmlConstantListObj *constantList) { int i; - if(!constantList) return; + if (!constantList) + return; - for(i=0; inumconstants; i++) { + for (i = 0; i < constantList->numconstants; i++) { msFree(constantList->constants[i].name); msFree(constantList->constants[i].value); msFree(constantList->constants[i].type); @@ -1215,79 +1407,89 @@ void msGMLFreeConstants(gmlConstantListObj *constantList) free(constantList); } -static void msGMLWriteConstant(FILE *stream, gmlConstantObj *constant, const char *namespace, const char *tab) -{ +static void msGMLWriteConstant(FILE *stream, gmlConstantObj *constant, + const char *namespace, const char *tab) { int add_namespace = MS_TRUE; - if(!stream || !constant) return; - if(!constant->value) return; - - if(!namespace) add_namespace = MS_FALSE; - if(strchr(constant->name, ':') != NULL) add_namespace = MS_FALSE; - - if(add_namespace == MS_TRUE && msIsXMLTagValid(constant->name) == MS_FALSE) - msIO_fprintf(stream, "\n", constant->name); - - if(add_namespace == MS_TRUE) - msIO_fprintf(stream, "%s<%s:%s>%s\n", tab, namespace, constant->name, constant->value, namespace, constant->name); + if (!stream || !constant) + return; + if (!constant->value) + return; + + if (!namespace) + add_namespace = MS_FALSE; + if (strchr(constant->name, ':') != NULL) + add_namespace = MS_FALSE; + + if (add_namespace == MS_TRUE && msIsXMLTagValid(constant->name) == MS_FALSE) + msIO_fprintf( + stream, + "\n", + constant->name); + + if (add_namespace == MS_TRUE) + msIO_fprintf(stream, "%s<%s:%s>%s\n", tab, namespace, + constant->name, constant->value, namespace, constant->name); else - msIO_fprintf(stream, "%s<%s>%s\n", tab, constant->name, constant->value, constant->name); + msIO_fprintf(stream, "%s<%s>%s\n", tab, constant->name, + constant->value, constant->name); return; } -static void msGMLWriteGroup(FILE *stream, - gmlGroupObj *group, shapeObj *shape, +static void msGMLWriteGroup(FILE *stream, gmlGroupObj *group, shapeObj *shape, gmlItemListObj *itemList, gmlConstantListObj *constantList, const char *namespace, const char *tab, - OWSGMLVersion outputformat, - const char *pszFID) -{ - int i,j; + OWSGMLVersion outputformat, const char *pszFID) { + int i, j; int add_namespace = MS_TRUE; char *itemtab; - gmlItemObj *item=NULL; - gmlConstantObj *constant=NULL; + gmlItemObj *item = NULL; + gmlConstantObj *constant = NULL; - if(!stream || !group) return; + if (!stream || !group) + return; /* setup the item/constant tab */ - itemtab = (char *) msSmallMalloc(sizeof(char)*strlen(tab)+3); + itemtab = (char *)msSmallMalloc(sizeof(char) * strlen(tab) + 3); sprintf(itemtab, "%s ", tab); - if(!namespace || strchr(group->name, ':') != NULL) add_namespace = MS_FALSE; + if (!namespace || strchr(group->name, ':') != NULL) + add_namespace = MS_FALSE; /* start the group */ - if(add_namespace == MS_TRUE) + if (add_namespace == MS_TRUE) msIO_fprintf(stream, "%s<%s:%s>\n", tab, namespace, group->name); else msIO_fprintf(stream, "%s<%s>\n", tab, group->name); /* now the items/constants in the group */ - for(i=0; inumitems; i++) { - for(j=0; jnumconstants; j++) { + for (i = 0; i < group->numitems; i++) { + for (j = 0; j < constantList->numconstants; j++) { constant = &(constantList->constants[j]); - if(strcasecmp(constant->name, group->items[i]) == 0) { + if (strcasecmp(constant->name, group->items[i]) == 0) { msGMLWriteConstant(stream, constant, namespace, itemtab); break; } } - if(j != constantList->numconstants) continue; /* found this one */ - for(j=0; jnumitems; j++) { + if (j != constantList->numconstants) + continue; /* found this one */ + for (j = 0; j < itemList->numitems; j++) { item = &(itemList->items[j]); - if(strcasecmp(item->name, group->items[i]) == 0) { + if (strcasecmp(item->name, group->items[i]) == 0) { /* the number of items matches the number of values exactly */ - msGMLWriteItem(stream, item, shape->values[j], namespace, itemtab, outputformat, pszFID); + msGMLWriteItem(stream, item, shape->values[j], namespace, itemtab, + outputformat, pszFID); break; } } } /* end the group */ - if(add_namespace == MS_TRUE) + if (add_namespace == MS_TRUE) msIO_fprintf(stream, "%s\n", tab, namespace, group->name); else msIO_fprintf(stream, "%s\n", tab, group->name); @@ -1298,40 +1500,43 @@ static void msGMLWriteGroup(FILE *stream, } #endif -gmlGroupListObj *msGMLGetGroups(layerObj *layer, const char *metadata_namespaces) -{ +gmlGroupListObj *msGMLGetGroups(layerObj *layer, + const char *metadata_namespaces) { int i; - const char *value=NULL; + const char *value = NULL; char tag[64]; - char **names=NULL; - int numnames=0; + char **names = NULL; + int numnames = 0; - gmlGroupListObj *groupList=NULL; - gmlGroupObj *group=NULL; + gmlGroupListObj *groupList = NULL; + gmlGroupObj *group = NULL; /* allocate the collection */ - groupList = (gmlGroupListObj *) malloc(sizeof(gmlGroupListObj)); - MS_CHECK_ALLOC(groupList, sizeof(gmlGroupListObj), NULL) ; + groupList = (gmlGroupListObj *)malloc(sizeof(gmlGroupListObj)); + MS_CHECK_ALLOC(groupList, sizeof(gmlGroupListObj), NULL); groupList->groups = NULL; groupList->numgroups = 0; /* list of groups (TODO: make this automatic by parsing metadata) */ - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "groups")) != NULL && - value[0] != '\0' ) { + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + "groups")) != NULL && + value[0] != '\0') { names = msStringSplit(value, ',', &numnames); /* allocation an array of gmlGroupObj's */ groupList->numgroups = numnames; - groupList->groups = (gmlGroupObj *) malloc(sizeof(gmlGroupObj)*groupList->numgroups); + groupList->groups = + (gmlGroupObj *)malloc(sizeof(gmlGroupObj) * groupList->numgroups); if (groupList->groups == NULL) { - msSetError(MS_MEMERR, "Out of memory allocating %u bytes.\n", "msGMLGetGroups()", - (unsigned int)(sizeof(gmlGroupObj)*groupList->numgroups)); + msSetError(MS_MEMERR, "Out of memory allocating %u bytes.\n", + "msGMLGetGroups()", + (unsigned int)(sizeof(gmlGroupObj) * groupList->numgroups)); free(groupList); return NULL; } - for(i=0; inumgroups; i++) { + for (i = 0; i < groupList->numgroups; i++) { group = &(groupList->groups[i]); group->name = msStrdup(names[i]); /* initialize a few things */ @@ -1340,11 +1545,13 @@ gmlGroupListObj *msGMLGetGroups(layerObj *layer, const char *metadata_namespaces group->type = NULL; snprintf(tag, 64, "%s_group", group->name); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) group->items = msStringSplit(value, ',', &group->numitems); snprintf(tag, 64, "%s_type", group->name); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) group->type = msStrdup(value); } @@ -1354,13 +1561,13 @@ gmlGroupListObj *msGMLGetGroups(layerObj *layer, const char *metadata_namespaces return groupList; } -void msGMLFreeGroups(gmlGroupListObj *groupList) -{ +void msGMLFreeGroups(gmlGroupListObj *groupList) { int i; - if(!groupList) return; + if (!groupList) + return; - for(i=0; inumgroups; i++) { + for (i = 0; i < groupList->numgroups; i++) { msFree(groupList->groups[i].name); msFreeCharArray(groupList->groups[i].items, groupList->groups[i].numitems); msFree(groupList->groups[i].type); @@ -1371,87 +1578,104 @@ void msGMLFreeGroups(gmlGroupListObj *groupList) } /* Dump GML query results for WMS GetFeatureInfo */ -int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces) -{ +int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces) { #if defined(USE_WMS_SVR) int status; - int i,j,k; - layerObj *lp=NULL; + int i, j, k; + layerObj *lp = NULL; shapeObj shape; FILE *stream_to_free = NULL; - FILE *stream=stdout; /* defaults to stdout */ + FILE *stream = stdout; /* defaults to stdout */ char szPath[MS_MAXPATHLEN]; char *value; char *pszMapSRS = NULL; - gmlGroupListObj *groupList=NULL; - gmlItemListObj *itemList=NULL; - gmlConstantListObj *constantList=NULL; - gmlGeometryListObj *geometryList=NULL; - gmlItemObj *item=NULL; - gmlConstantObj *constant=NULL; + gmlGroupListObj *groupList = NULL; + gmlItemListObj *itemList = NULL; + gmlConstantListObj *constantList = NULL; + gmlGeometryListObj *geometryList = NULL; + gmlItemObj *item = NULL; + gmlConstantObj *constant = NULL; msInitShape(&shape); - if(filename && strlen(filename) > 0) { /* deal with the filename if present */ + if (filename && + strlen(filename) > 0) { /* deal with the filename if present */ stream_to_free = fopen(msBuildPath(szPath, map->mappath, filename), "w"); - if(!stream_to_free) { + if (!stream_to_free) { msSetError(MS_IOERR, "(%s)", "msGMLWriteQuery()", filename); - return(MS_FAILURE); + return (MS_FAILURE); } stream = stream_to_free; } msIO_fprintf(stream, "\n\n"); - msOWSPrintValidateMetadata(stream, &(map->web.metadata), namespaces, "rootname", OWS_NOERR, "<%s ", "msGMLOutput"); + msOWSPrintValidateMetadata(stream, &(map->web.metadata), namespaces, + "rootname", OWS_NOERR, "<%s ", "msGMLOutput"); - msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "uri", OWS_NOERR, "xmlns=\"%s\"", NULL); - msIO_fprintf(stream, "\n\t xmlns:gml=\"http://www.opengis.net/gml\"" ); + msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "uri", + OWS_NOERR, "xmlns=\"%s\"", NULL); + msIO_fprintf(stream, "\n\t xmlns:gml=\"http://www.opengis.net/gml\""); msIO_fprintf(stream, "\n\t xmlns:xlink=\"http://www.w3.org/1999/xlink\""); - msIO_fprintf(stream, "\n\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); - msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "schema", OWS_NOERR, "\n\t xsi:schemaLocation=\"%s\"", NULL); + msIO_fprintf(stream, + "\n\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); + msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "schema", + OWS_NOERR, "\n\t xsi:schemaLocation=\"%s\"", NULL); msIO_fprintf(stream, ">\n"); /* a schema *should* be required */ - msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, "description", OWS_NOERR, "\t%s\n", NULL); + msOWSPrintEncodeMetadata(stream, &(map->web.metadata), namespaces, + "description", OWS_NOERR, + "\t%s\n", NULL); - /* Look up map SRS. We need an EPSG code for GML, if not then we get null and we'll fall back on the layer's SRS */ + /* Look up map SRS. We need an EPSG code for GML, if not then we get null and + * we'll fall back on the layer's SRS */ msOWSGetEPSGProj(&(map->projection), NULL, namespaces, MS_TRUE, &pszMapSRS); /* step through the layers looking for query results */ - for(i=0; inumlayers; i++) { + for (i = 0; i < map->numlayers; i++) { char *pszOutputSRS = NULL; int nSRSDimension = 2; - const char* geomtype; + const char *geomtype; lp = (GET_LAYER(map, map->layerorder[i])); - if(lp->resultcache && lp->resultcache->numresults > 0) { /* found results */ + if (lp->resultcache && + lp->resultcache->numresults > 0) { /* found results */ - reprojectionObj* reprojector = NULL; + reprojectionObj *reprojector = NULL; - /* Determine output SRS, if map has none, then try using layer's native SRS */ + /* Determine output SRS, if map has none, then try using layer's native + * SRS */ if ((pszOutputSRS = pszMapSRS) == NULL) { - msOWSGetEPSGProj(&(lp->projection), NULL, namespaces, MS_TRUE, &pszOutputSRS); + msOWSGetEPSGProj(&(lp->projection), NULL, namespaces, MS_TRUE, + &pszOutputSRS); if (pszOutputSRS == NULL) { - msSetError(MS_WMSERR, "No valid EPSG code in map or layer projection for GML output", "msGMLWriteQuery()"); - continue; /* No EPSG code, cannot output this layer */ + msSetError( + MS_WMSERR, + "No valid EPSG code in map or layer projection for GML output", + "msGMLWriteQuery()"); + continue; /* No EPSG code, cannot output this layer */ } } /* start this collection (layer) */ /* if no layer name provided fall back on the layer name + "_layer" */ - value = (char*) msSmallMalloc(strlen(lp->name)+7); + value = (char *)msSmallMalloc(strlen(lp->name) + 7); sprintf(value, "%s_layer", lp->name); - msOWSPrintValidateMetadata(stream, &(lp->metadata), namespaces, "layername", OWS_NOERR, "\t<%s>\n", value); + msOWSPrintValidateMetadata(stream, &(lp->metadata), namespaces, + "layername", OWS_NOERR, "\t<%s>\n", value); msFree(value); - value = (char *) msOWSLookupMetadata(&(lp->metadata), "OM", "title"); + value = (char *)msOWSLookupMetadata(&(lp->metadata), "OM", "title"); if (value) { - msOWSPrintEncodeMetadata(stream, &(lp->metadata), namespaces, "title", OWS_NOERR, "\t%s\n", value); + msOWSPrintEncodeMetadata(stream, &(lp->metadata), namespaces, "title", + OWS_NOERR, "\t%s\n", + value); } geomtype = msOWSLookupMetadata(&(lp->metadata), "OFG", "geomtype"); - if( geomtype != NULL && (strstr(geomtype, "25d") != NULL || strstr(geomtype, "25D") != NULL) ) { + if (geomtype != NULL && (strstr(geomtype, "25d") != NULL || + strstr(geomtype, "25D") != NULL)) { nSRSDimension = 3; } @@ -1460,87 +1684,111 @@ int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces) constantList = msGMLGetConstants(lp, namespaces); groupList = msGMLGetGroups(lp, namespaces); geometryList = msGMLGetGeometries(lp, namespaces, MS_FALSE); - if (itemList == NULL || constantList == NULL || groupList == NULL || geometryList == NULL) { - msSetError(MS_MISCERR, "Unable to populate item and group metadata structures", "msGMLWriteQuery()"); - if(stream_to_free != NULL) fclose(stream_to_free); + if (itemList == NULL || constantList == NULL || groupList == NULL || + geometryList == NULL) { + msSetError(MS_MISCERR, + "Unable to populate item and group metadata structures", + "msGMLWriteQuery()"); + if (stream_to_free != NULL) + fclose(stream_to_free); return MS_FAILURE; } - if(pszOutputSRS == pszMapSRS && msProjectionsDiffer(&(lp->projection), &(map->projection))) { - reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection)); - if( reprojector == NULL ) { + if (pszOutputSRS == pszMapSRS && + msProjectionsDiffer(&(lp->projection), &(map->projection))) { + reprojector = + msProjectCreateReprojector(&(lp->projection), &(map->projection)); + if (reprojector == NULL) { msGMLFreeGroups(groupList); msGMLFreeConstants(constantList); msGMLFreeItems(itemList); msGMLFreeGeometries(geometryList); msFree(pszOutputSRS); - if(stream_to_free != NULL) fclose(stream_to_free); + if (stream_to_free != NULL) + fclose(stream_to_free); return MS_FAILURE; } } - for(j=0; jresultcache->numresults; j++) { + for (j = 0; j < lp->resultcache->numresults; j++) { status = msLayerGetShape(lp, &shape, &(lp->resultcache->results[j])); - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { msGMLFreeGroups(groupList); msGMLFreeConstants(constantList); msGMLFreeItems(itemList); msGMLFreeGeometries(geometryList); msProjectDestroyReprojector(reprojector); msFree(pszOutputSRS); - if(stream_to_free != NULL) fclose(stream_to_free); + if (stream_to_free != NULL) + fclose(stream_to_free); return MS_FAILURE; } - /* project the shape into the map projection (if necessary), note that this projects the bounds as well */ - if(reprojector) { + /* project the shape into the map projection (if necessary), note that + * this projects the bounds as well */ + if (reprojector) { status = msProjectShapeEx(reprojector, &shape); - if(status != MS_SUCCESS) { - msIO_fprintf(stream, "\n",msGetErrorString(",")); + if (status != MS_SUCCESS) { + msIO_fprintf(stream, + "\n", + msGetErrorString(",")); msFreeShape(&shape); continue; } } /* start this feature */ - /* specify a feature name, if nothing provided fall back on the layer name + "_feature" */ - value = (char*) msSmallMalloc(strlen(lp->name)+9); + /* specify a feature name, if nothing provided fall back on the layer + * name + "_feature" */ + value = (char *)msSmallMalloc(strlen(lp->name) + 9); sprintf(value, "%s_feature", lp->name); - msOWSPrintValidateMetadata(stream, &(lp->metadata), namespaces, "featurename", OWS_NOERR, "\t\t<%s>\n", value); + msOWSPrintValidateMetadata(stream, &(lp->metadata), namespaces, + "featurename", OWS_NOERR, "\t\t<%s>\n", + value); msFree(value); - /* Write the feature geometry and bounding box unless 'none' was requested. */ - /* Default to bbox only if nothing specified and output full geometry only if explicitly requested */ - if(!(geometryList && geometryList->numgeometries == 1 && strcasecmp(geometryList->geometries[0].name, "none") == 0)) { - gmlWriteBounds(stream, OWS_GML2, &(shape.bounds), pszOutputSRS, "\t\t\t", "gml"); - if (geometryList && geometryList->numgeometries > 0 ) - gmlWriteGeometry(stream, geometryList, OWS_GML2, &(shape), pszOutputSRS, NULL, "\t\t\t", "", nSRSDimension, 6); + /* Write the feature geometry and bounding box unless 'none' was + * requested. */ + /* Default to bbox only if nothing specified and output full geometry + * only if explicitly requested */ + if (!(geometryList && geometryList->numgeometries == 1 && + strcasecmp(geometryList->geometries[0].name, "none") == 0)) { + gmlWriteBounds(stream, OWS_GML2, &(shape.bounds), pszOutputSRS, + "\t\t\t", "gml"); + if (geometryList && geometryList->numgeometries > 0) + gmlWriteGeometry(stream, geometryList, OWS_GML2, &(shape), + pszOutputSRS, NULL, "\t\t\t", "", nSRSDimension, + 6); } /* write any item/values */ - for(k=0; knumitems; k++) { + for (k = 0; k < itemList->numitems; k++) { item = &(itemList->items[k]); - if(msItemInGroups(item->name, groupList) == MS_FALSE) - msGMLWriteItem(stream, item, shape.values[k], NULL, "\t\t\t", OWS_GML2, NULL); + if (msItemInGroups(item->name, groupList) == MS_FALSE) + msGMLWriteItem(stream, item, shape.values[k], NULL, "\t\t\t", + OWS_GML2, NULL); } /* write any constants */ - for(k=0; knumconstants; k++) { + for (k = 0; k < constantList->numconstants; k++) { constant = &(constantList->constants[k]); - if(msItemInGroups(constant->name, groupList) == MS_FALSE) + if (msItemInGroups(constant->name, groupList) == MS_FALSE) msGMLWriteConstant(stream, constant, NULL, "\t\t\t"); } /* write any groups */ - for(k=0; knumgroups; k++) - msGMLWriteGroup(stream, &(groupList->groups[k]), &shape, itemList, constantList, NULL, "\t\t\t", OWS_GML2, NULL); + for (k = 0; k < groupList->numgroups; k++) + msGMLWriteGroup(stream, &(groupList->groups[k]), &shape, itemList, + constantList, NULL, "\t\t\t", OWS_GML2, NULL); /* end this feature */ /* specify a feature name if nothing provided */ /* fall back on the layer name + "Feature" */ - value = (char*) msSmallMalloc(strlen(lp->name)+9); + value = (char *)msSmallMalloc(strlen(lp->name) + 9); sprintf(value, "%s_feature", lp->name); - msOWSPrintValidateMetadata(stream, &(lp->metadata), namespaces, "featurename", OWS_NOERR, "\t\t\n", value); + msOWSPrintValidateMetadata(stream, &(lp->metadata), namespaces, + "featurename", OWS_NOERR, "\t\t\n", + value); msFree(value); msFreeShape(&shape); /* init too */ @@ -1550,9 +1798,10 @@ int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces) /* end this collection (layer) */ /* if no layer name provided fall back on the layer name + "_layer" */ - value = (char*) msSmallMalloc(strlen(lp->name)+7); + value = (char *)msSmallMalloc(strlen(lp->name) + 7); sprintf(value, "%s_layer", lp->name); - msOWSPrintValidateMetadata(stream, &(lp->metadata), namespaces, "layername", OWS_NOERR, "\t\n", value); + msOWSPrintValidateMetadata(stream, &(lp->metadata), namespaces, + "layername", OWS_NOERR, "\t\n", value); msFree(value); msGMLFreeGroups(groupList); @@ -1562,18 +1811,20 @@ int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces) /* msLayerClose(lp); */ } - if(pszOutputSRS!=pszMapSRS) { + if (pszOutputSRS != pszMapSRS) { msFree(pszOutputSRS); } } /* next layer */ /* end this document */ - msOWSPrintValidateMetadata(stream, &(map->web.metadata), namespaces, "rootname", OWS_NOERR, "\n", "msGMLOutput"); + msOWSPrintValidateMetadata(stream, &(map->web.metadata), namespaces, + "rootname", OWS_NOERR, "\n", "msGMLOutput"); - if(stream_to_free != NULL) fclose(stream_to_free); + if (stream_to_free != NULL) + fclose(stream_to_free); msFree(pszMapSRS); - return(MS_SUCCESS); + return (MS_SUCCESS); #else /* Stub for mapscript */ msSetError(MS_MISCERR, "WMS server support not enabled", "msGMLWriteQuery()"); @@ -1583,39 +1834,37 @@ int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces) #ifdef USE_WFS_SVR void msGMLWriteWFSBounds(mapObj *map, FILE *stream, const char *tab, - OWSGMLVersion outputformat, int nWFSVersion, int bUseURN) -{ - rectObj resultBounds = {-1.0,-1.0,-1.0,-1.0}; + OWSGMLVersion outputformat, int nWFSVersion, + int bUseURN) { + rectObj resultBounds = {-1.0, -1.0, -1.0, -1.0}; /*add a check to see if the map projection is set to be north-east*/ int bSwapAxis = msIsAxisInvertedProj(&(map->projection)); /* Need to start with BBOX of the whole resultset */ if (msGetQueryResultBounds(map, &resultBounds) > 0) { - char* srs = NULL; + char *srs = NULL; if (bSwapAxis) { double tmp; tmp = resultBounds.minx; - resultBounds.minx = resultBounds.miny; + resultBounds.minx = resultBounds.miny; resultBounds.miny = tmp; tmp = resultBounds.maxx; - resultBounds.maxx = resultBounds.maxy; + resultBounds.maxx = resultBounds.maxy; resultBounds.maxy = tmp; - - } - if( bUseURN ) - { - srs = msOWSGetProjURN(&(map->projection), NULL, "FGO", MS_TRUE); - if (!srs) - srs = msOWSGetProjURN(&(map->projection), &(map->web.metadata), "FGO", MS_TRUE); } - else - { - msOWSGetEPSGProj(&(map->projection), NULL, "FGO", MS_TRUE, &srs); - if (!srs) - msOWSGetEPSGProj(&(map->projection), &(map->web.metadata), "FGO", MS_TRUE, &srs); + if (bUseURN) { + srs = msOWSGetProjURN(&(map->projection), NULL, "FGO", MS_TRUE); + if (!srs) + srs = msOWSGetProjURN(&(map->projection), &(map->web.metadata), "FGO", + MS_TRUE); + } else { + msOWSGetEPSGProj(&(map->projection), NULL, "FGO", MS_TRUE, &srs); + if (!srs) + msOWSGetEPSGProj(&(map->projection), &(map->web.metadata), "FGO", + MS_TRUE, &srs); } gmlWriteBounds(stream, outputformat, &resultBounds, srs, tab, @@ -1631,24 +1880,24 @@ void msGMLWriteWFSBounds(mapObj *map, FILE *stream, const char *tab, ** ** Similar to msGMLWriteQuery() but tuned for use with WFS */ -int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_prefix, +int msGMLWriteWFSQuery(mapObj *map, FILE *stream, + const char *default_namespace_prefix, OWSGMLVersion outputformat, int nWFSVersion, int bUseURN, - int bGetPropertyValueRequest) -{ + int bGetPropertyValueRequest) { #ifdef USE_WFS_SVR int status; - int i,j,k; - layerObj *lp=NULL; + int i, j, k; + layerObj *lp = NULL; shapeObj shape; - gmlGroupListObj *groupList=NULL; - gmlItemListObj *itemList=NULL; - gmlConstantListObj *constantList=NULL; - gmlGeometryListObj *geometryList=NULL; - gmlItemObj *item=NULL; - gmlConstantObj *constant=NULL; + gmlGroupListObj *groupList = NULL; + gmlItemListObj *itemList = NULL; + gmlConstantListObj *constantList = NULL; + gmlGeometryListObj *geometryList = NULL; + gmlItemObj *item = NULL; + gmlConstantObj *constant = NULL; - const char *namespace_prefix=NULL; + const char *namespace_prefix = NULL; int bSwapAxis; msInitShape(&shape); @@ -1658,218 +1907,240 @@ int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_ /* Need to start with BBOX of the whole resultset */ if (!bGetPropertyValueRequest) { - msGMLWriteWFSBounds(map, stream, " ", outputformat, nWFSVersion, bUseURN); + msGMLWriteWFSBounds(map, stream, " ", outputformat, nWFSVersion, + bUseURN); } /* step through the layers looking for query results */ - for(i=0; inumlayers; i++) { + for (i = 0; i < map->numlayers; i++) { lp = GET_LAYER(map, map->layerorder[i]); - if(lp->resultcache && lp->resultcache->numresults > 0) { /* found results */ + if (lp->resultcache && + lp->resultcache->numresults > 0) { /* found results */ char *layerName; const char *value; - int featureIdIndex=-1; /* no feature id */ - char* srs = NULL; + int featureIdIndex = -1; /* no feature id */ + char *srs = NULL; int bOutputGMLIdOnly = MS_FALSE; int nSRSDimension = 2; - const char* geomtype; - reprojectionObj* reprojector = NULL; + const char *geomtype; + reprojectionObj *reprojector = NULL; int geometry_precision = 6; /* setup namespace, a layer can override the default */ - namespace_prefix = msOWSLookupMetadata(&(lp->metadata), "OFG", "namespace_prefix"); - if(!namespace_prefix) namespace_prefix = default_namespace_prefix; + namespace_prefix = + msOWSLookupMetadata(&(lp->metadata), "OFG", "namespace_prefix"); + if (!namespace_prefix) + namespace_prefix = default_namespace_prefix; geomtype = msOWSLookupMetadata(&(lp->metadata), "OFG", "geomtype"); - if( geomtype != NULL && (strstr(geomtype, "25d") != NULL || strstr(geomtype, "25D") != NULL) ) - { - nSRSDimension = 3; + if (geomtype != NULL && (strstr(geomtype, "25d") != NULL || + strstr(geomtype, "25D") != NULL)) { + nSRSDimension = 3; } value = msOWSLookupMetadata(&(lp->metadata), "OFG", "featureid"); - if(value) { /* find the featureid amongst the items for this layer */ - for(j=0; jnumitems; j++) { - if(strcasecmp(lp->items[j], value) == 0) { /* found it */ + if (value) { /* find the featureid amongst the items for this layer */ + for (j = 0; j < lp->numitems; j++) { + if (strcasecmp(lp->items[j], value) == 0) { /* found it */ featureIdIndex = j; break; } } - /* Produce a warning if a featureid was set but the corresponding item is not found. */ + /* Produce a warning if a featureid was set but the corresponding item + * is not found. */ if (featureIdIndex == -1) - msIO_fprintf(stream, "\n", value, lp->name); - } - else if( outputformat == OWS_GML32 ) - msIO_fprintf(stream, "\n", lp->name); + msIO_fprintf(stream, + "\n", + value, lp->name); + } else if (outputformat == OWS_GML32) + msIO_fprintf(stream, + "\n", + lp->name); /* populate item and group metadata structures */ itemList = msGMLGetItems(lp, "G"); constantList = msGMLGetConstants(lp, "G"); groupList = msGMLGetGroups(lp, "G"); geometryList = msGMLGetGeometries(lp, "GFO", MS_FALSE); - if (itemList == NULL || constantList == NULL || groupList == NULL || geometryList == NULL) { - msSetError(MS_MISCERR, "Unable to populate item and group metadata structures", "msGMLWriteWFSQuery()"); + if (itemList == NULL || constantList == NULL || groupList == NULL || + geometryList == NULL) { + msSetError(MS_MISCERR, + "Unable to populate item and group metadata structures", + "msGMLWriteWFSQuery()"); return MS_FAILURE; } - if( bGetPropertyValueRequest ) - { - const char* value = msOWSLookupMetadata(&(lp->metadata), "G", "include_items"); - if( value != NULL && strcmp(value, "@gml:id") == 0 ) - bOutputGMLIdOnly = MS_TRUE; + if (bGetPropertyValueRequest) { + const char *value = + msOWSLookupMetadata(&(lp->metadata), "G", "include_items"); + if (value != NULL && strcmp(value, "@gml:id") == 0) + bOutputGMLIdOnly = MS_TRUE; } if (namespace_prefix) { - layerName = (char *) msSmallMalloc(strlen(namespace_prefix)+strlen(lp->name)+2); + layerName = (char *)msSmallMalloc(strlen(namespace_prefix) + + strlen(lp->name) + 2); sprintf(layerName, "%s:%s", namespace_prefix, lp->name); } else { layerName = msStrdup(lp->name); } - if( bUseURN ) - { - srs = msOWSGetProjURN(&(map->projection), NULL, "FGO", MS_TRUE); - if (!srs) - srs = msOWSGetProjURN(&(map->projection), &(map->web.metadata), "FGO", MS_TRUE); - if (!srs) - srs = msOWSGetProjURN(&(lp->projection), &(lp->metadata), "FGO", MS_TRUE); - } - else - { - msOWSGetEPSGProj(&(map->projection), NULL, "FGO", MS_TRUE, &srs); - if (!srs) - msOWSGetEPSGProj(&(map->projection), &(map->web.metadata), "FGO", MS_TRUE, &srs); - if (!srs) - msOWSGetEPSGProj(&(lp->projection), &(lp->metadata), "FGO", MS_TRUE, &srs); + if (bUseURN) { + srs = msOWSGetProjURN(&(map->projection), NULL, "FGO", MS_TRUE); + if (!srs) + srs = msOWSGetProjURN(&(map->projection), &(map->web.metadata), "FGO", + MS_TRUE); + if (!srs) + srs = msOWSGetProjURN(&(lp->projection), &(lp->metadata), "FGO", + MS_TRUE); + } else { + msOWSGetEPSGProj(&(map->projection), NULL, "FGO", MS_TRUE, &srs); + if (!srs) + msOWSGetEPSGProj(&(map->projection), &(map->web.metadata), "FGO", + MS_TRUE, &srs); + if (!srs) + msOWSGetEPSGProj(&(lp->projection), &(lp->metadata), "FGO", MS_TRUE, + &srs); } - if(msProjectionsDiffer(&(lp->projection), &(map->projection))) { - reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection)); - if( reprojector == NULL ) { - msGMLFreeGroups(groupList); - msGMLFreeConstants(constantList); - msGMLFreeItems(itemList); - msGMLFreeGeometries(geometryList); - msFree(layerName); - msFree(srs); - return MS_FAILURE; + if (msProjectionsDiffer(&(lp->projection), &(map->projection))) { + reprojector = + msProjectCreateReprojector(&(lp->projection), &(map->projection)); + if (reprojector == NULL) { + msGMLFreeGroups(groupList); + msGMLFreeConstants(constantList); + msGMLFreeItems(itemList); + msGMLFreeGeometries(geometryList); + msFree(layerName); + msFree(srs); + return MS_FAILURE; } } - for(j=0; jresultcache->numresults; j++) { - char* pszFID; + for (j = 0; j < lp->resultcache->numresults; j++) { + char *pszFID; - if( lp->resultcache->results[j].shape ) - { - /* msDebug("Using cached shape %ld\n", lp->resultcache->results[j].shapeindex); */ - msCopyShape(lp->resultcache->results[j].shape, &shape); - } - else - { - status = msLayerGetShape(lp, &shape, &(lp->resultcache->results[j])); - if(status != MS_SUCCESS) { - msGMLFreeGroups(groupList); - msGMLFreeConstants(constantList); - msGMLFreeItems(itemList); - msGMLFreeGeometries(geometryList); - msFree(layerName); - msProjectDestroyReprojector(reprojector); - msFree(srs); - return(status); - } + if (lp->resultcache->results[j].shape) { + /* msDebug("Using cached shape %ld\n", + * lp->resultcache->results[j].shapeindex); */ + msCopyShape(lp->resultcache->results[j].shape, &shape); + } else { + status = msLayerGetShape(lp, &shape, &(lp->resultcache->results[j])); + if (status != MS_SUCCESS) { + msGMLFreeGroups(groupList); + msGMLFreeConstants(constantList); + msGMLFreeItems(itemList); + msGMLFreeGeometries(geometryList); + msFree(layerName); + msProjectDestroyReprojector(reprojector); + msFree(srs); + return (status); + } } - /* project the shape into the map projection (if necessary), note that this projects the bounds as well */ - if(reprojector) + /* project the shape into the map projection (if necessary), note that + * this projects the bounds as well */ + if (reprojector) msProjectShapeEx(reprojector, &shape); - if(featureIdIndex != -1) { - pszFID = (char*) msSmallMalloc( strlen(lp->name) + 1 + strlen(shape.values[featureIdIndex]) + 1 ); - sprintf(pszFID, "%s.%s", lp->name, shape.values[featureIdIndex]); - } - else - pszFID = msStrdup(""); - - - if( bOutputGMLIdOnly ) - { - msIO_fprintf(stream, " %s\n", pszFID); - msFree(pszFID); - msFreeShape(&shape); /* init too */ - continue; + if (featureIdIndex != -1) { + pszFID = (char *)msSmallMalloc( + strlen(lp->name) + 1 + strlen(shape.values[featureIdIndex]) + 1); + sprintf(pszFID, "%s.%s", lp->name, shape.values[featureIdIndex]); + } else + pszFID = msStrdup(""); + + if (bOutputGMLIdOnly) { + msIO_fprintf(stream, " %s\n", pszFID); + msFree(pszFID); + msFreeShape(&shape); /* init too */ + continue; } /* ** start this feature */ - if( nWFSVersion == OWS_2_0_0 ) - msIO_fprintf(stream, " \n"); + if (nWFSVersion == OWS_2_0_0) + msIO_fprintf(stream, " \n"); else - msIO_fprintf(stream, " \n"); - if(msIsXMLTagValid(layerName) == MS_FALSE) - msIO_fprintf(stream, "\n", layerName); - if(featureIdIndex != -1) { - if( !bGetPropertyValueRequest ) - { - if(outputformat == OWS_GML2) - msIO_fprintf(stream, " <%s fid=\"%s\">\n", layerName, pszFID); - else /* OWS_GML3 or OWS_GML32 */ - msIO_fprintf(stream, " <%s gml:id=\"%s\">\n", layerName, pszFID); - } + msIO_fprintf(stream, " \n"); + if (msIsXMLTagValid(layerName) == MS_FALSE) + msIO_fprintf(stream, + "\n", + layerName); + if (featureIdIndex != -1) { + if (!bGetPropertyValueRequest) { + if (outputformat == OWS_GML2) + msIO_fprintf(stream, " <%s fid=\"%s\">\n", layerName, + pszFID); + else /* OWS_GML3 or OWS_GML32 */ + msIO_fprintf(stream, " <%s gml:id=\"%s\">\n", layerName, + pszFID); + } } else { - if( !bGetPropertyValueRequest ) - msIO_fprintf(stream, " <%s>\n", layerName); + if (!bGetPropertyValueRequest) + msIO_fprintf(stream, " <%s>\n", layerName); } if (bSwapAxis) msAxisSwapShape(&shape); /* write the feature geometry and bounding box */ - if(!(geometryList && geometryList->numgeometries == 1 && - strcasecmp(geometryList->geometries[0].name, "none") == 0)) { - if( !bGetPropertyValueRequest ) - gmlWriteBounds(stream, outputformat, &(shape.bounds), srs, " ", "gml"); - - if(msOWSLookupMetadata(&(lp->metadata), "F", "geometry_precision")){ - geometry_precision=atoi(msOWSLookupMetadata(&(lp->metadata), "F", "geometry_precision")); - } else if(msOWSLookupMetadata(&map->web.metadata, "F", "geometry_precision")){ - geometry_precision=atoi(msOWSLookupMetadata(&map->web.metadata, "F", "geometry_precision")); + if (!(geometryList && geometryList->numgeometries == 1 && + strcasecmp(geometryList->geometries[0].name, "none") == 0)) { + if (!bGetPropertyValueRequest) + gmlWriteBounds(stream, outputformat, &(shape.bounds), srs, + " ", "gml"); + + if (msOWSLookupMetadata(&(lp->metadata), "F", "geometry_precision")) { + geometry_precision = atoi(msOWSLookupMetadata( + &(lp->metadata), "F", "geometry_precision")); + } else if (msOWSLookupMetadata(&map->web.metadata, "F", + "geometry_precision")) { + geometry_precision = atoi(msOWSLookupMetadata( + &map->web.metadata, "F", "geometry_precision")); } gmlWriteGeometry(stream, geometryList, outputformat, &(shape), srs, - namespace_prefix, " ", pszFID, nSRSDimension,geometry_precision); + namespace_prefix, " ", pszFID, nSRSDimension, + geometry_precision); } /* write any item/values */ - for(k=0; knumitems; k++) { + for (k = 0; k < itemList->numitems; k++) { item = &(itemList->items[k]); - if(msItemInGroups(item->name, groupList) == MS_FALSE) + if (msItemInGroups(item->name, groupList) == MS_FALSE) msGMLWriteItem(stream, item, shape.values[k], namespace_prefix, " ", outputformat, pszFID); } /* write any constants */ - for(k=0; knumconstants; k++) { + for (k = 0; k < constantList->numconstants; k++) { constant = &(constantList->constants[k]); - if(msItemInGroups(constant->name, groupList) == MS_FALSE) + if (msItemInGroups(constant->name, groupList) == MS_FALSE) msGMLWriteConstant(stream, constant, namespace_prefix, " "); } /* write any groups */ - for(k=0; knumgroups; k++) + for (k = 0; k < groupList->numgroups; k++) msGMLWriteGroup(stream, &(groupList->groups[k]), &shape, itemList, - constantList, namespace_prefix, " ", outputformat, pszFID); + constantList, namespace_prefix, " ", + outputformat, pszFID); - if( !bGetPropertyValueRequest ) - /* end this feature */ - msIO_fprintf(stream, " \n", layerName); + if (!bGetPropertyValueRequest) + /* end this feature */ + msIO_fprintf(stream, " \n", layerName); - if( nWFSVersion == OWS_2_0_0 ) + if (nWFSVersion == OWS_2_0_0) msIO_fprintf(stream, " \n"); else msIO_fprintf(stream, " \n"); - msFree(pszFID); pszFID = NULL; msFreeShape(&shape); /* init too */ @@ -1892,15 +2163,15 @@ int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_ } /* next layer */ - return(MS_SUCCESS); + return (MS_SUCCESS); -#else /* Stub for mapscript */ - msSetError(MS_MISCERR, "WFS server support not enabled", "msGMLWriteWFSQuery()"); +#else /* Stub for mapscript */ + msSetError(MS_MISCERR, "WFS server support not enabled", + "msGMLWriteWFSQuery()"); return MS_FAILURE; #endif /* USE_WFS_SVR */ } - #ifdef USE_LIBXML2 /** @@ -1920,8 +2191,8 @@ int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_ * */ -xmlNodePtr msGML3BoundedBy(xmlNsPtr psNs, double minx, double miny, double maxx, double maxy, const char *psEpsg) -{ +xmlNodePtr msGML3BoundedBy(xmlNsPtr psNs, double minx, double miny, double maxx, + double maxy, const char *psEpsg) { xmlNodePtr psNode = NULL, psSubNode = NULL; char *pszTmp = NULL; char *pszTmp2 = NULL; @@ -1931,8 +2202,8 @@ xmlNodePtr msGML3BoundedBy(xmlNsPtr psNs, double minx, double miny, double maxx, psSubNode = xmlNewChild(psNode, NULL, BAD_CAST "Envelope", NULL); if (psEpsg) { - const size_t bufferSize = strlen(psEpsg)+1; - pszEpsg = (char*) msSmallMalloc(bufferSize); + const size_t bufferSize = strlen(psEpsg) + 1; + pszEpsg = (char *)msSmallMalloc(bufferSize); snprintf(pszEpsg, bufferSize, "%s", psEpsg); msStringToLower(pszEpsg); pszTmp = msStringConcatenate(pszTmp, "urn:ogc:crs:"); @@ -1955,7 +2226,7 @@ xmlNodePtr msGML3BoundedBy(xmlNsPtr psNs, double minx, double miny, double maxx, pszTmp = msDoubleToString(maxx, MS_TRUE); pszTmp = msStringConcatenate(pszTmp, " "); - pszTmp2 = msDoubleToString(maxy,MS_TRUE); + pszTmp2 = msDoubleToString(maxy, MS_TRUE); pszTmp = msStringConcatenate(pszTmp, pszTmp2); xmlNewChild(psSubNode, NULL, BAD_CAST "upperCorner", BAD_CAST pszTmp); free(pszTmp); @@ -1979,9 +2250,9 @@ xmlNodePtr msGML3BoundedBy(xmlNsPtr psNs, double minx, double miny, double maxx, * */ -xmlNodePtr msGML3Point(xmlNsPtr psNs, const char *psSrsName, const char *id, double x, double y) -{ - +xmlNodePtr msGML3Point(xmlNsPtr psNs, const char *psSrsName, const char *id, + double x, double y) { + xmlNodePtr psNode = xmlNewNode(psNs, BAD_CAST "Point"); if (id) { @@ -1989,8 +2260,8 @@ xmlNodePtr msGML3Point(xmlNsPtr psNs, const char *psSrsName, const char *id, dou } if (psSrsName) { - const size_t bufferSize = strlen(psSrsName)+1; - char* pszSrsName = (char *) msSmallMalloc(bufferSize); + const size_t bufferSize = strlen(psSrsName) + 1; + char *pszSrsName = (char *)msSmallMalloc(bufferSize); snprintf(pszSrsName, bufferSize, "%s", psSrsName); msStringToLower(pszSrsName); char *pszTmp = NULL; @@ -2005,9 +2276,9 @@ xmlNodePtr msGML3Point(xmlNsPtr psNs, const char *psSrsName, const char *id, dou free(pszTmp); } - char* pszTmp = msDoubleToString(x, MS_TRUE); + char *pszTmp = msDoubleToString(x, MS_TRUE); pszTmp = msStringConcatenate(pszTmp, " "); - char* pszTmp2 = msDoubleToString(y, MS_TRUE); + char *pszTmp2 = msDoubleToString(y, MS_TRUE); pszTmp = msStringConcatenate(pszTmp, pszTmp2); xmlNewChild(psNode, NULL, BAD_CAST "pos", BAD_CAST pszTmp); @@ -2029,9 +2300,8 @@ xmlNodePtr msGML3Point(xmlNsPtr psNs, const char *psSrsName, const char *id, dou * */ -xmlNodePtr msGML3TimePeriod(xmlNsPtr psNs, char *pszStart, char *pszEnd) -{ - xmlNodePtr psNode=NULL; +xmlNodePtr msGML3TimePeriod(xmlNsPtr psNs, char *pszStart, char *pszEnd) { + xmlNodePtr psNode = NULL; psNode = xmlNewNode(psNs, BAD_CAST "TimePeriod"); xmlNewChild(psNode, NULL, BAD_CAST "beginPosition", BAD_CAST pszStart); @@ -2056,9 +2326,8 @@ xmlNodePtr msGML3TimePeriod(xmlNsPtr psNs, char *pszStart, char *pszEnd) * */ -xmlNodePtr msGML3TimeInstant(xmlNsPtr psNs, char *pszTime) -{ - xmlNodePtr psNode=NULL; +xmlNodePtr msGML3TimeInstant(xmlNsPtr psNs, char *pszTime) { + xmlNodePtr psNode = NULL; psNode = xmlNewNode(psNs, BAD_CAST "TimeInstant"); xmlNewChild(psNode, NULL, BAD_CAST "timePosition", BAD_CAST pszTime); @@ -2067,83 +2336,93 @@ xmlNodePtr msGML3TimeInstant(xmlNsPtr psNs, char *pszTime) #endif /* USE_LIBXML2 */ - /************************************************************************/ /* The following functions are enabled in all cases, even if */ /* WMS and WFS are not available. */ /************************************************************************/ -gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces) -{ - int i,j; +gmlItemListObj *msGMLGetItems(layerObj *layer, + const char *metadata_namespaces) { + int i, j; - char **xmlitems=NULL; - int numxmlitems=0; + char **xmlitems = NULL; + int numxmlitems = 0; - char **incitems=NULL; - int numincitems=0; + char **incitems = NULL; + int numincitems = 0; - char **excitems=NULL; - int numexcitems=0; + char **excitems = NULL; + int numexcitems = 0; - char **optionalitems=NULL; - int numoptionalitems=0; + char **optionalitems = NULL; + int numoptionalitems = 0; - char **mandatoryitems=NULL; - int nummandatoryitems=0; + char **mandatoryitems = NULL; + int nummandatoryitems = 0; - char **defaultitems=NULL; - int numdefaultitems=0; + char **defaultitems = NULL; + int numdefaultitems = 0; - const char *value=NULL; + const char *value = NULL; char tag[64]; - gmlItemListObj *itemList=NULL; - gmlItemObj *item=NULL; + gmlItemListObj *itemList = NULL; + gmlItemObj *item = NULL; /* get a list of items that might be included in output */ - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "include_items")) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + "include_items")) != NULL) incitems = msStringSplit(value, ',', &numincitems); /* get a list of items that should be excluded in output */ - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "exclude_items")) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + "exclude_items")) != NULL) excitems = msStringSplit(value, ',', &numexcitems); /* get a list of items that should not be XML encoded */ - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "xml_items")) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + "xml_items")) != NULL) xmlitems = msStringSplit(value, ',', &numxmlitems); - /* get a list of items that should be indicated as optional in DescribeFeatureType */ - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "optional_items")) != NULL) + /* get a list of items that should be indicated as optional in + * DescribeFeatureType */ + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + "optional_items")) != NULL) optionalitems = msStringSplit(value, ',', &numoptionalitems); - /* get a list of items that should be indicated as mandatory in DescribeFeatureType */ - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "mandatory_items")) != NULL) + /* get a list of items that should be indicated as mandatory in + * DescribeFeatureType */ + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + "mandatory_items")) != NULL) mandatoryitems = msStringSplit(value, ',', &nummandatoryitems); /* get a list of items that should be presented by default in GetFeature */ - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, "default_items")) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + "default_items")) != NULL) defaultitems = msStringSplit(value, ',', &numdefaultitems); /* allocate memory and iinitialize the item collection */ - itemList = (gmlItemListObj *) malloc(sizeof(gmlItemListObj)); - if(itemList == NULL) { - msSetError(MS_MEMERR, "Error allocating a collection GML item structures.", "msGMLGetItems()"); + itemList = (gmlItemListObj *)malloc(sizeof(gmlItemListObj)); + if (itemList == NULL) { + msSetError(MS_MEMERR, "Error allocating a collection GML item structures.", + "msGMLGetItems()"); return NULL; } itemList->numitems = layer->numitems; - itemList->items = (gmlItemObj *) malloc(sizeof(gmlItemObj)*itemList->numitems); - if(!itemList->items) { - msSetError(MS_MEMERR, "Error allocating a collection GML item structures.", "msGMLGetItems()"); + itemList->items = + (gmlItemObj *)malloc(sizeof(gmlItemObj) * itemList->numitems); + if (!itemList->items) { + msSetError(MS_MEMERR, "Error allocating a collection GML item structures.", + "msGMLGetItems()"); free(itemList); return NULL; } - for(i=0; inumitems; i++) { + for (i = 0; i < layer->numitems; i++) { item = &(itemList->items[i]); - item->name = msStrdup(layer->items[i]); /* initialize the item */ + item->name = msStrdup(layer->items[i]); /* initialize the item */ item->alias = NULL; item->type = NULL; item->template = NULL; @@ -2155,73 +2434,78 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces) item->minOccurs = 0; /* check visibility, included items first... */ - if(numincitems == 1 && strcasecmp("all", incitems[0]) == 0) { + if (numincitems == 1 && strcasecmp("all", incitems[0]) == 0) { item->visible = MS_TRUE; } else { - for(j=0; jitems[i], incitems[j]) == 0) + for (j = 0; j < numincitems; j++) { + if (strcasecmp(layer->items[i], incitems[j]) == 0) item->visible = MS_TRUE; } } /* ...and now excluded items */ - for(j=0; jitems[i], excitems[j]) == 0) + for (j = 0; j < numexcitems; j++) { + if (strcasecmp(layer->items[i], excitems[j]) == 0) item->visible = MS_FALSE; } /* check encoding */ - for(j=0; jitems[i], xmlitems[j]) == 0) + for (j = 0; j < numxmlitems; j++) { + if (strcasecmp(layer->items[i], xmlitems[j]) == 0) item->encode = MS_FALSE; } /* check optional */ - if(numoptionalitems == 1 && strcasecmp("all", optionalitems[0]) == 0) { + if (numoptionalitems == 1 && strcasecmp("all", optionalitems[0]) == 0) { item->minOccurs = 0; - } else if( numoptionalitems > 0) { + } else if (numoptionalitems > 0) { item->minOccurs = 1; - for(j=0; jitems[i], optionalitems[j]) == 0) + for (j = 0; j < numoptionalitems; j++) { + if (strcasecmp(layer->items[i], optionalitems[j]) == 0) item->minOccurs = 0; } } /* check mandatory */ - if(nummandatoryitems == 1 && strcasecmp("all", mandatoryitems[0]) == 0) { + if (nummandatoryitems == 1 && strcasecmp("all", mandatoryitems[0]) == 0) { item->minOccurs = 1; - } else if( nummandatoryitems > 0) { + } else if (nummandatoryitems > 0) { item->minOccurs = 0; - for(j=0; jitems[i], mandatoryitems[j]) == 0) + for (j = 0; j < nummandatoryitems; j++) { + if (strcasecmp(layer->items[i], mandatoryitems[j]) == 0) item->minOccurs = 1; } } /* check default */ - for(j=0; jitems[i], defaultitems[j]) == 0) + for (j = 0; j < numdefaultitems; j++) { + if (strcasecmp(layer->items[i], defaultitems[j]) == 0) item->outputByDefault = 1; } snprintf(tag, sizeof(tag), "%s_alias", layer->items[i]); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) item->alias = msStrdup(value); snprintf(tag, sizeof(tag), "%s_type", layer->items[i]); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) item->type = msStrdup(value); snprintf(tag, sizeof(tag), "%s_template", layer->items[i]); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) item->template = msStrdup(value); snprintf(tag, sizeof(tag), "%s_width", layer->items[i]); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) item->width = atoi(value); snprintf(tag, sizeof(tag), "%s_precision", layer->items[i]); - if((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, tag)) != NULL) + if ((value = msOWSLookupMetadata(&(layer->metadata), metadata_namespaces, + tag)) != NULL) item->precision = atoi(value); } @@ -2235,20 +2519,20 @@ gmlItemListObj *msGMLGetItems(layerObj *layer, const char *metadata_namespaces) return itemList; } -void msGMLFreeItems(gmlItemListObj *itemList) -{ +void msGMLFreeItems(gmlItemListObj *itemList) { int i; - if(!itemList) return; + if (!itemList) + return; - for(i=0; inumitems; i++) { + for (i = 0; i < itemList->numitems; i++) { msFree(itemList->items[i].name); msFree(itemList->items[i].alias); msFree(itemList->items[i].type); msFree(itemList->items[i].template); } - if( itemList->items != NULL ) + if (itemList->items != NULL) free(itemList->items); free(itemList); diff --git a/mapgml.h b/mapgml.h index 1bff8db780..c5cebd83d9 100644 --- a/mapgml.h +++ b/mapgml.h @@ -28,18 +28,19 @@ * DEALINGS IN THE SOFTWARE. ****************************************************************************/ - #ifndef MAPGML_H #define MAPGML_H #ifdef USE_LIBXML2 -#include -#include +#include +#include -xmlNodePtr msGML3BoundedBy(xmlNsPtr psNs, double minx, double miny, double maxx, double maxy, const char *psEpsg); +xmlNodePtr msGML3BoundedBy(xmlNsPtr psNs, double minx, double miny, double maxx, + double maxy, const char *psEpsg); xmlNodePtr msGML3TimePeriod(xmlNsPtr psNs, char *pszStart, char *pszEnd); xmlNodePtr msGML3TimeInstant(xmlNsPtr psNs, char *timeInstant); -xmlNodePtr msGML3Point(xmlNsPtr psNs, const char *psSrsName, const char *id, double x, double y); +xmlNodePtr msGML3Point(xmlNsPtr psNs, const char *psSrsName, const char *id, + double x, double y); #endif /* USE_LIBXML2 */ diff --git a/mapgraph.cpp b/mapgraph.cpp index 0601081649..e578bd951b 100644 --- a/mapgraph.cpp +++ b/mapgraph.cpp @@ -31,17 +31,18 @@ #include "mapgraph.h" #include // for std::swap -graphObj *msCreateGraph(signed int numnodes) -{ - graphObj *graph=nullptr; +graphObj *msCreateGraph(signed int numnodes) { + graphObj *graph = nullptr; - if(numnodes <= 0) return nullptr; + if (numnodes <= 0) + return nullptr; - graph = (graphObj *) malloc(sizeof(graphObj)); - if(!graph) return nullptr; + graph = (graphObj *)malloc(sizeof(graphObj)); + if (!graph) + return nullptr; - graph->head = (graphNodeObj **) calloc(numnodes, sizeof(graphNodeObj*)); - if(!graph->head) { + graph->head = (graphNodeObj **)calloc(numnodes, sizeof(graphNodeObj *)); + if (!graph->head) { free(graph); return nullptr; } @@ -50,14 +51,14 @@ graphObj *msCreateGraph(signed int numnodes) return graph; } -void msFreeGraph(graphObj *graph) -{ - if(!graph) return; +void msFreeGraph(graphObj *graph) { + if (!graph) + return; - graphNodeObj *tmp=nullptr; - - for(int i=0; inumnodes; i++) { - while(graph->head[i] != nullptr) { + graphNodeObj *tmp = nullptr; + + for (int i = 0; i < graph->numnodes; i++) { + while (graph->head[i] != nullptr) { tmp = graph->head[i]; graph->head[i] = graph->head[i]->next; free(tmp); @@ -68,15 +69,16 @@ void msFreeGraph(graphObj *graph) free(graph); } -int msGraphAddEdge(graphObj *graph, int src, int dest, double weight) -{ - graphNodeObj *node=nullptr; +int msGraphAddEdge(graphObj *graph, int src, int dest, double weight) { + graphNodeObj *node = nullptr; - if(!graph) return MS_FAILURE; + if (!graph) + return MS_FAILURE; // src -> dest - node = (graphNodeObj *) malloc(sizeof(graphNodeObj)); - if(!node) return MS_FAILURE; + node = (graphNodeObj *)malloc(sizeof(graphNodeObj)); + if (!node) + return MS_FAILURE; node->dest = dest; node->weight = weight; @@ -84,8 +86,9 @@ int msGraphAddEdge(graphObj *graph, int src, int dest, double weight) graph->head[src] = node; // dest -> src - node = (graphNodeObj *) malloc(sizeof(graphNodeObj)); - if(!node) return MS_FAILURE; + node = (graphNodeObj *)malloc(sizeof(graphNodeObj)); + if (!node) + return MS_FAILURE; node->dest = src; node->weight = weight; @@ -95,15 +98,15 @@ int msGraphAddEdge(graphObj *graph, int src, int dest, double weight) return MS_SUCCESS; } -void msPrintGraph(graphObj *graph) -{ +void msPrintGraph(graphObj *graph) { int i; - if(!graph) return; + if (!graph) + return; - for(i=0; inumnodes; i++) { + for (i = 0; i < graph->numnodes; i++) { graphNodeObj *node = graph->head[i]; - if(node != nullptr) { + if (node != nullptr) { do { msDebug("%d -> %d (%.6f)\t", i, node->dest, node->weight); node = node->next; @@ -116,7 +119,8 @@ void msPrintGraph(graphObj *graph) /* ** Derived from an number web resources including: ** -** https://www.geeksforgeeks.org/dijkstras-algorithm-for-adjacency-list-representation-greedy-algo-8/ +** +*https://www.geeksforgeeks.org/dijkstras-algorithm-for-adjacency-list-representation-greedy-algo-8/ ** https://youtube.com/watch?v=pSqmAO-m7Lk ** https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm ** @@ -135,41 +139,42 @@ typedef struct { minHeapNodeObj **nodes; } minHeapObj; -static minHeapNodeObj *newMinHeapNode(int idx, double dist) -{ - minHeapNodeObj *node = (minHeapNodeObj *) malloc(sizeof(minHeapNodeObj)); - if(!node) return nullptr; +static minHeapNodeObj *newMinHeapNode(int idx, double dist) { + minHeapNodeObj *node = (minHeapNodeObj *)malloc(sizeof(minHeapNodeObj)); + if (!node) + return nullptr; node->idx = idx; node->dist = dist; return node; } -static void freeMinHeap(minHeapObj *minHeap) -{ - if(!minHeap) return; +static void freeMinHeap(minHeapObj *minHeap) { + if (!minHeap) + return; free(minHeap->pos); - for(int i=0; isize; i++) { + for (int i = 0; i < minHeap->size; i++) { free(minHeap->nodes[i]); } free(minHeap->nodes); free(minHeap); } -static minHeapObj *createMinHeap(signed int capacity) -{ - minHeapObj *minHeap = (minHeapObj *) malloc(sizeof(minHeapObj)); - if(!minHeap) return nullptr; +static minHeapObj *createMinHeap(signed int capacity) { + minHeapObj *minHeap = (minHeapObj *)malloc(sizeof(minHeapObj)); + if (!minHeap) + return nullptr; - minHeap->pos = (int *) malloc(capacity * sizeof(int)); - if(!minHeap->pos) { + minHeap->pos = (int *)malloc(capacity * sizeof(int)); + if (!minHeap->pos) { free(minHeap); return nullptr; } minHeap->size = 0; minHeap->capacity = capacity; - minHeap->nodes = (minHeapNodeObj **) malloc(capacity * sizeof(minHeapNodeObj *)); - if(!minHeap->nodes) { + minHeap->nodes = + (minHeapNodeObj **)malloc(capacity * sizeof(minHeapNodeObj *)); + if (!minHeap->nodes) { free(minHeap->pos); free(minHeap); return nullptr; @@ -177,79 +182,75 @@ static minHeapObj *createMinHeap(signed int capacity) return minHeap; } -static void minHeapify(minHeapObj *minHeap, int idx) -{ +static void minHeapify(minHeapObj *minHeap, int idx) { int smallest = idx; - const int left = 2*idx + 1; - const int right = 2*idx + 2; - - if (left < minHeap->size && minHeap->nodes[left]->dist < minHeap->nodes[smallest]->dist) + const int left = 2 * idx + 1; + const int right = 2 * idx + 2; + + if (left < minHeap->size && + minHeap->nodes[left]->dist < minHeap->nodes[smallest]->dist) smallest = left; - - if (right < minHeap->size && minHeap->nodes[right]->dist < minHeap->nodes[smallest]->dist) + + if (right < minHeap->size && + minHeap->nodes[right]->dist < minHeap->nodes[smallest]->dist) smallest = right; - + if (smallest != idx) { minHeapNodeObj *smallestNode = minHeap->nodes[smallest]; minHeapNodeObj *idxNode = minHeap->nodes[idx]; - + minHeap->pos[smallestNode->idx] = idx; // swap positions minHeap->pos[idxNode->idx] = smallest; - + std::swap(minHeap->nodes[smallest], minHeap->nodes[idx]); // swap nodes minHeapify(minHeap, smallest); } } -static bool isEmpty(const minHeapObj *minHeap) -{ - return minHeap->size == 0; -} +static bool isEmpty(const minHeapObj *minHeap) { return minHeap->size == 0; } + +static minHeapNodeObj *extractMin(minHeapObj *minHeap) { + if (isEmpty(minHeap)) + return nullptr; -static minHeapNodeObj *extractMin(minHeapObj *minHeap) -{ - if (isEmpty(minHeap)) return nullptr; - // store root node minHeapNodeObj *root = minHeap->nodes[0]; - + // replace root node with last node minHeapNodeObj *lastNode = minHeap->nodes[minHeap->size - 1]; minHeap->nodes[0] = lastNode; - + // update position of last node minHeap->pos[root->idx] = minHeap->size - 1; minHeap->pos[lastNode->idx] = 0; - + // Reduce heap size and heapify root --minHeap->size; minHeapify(minHeap, 0); - + return root; } -static void decreaseKey(minHeapObj *minHeap, int idx, int dist) -{ +static void decreaseKey(minHeapObj *minHeap, int idx, int dist) { // get the index of idx in min heap nodes int i = minHeap->pos[idx]; - + // get the node and update its dist value minHeap->nodes[i]->dist = dist; - + // travel up while the complete tree is not hepified (this is a O(Logn) loop) while (i && minHeap->nodes[i]->dist < minHeap->nodes[(i - 1) / 2]->dist) { // swap this node with its parent - minHeap->pos[minHeap->nodes[i]->idx] = (i-1)/2; - minHeap->pos[minHeap->nodes[(i-1)/2]->idx] = i; + minHeap->pos[minHeap->nodes[i]->idx] = (i - 1) / 2; + minHeap->pos[minHeap->nodes[(i - 1) / 2]->idx] = i; std::swap(minHeap->nodes[i], minHeap->nodes[(i - 1) / 2]); - + // move to parent index i = (i - 1) / 2; } } -static bool isInMinHeap(const minHeapObj *minHeap, int idx) -{ +static bool isInMinHeap(const minHeapObj *minHeap, int idx) { return minHeap->pos[idx] < minHeap->size; } @@ -258,18 +259,19 @@ typedef struct { int *prev; } dijkstraOutputObj; -static dijkstraOutputObj *dijkstra(graphObj *graph, int src) -{ +static dijkstraOutputObj *dijkstra(graphObj *graph, int src) { int n = graph->numnodes; - minHeapObj *minHeap = createMinHeap(n); // priority queue implemented as a min heap structure - if(!minHeap) return nullptr; + minHeapObj *minHeap = + createMinHeap(n); // priority queue implemented as a min heap structure + if (!minHeap) + return nullptr; dijkstraOutputObj *output = nullptr; - output = (dijkstraOutputObj *) malloc(sizeof(dijkstraOutputObj)); - output->dist = (double *) malloc(n * sizeof(double)); - output->prev = (int *) malloc(n * sizeof(int)); - if(!output->dist || !output->prev) { + output = (dijkstraOutputObj *)malloc(sizeof(dijkstraOutputObj)); + output->dist = (double *)malloc(n * sizeof(double)); + output->prev = (int *)malloc(n * sizeof(int)); + if (!output->dist || !output->prev) { msFree(output->dist); msFree(output->prev); free(output); @@ -278,21 +280,22 @@ static dijkstraOutputObj *dijkstra(graphObj *graph, int src) } // initialize - for (int i=0; idist[i] = HUGE_VAL; output->prev[i] = -1; - minHeap->nodes[i] = newMinHeapNode(i, output->dist[i]); // allocate a min heap node for each graph node + minHeap->nodes[i] = newMinHeapNode( + i, output->dist[i]); // allocate a min heap node for each graph node minHeap->pos[i] = i; } - + // make dist value of src vertex as 0 so that it is extracted first minHeap->pos[src] = src; output->dist[src] = 0; decreaseKey(minHeap, src, output->dist[src]); - + // initially size of min heap is equal to graph->numnodes (n) minHeap->size = n; - + // In the following loop, minHeap contains all nodes // whose shortest distance is not yet finalized. while (!isEmpty(minHeap)) { @@ -306,10 +309,11 @@ static dijkstraOutputObj *dijkstra(graphObj *graph, int src) graphNodeObj *node = graph->head[u]; while (node != nullptr) { int v = node->dest; - + // if shortest distance to v is not finalized yet, and distance to v // through u is less than its previously calculated distance - if (isInMinHeap(minHeap, v) && output->dist[u] != HUGE_VAL && node->weight + output->dist[u] < output->dist[v]) { + if (isInMinHeap(minHeap, v) && output->dist[u] != HUGE_VAL && + node->weight + output->dist[u] < output->dist[v]) { output->dist[v] = output->dist[u] + node->weight; output->prev[v] = u; decreaseKey(minHeap, v, output->dist[v]); @@ -317,21 +321,25 @@ static dijkstraOutputObj *dijkstra(graphObj *graph, int src) node = node->next; } } - + freeMinHeap(minHeap); return output; } -int *msGraphGetLongestShortestPath(graphObj *graph, int src, int *path_size, double *path_dist) -{ - if(!graph || src < 0 || src > graph->numnodes) return nullptr; +int *msGraphGetLongestShortestPath(graphObj *graph, int src, int *path_size, + double *path_dist) { + if (!graph || src < 0 || src > graph->numnodes) + return nullptr; - int* path = (int *) malloc((graph->numnodes)*sizeof(int)); // worst case is path traverses all nodes - if(!path) return nullptr; + int *path = + (int *)malloc((graph->numnodes) * + sizeof(int)); // worst case is path traverses all nodes + if (!path) + return nullptr; dijkstraOutputObj *output = dijkstra(graph, src); - if(!output) { + if (!output) { free(path); return nullptr; // algorithm failed for some reason } @@ -339,14 +347,14 @@ int *msGraphGetLongestShortestPath(graphObj *graph, int src, int *path_size, dou // get longest shortest distance from src to another node (our dest) *path_dist = -1; int dest = -1; - for(int i=0; inumnodes; i++) { - if(output->dist[i] != HUGE_VAL && *path_dist < output->dist[i]) { + for (int i = 0; i < graph->numnodes; i++) { + if (output->dist[i] != HUGE_VAL && *path_dist < output->dist[i]) { *path_dist = output->dist[i]; dest = i; } } - if(dest == -1) { // unable to determine destination node + if (dest == -1) { // unable to determine destination node free(path); free(output->dist); free(output->prev); @@ -356,7 +364,8 @@ int *msGraphGetLongestShortestPath(graphObj *graph, int src, int *path_size, dou // construct the path from src to dest int j = 0; - for(int i=dest; i!=-1; i=output->prev[i],j++) path[j] = i; + for (int i = dest; i != -1; i = output->prev[i], j++) + path[j] = i; std::reverse(path, path + j); *path_size = j; diff --git a/mapgraph.h b/mapgraph.h index e05401d3c4..d6730867ed 100644 --- a/mapgraph.h +++ b/mapgraph.h @@ -30,7 +30,7 @@ #ifndef MAPGRAPH_H #define MAPGRAPH_H -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -50,9 +50,10 @@ void msFreeGraph(graphObj *graph); int msGraphAddEdge(graphObj *graph, int src, int dest, double weight); void msPrintGraph(graphObj *graph); -int *msGraphGetLongestShortestPath(graphObj *graph, int src, int *path_size, double *path_dist); +int *msGraphGetLongestShortestPath(graphObj *graph, int src, int *path_size, + double *path_dist); -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/mapgraticule.c b/mapgraticule.c index d5586f1998..80b8c562e1 100644 --- a/mapgraticule.c +++ b/mapgraticule.c @@ -30,17 +30,10 @@ #include #include "mapproject.h" - - /********************************************************************************************************************** * */ -typedef enum { - posBottom = 1, - posTop, - posLeft, - posRight -} msGraticulePosition; +typedef enum { posBottom = 1, posTop, posLeft, posRight } msGraticulePosition; typedef enum { lpDefault = 0, @@ -49,27 +42,28 @@ typedef enum { lpDD } msLabelProcessingType; -void DefineAxis( int iTickCountTarget, double *Min, double *Max, double *Inc ); -static int _AdjustLabelPosition( layerObj *pLayer, shapeObj *pShape, msGraticulePosition ePosition ); -static void _FormatLabel( layerObj *pLayer, shapeObj *pShape, double dDataToFormat ); +void DefineAxis(int iTickCountTarget, double *Min, double *Max, double *Inc); +static int _AdjustLabelPosition(layerObj *pLayer, shapeObj *pShape, + msGraticulePosition ePosition); +static void _FormatLabel(layerObj *pLayer, shapeObj *pShape, + double dDataToFormat); int msGraticuleLayerInitItemInfo(layerObj *layer); -#define MAPGRATICULE_ARC_SUBDIVISION_DEFAULT (256) -#define MAPGRATICULE_ARC_MINIMUM (16) -#define MAPGRATICULE_FORMAT_STRING_DEFAULT "%5.2g" -#define MAPGRATICULE_FORMAT_STRING_DDMMSS "%3d %02d %02d" -#define MAPGRATICULE_FORMAT_STRING_DDMM "%3d %02d" -#define MAPGRATICULE_FORMAT_STRING_DD "%3d" +#define MAPGRATICULE_ARC_SUBDIVISION_DEFAULT (256) +#define MAPGRATICULE_ARC_MINIMUM (16) +#define MAPGRATICULE_FORMAT_STRING_DEFAULT "%5.2g" +#define MAPGRATICULE_FORMAT_STRING_DDMMSS "%3d %02d %02d" +#define MAPGRATICULE_FORMAT_STRING_DDMM "%3d %02d" +#define MAPGRATICULE_FORMAT_STRING_DD "%3d" /********************************************************************************************************************** * */ -int msGraticuleLayerOpen(layerObj *layer) -{ +int msGraticuleLayerOpen(layerObj *layer) { graticuleObj *pInfo = layer->grid; - if( pInfo == NULL ) + if (pInfo == NULL) return MS_FAILURE; pInfo->dincrementlatitude = 15.0; @@ -78,33 +72,37 @@ int msGraticuleLayerOpen(layerObj *layer) pInfo->dwhichlongitude = -180.0; pInfo->bvertical = 1; - if( layer->numclasses == 0 ) - msDebug( "GRID layer has no classes, nothing will be rendered.\n" ); + if (layer->numclasses == 0) + msDebug("GRID layer has no classes, nothing will be rendered.\n"); - if( layer->numclasses > 0 && layer->class[0]->numlabels > 0 ) + if (layer->numclasses > 0 && layer->class[0] -> numlabels > 0) pInfo->blabelaxes = 1; else pInfo->blabelaxes = 0; - if( pInfo->labelformat == NULL ) { - pInfo->labelformat = (char *) msSmallMalloc( strlen( MAPGRATICULE_FORMAT_STRING_DEFAULT ) + 1 ); - pInfo->ilabeltype = (int) lpDefault; - strcpy( pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DEFAULT ); - } else if( strcmp( pInfo->labelformat, "DDMMSS" ) == 0 ) { + if (pInfo->labelformat == NULL) { + pInfo->labelformat = + (char *)msSmallMalloc(strlen(MAPGRATICULE_FORMAT_STRING_DEFAULT) + 1); + pInfo->ilabeltype = (int)lpDefault; + strcpy(pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DEFAULT); + } else if (strcmp(pInfo->labelformat, "DDMMSS") == 0) { msFree(pInfo->labelformat); - pInfo->labelformat = (char *) msSmallMalloc( strlen( MAPGRATICULE_FORMAT_STRING_DDMMSS ) + 1 ); - pInfo->ilabeltype = (int) lpDDMMSS; - strcpy( pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DDMMSS ); - } else if( strcmp( pInfo->labelformat, "DDMM" ) == 0 ) { + pInfo->labelformat = + (char *)msSmallMalloc(strlen(MAPGRATICULE_FORMAT_STRING_DDMMSS) + 1); + pInfo->ilabeltype = (int)lpDDMMSS; + strcpy(pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DDMMSS); + } else if (strcmp(pInfo->labelformat, "DDMM") == 0) { msFree(pInfo->labelformat); - pInfo->labelformat = (char *) msSmallMalloc( strlen( MAPGRATICULE_FORMAT_STRING_DDMM ) + 1 ); - pInfo->ilabeltype = (int) lpDDMM; - strcpy( pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DDMM ); - } else if( strcmp( pInfo->labelformat, "DD" ) == 0 ) { + pInfo->labelformat = + (char *)msSmallMalloc(strlen(MAPGRATICULE_FORMAT_STRING_DDMM) + 1); + pInfo->ilabeltype = (int)lpDDMM; + strcpy(pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DDMM); + } else if (strcmp(pInfo->labelformat, "DD") == 0) { msFree(pInfo->labelformat); - pInfo->labelformat = (char *) msSmallMalloc( strlen( MAPGRATICULE_FORMAT_STRING_DD ) + 1 ); - pInfo->ilabeltype = (int) lpDD; - strcpy( pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DD ); + pInfo->labelformat = + (char *)msSmallMalloc(strlen(MAPGRATICULE_FORMAT_STRING_DD) + 1); + pInfo->ilabeltype = (int)lpDD; + strcpy(pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DD); } return MS_SUCCESS; @@ -113,20 +111,17 @@ int msGraticuleLayerOpen(layerObj *layer) /********************************************************************************************************************** * Return MS_TRUE if layer is open, MS_FALSE otherwise. */ -int msGraticuleLayerIsOpen(layerObj *layer) -{ - if(layer->grid) +int msGraticuleLayerIsOpen(layerObj *layer) { + if (layer->grid) return MS_TRUE; return MS_FALSE; } - /********************************************************************************************************************** * */ -int msGraticuleLayerClose(layerObj *layer) -{ +int msGraticuleLayerClose(layerObj *layer) { (void)layer; return MS_SUCCESS; } @@ -134,14 +129,13 @@ int msGraticuleLayerClose(layerObj *layer) /********************************************************************************************************************** * */ -int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) -{ +int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) { (void)isQuery; graticuleObj *pInfo = layer->grid; int iAxisTickCount = 0; rectObj rectMapCoordinates; - if(msCheckParentPointer(layer->map,"map") == MS_FAILURE) + if (msCheckParentPointer(layer->map, "map") == MS_FAILURE) return MS_FAILURE; pInfo->dstartlatitude = rect.miny; @@ -149,12 +143,12 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) pInfo->dendlatitude = rect.maxy; pInfo->dendlongitude = rect.maxx; pInfo->bvertical = 1; - pInfo->extent = rect; + pInfo->extent = rect; - if( pInfo->minincrement > 0.0 ) { + if (pInfo->minincrement > 0.0) { pInfo->dincrementlongitude = pInfo->minincrement; pInfo->dincrementlatitude = pInfo->minincrement; - } else if( pInfo->maxincrement > 0.0 ) { + } else if (pInfo->maxincrement > 0.0) { pInfo->dincrementlongitude = pInfo->maxincrement; pInfo->dincrementlatitude = pInfo->maxincrement; } else { @@ -162,64 +156,68 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) pInfo->dincrementlatitude = 0; } - if( pInfo->maxarcs > 0 ) - iAxisTickCount = (int) pInfo->maxarcs; - else if( pInfo->minarcs > 0 ) - iAxisTickCount = (int) pInfo->minarcs; + if (pInfo->maxarcs > 0) + iAxisTickCount = (int)pInfo->maxarcs; + else if (pInfo->minarcs > 0) + iAxisTickCount = (int)pInfo->minarcs; - DefineAxis( iAxisTickCount, &pInfo->dstartlongitude, &pInfo->dendlongitude, &pInfo->dincrementlongitude); - DefineAxis( iAxisTickCount, &pInfo->dstartlatitude, &pInfo->dendlatitude, &pInfo->dincrementlatitude); + DefineAxis(iAxisTickCount, &pInfo->dstartlongitude, &pInfo->dendlongitude, + &pInfo->dincrementlongitude); + DefineAxis(iAxisTickCount, &pInfo->dstartlatitude, &pInfo->dendlatitude, + &pInfo->dincrementlatitude); - pInfo->dwhichlatitude = pInfo->dstartlatitude; + pInfo->dwhichlatitude = pInfo->dstartlatitude; pInfo->dwhichlongitude = pInfo->dstartlongitude; - if( pInfo->minincrement > 0.0 && pInfo->maxincrement > 0.0 && pInfo->minincrement == pInfo->maxincrement ) { + if (pInfo->minincrement > 0.0 && pInfo->maxincrement > 0.0 && + pInfo->minincrement == pInfo->maxincrement) { pInfo->dincrementlongitude = pInfo->minincrement; pInfo->dincrementlatitude = pInfo->minincrement; - } else if( pInfo->minincrement > 0.0 ) { + } else if (pInfo->minincrement > 0.0) { pInfo->dincrementlongitude = pInfo->minincrement; pInfo->dincrementlatitude = pInfo->minincrement; - } else if( pInfo->maxincrement > 0.0 ) { + } else if (pInfo->maxincrement > 0.0) { pInfo->dincrementlongitude = pInfo->maxincrement; pInfo->dincrementlatitude = pInfo->maxincrement; } /* - * If using PROJ, project rect back into map system, and generate rect corner points in native system. - * These lines will be used when generating labels to get correct placement at arc/rect edge intersections. + * If using PROJ, project rect back into map system, and generate rect corner + * points in native system. These lines will be used when generating labels to + * get correct placement at arc/rect edge intersections. */ rectMapCoordinates = layer->map->extent; - layer->project = msProjectionsDiffer(&(layer->projection), &(layer->map->projection)); - if( layer->project && - strstr(layer->map->projection.args[0], "epsg:3857") && - msProjIsGeographicCRS(&(layer->projection)) ) - { - if( rectMapCoordinates.minx < -20037508) - rectMapCoordinates.minx = -20037508; - if( rectMapCoordinates.maxx > 20037508 ) - rectMapCoordinates.maxx = 20037508; + layer->project = + msProjectionsDiffer(&(layer->projection), &(layer->map->projection)); + if (layer->project && strstr(layer->map->projection.args[0], "epsg:3857") && + msProjIsGeographicCRS(&(layer->projection))) { + if (rectMapCoordinates.minx < -20037508) + rectMapCoordinates.minx = -20037508; + if (rectMapCoordinates.maxx > 20037508) + rectMapCoordinates.maxx = 20037508; } msFree(pInfo->pboundinglines); - pInfo->pboundinglines = (lineObj *) msSmallMalloc( sizeof( lineObj ) * 4 ); + pInfo->pboundinglines = (lineObj *)msSmallMalloc(sizeof(lineObj) * 4); msFree(pInfo->pboundingpoints); - pInfo->pboundingpoints = (pointObj *) msSmallMalloc( sizeof( pointObj ) * 8 ); + pInfo->pboundingpoints = (pointObj *)msSmallMalloc(sizeof(pointObj) * 8); { /* * top */ - pInfo->pboundinglines[0].numpoints = 2; + pInfo->pboundinglines[0].numpoints = 2; pInfo->pboundinglines[0].point = &pInfo->pboundingpoints[0]; pInfo->pboundinglines[0].point[0].x = rectMapCoordinates.minx; pInfo->pboundinglines[0].point[0].y = rectMapCoordinates.maxy; pInfo->pboundinglines[0].point[1].x = rectMapCoordinates.maxx; pInfo->pboundinglines[0].point[1].y = rectMapCoordinates.maxy; - if(layer->project) - msProjectLine(&layer->map->projection, &layer->projection, &pInfo->pboundinglines[0]); + if (layer->project) + msProjectLine(&layer->map->projection, &layer->projection, + &pInfo->pboundinglines[0]); /* * bottom @@ -227,38 +225,41 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) pInfo->pboundinglines[1].numpoints = 2; pInfo->pboundinglines[1].point = &pInfo->pboundingpoints[2]; pInfo->pboundinglines[1].point[0].x = rectMapCoordinates.minx; - pInfo->pboundinglines[1].point[0].y = rectMapCoordinates.miny; - pInfo->pboundinglines[1].point[1].x = rectMapCoordinates.maxx; + pInfo->pboundinglines[1].point[0].y = rectMapCoordinates.miny; + pInfo->pboundinglines[1].point[1].x = rectMapCoordinates.maxx; pInfo->pboundinglines[1].point[1].y = rectMapCoordinates.miny; - if(layer->project) - msProjectLine(&layer->map->projection, &layer->projection, &pInfo->pboundinglines[1]); + if (layer->project) + msProjectLine(&layer->map->projection, &layer->projection, + &pInfo->pboundinglines[1]); /* * left */ pInfo->pboundinglines[2].numpoints = 2; pInfo->pboundinglines[2].point = &pInfo->pboundingpoints[4]; - pInfo->pboundinglines[2].point[0].x = rectMapCoordinates.minx; - pInfo->pboundinglines[2].point[0].y = rectMapCoordinates.miny; - pInfo->pboundinglines[2].point[1].x = rectMapCoordinates.minx; - pInfo->pboundinglines[2].point[1].y = rectMapCoordinates.maxy; + pInfo->pboundinglines[2].point[0].x = rectMapCoordinates.minx; + pInfo->pboundinglines[2].point[0].y = rectMapCoordinates.miny; + pInfo->pboundinglines[2].point[1].x = rectMapCoordinates.minx; + pInfo->pboundinglines[2].point[1].y = rectMapCoordinates.maxy; - if(layer->project) - msProjectLine(&layer->map->projection, &layer->projection, &pInfo->pboundinglines[2]); + if (layer->project) + msProjectLine(&layer->map->projection, &layer->projection, + &pInfo->pboundinglines[2]); /* * right */ pInfo->pboundinglines[3].numpoints = 2; pInfo->pboundinglines[3].point = &pInfo->pboundingpoints[6]; - pInfo->pboundinglines[3].point[0].x = rectMapCoordinates.maxx; - pInfo->pboundinglines[3].point[0].y = rectMapCoordinates.miny; + pInfo->pboundinglines[3].point[0].x = rectMapCoordinates.maxx; + pInfo->pboundinglines[3].point[0].y = rectMapCoordinates.miny; pInfo->pboundinglines[3].point[1].x = rectMapCoordinates.maxx; pInfo->pboundinglines[3].point[1].y = rectMapCoordinates.maxy; - if(layer->project) - msProjectLine(&layer->map->projection, &layer->projection, &pInfo->pboundinglines[3]); + if (layer->project) + msProjectLine(&layer->map->projection, &layer->projection, + &pInfo->pboundinglines[3]); } return MS_SUCCESS; @@ -267,219 +268,242 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) /********************************************************************************************************************** * */ -int msGraticuleLayerNextShape(layerObj *layer, shapeObj *shape) -{ +int msGraticuleLayerNextShape(layerObj *layer, shapeObj *shape) { graticuleObj *pInfo = layer->grid; - if( pInfo->minsubdivides <= 0.0 || pInfo->maxsubdivides <= 0.0 ) - pInfo->minsubdivides = pInfo->maxsubdivides = MAPGRATICULE_ARC_SUBDIVISION_DEFAULT; + if (pInfo->minsubdivides <= 0.0 || pInfo->maxsubdivides <= 0.0) + pInfo->minsubdivides = pInfo->maxsubdivides = + MAPGRATICULE_ARC_SUBDIVISION_DEFAULT; shape->numlines = 1; shape->type = MS_SHAPE_LINE; - shape->line = (lineObj *) msSmallMalloc(sizeof( lineObj )); - shape->line->numpoints = (int) pInfo->maxsubdivides; + shape->line = (lineObj *)msSmallMalloc(sizeof(lineObj)); + shape->line->numpoints = (int)pInfo->maxsubdivides; shape->line->point = NULL; /* * Subdivide and draw current arc, rendering the arc labels first */ - if( pInfo->bvertical ) { + if (pInfo->bvertical) { int iPointIndex; - double dArcDelta = (pInfo->dendlatitude - pInfo->dstartlatitude) / (double) shape->line->numpoints; - double dArcPosition = pInfo->dstartlatitude + dArcDelta; + double dArcDelta = (pInfo->dendlatitude - pInfo->dstartlatitude) / + (double)shape->line->numpoints; + double dArcPosition = pInfo->dstartlatitude + dArcDelta; double dStartY, dDeltaX; - switch( pInfo->ilabelstate ) { - case 0: - if(!pInfo->blabelaxes) { /* Bottom */ - pInfo->ilabelstate++; - msFreeShape(shape); - return MS_SUCCESS; - } - - dDeltaX = (pInfo->dwhichlongitude - pInfo->pboundinglines[1].point[0].x) / (pInfo->pboundinglines[1].point[1].x - pInfo->pboundinglines[1].point[0].x); - if (dDeltaX < 0) - dDeltaX=dDeltaX*-1; - - dStartY = (pInfo->pboundinglines[1].point[1].y - pInfo->pboundinglines[1].point[0].y) * dDeltaX + pInfo->pboundinglines[1].point[0].y; - shape->line->numpoints = (int) 2; - shape->line->point = (pointObj *) msSmallMalloc( sizeof( pointObj ) * 2 ); - - shape->line->point[0].x = pInfo->dwhichlongitude; - shape->line->point[0].y = dStartY; - shape->line->point[1].x = pInfo->dwhichlongitude; - shape->line->point[1].y = dStartY + dArcDelta; - - _FormatLabel( layer, shape, shape->line->point[0].x ); - if(_AdjustLabelPosition( layer, shape, posBottom ) != MS_SUCCESS) - { - msFreeShape(shape); - pInfo->ilabelstate++; - return MS_SUCCESS; - } + switch (pInfo->ilabelstate) { + case 0: + if (!pInfo->blabelaxes) { /* Bottom */ + pInfo->ilabelstate++; + msFreeShape(shape); + return MS_SUCCESS; + } + dDeltaX = (pInfo->dwhichlongitude - pInfo->pboundinglines[1].point[0].x) / + (pInfo->pboundinglines[1].point[1].x - + pInfo->pboundinglines[1].point[0].x); + if (dDeltaX < 0) + dDeltaX = dDeltaX * -1; + + dStartY = (pInfo->pboundinglines[1].point[1].y - + pInfo->pboundinglines[1].point[0].y) * + dDeltaX + + pInfo->pboundinglines[1].point[0].y; + shape->line->numpoints = (int)2; + shape->line->point = (pointObj *)msSmallMalloc(sizeof(pointObj) * 2); + + shape->line->point[0].x = pInfo->dwhichlongitude; + shape->line->point[0].y = dStartY; + shape->line->point[1].x = pInfo->dwhichlongitude; + shape->line->point[1].y = dStartY + dArcDelta; + + _FormatLabel(layer, shape, shape->line->point[0].x); + if (_AdjustLabelPosition(layer, shape, posBottom) != MS_SUCCESS) { + msFreeShape(shape); pInfo->ilabelstate++; return MS_SUCCESS; + } - case 1: - if(!pInfo->blabelaxes) { /* Top */ - pInfo->ilabelstate++; - msFreeShape(shape); - return MS_SUCCESS; - } + pInfo->ilabelstate++; + return MS_SUCCESS; - dDeltaX = (pInfo->dwhichlongitude - pInfo->pboundinglines[0].point[0].x) / (pInfo->pboundinglines[0].point[1].x - pInfo->pboundinglines[0].point[0].x ); - if (dDeltaX < 0) - dDeltaX=dDeltaX*-1; - - dStartY = (pInfo->pboundinglines[0].point[1].y - pInfo->pboundinglines[0].point[0].y) * dDeltaX + pInfo->pboundinglines[0].point[1].y; - shape->line->numpoints = (int) 2; - shape->line->point = (pointObj *) msSmallMalloc( sizeof( pointObj ) * 2 ); - - shape->line->point[0].x = pInfo->dwhichlongitude; - shape->line->point[0].y = dStartY - dArcDelta; - shape->line->point[1].x = pInfo->dwhichlongitude; - shape->line->point[1].y = dStartY; - - _FormatLabel( layer, shape, shape->line->point[0].x ); - if(_AdjustLabelPosition( layer, shape, posTop ) != MS_SUCCESS) - { - msFreeShape(shape); - pInfo->ilabelstate++; - return MS_SUCCESS; - } + case 1: + if (!pInfo->blabelaxes) { /* Top */ + pInfo->ilabelstate++; + msFreeShape(shape); + return MS_SUCCESS; + } + dDeltaX = (pInfo->dwhichlongitude - pInfo->pboundinglines[0].point[0].x) / + (pInfo->pboundinglines[0].point[1].x - + pInfo->pboundinglines[0].point[0].x); + if (dDeltaX < 0) + dDeltaX = dDeltaX * -1; + + dStartY = (pInfo->pboundinglines[0].point[1].y - + pInfo->pboundinglines[0].point[0].y) * + dDeltaX + + pInfo->pboundinglines[0].point[1].y; + shape->line->numpoints = (int)2; + shape->line->point = (pointObj *)msSmallMalloc(sizeof(pointObj) * 2); + + shape->line->point[0].x = pInfo->dwhichlongitude; + shape->line->point[0].y = dStartY - dArcDelta; + shape->line->point[1].x = pInfo->dwhichlongitude; + shape->line->point[1].y = dStartY; + + _FormatLabel(layer, shape, shape->line->point[0].x); + if (_AdjustLabelPosition(layer, shape, posTop) != MS_SUCCESS) { + msFreeShape(shape); pInfo->ilabelstate++; return MS_SUCCESS; + } - case 2: - shape->line->numpoints = (int) shape->line->numpoints + 1; - shape->line->point = (pointObj *) msSmallMalloc( sizeof( pointObj ) * shape->line->numpoints ); + pInfo->ilabelstate++; + return MS_SUCCESS; - shape->line->point[0].x = pInfo->dwhichlongitude; - shape->line->point[0].y = pInfo->dstartlatitude; + case 2: + shape->line->numpoints = (int)shape->line->numpoints + 1; + shape->line->point = + (pointObj *)msSmallMalloc(sizeof(pointObj) * shape->line->numpoints); - for( iPointIndex = 1; iPointIndex < shape->line->numpoints; iPointIndex++ ) { - shape->line->point[iPointIndex].x = pInfo->dwhichlongitude; - shape->line->point[iPointIndex].y = dArcPosition; + shape->line->point[0].x = pInfo->dwhichlongitude; + shape->line->point[0].y = pInfo->dstartlatitude; - dArcPosition += dArcDelta; - } + for (iPointIndex = 1; iPointIndex < shape->line->numpoints; + iPointIndex++) { + shape->line->point[iPointIndex].x = pInfo->dwhichlongitude; + shape->line->point[iPointIndex].y = dArcPosition; - pInfo->ilabelstate = 0; + dArcPosition += dArcDelta; + } - pInfo->dwhichlongitude += pInfo->dincrementlongitude; - break; + pInfo->ilabelstate = 0; - default: - pInfo->ilabelstate = 0; - break; + pInfo->dwhichlongitude += pInfo->dincrementlongitude; + break; + + default: + pInfo->ilabelstate = 0; + break; } } else { /*horizontal*/ int iPointIndex; - double dArcDelta = (pInfo->dendlongitude - pInfo->dstartlongitude) / (double) shape->line->numpoints; - double dArcPosition = pInfo->dstartlongitude + dArcDelta; + double dArcDelta = (pInfo->dendlongitude - pInfo->dstartlongitude) / + (double)shape->line->numpoints; + double dArcPosition = pInfo->dstartlongitude + dArcDelta; double dStartX, dDeltaY; - switch( pInfo->ilabelstate ) { - case 0: - if(!pInfo->blabelaxes) { /* Left side */ - pInfo->ilabelstate++; - msFreeShape(shape); - return MS_SUCCESS; - } - - dDeltaY = (pInfo->dwhichlatitude - pInfo->pboundinglines[2].point[0].y) / (pInfo->pboundinglines[2].point[1].y - pInfo->pboundinglines[2].point[0].y ); - if (dDeltaY < 0) - dDeltaY= dDeltaY*-1; - - dStartX = (pInfo->pboundinglines[2].point[1].x - pInfo->pboundinglines[2].point[0].x) * dDeltaY + pInfo->pboundinglines[2].point[0].x; - shape->line->numpoints = (int) 2; - shape->line->point = (pointObj *) msSmallMalloc( sizeof( pointObj ) * 2 ); - - shape->line->point[0].x = dStartX; - shape->line->point[0].y = pInfo->dwhichlatitude; - shape->line->point[1].x = dStartX + dArcDelta; - shape->line->point[1].y = pInfo->dwhichlatitude; - - _FormatLabel( layer, shape, shape->line->point[0].y ); - if(_AdjustLabelPosition( layer, shape, posLeft ) != MS_SUCCESS) - { - msFreeShape(shape); - pInfo->ilabelstate++; - return MS_SUCCESS; - } + switch (pInfo->ilabelstate) { + case 0: + if (!pInfo->blabelaxes) { /* Left side */ + pInfo->ilabelstate++; + msFreeShape(shape); + return MS_SUCCESS; + } + dDeltaY = (pInfo->dwhichlatitude - pInfo->pboundinglines[2].point[0].y) / + (pInfo->pboundinglines[2].point[1].y - + pInfo->pboundinglines[2].point[0].y); + if (dDeltaY < 0) + dDeltaY = dDeltaY * -1; + + dStartX = (pInfo->pboundinglines[2].point[1].x - + pInfo->pboundinglines[2].point[0].x) * + dDeltaY + + pInfo->pboundinglines[2].point[0].x; + shape->line->numpoints = (int)2; + shape->line->point = (pointObj *)msSmallMalloc(sizeof(pointObj) * 2); + + shape->line->point[0].x = dStartX; + shape->line->point[0].y = pInfo->dwhichlatitude; + shape->line->point[1].x = dStartX + dArcDelta; + shape->line->point[1].y = pInfo->dwhichlatitude; + + _FormatLabel(layer, shape, shape->line->point[0].y); + if (_AdjustLabelPosition(layer, shape, posLeft) != MS_SUCCESS) { + msFreeShape(shape); pInfo->ilabelstate++; return MS_SUCCESS; + } - case 1: - if(!pInfo->blabelaxes) { /* Right side */ - pInfo->ilabelstate++; - msFreeShape(shape); - return MS_SUCCESS; - } + pInfo->ilabelstate++; + return MS_SUCCESS; - dDeltaY = (pInfo->dwhichlatitude - pInfo->pboundinglines[3].point[0].y) / (pInfo->pboundinglines[3].point[1].y - pInfo->pboundinglines[3].point[0].y ); - if (dDeltaY < 0) - dDeltaY= dDeltaY*-1; - - dStartX = (pInfo->pboundinglines[3].point[1].x - pInfo->pboundinglines[3].point[0].x) * dDeltaY + pInfo->pboundinglines[3].point[0].x; - shape->line->numpoints = (int) 2; - shape->line->point = (pointObj *) msSmallMalloc( sizeof( pointObj ) * 2 ); - - shape->line->point[0].x = dStartX - dArcDelta; - shape->line->point[0].y = pInfo->dwhichlatitude; - shape->line->point[1].x = dStartX; - shape->line->point[1].y = pInfo->dwhichlatitude; - - _FormatLabel( layer, shape, shape->line->point[0].y ); - if(_AdjustLabelPosition( layer, shape, posRight ) != MS_SUCCESS) - { - msFreeShape(shape); - pInfo->ilabelstate++; - return MS_SUCCESS; - } + case 1: + if (!pInfo->blabelaxes) { /* Right side */ + pInfo->ilabelstate++; + msFreeShape(shape); + return MS_SUCCESS; + } + dDeltaY = (pInfo->dwhichlatitude - pInfo->pboundinglines[3].point[0].y) / + (pInfo->pboundinglines[3].point[1].y - + pInfo->pboundinglines[3].point[0].y); + if (dDeltaY < 0) + dDeltaY = dDeltaY * -1; + + dStartX = (pInfo->pboundinglines[3].point[1].x - + pInfo->pboundinglines[3].point[0].x) * + dDeltaY + + pInfo->pboundinglines[3].point[0].x; + shape->line->numpoints = (int)2; + shape->line->point = (pointObj *)msSmallMalloc(sizeof(pointObj) * 2); + + shape->line->point[0].x = dStartX - dArcDelta; + shape->line->point[0].y = pInfo->dwhichlatitude; + shape->line->point[1].x = dStartX; + shape->line->point[1].y = pInfo->dwhichlatitude; + + _FormatLabel(layer, shape, shape->line->point[0].y); + if (_AdjustLabelPosition(layer, shape, posRight) != MS_SUCCESS) { + msFreeShape(shape); pInfo->ilabelstate++; return MS_SUCCESS; + } - case 2: - shape->line->numpoints = (int) shape->line->numpoints + 1; - shape->line->point = (pointObj *) msSmallMalloc( sizeof( pointObj ) * shape->line->numpoints ); + pInfo->ilabelstate++; + return MS_SUCCESS; - shape->line->point[0].x = pInfo->dstartlongitude; - shape->line->point[0].y = pInfo->dwhichlatitude; + case 2: + shape->line->numpoints = (int)shape->line->numpoints + 1; + shape->line->point = + (pointObj *)msSmallMalloc(sizeof(pointObj) * shape->line->numpoints); - for(iPointIndex = 1; iPointIndex < shape->line->numpoints; iPointIndex++) { - shape->line->point[iPointIndex].x = dArcPosition; - shape->line->point[iPointIndex].y = pInfo->dwhichlatitude; + shape->line->point[0].x = pInfo->dstartlongitude; + shape->line->point[0].y = pInfo->dwhichlatitude; - dArcPosition += dArcDelta; - } + for (iPointIndex = 1; iPointIndex < shape->line->numpoints; + iPointIndex++) { + shape->line->point[iPointIndex].x = dArcPosition; + shape->line->point[iPointIndex].y = pInfo->dwhichlatitude; - pInfo->ilabelstate = 0; - pInfo->dwhichlatitude += pInfo->dincrementlatitude; - break; + dArcPosition += dArcDelta; + } + + pInfo->ilabelstate = 0; + pInfo->dwhichlatitude += pInfo->dincrementlatitude; + break; - default: - pInfo->ilabelstate = 0; - break; + default: + pInfo->ilabelstate = 0; + break; } } /* - * Increment and move to next arc - */ + * Increment and move to next arc + */ - if( pInfo->bvertical && pInfo->dwhichlongitude > pInfo->dendlongitude ) { - pInfo->dwhichlatitude = pInfo->dstartlatitude; - pInfo->bvertical = 0; + if (pInfo->bvertical && pInfo->dwhichlongitude > pInfo->dendlongitude) { + pInfo->dwhichlatitude = pInfo->dstartlatitude; + pInfo->bvertical = 0; } - if (pInfo->dwhichlatitude > pInfo->dendlatitude) { - /* free the lineObj and pointObj that have been erroneously allocated beforehand */ + if (pInfo->dwhichlatitude > pInfo->dendlatitude) { + /* free the lineObj and pointObj that have been erroneously allocated + * beforehand */ msFreeShape(shape); return MS_DONE; } @@ -490,15 +514,14 @@ int msGraticuleLayerNextShape(layerObj *layer, shapeObj *shape) /********************************************************************************************************************** * */ -int msGraticuleLayerGetItems(layerObj *layer) -{ - char **ppItemName = (char **) msSmallMalloc( sizeof( char * ) ); +int msGraticuleLayerGetItems(layerObj *layer) { + char **ppItemName = (char **)msSmallMalloc(sizeof(char *)); - *ppItemName = (char *) msSmallMalloc( 64 ); /* why is this necessary? */ - strcpy( *ppItemName, "Graticule" ); + *ppItemName = (char *)msSmallMalloc(64); /* why is this necessary? */ + strcpy(*ppItemName, "Graticule"); - layer->numitems = 1; - layer->items = ppItemName; + layer->numitems = 1; + layer->items = ppItemName; return MS_SUCCESS; } @@ -506,8 +529,7 @@ int msGraticuleLayerGetItems(layerObj *layer) /********************************************************************************************************************** * */ -int msGraticuleLayerInitItemInfo(layerObj *layer) -{ +int msGraticuleLayerInitItemInfo(layerObj *layer) { (void)layer; return MS_SUCCESS; } @@ -515,16 +537,13 @@ int msGraticuleLayerInitItemInfo(layerObj *layer) /********************************************************************************************************************** * */ -void msGraticuleLayerFreeItemInfo(layerObj *layer) -{ - (void)layer; -} +void msGraticuleLayerFreeItemInfo(layerObj *layer) { (void)layer; } /********************************************************************************************************************** * */ -int msGraticuleLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) -{ +int msGraticuleLayerGetShape(layerObj *layer, shapeObj *shape, + resultObj *record) { (void)layer; (void)shape; (void)record; @@ -534,11 +553,10 @@ int msGraticuleLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record /********************************************************************************************************************** * */ -int msGraticuleLayerGetExtent(layerObj *layer, rectObj *extent) -{ +int msGraticuleLayerGetExtent(layerObj *layer, rectObj *extent) { graticuleObj *pInfo = layer->grid; - if(pInfo) { + if (pInfo) { *extent = pInfo->extent; return MS_SUCCESS; } @@ -549,8 +567,8 @@ int msGraticuleLayerGetExtent(layerObj *layer, rectObj *extent) /********************************************************************************************************************** * */ -int msGraticuleLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj* shape) -{ +int msGraticuleLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, + shapeObj *shape) { (void)map; (void)layer; (void)c; @@ -558,32 +576,29 @@ int msGraticuleLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, shap return MS_SUCCESS; } - /************************************************************************/ /* msGraticuleLayerFreeIntersectionPoints */ /* */ /* Free intersection object. */ /************************************************************************/ -void msGraticuleLayerFreeIntersectionPoints( graticuleIntersectionObj *psValue) -{ +void msGraticuleLayerFreeIntersectionPoints(graticuleIntersectionObj *psValue) { if (psValue) { - for (int i=0; inTop; i++) + for (int i = 0; i < psValue->nTop; i++) msFree(psValue->papszTopLabels[i]); msFree(psValue->papszTopLabels); msFree(psValue->pasTop); - for (int i=0; inBottom; i++) + for (int i = 0; i < psValue->nBottom; i++) msFree(psValue->papszBottomLabels[i]); msFree(psValue->papszBottomLabels); msFree(psValue->pasBottom); - - for (int i=0; inLeft; i++) + for (int i = 0; i < psValue->nLeft; i++) msFree(psValue->papszLeftLabels[i]); msFree(psValue->papszLeftLabels); msFree(psValue->pasLeft); - for (int i=0; inRight; i++) + for (int i = 0; i < psValue->nRight; i++) msFree(psValue->papszRightLabels[i]); msFree(psValue->papszRightLabels); msFree(psValue->pasRight); @@ -592,14 +607,13 @@ void msGraticuleLayerFreeIntersectionPoints( graticuleIntersectionObj *psValue) } } - /************************************************************************/ /* msGraticuleLayerInitIntersectionPoints */ /* */ /* init intersection object. */ /************************************************************************/ -static void msGraticuleLayerInitIntersectionPoints( graticuleIntersectionObj *psValue) -{ +static void +msGraticuleLayerInitIntersectionPoints(graticuleIntersectionObj *psValue) { if (psValue) { psValue->nTop = 0; psValue->pasTop = NULL; @@ -616,81 +630,82 @@ static void msGraticuleLayerInitIntersectionPoints( graticuleIntersectionObj *ps } } - /************************************************************************/ /* msGraticuleLayerGetIntersectionPoints */ /* */ /* Utility function thar returns all intersection positions and */ /* labels (4 sides of the map) for a grid layer. */ /************************************************************************/ -graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, - layerObj *layer) -{ +graticuleIntersectionObj * +msGraticuleLayerGetIntersectionPoints(mapObj *map, layerObj *layer) { - shapeObj shapegrid, tmpshape; - rectObj searchrect; - int status; + shapeObj shapegrid, tmpshape; + rectObj searchrect; + int status; pointObj oFirstPoint; pointObj oLastPoint; lineObj oLineObj; rectObj cliprect; - graticuleObj *pInfo = NULL; + graticuleObj *pInfo = NULL; double dfTmp; graticuleIntersectionObj *psValues = NULL; - int i=0; + int i = 0; if (layer->connectiontype != MS_GRATICULE) return NULL; - pInfo = layer->grid; + pInfo = layer->grid; /*set cellsize if bnot already set*/ if (map->cellsize == 0) - map->cellsize = msAdjustExtent(&(map->extent),map->width,map->height); + map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height); - psValues = (graticuleIntersectionObj *)msSmallMalloc(sizeof(graticuleIntersectionObj)); + psValues = (graticuleIntersectionObj *)msSmallMalloc( + sizeof(graticuleIntersectionObj)); msGraticuleLayerInitIntersectionPoints(psValues); - if(layer->transform == MS_TRUE) + if (layer->transform == MS_TRUE) searchrect = map->extent; else { searchrect.minx = searchrect.miny = 0; - searchrect.maxx = map->width-1; - searchrect.maxy = map->height-1; + searchrect.maxx = map->width - 1; + searchrect.maxy = map->height - 1; } - if((map->projection.numargs > 0) && (layer->projection.numargs > 0)) - msProjectRect(&map->projection, &layer->projection, &searchrect); /* project the searchrect to source coords */ + if ((map->projection.numargs > 0) && (layer->projection.numargs > 0)) + msProjectRect(&map->projection, &layer->projection, + &searchrect); /* project the searchrect to source coords */ - status = msLayerOpen(layer); - if(status != MS_SUCCESS) - return NULL; + status = msLayerOpen(layer); + if (status != MS_SUCCESS) + return NULL; status = msLayerWhichShapes(layer, searchrect, MS_FALSE); - if(status == MS_DONE) { /* no overlap */ + if (status == MS_DONE) { /* no overlap */ msLayerClose(layer); return NULL; - } else if(status != MS_SUCCESS) { + } else if (status != MS_SUCCESS) { msLayerClose(layer); return NULL; } /* step through the target shapes */ msInitShape(&shapegrid); - cliprect.minx = map->extent.minx- map->cellsize; - cliprect.miny = map->extent.miny- map->cellsize; + cliprect.minx = map->extent.minx - map->cellsize; + cliprect.miny = map->extent.miny - map->cellsize; cliprect.maxx = map->extent.maxx + map->cellsize; cliprect.maxy = map->extent.maxy + map->cellsize; /* clip using the layer projection */ /* msProjectRect(&map->projection , &layer->projection, &cliprect); */ - while((status = msLayerNextShape(layer, &shapegrid)) == MS_SUCCESS) { + while ((status = msLayerNextShape(layer, &shapegrid)) == MS_SUCCESS) { /*don't really need a class here*/ /* - shapegrid.classindex = msShapeGetClass(layer, &shapegrid, map->scaledenom, NULL, 0); - if((shapegrid.classindex == -1) || (layer->class[shapegrid.classindex]->status == MS_OFF)) { + shapegrid.classindex = msShapeGetClass(layer, &shapegrid, map->scaledenom, + NULL, 0); if((shapegrid.classindex == -1) || + (layer->class[shapegrid.classindex]->status == MS_OFF)) { msFreeShape(&shapegrid); continue; } @@ -700,31 +715,27 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, msCopyShape(&shapegrid, &tmpshape); /* status = msDrawShape(map, layer, &tmpshape, image, -1); */ - if(layer->project) { - if( layer->reprojectorLayerToMap == NULL ) - { - layer->reprojectorLayerToMap = msProjectCreateReprojector( - &layer->projection, &map->projection); + if (layer->project) { + if (layer->reprojectorLayerToMap == NULL) { + layer->reprojectorLayerToMap = + msProjectCreateReprojector(&layer->projection, &map->projection); } - if( layer->reprojectorLayerToMap ) + if (layer->reprojectorLayerToMap) msProjectShapeEx(layer->reprojectorLayerToMap, &shapegrid); } msClipPolylineRect(&shapegrid, cliprect); - msTransformShapeToPixelRound(&shapegrid, map->extent, map->cellsize); - - - if(shapegrid.numlines <= 0 || shapegrid.line[0].numpoints < 2) { /* once clipped the shape didn't need to be drawn */ + if (shapegrid.numlines <= 0 || + shapegrid.line[0].numpoints < + 2) { /* once clipped the shape didn't need to be drawn */ msFreeShape(&shapegrid); msFreeShape(&tmpshape); continue; } - - { int iTmpLine = 0; int nNumPoints = 0; @@ -733,7 +744,7 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, points, which should be the most likley to be correct*/ if (shapegrid.numlines > 1) { - for (i=0; i nNumPoints) { nNumPoints = shapegrid.line[i].numpoints; iTmpLine = i; @@ -744,14 +755,14 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, oFirstPoint.x = shapegrid.line[iTmpLine].point[0].x; oFirstPoint.y = shapegrid.line[iTmpLine].point[0].y; oLineObj = shapegrid.line[iTmpLine]; - oLastPoint.x = oLineObj.point[oLineObj.numpoints-1].x; - oLastPoint.y = oLineObj.point[oLineObj.numpoints-1].y; + oLastPoint.x = oLineObj.point[oLineObj.numpoints - 1].x; + oLastPoint.y = oLineObj.point[oLineObj.numpoints - 1].y; - if ( pInfo->bvertical) { /*vertical*/ + if (pInfo->bvertical) { /*vertical*/ /*SHAPES ARE DRAWN FROM BOTTOM TO TOP.*/ - /*Normally lines are drawn FROM BOTTOM TO TOP but not always for some reason, so - make sure that firstpoint < lastpoint in y, We are in pixel coordinates so y increases as we - we go down*/ + /*Normally lines are drawn FROM BOTTOM TO TOP but not always for some + reason, so make sure that firstpoint < lastpoint in y, We are in pixel + coordinates so y increases as we we go down*/ if (oFirstPoint.y < oLastPoint.y) { dfTmp = oFirstPoint.x; oFirstPoint.x = oLastPoint.x; @@ -759,13 +770,12 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, dfTmp = oFirstPoint.y; oFirstPoint.y = oLastPoint.y; oLastPoint.y = dfTmp; - } /*first point should cross the BOTTOM base where y== map->height*/ - if (abs ((int)oFirstPoint.y - map->height) <=1) { - char *pszLabel=NULL; + if (abs((int)oFirstPoint.y - map->height) <= 1) { + char *pszLabel = NULL; oFirstPoint.y = map->height; /*validate point is in map width/height*/ @@ -777,46 +787,51 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, continue; if (shapegrid.text) - pszLabel = msStrdup(shapegrid.text); + pszLabel = msStrdup(shapegrid.text); else { - _FormatLabel(layer, &tmpshape, tmpshape.line[0].point[tmpshape.line[0].numpoints-1].x ); + _FormatLabel( + layer, &tmpshape, + tmpshape.line[0].point[tmpshape.line[0].numpoints - 1].x); if (tmpshape.text) pszLabel = msStrdup(tmpshape.text); else pszLabel = msStrdup("unknown"); } /*validate that the value is not already in the array*/ - if ( psValues->nBottom > 0) { + if (psValues->nBottom > 0) { /* if (psValues->pasBottom[psValues->nBottom-1].x == oFirstPoint.x) continue; */ - for (i=0; inBottom; i++) { + for (i = 0; i < psValues->nBottom; i++) { if (psValues->pasBottom[i].x == oFirstPoint.x) break; } - if (i < psValues->nBottom) { + if (i < psValues->nBottom) { msFree(pszLabel); continue; } } if (psValues->pasBottom == NULL) { psValues->pasBottom = (pointObj *)msSmallMalloc(sizeof(pointObj)); - psValues->papszBottomLabels = (char **)msSmallMalloc(sizeof(char *)); + psValues->papszBottomLabels = + (char **)msSmallMalloc(sizeof(char *)); psValues->nBottom = 1; } else { psValues->nBottom++; - psValues->pasBottom = (pointObj *)msSmallRealloc(psValues->pasBottom, sizeof(pointObj)*psValues->nBottom); - psValues->papszBottomLabels = (char **)msSmallRealloc(psValues->papszBottomLabels, sizeof(char *)*psValues->nBottom); + psValues->pasBottom = (pointObj *)msSmallRealloc( + psValues->pasBottom, sizeof(pointObj) * psValues->nBottom); + psValues->papszBottomLabels = + (char **)msSmallRealloc(psValues->papszBottomLabels, + sizeof(char *) * psValues->nBottom); } - psValues->pasBottom[psValues->nBottom-1].x = oFirstPoint.x; - psValues->pasBottom[psValues->nBottom-1].y = oFirstPoint.y; - psValues->papszBottomLabels[psValues->nBottom-1] = pszLabel; - + psValues->pasBottom[psValues->nBottom - 1].x = oFirstPoint.x; + psValues->pasBottom[psValues->nBottom - 1].y = oFirstPoint.y; + psValues->papszBottomLabels[psValues->nBottom - 1] = pszLabel; } /*first point should cross the TOP base where y==0*/ - if (abs((int)oLastPoint.y) <=1) { - char *pszLabel=NULL; + if (abs((int)oLastPoint.y) <= 1) { + char *pszLabel = NULL; oLastPoint.y = 0; /*validate point is in map width/height*/ @@ -824,20 +839,22 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, continue; if (shapegrid.text) - pszLabel = msStrdup(shapegrid.text); + pszLabel = msStrdup(shapegrid.text); else { - _FormatLabel(layer, &tmpshape, tmpshape.line[0].point[tmpshape.line[0].numpoints-1].x ); + _FormatLabel( + layer, &tmpshape, + tmpshape.line[0].point[tmpshape.line[0].numpoints - 1].x); if (tmpshape.text) pszLabel = msStrdup(tmpshape.text); else pszLabel = msStrdup("unknown"); } /*validate if same value is not already there*/ - if ( psValues->nTop > 0) { + if (psValues->nTop > 0) { /* if (psValues->pasTop[psValues->nTop-1].x == oLastPoint.x) continue; */ - for (i=0; inTop; i++) { + for (i = 0; i < psValues->nTop; i++) { if (psValues->pasTop[i].x == oLastPoint.x || strcasecmp(pszLabel, psValues->papszTopLabels[i]) == 0) break; @@ -848,24 +865,25 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, } } - if (psValues->pasTop == NULL) { psValues->pasTop = (pointObj *)msSmallMalloc(sizeof(pointObj)); psValues->papszTopLabels = (char **)msSmallMalloc(sizeof(char *)); psValues->nTop = 1; } else { psValues->nTop++; - psValues->pasTop = (pointObj *)msSmallRealloc(psValues->pasTop, sizeof(pointObj)*psValues->nTop); - psValues->papszTopLabels = (char **)msSmallRealloc(psValues->papszTopLabels, sizeof(char *)*psValues->nTop); + psValues->pasTop = (pointObj *)msSmallRealloc( + psValues->pasTop, sizeof(pointObj) * psValues->nTop); + psValues->papszTopLabels = (char **)msSmallRealloc( + psValues->papszTopLabels, sizeof(char *) * psValues->nTop); } - psValues->pasTop[psValues->nTop-1].x = oLastPoint.x; - psValues->pasTop[psValues->nTop-1].y = oLastPoint.y; - psValues->papszTopLabels[psValues->nTop-1] = pszLabel; + psValues->pasTop[psValues->nTop - 1].x = oLastPoint.x; + psValues->pasTop[psValues->nTop - 1].y = oLastPoint.y; + psValues->papszTopLabels[psValues->nTop - 1] = pszLabel; } } else { /*horzontal*/ - /*Normally lines are drawn from left to right but not always for some reason, so - make sure that firstpoint < lastpoint in x*/ + /*Normally lines are drawn from left to right but not always for some + reason, so make sure that firstpoint < lastpoint in x*/ if (oFirstPoint.x > oLastPoint.x) { dfTmp = oFirstPoint.x; @@ -874,11 +892,10 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, dfTmp = oFirstPoint.y; oFirstPoint.y = oLastPoint.y; oLastPoint.y = dfTmp; - } /*first point should cross the LEFT base where x=0 axis*/ - if (abs((int)oFirstPoint.x) <=1) { - char *pszLabel=NULL; + if (abs((int)oFirstPoint.x) <= 1) { + char *pszLabel = NULL; oFirstPoint.x = 0; /*validate point is in map width/height*/ @@ -886,9 +903,11 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, continue; if (shapegrid.text) - pszLabel = msStrdup(shapegrid.text); + pszLabel = msStrdup(shapegrid.text); else { - _FormatLabel(layer, &tmpshape, tmpshape.line[0].point[tmpshape.line[0].numpoints-1].y ); + _FormatLabel( + layer, &tmpshape, + tmpshape.line[0].point[tmpshape.line[0].numpoints - 1].y); if (tmpshape.text) pszLabel = msStrdup(tmpshape.text); else @@ -896,11 +915,11 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, } /*validate that the previous value is not the same*/ - if ( psValues->nLeft > 0) { + if (psValues->nLeft > 0) { /* if (psValues->pasLeft[psValues->nLeft-1].y == oFirstPoint.y) continue; */ - for (i=0; inLeft; i++) { + for (i = 0; i < psValues->nLeft; i++) { if (psValues->pasLeft[i].y == oFirstPoint.y) break; } @@ -915,27 +934,32 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, psValues->nLeft = 1; } else { psValues->nLeft++; - psValues->pasLeft = (pointObj *)msSmallRealloc(psValues->pasLeft, sizeof(pointObj)*psValues->nLeft); - psValues->papszLeftLabels = (char **)msSmallRealloc(psValues->papszLeftLabels, sizeof(char *)*psValues->nLeft); + psValues->pasLeft = (pointObj *)msSmallRealloc( + psValues->pasLeft, sizeof(pointObj) * psValues->nLeft); + psValues->papszLeftLabels = (char **)msSmallRealloc( + psValues->papszLeftLabels, sizeof(char *) * psValues->nLeft); } - psValues->pasLeft[psValues->nLeft-1].x = oFirstPoint.x; - psValues->pasLeft[psValues->nLeft-1].y = oFirstPoint.y; - psValues->papszLeftLabels[psValues->nLeft-1] = pszLabel; /* takes ownership of allocated pszLabel */ + psValues->pasLeft[psValues->nLeft - 1].x = oFirstPoint.x; + psValues->pasLeft[psValues->nLeft - 1].y = oFirstPoint.y; + psValues->papszLeftLabels[psValues->nLeft - 1] = + pszLabel; /* takes ownership of allocated pszLabel */ } /*first point should cross the RIGHT base where x=map=>width axis*/ - if (abs((int)oLastPoint.x - map->width) <=1) { - char *pszLabel=NULL; - oLastPoint.x = map->width; + if (abs((int)oLastPoint.x - map->width) <= 1) { + char *pszLabel = NULL; + oLastPoint.x = map->width; /*validate point is in map width/height*/ if (oLastPoint.y < 0 || oLastPoint.y > map->height) continue; if (shapegrid.text) - pszLabel = msStrdup(shapegrid.text); + pszLabel = msStrdup(shapegrid.text); else { - _FormatLabel(layer, &tmpshape, tmpshape.line[0].point[tmpshape.line[0].numpoints-1].y ); + _FormatLabel( + layer, &tmpshape, + tmpshape.line[0].point[tmpshape.line[0].numpoints - 1].y); if (tmpshape.text) pszLabel = msStrdup(tmpshape.text); else @@ -943,10 +967,10 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, } /*validate that the previous value is not the same*/ - if ( psValues->nRight > 0) { + if (psValues->nRight > 0) { /* if (psValues->pasRight[psValues->nRight-1].y == oLastPoint.y) continue; */ - for (i=0; inRight; i++) { + for (i = 0; i < psValues->nRight; i++) { if (psValues->pasRight[i].y == oLastPoint.y) break; } @@ -961,38 +985,36 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, psValues->nRight = 1; } else { psValues->nRight++; - psValues->pasRight = (pointObj *)msSmallRealloc(psValues->pasRight, sizeof(pointObj)*psValues->nRight); - psValues->papszRightLabels = (char **)msSmallRealloc(psValues->papszRightLabels, sizeof(char *)*psValues->nRight); + psValues->pasRight = (pointObj *)msSmallRealloc( + psValues->pasRight, sizeof(pointObj) * psValues->nRight); + psValues->papszRightLabels = (char **)msSmallRealloc( + psValues->papszRightLabels, sizeof(char *) * psValues->nRight); } - psValues->pasRight[psValues->nRight-1].x = oLastPoint.x; - psValues->pasRight[psValues->nRight-1].y = oLastPoint.y; - psValues->papszRightLabels[psValues->nRight-1] = pszLabel; + psValues->pasRight[psValues->nRight - 1].x = oLastPoint.x; + psValues->pasRight[psValues->nRight - 1].y = oLastPoint.y; + psValues->papszRightLabels[psValues->nRight - 1] = pszLabel; } } msFreeShape(&shapegrid); msFreeShape(&tmpshape); } msInitShape(&shapegrid); - - - } msLayerClose(layer); return psValues; - } - /********************************************************************************************************************** * */ -int msGraticuleLayerInitializeVirtualTable(layerObj *layer) -{ +int msGraticuleLayerInitializeVirtualTable(layerObj *layer) { assert(layer != NULL); assert(layer->vtable != NULL); - layer->vtable->LayerInitItemInfo = msGraticuleLayerInitItemInfo; /* should use defaults for item info functions */ + layer->vtable->LayerInitItemInfo = + msGraticuleLayerInitItemInfo; /* should use defaults for item info + functions */ layer->vtable->LayerFreeItemInfo = msGraticuleLayerFreeItemInfo; layer->vtable->LayerOpen = msGraticuleLayerOpen; layer->vtable->LayerIsOpen = msGraticuleLayerIsOpen; @@ -1017,208 +1039,208 @@ int msGraticuleLayerInitializeVirtualTable(layerObj *layer) /********************************************************************************************************************** * */ -static void _FormatLabel( layerObj *pLayer, shapeObj *pShape, double dDataToFormat ) -{ +static void _FormatLabel(layerObj *pLayer, shapeObj *pShape, + double dDataToFormat) { graticuleObj *pInfo = pLayer->grid; char cBuffer[32]; int iDegrees, iMinutes; - switch( pInfo->ilabeltype ) { - case lpDDMMSS: - iDegrees = (int) dDataToFormat; - dDataToFormat = fabs( dDataToFormat - (double) iDegrees ); - iMinutes = (int) (dDataToFormat * 60.0); - dDataToFormat = dDataToFormat - (((double) iMinutes) / 60.0); - sprintf( cBuffer, pInfo->labelformat, iDegrees, iMinutes, (int) (dDataToFormat * 3600.0) ); - break; - case lpDDMM: - iDegrees = (int) dDataToFormat; - dDataToFormat = fabs( dDataToFormat - (double) iDegrees ); - sprintf( cBuffer, pInfo->labelformat, iDegrees, (int) (dDataToFormat * 60.0) ); - break; - case lpDD: - iDegrees = (int) dDataToFormat; - sprintf( cBuffer, pInfo->labelformat, iDegrees); - break; - case lpDefault: - default: - sprintf( cBuffer, pInfo->labelformat, dDataToFormat ); + switch (pInfo->ilabeltype) { + case lpDDMMSS: + iDegrees = (int)dDataToFormat; + dDataToFormat = fabs(dDataToFormat - (double)iDegrees); + iMinutes = (int)(dDataToFormat * 60.0); + dDataToFormat = dDataToFormat - (((double)iMinutes) / 60.0); + sprintf(cBuffer, pInfo->labelformat, iDegrees, iMinutes, + (int)(dDataToFormat * 3600.0)); + break; + case lpDDMM: + iDegrees = (int)dDataToFormat; + dDataToFormat = fabs(dDataToFormat - (double)iDegrees); + sprintf(cBuffer, pInfo->labelformat, iDegrees, (int)(dDataToFormat * 60.0)); + break; + case lpDD: + iDegrees = (int)dDataToFormat; + sprintf(cBuffer, pInfo->labelformat, iDegrees); + break; + case lpDefault: + default: + sprintf(cBuffer, pInfo->labelformat, dDataToFormat); } - pShape->text = msStrdup( cBuffer ); + pShape->text = msStrdup(cBuffer); } /********************************************************************************************************************** * * Move label position into display area by adjusting underlying shape line. */ -static int _AdjustLabelPosition( layerObj *pLayer, shapeObj *pShape, msGraticulePosition ePosition ) -{ +static int _AdjustLabelPosition(layerObj *pLayer, shapeObj *pShape, + msGraticulePosition ePosition) { graticuleObj *pInfo = pLayer->grid; rectObj rectLabel; pointObj ptPoint; double size = -1; char *labeltxt; - if( pInfo == NULL || pShape == NULL ) { - msSetError(MS_MISCERR, "Assertion failed: Null shape or non-configured grid!, ", "_AdjustLabelPosition()"); + if (pInfo == NULL || pShape == NULL) { + msSetError(MS_MISCERR, + "Assertion failed: Null shape or non-configured grid!, ", + "_AdjustLabelPosition()"); return MS_FAILURE; } - assert(pLayer->class[0]->numlabels >= 1); + assert(pLayer->class[0] -> numlabels >= 1); - if(msCheckParentPointer(pLayer->map,"map")==MS_FAILURE) + if (msCheckParentPointer(pLayer->map, "map") == MS_FAILURE) return MS_FAILURE; ptPoint = pShape->line->point[0]; - if(pLayer->project) - { - if( pLayer->reprojectorLayerToMap == NULL ) - { - pLayer->reprojectorLayerToMap = msProjectCreateReprojector( - &pLayer->projection, &pLayer->map->projection); + if (pLayer->project) { + if (pLayer->reprojectorLayerToMap == NULL) { + pLayer->reprojectorLayerToMap = msProjectCreateReprojector( + &pLayer->projection, &pLayer->map->projection); } - if( pLayer->reprojectorLayerToMap ) - msProjectShapeEx(pLayer->reprojectorLayerToMap, pShape ); + if (pLayer->reprojectorLayerToMap) + msProjectShapeEx(pLayer->reprojectorLayerToMap, pShape); /* Poor man detection of reprojection failure */ - if( msProjIsGeographicCRS(&(pLayer->projection)) != - msProjIsGeographicCRS(&(pLayer->map->projection)) ) - { - if( ptPoint.x == pShape->line->point[0].x && - ptPoint.y == pShape->line->point[0].y ) - { - return MS_FAILURE; - } + if (msProjIsGeographicCRS(&(pLayer->projection)) != + msProjIsGeographicCRS(&(pLayer->map->projection))) { + if (ptPoint.x == pShape->line->point[0].x && + ptPoint.y == pShape->line->point[0].y) { + return MS_FAILURE; + } } } - if(pLayer->transform) { - msTransformShapeToPixelRound(pShape, pLayer->map->extent, pLayer->map->cellsize); + if (pLayer->transform) { + msTransformShapeToPixelRound(pShape, pLayer->map->extent, + pLayer->map->cellsize); } - - size = pLayer->class[0]->labels[0]->size; /* TODO someday: adjust minsize/maxsize/resolution*/ - /* We only use the first label as there's no use (yet) in defining multiple lables for GRID layers, - as the only label to represent is the longitude or latitude */ - labeltxt = msShapeGetLabelAnnotation(pLayer, pShape, pLayer->class[0]->labels[0]); + + size = pLayer->class[0] + ->labels[0] + ->size; /* TODO someday: adjust minsize/maxsize/resolution*/ + /* We only use the first label as there's no use (yet) in defining multiple + lables for GRID layers, as the only label to represent is the longitude or + latitude */ + labeltxt = + msShapeGetLabelAnnotation(pLayer, pShape, pLayer->class[0] -> labels[0]); assert(labeltxt); - if(msGetStringSize(pLayer->map, pLayer->class[0]->labels[0], size, labeltxt, &rectLabel) != MS_SUCCESS) { + if (msGetStringSize(pLayer->map, pLayer->class[0] -> labels[0], size, + labeltxt, &rectLabel) != MS_SUCCESS) { free(labeltxt); - return MS_FAILURE; /* msSetError already called */ + return MS_FAILURE; /* msSetError already called */ } free(labeltxt); - switch( ePosition ) { - case posBottom: - pShape->line->point[1].y = pLayer->map->height; - pShape->line->point[0].y = pLayer->map->height - (fabs(rectLabel.maxy - rectLabel.miny) * 2 + 5); - break; - case posTop: - pShape->line->point[1].y = 0; - pShape->line->point[0].y = fabs(rectLabel.maxy - rectLabel.miny) * 2 + 5; - break; - case posLeft: - pShape->line->point[0].x = 0; - pShape->line->point[1].x = fabs(rectLabel.maxx - rectLabel.minx) * 2 + 5; - break; - case posRight: - pShape->line->point[1].x = pLayer->map->width; - pShape->line->point[0].x = pLayer->map->width - (fabs(rectLabel.maxx - rectLabel.minx) * 2 + 5); - break; + switch (ePosition) { + case posBottom: + pShape->line->point[1].y = pLayer->map->height; + pShape->line->point[0].y = + pLayer->map->height - (fabs(rectLabel.maxy - rectLabel.miny) * 2 + 5); + break; + case posTop: + pShape->line->point[1].y = 0; + pShape->line->point[0].y = fabs(rectLabel.maxy - rectLabel.miny) * 2 + 5; + break; + case posLeft: + pShape->line->point[0].x = 0; + pShape->line->point[1].x = fabs(rectLabel.maxx - rectLabel.minx) * 2 + 5; + break; + case posRight: + pShape->line->point[1].x = pLayer->map->width; + pShape->line->point[0].x = + pLayer->map->width - (fabs(rectLabel.maxx - rectLabel.minx) * 2 + 5); + break; } - if(pLayer->transform) - msTransformPixelToShape( pShape, pLayer->map->extent, pLayer->map->cellsize ); + if (pLayer->transform) + msTransformPixelToShape(pShape, pLayer->map->extent, pLayer->map->cellsize); - if(pLayer->project) - { + if (pLayer->project) { /* Clamp coordinates into the validity area of the projection, in the */ /* particular case of EPSG:3857 (WebMercator) to longlat reprojection */ - if( strstr(pLayer->map->projection.args[0], "epsg:3857") && - msProjIsGeographicCRS(&(pLayer->projection)) ) - { - if( !pLayer->map->projection.gt.need_geotransform && - ePosition == posLeft && pShape->line->point[0].x < -20037508) - { - pShape->line->point[1].x = -20037508 + (pShape->line->point[1].x - - pShape->line->point[0].x); - pShape->line->point[0].x = -20037508; - } - else if( pLayer->map->projection.gt.need_geotransform && + if (strstr(pLayer->map->projection.args[0], "epsg:3857") && + msProjIsGeographicCRS(&(pLayer->projection))) { + if (!pLayer->map->projection.gt.need_geotransform && + ePosition == posLeft && pShape->line->point[0].x < -20037508) { + pShape->line->point[1].x = + -20037508 + (pShape->line->point[1].x - pShape->line->point[0].x); + pShape->line->point[0].x = -20037508; + } else if (pLayer->map->projection.gt.need_geotransform && ePosition == posLeft && pLayer->map->projection.gt.geotransform[0] + - pShape->line->point[0].x * - pLayer->map->projection.gt.geotransform[1] + - pShape->line->point[0].y * - pLayer->map->projection.gt.geotransform[2] < -20037508) - { - double y_tmp; - double width = pShape->line->point[1].x - pShape->line->point[0].x; - - y_tmp = pLayer->map->projection.gt.geotransform[3] + - pShape->line->point[0].x * + pShape->line->point[0].x * + pLayer->map->projection.gt.geotransform[1] + + pShape->line->point[0].y * + pLayer->map->projection.gt.geotransform[2] < + -20037508) { + double y_tmp; + double width = pShape->line->point[1].x - pShape->line->point[0].x; + + y_tmp = pLayer->map->projection.gt.geotransform[3] + + pShape->line->point[0].x * pLayer->map->projection.gt.geotransform[4] + - pShape->line->point[0].y * + pShape->line->point[0].y * pLayer->map->projection.gt.geotransform[5]; - pShape->line->point[0].x = + pShape->line->point[0].x = pLayer->map->projection.gt.invgeotransform[0] + - -20037508 * pLayer->map->projection.gt.invgeotransform[1] + - y_tmp * pLayer->map->projection.gt.invgeotransform[2]; - pShape->line->point[1].x = pShape->line->point[0].x + width; - } + -20037508 * pLayer->map->projection.gt.invgeotransform[1] + + y_tmp * pLayer->map->projection.gt.invgeotransform[2]; + pShape->line->point[1].x = pShape->line->point[0].x + width; + } - if( !pLayer->map->projection.gt.need_geotransform && - ePosition == posRight && pShape->line->point[1].x > 20037508) - { - pShape->line->point[0].x = 20037508 - (pShape->line->point[1].x - - pShape->line->point[0].x); - pShape->line->point[1].x = 20037508; - } - else if( pLayer->map->projection.gt.need_geotransform && + if (!pLayer->map->projection.gt.need_geotransform && + ePosition == posRight && pShape->line->point[1].x > 20037508) { + pShape->line->point[0].x = + 20037508 - (pShape->line->point[1].x - pShape->line->point[0].x); + pShape->line->point[1].x = 20037508; + } else if (pLayer->map->projection.gt.need_geotransform && ePosition == posRight && pLayer->map->projection.gt.geotransform[0] + - pShape->line->point[1].x * - pLayer->map->projection.gt.geotransform[1] + - pShape->line->point[1].y * - pLayer->map->projection.gt.geotransform[2] > 20037508) - { - double y_tmp; - double width = pShape->line->point[1].x - pShape->line->point[0].x; - - y_tmp = pLayer->map->projection.gt.geotransform[3] + - pShape->line->point[1].x * + pShape->line->point[1].x * + pLayer->map->projection.gt.geotransform[1] + + pShape->line->point[1].y * + pLayer->map->projection.gt.geotransform[2] > + 20037508) { + double y_tmp; + double width = pShape->line->point[1].x - pShape->line->point[0].x; + + y_tmp = pLayer->map->projection.gt.geotransform[3] + + pShape->line->point[1].x * pLayer->map->projection.gt.geotransform[4] + - pShape->line->point[1].y * + pShape->line->point[1].y * pLayer->map->projection.gt.geotransform[5]; - pShape->line->point[1].x = + pShape->line->point[1].x = pLayer->map->projection.gt.invgeotransform[0] + - 20037508 * pLayer->map->projection.gt.invgeotransform[1] + - y_tmp * pLayer->map->projection.gt.invgeotransform[2]; - pShape->line->point[0].x = pShape->line->point[1].x - width; - } + 20037508 * pLayer->map->projection.gt.invgeotransform[1] + + y_tmp * pLayer->map->projection.gt.invgeotransform[2]; + pShape->line->point[0].x = pShape->line->point[1].x - width; + } } - if( pLayer->reprojectorMapToLayer == NULL ) - { - pLayer->reprojectorMapToLayer = msProjectCreateReprojector( - &pLayer->map->projection, &pLayer->projection); + if (pLayer->reprojectorMapToLayer == NULL) { + pLayer->reprojectorMapToLayer = msProjectCreateReprojector( + &pLayer->map->projection, &pLayer->projection); } - if( pLayer->reprojectorMapToLayer ) - msProjectShapeEx(pLayer->reprojectorMapToLayer, pShape ); + if (pLayer->reprojectorMapToLayer) + msProjectShapeEx(pLayer->reprojectorMapToLayer, pShape); } - switch( ePosition ) { - case posBottom: - case posTop: - pShape->line->point[1].x = ptPoint.x; - pShape->line->point[0].x = ptPoint.x; - break; - case posLeft: - case posRight: - pShape->line->point[1].y = ptPoint.y; - pShape->line->point[0].y = ptPoint.y; - break; + switch (ePosition) { + case posBottom: + case posTop: + pShape->line->point[1].x = ptPoint.x; + pShape->line->point[0].x = ptPoint.x; + break; + case posLeft: + case posRight: + pShape->line->point[1].y = ptPoint.y; + pShape->line->point[0].y = ptPoint.y; + break; } return MS_SUCCESS; @@ -1233,51 +1255,50 @@ static int _AdjustLabelPosition( layerObj *pLayer, shapeObj *pShape, msGraticule * * Minor tweaks to incrment calculations - jnovak */ -void DefineAxis( int iTickCountTarget, double *Min, double *Max, double *Inc ) -{ +void DefineAxis(int iTickCountTarget, double *Min, double *Max, double *Inc) { /* define local variables... */ - double Test_inc, /* candidate increment value */ - Test_min, /* minimum scale value */ - Test_max, /* maximum scale value */ - Range = *Max - *Min ; /* range of data */ + double Test_inc, /* candidate increment value */ + Test_min, /* minimum scale value */ + Test_max, /* maximum scale value */ + Range = *Max - *Min; /* range of data */ - int i = 0 ; /* counter */ + int i = 0; /* counter */ /* don't create problems -- solve them */ - if( Range < 0 ) { - *Inc = 0 ; - return ; + if (Range < 0) { + *Inc = 0; + return; } /* handle special case of repeated values */ - else if( Range == 0) { - *Min = ceil(*Max) - 1 ; - *Max = *Min + 1 ; - *Inc = 1 ; - return ; + else if (Range == 0) { + *Min = ceil(*Max) - 1; + *Max = *Min + 1; + *Inc = 1; + return; } /* compute candidate for increment */ - Test_inc = pow( 10.0, ceil( log10( Range/10 ) ) ) ; - if(*Inc > 0 && ( Test_inc < *Inc || Test_inc > *Inc )) + Test_inc = pow(10.0, ceil(log10(Range / 10))); + if (*Inc > 0 && (Test_inc < *Inc || Test_inc > *Inc)) Test_inc = *Inc; /* establish maximum scale value... */ - Test_max = ( (long)(*Max / Test_inc)) * Test_inc ; + Test_max = ((long)(*Max / Test_inc)) * Test_inc; - if( Test_max < *Max ) - Test_max += Test_inc ; + if (Test_max < *Max) + Test_max += Test_inc; /* establish minimum scale value... */ - Test_min = Test_max ; + Test_min = Test_max; do { - ++i ; - Test_min -= Test_inc ; - } while( Test_min > *Min ) ; + ++i; + Test_min -= Test_inc; + } while (Test_min > *Min); /* subtracting small values can screw up the scale limits, */ /* eg: if DefineAxis is called with (min,max)=(0.01, 0.1), */ @@ -1289,20 +1310,20 @@ void DefineAxis( int iTickCountTarget, double *Min, double *Max, double *Inc ) /* adjust for too few tick marks */ - if(iTickCountTarget <= 0) - iTickCountTarget = MAPGRATICULE_ARC_MINIMUM; + if (iTickCountTarget <= 0) + iTickCountTarget = MAPGRATICULE_ARC_MINIMUM; - while(i < iTickCountTarget) { - Test_inc /= 2 ; - i *= 2 ; + while (i < iTickCountTarget) { + Test_inc /= 2; + i *= 2; } - if(i < 6 && 0) { - Test_inc /= 2 ; - if((Test_min + Test_inc) <= *Min) - Test_min += Test_inc ; - if((Test_max - Test_inc) >= *Max) - Test_max -= Test_inc ; + if (i < 6 && 0) { + Test_inc /= 2; + if ((Test_min + Test_inc) <= *Min) + Test_min += Test_inc; + if ((Test_max - Test_inc) >= *Max) + Test_max -= Test_inc; } /* pass back axis definition to caller */ diff --git a/maphash.c b/maphash.c index 5eaa9e9428..c11f47dd6a 100644 --- a/maphash.c +++ b/maphash.c @@ -32,74 +32,69 @@ #include "mapserver.h" #include "maphash.h" - - -static unsigned hash(const char *key) -{ +static unsigned hash(const char *key) { unsigned hashval; - for(hashval=0; *key!='\0'; key++) + for (hashval = 0; *key != '\0'; key++) hashval = tolower(*key) + 31 * hashval; - return(hashval % MS_HASHSIZE); + return (hashval % MS_HASHSIZE); } -hashTableObj *msCreateHashTable() -{ +hashTableObj *msCreateHashTable() { int i; hashTableObj *table; - table = (hashTableObj *) msSmallMalloc(sizeof(hashTableObj)); - table->items = (struct hashObj **) msSmallMalloc(sizeof(struct hashObj *)*MS_HASHSIZE); + table = (hashTableObj *)msSmallMalloc(sizeof(hashTableObj)); + table->items = + (struct hashObj **)msSmallMalloc(sizeof(struct hashObj *) * MS_HASHSIZE); - for (i=0; iitems[i] = NULL; table->numitems = 0; return table; } -int initHashTable( hashTableObj *table ) -{ +int initHashTable(hashTableObj *table) { int i; - table->items = (struct hashObj **) malloc(sizeof(struct hashObj *)*MS_HASHSIZE); - MS_CHECK_ALLOC(table->items, sizeof(struct hashObj *)*MS_HASHSIZE, MS_FAILURE); + table->items = + (struct hashObj **)malloc(sizeof(struct hashObj *) * MS_HASHSIZE); + MS_CHECK_ALLOC(table->items, sizeof(struct hashObj *) * MS_HASHSIZE, + MS_FAILURE); - for (i=0; iitems[i] = NULL; table->numitems = 0; return MS_SUCCESS; } -void msFreeHashTable( hashTableObj *table ) -{ - if( table != NULL ) { +void msFreeHashTable(hashTableObj *table) { + if (table != NULL) { msFreeHashItems(table); free(table); } } -int msHashIsEmpty( const hashTableObj *table ) -{ - if (table->numitems == 0 ) +int msHashIsEmpty(const hashTableObj *table) { + if (table->numitems == 0) return MS_TRUE; else return MS_FALSE; } - -void msFreeHashItems( hashTableObj *table ) -{ +void msFreeHashItems(hashTableObj *table) { int i; - struct hashObj *tp=NULL; - struct hashObj *prev_tp=NULL; + struct hashObj *tp = NULL; + struct hashObj *prev_tp = NULL; if (table) { - if(table->items) { - for (i=0; iitems) { + for (i = 0; i < MS_HASHSIZE; i++) { if (table->items[i] != NULL) { - for (tp=table->items[i]; tp!=NULL; prev_tp=tp,tp=tp->next,free(prev_tp)) { + for (tp = table->items[i]; tp != NULL; + prev_tp = tp, tp = tp->next, free(prev_tp)) { msFree(tp->key); msFree(tp->data); } @@ -115,23 +110,22 @@ void msFreeHashItems( hashTableObj *table ) } } -struct hashObj *msInsertHashTable(hashTableObj *table, - const char *key, const char *value) { +struct hashObj *msInsertHashTable(hashTableObj *table, const char *key, + const char *value) { struct hashObj *tp; unsigned hashval; if (!table || !key || !value) { - msSetError(MS_HASHERR, "Invalid hash table or key", - "msInsertHashTable"); + msSetError(MS_HASHERR, "Invalid hash table or key", "msInsertHashTable"); return NULL; } - for (tp=table->items[hash(key)]; tp!=NULL; tp=tp->next) - if(strcasecmp(key, tp->key) == 0) + for (tp = table->items[hash(key)]; tp != NULL; tp = tp->next) + if (strcasecmp(key, tp->key) == 0) break; if (tp == NULL) { /* not found */ - tp = (struct hashObj *) malloc(sizeof(*tp)); + tp = (struct hashObj *)malloc(sizeof(*tp)); MS_CHECK_ALLOC(tp, sizeof(*tp), NULL); tp->key = msStrdup(key); hashval = hash(key); @@ -148,25 +142,23 @@ struct hashObj *msInsertHashTable(hashTableObj *table, return tp; } -const char *msLookupHashTable(const hashTableObj *table, const char *key) -{ +const char *msLookupHashTable(const hashTableObj *table, const char *key) { struct hashObj *tp; if (!table || !key) { - return(NULL); + return (NULL); } - for (tp=table->items[hash(key)]; tp!=NULL; tp=tp->next) + for (tp = table->items[hash(key)]; tp != NULL; tp = tp->next) if (strcasecmp(key, tp->key) == 0) - return(tp->data); + return (tp->data); return NULL; } -int msRemoveHashTable(hashTableObj *table, const char *key) -{ +int msRemoveHashTable(hashTableObj *table, const char *key) { struct hashObj *tp; - struct hashObj *prev_tp=NULL; + struct hashObj *prev_tp = NULL; int status = MS_FAILURE; if (!table || !key) { @@ -174,7 +166,7 @@ int msRemoveHashTable(hashTableObj *table, const char *key) return MS_FAILURE; } - tp=table->items[hash(key)]; + tp = table->items[hash(key)]; if (!tp) { msSetError(MS_HASHERR, "No such hash entry", "msRemoveHashTable"); return MS_FAILURE; @@ -208,8 +200,7 @@ int msRemoveHashTable(hashTableObj *table, const char *key) return status; } -const char *msFirstKeyFromHashTable( const hashTableObj *table ) -{ +const char *msFirstKeyFromHashTable(const hashTableObj *table) { int hash_index; if (!table) { @@ -217,16 +208,16 @@ const char *msFirstKeyFromHashTable( const hashTableObj *table ) return NULL; } - for (hash_index = 0; hash_index < MS_HASHSIZE; hash_index++ ) { - if (table->items[hash_index] != NULL ) + for (hash_index = 0; hash_index < MS_HASHSIZE; hash_index++) { + if (table->items[hash_index] != NULL) return table->items[hash_index]->key; } return NULL; } -const char *msNextKeyFromHashTable( const hashTableObj *table, const char *lastKey ) -{ +const char *msNextKeyFromHashTable(const hashTableObj *table, + const char *lastKey) { int hash_index; struct hashObj *link; @@ -235,22 +226,21 @@ const char *msNextKeyFromHashTable( const hashTableObj *table, const char *lastK return NULL; } - if ( lastKey == NULL ) - return msFirstKeyFromHashTable( table ); + if (lastKey == NULL) + return msFirstKeyFromHashTable(table); hash_index = hash(lastKey); - for ( link = table->items[hash_index]; - link != NULL && strcasecmp(lastKey,link->key) != 0; - link = link->next ) {} + for (link = table->items[hash_index]; + link != NULL && strcasecmp(lastKey, link->key) != 0; link = link->next) { + } - if ( link != NULL && link->next != NULL ) + if (link != NULL && link->next != NULL) return link->next->key; - while ( ++hash_index < MS_HASHSIZE ) { - if ( table->items[hash_index] != NULL ) + while (++hash_index < MS_HASHSIZE) { + if (table->items[hash_index] != NULL) return table->items[hash_index]->key; } return NULL; } - diff --git a/maphash.h b/maphash.h index c349a16515..06dc46df66 100644 --- a/maphash.h +++ b/maphash.h @@ -35,128 +35,127 @@ extern "C" { #endif #if defined(_WIN32) && !defined(__CYGWIN__) -# define MS_DLL_EXPORT __declspec(dllexport) +#define MS_DLL_EXPORT __declspec(dllexport) #else -#define MS_DLL_EXPORT +#define MS_DLL_EXPORT #endif #define MS_HASHSIZE 41 - /* ========================================================================= - * Structs - * ========================================================================= */ +/* ========================================================================= + * Structs + * ========================================================================= */ #ifndef SWIG - struct hashObj { - struct hashObj *next; /* pointer to next item */ - char *key; /* string key that is hashed */ - char *data; /* string stored in this item */ - }; +struct hashObj { + struct hashObj *next; /* pointer to next item */ + char *key; /* string key that is hashed */ + char *data; /* string stored in this item */ +}; #endif /*SWIG*/ - /** * An object to store key-value pairs * */ - typedef struct { +typedef struct { #ifndef SWIG - struct hashObj **items; /* the hash table */ + struct hashObj **items; /* the hash table */ #endif #ifdef SWIG %immutable; -#endif /*SWIG*/ - int numitems; ///< \**immutable** number of items +#endif /*SWIG*/ + int numitems; ///< \**immutable** number of items #ifdef SWIG %mutable; #endif /*SWIG*/ - } hashTableObj; +} hashTableObj; - /* ========================================================================= - * Functions - * ========================================================================= */ +/* ========================================================================= + * Functions + * ========================================================================= */ #ifndef SWIG - /* msCreateHashTable - create a hash table - * ARGS: - * None - * RETURNS: - * New hash table - */ - MS_DLL_EXPORT hashTableObj *msCreateHashTable( void ); - - /* For use in mapfile.c with hashTableObj structure members */ - MS_DLL_EXPORT int initHashTable( hashTableObj *table ); - - /* msFreeHashTable - free allocated memory - * ARGS: - * table - target hash table - * RETURNS: - * None - */ - MS_DLL_EXPORT void msFreeHashTable( hashTableObj *table ); - - /* Free only the items for hashTableObj structure members (metadata, &c) */ - MS_DLL_EXPORT void msFreeHashItems( hashTableObj *table ); - - /* msInsertHashTable - insert new item - * ARGS: - * table - the target hash table - * key - key string for new item - * value - data string for new item - * RETURNS: - * pointer to the new item or NULL - * EXCEPTIONS: - * raise MS_HASHERR on failure - */ - MS_DLL_EXPORT struct hashObj *msInsertHashTable( hashTableObj *table, - const char *key, - const char *value ); - - /* msLookupHashTable - get the value of an item by its key - * ARGS: - * table - the target hash table - * key - key string of item - * RETURNS: - * string value of item - */ - MS_DLL_EXPORT const char *msLookupHashTable( const hashTableObj *table, const char *key); - - /* msRemoveHashTable - remove item from table at key - * ARGS: - * table - target hash table - * key - key string - * RETURNS: - * MS_SUCCESS or MS_FAILURE - */ - MS_DLL_EXPORT int msRemoveHashTable( hashTableObj *table, const char *key); - - /* msFirstKeyFromHashTable - get key of first item - * ARGS: - * table - target hash table - * RETURNS: - * first key as a string - */ - MS_DLL_EXPORT const char *msFirstKeyFromHashTable( const hashTableObj *table ); - - /* msNextKeyFromHashTable - get next key - * ARGS: - * table - target hash table - * prevkey - the previous key - * RETURNS: - * the key of the item of following prevkey as a string - */ - MS_DLL_EXPORT const char *msNextKeyFromHashTable( const hashTableObj *table, - const char *prevkey ); - - /* msHashIsEmpty - get next key - * ARGS: - * table - target hash table - * RETURNS: - * MS_TRUE if the table is empty and MS_FALSE if the table has items - */ - - MS_DLL_EXPORT int msHashIsEmpty( const hashTableObj* table ); +/* msCreateHashTable - create a hash table + * ARGS: + * None + * RETURNS: + * New hash table + */ +MS_DLL_EXPORT hashTableObj *msCreateHashTable(void); + +/* For use in mapfile.c with hashTableObj structure members */ +MS_DLL_EXPORT int initHashTable(hashTableObj *table); + +/* msFreeHashTable - free allocated memory + * ARGS: + * table - target hash table + * RETURNS: + * None + */ +MS_DLL_EXPORT void msFreeHashTable(hashTableObj *table); + +/* Free only the items for hashTableObj structure members (metadata, &c) */ +MS_DLL_EXPORT void msFreeHashItems(hashTableObj *table); + +/* msInsertHashTable - insert new item + * ARGS: + * table - the target hash table + * key - key string for new item + * value - data string for new item + * RETURNS: + * pointer to the new item or NULL + * EXCEPTIONS: + * raise MS_HASHERR on failure + */ +MS_DLL_EXPORT struct hashObj * +msInsertHashTable(hashTableObj *table, const char *key, const char *value); + +/* msLookupHashTable - get the value of an item by its key + * ARGS: + * table - the target hash table + * key - key string of item + * RETURNS: + * string value of item + */ +MS_DLL_EXPORT const char *msLookupHashTable(const hashTableObj *table, + const char *key); + +/* msRemoveHashTable - remove item from table at key + * ARGS: + * table - target hash table + * key - key string + * RETURNS: + * MS_SUCCESS or MS_FAILURE + */ +MS_DLL_EXPORT int msRemoveHashTable(hashTableObj *table, const char *key); + +/* msFirstKeyFromHashTable - get key of first item + * ARGS: + * table - target hash table + * RETURNS: + * first key as a string + */ +MS_DLL_EXPORT const char *msFirstKeyFromHashTable(const hashTableObj *table); + +/* msNextKeyFromHashTable - get next key + * ARGS: + * table - target hash table + * prevkey - the previous key + * RETURNS: + * the key of the item of following prevkey as a string + */ +MS_DLL_EXPORT const char *msNextKeyFromHashTable(const hashTableObj *table, + const char *prevkey); + +/* msHashIsEmpty - get next key + * ARGS: + * table - target hash table + * RETURNS: + * MS_TRUE if the table is empty and MS_FALSE if the table has items + */ + +MS_DLL_EXPORT int msHashIsEmpty(const hashTableObj *table); #endif /*SWIG*/ diff --git a/maphttp.c b/maphttp.c index 8e6f9bc59a..1c9743614d 100644 --- a/maphttp.c +++ b/maphttp.c @@ -57,8 +57,8 @@ */ #include - -#define unchecked_curl_easy_setopt(handle,opt,param) IGNORE_RET_VAL(curl_easy_setopt(handle,opt,param)) +#define unchecked_curl_easy_setopt(handle, opt, param) \ + IGNORE_RET_VAL(curl_easy_setopt(handle, opt, param)) /********************************************************************** * msHTTPInit() @@ -74,19 +74,16 @@ **********************************************************************/ static int gbCurlInitialized = MS_FALSE; -int msHTTPInit() -{ +int msHTTPInit() { /* curl_global_init() should only be called once (no matter how * many threads or libcurl sessions that'll be used) by every * application that uses libcurl. */ msAcquireLock(TLOCK_OWS); - if (!gbCurlInitialized && - curl_global_init(CURL_GLOBAL_ALL) != 0) { + if (!gbCurlInitialized && curl_global_init(CURL_GLOBAL_ALL) != 0) { msReleaseLock(TLOCK_OWS); - msSetError(MS_HTTPERR, "Libcurl initialization failed.", - "msHTTPInit()"); + msSetError(MS_HTTPERR, "Libcurl initialization failed.", "msHTTPInit()"); return MS_FAILURE; } @@ -96,13 +93,11 @@ int msHTTPInit() return MS_SUCCESS; } - /********************************************************************** * msHTTPCleanup() * **********************************************************************/ -void msHTTPCleanup() -{ +void msHTTPCleanup() { msAcquireLock(TLOCK_OWS); if (gbCurlInitialized) curl_global_cleanup(); @@ -111,7 +106,6 @@ void msHTTPCleanup() msReleaseLock(TLOCK_OWS); } - /********************************************************************** * msHTTPInitRequestObj() * @@ -119,11 +113,10 @@ void msHTTPCleanup() * for use with msHTTPExecuteRequest(), etc. * **********************************************************************/ -void msHTTPInitRequestObj(httpRequestObj *pasReqInfo, int numRequests) -{ +void msHTTPInitRequestObj(httpRequestObj *pasReqInfo, int numRequests) { int i; - for(i=0; idebug) { - msDebug("msHTTPWriteFct(id=%d, %d bytes)\n", - psReq->nLayerId, (int)(size*nmemb)); + msDebug("msHTTPWriteFct(id=%d, %d bytes)\n", psReq->nLayerId, + (int)(size * nmemb)); } - if(psReq->nMaxBytes > 0 && (psReq->result_size + size*nmemb) > (size_t)psReq->nMaxBytes) { - msSetError(MS_HTTPERR, "Requested transfer larger than configured maximum %d.", - "msHTTPWriteFct()", - psReq->nMaxBytes ); - return -1; + if (psReq->nMaxBytes > 0 && + (psReq->result_size + size * nmemb) > (size_t)psReq->nMaxBytes) { + msSetError(MS_HTTPERR, + "Requested transfer larger than configured maximum %d.", + "msHTTPWriteFct()", psReq->nMaxBytes); + return -1; } /* Case where we are writing to a disk file. */ - if( psReq->fp != NULL ) { - psReq->result_size += size*nmemb; + if (psReq->fp != NULL) { + psReq->result_size += size * nmemb; return fwrite(buffer, size, nmemb, psReq->fp); } /* Case where we build up the result in memory */ else { - if( psReq->result_data == NULL ) { - psReq->result_buf_size = size*nmemb + 10000; - psReq->result_data = (char *) msSmallMalloc( psReq->result_buf_size ); - } else if( psReq->result_size + nmemb * size > (size_t)psReq->result_buf_size ) { - psReq->result_buf_size = psReq->result_size + nmemb*size + 10000; - psReq->result_data = (char *) msSmallRealloc( psReq->result_data, - psReq->result_buf_size ); + if (psReq->result_data == NULL) { + psReq->result_buf_size = size * nmemb + 10000; + psReq->result_data = (char *)msSmallMalloc(psReq->result_buf_size); + } else if (psReq->result_size + nmemb * size > + (size_t)psReq->result_buf_size) { + psReq->result_buf_size = psReq->result_size + nmemb * size + 10000; + psReq->result_data = + (char *)msSmallRealloc(psReq->result_data, psReq->result_buf_size); } - if( psReq->result_data == NULL ) { - msSetError(MS_HTTPERR, - "Unable to grow HTTP result buffer to size %d.", - "msHTTPWriteFct()", - psReq->result_buf_size ); + if (psReq->result_data == NULL) { + msSetError(MS_HTTPERR, "Unable to grow HTTP result buffer to size %d.", + "msHTTPWriteFct()", psReq->result_buf_size); psReq->result_buf_size = 0; psReq->result_size = 0; return -1; } - memcpy( psReq->result_data + psReq->result_size, - buffer, size*nmemb ); - psReq->result_size += size*nmemb; + memcpy(psReq->result_data + psReq->result_size, buffer, size * nmemb); + psReq->result_size += size * nmemb; - return size*nmemb; + return size * nmemb; } } @@ -272,25 +260,23 @@ static size_t msHTTPWriteFct(void *buffer, size_t size, size_t nmemb, * Returns the equivalent CURL CURLAUTH_ constant given a * MS_HTTP_AUTH_TYPE, or CURLAUTH_BASIC if no match is found. **********************************************************************/ -long msGetCURLAuthType(enum MS_HTTP_AUTH_TYPE authType) -{ +long msGetCURLAuthType(enum MS_HTTP_AUTH_TYPE authType) { switch (authType) { - case MS_BASIC: - return CURLAUTH_BASIC; - case MS_DIGEST: - return CURLAUTH_DIGEST; - case MS_NTLM: - return CURLAUTH_NTLM; - case MS_ANY: - return CURLAUTH_ANY; - case MS_ANYSAFE: - return CURLAUTH_ANYSAFE; - default: - return CURLAUTH_BASIC; + case MS_BASIC: + return CURLAUTH_BASIC; + case MS_DIGEST: + return CURLAUTH_DIGEST; + case MS_NTLM: + return CURLAUTH_NTLM; + case MS_ANY: + return CURLAUTH_ANY; + case MS_ANYSAFE: + return CURLAUTH_ANYSAFE; + default: + return CURLAUTH_BASIC; } } - /********************************************************************** * msHTTPAuthProxySetup() * @@ -303,35 +289,33 @@ long msGetCURLAuthType(enum MS_HTTP_AUTH_TYPE authType) **********************************************************************/ int msHTTPAuthProxySetup(hashTableObj *mapmd, hashTableObj *lyrmd, httpRequestObj *pasReqInfo, int numRequests, - mapObj *map, const char* namespaces) -{ + mapObj *map, const char *namespaces) { const char *pszTmp; - char *pszProxyHost=NULL; - long nProxyPort=0; - char *pszProxyUsername=NULL, *pszProxyPassword=NULL; - char *pszHttpAuthUsername=NULL, *pszHttpAuthPassword=NULL; + char *pszProxyHost = NULL; + long nProxyPort = 0; + char *pszProxyUsername = NULL, *pszProxyPassword = NULL; + char *pszHttpAuthUsername = NULL, *pszHttpAuthPassword = NULL; enum MS_HTTP_AUTH_TYPE eHttpAuthType = MS_BASIC; enum MS_HTTP_AUTH_TYPE eProxyAuthType = MS_BASIC; enum MS_HTTP_PROXY_TYPE eProxyType = MS_HTTP; - /* ------------------------------------------------------------------ - * Check for authentication and proxying metadata. If the metadata is not found - * in the layer metadata, check the map-level metadata. + * Check for authentication and proxying metadata. If the metadata is not + * found in the layer metadata, check the map-level metadata. * ------------------------------------------------------------------ */ - if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces, - "proxy_host")) != NULL) { + if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces, "proxy_host")) != + NULL) { pszProxyHost = msStrdup(pszTmp); } - if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces, - "proxy_port")) != NULL) { + if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces, "proxy_port")) != + NULL) { nProxyPort = atol(pszTmp); } - if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces, - "proxy_type")) != NULL) { + if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces, "proxy_type")) != + NULL) { if (strcasecmp(pszTmp, "HTTP") == 0) eProxyType = MS_HTTP; @@ -363,7 +347,6 @@ int msHTTPAuthProxySetup(hashTableObj *mapmd, hashTableObj *lyrmd, } } - if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces, "proxy_username")) != NULL) { pszProxyUsername = msStrdup(pszTmp); @@ -375,12 +358,12 @@ int msHTTPAuthProxySetup(hashTableObj *mapmd, hashTableObj *lyrmd, if (pszProxyPassword == NULL) { msFree(pszProxyHost); msFree(pszProxyUsername); - return(MS_FAILURE); /* An error should already have been produced */ + return (MS_FAILURE); /* An error should already have been produced */ } } - if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces, - "auth_type")) != NULL) { + if ((pszTmp = msOWSLookupMetadata2(lyrmd, mapmd, namespaces, "auth_type")) != + NULL) { if (strcasecmp(pszTmp, "BASIC") == 0) eHttpAuthType = MS_BASIC; else if (strcasecmp(pszTmp, "DIGEST") == 0) @@ -411,19 +394,19 @@ int msHTTPAuthProxySetup(hashTableObj *mapmd, hashTableObj *lyrmd, msFree(pszProxyHost); msFree(pszProxyUsername); msFree(pszProxyPassword); - return(MS_FAILURE); /* An error should already have been produced */ + return (MS_FAILURE); /* An error should already have been produced */ } } - pasReqInfo[numRequests].pszProxyAddress = pszProxyHost; - pasReqInfo[numRequests].nProxyPort = nProxyPort; - pasReqInfo[numRequests].eProxyType = eProxyType; - pasReqInfo[numRequests].eProxyAuthType = eProxyAuthType; + pasReqInfo[numRequests].pszProxyAddress = pszProxyHost; + pasReqInfo[numRequests].nProxyPort = nProxyPort; + pasReqInfo[numRequests].eProxyType = eProxyType; + pasReqInfo[numRequests].eProxyAuthType = eProxyAuthType; pasReqInfo[numRequests].pszProxyUsername = pszProxyUsername; pasReqInfo[numRequests].pszProxyPassword = pszProxyPassword; - pasReqInfo[numRequests].eHttpAuthType = eHttpAuthType; - pasReqInfo[numRequests].pszHttpUsername = pszHttpAuthUsername; - pasReqInfo[numRequests].pszHttpPassword = pszHttpAuthPassword; + pasReqInfo[numRequests].eHttpAuthType = eHttpAuthType; + pasReqInfo[numRequests].pszHttpUsername = pszHttpAuthUsername; + pasReqInfo[numRequests].pszHttpPassword = pszHttpAuthPassword; return MS_SUCCESS; } @@ -442,16 +425,15 @@ int msHTTPAuthProxySetup(hashTableObj *mapmd, hashTableObj *lyrmd, * MS_DONE if some requests failed with 40x status for instance (not fatal) **********************************************************************/ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, - int bCheckLocalCache) -{ - int i, nStatus = MS_SUCCESS, nTimeout, still_running=0, num_msgs=0; - CURLM *multi_handle; + int bCheckLocalCache) { + int i, nStatus = MS_SUCCESS, nTimeout, still_running = 0, num_msgs = 0; + CURLM *multi_handle; CURLMsg *curl_msg; - char debug = MS_FALSE; + char debug = MS_FALSE; const char *pszCurlCABundle = NULL; if (numRequests == 0) - return MS_SUCCESS; /* Nothing to do */ + return MS_SUCCESS; /* Nothing to do */ if (!gbCurlInitialized) msHTTPInit(); @@ -461,12 +443,12 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, * We use the longest timeout value in the array of requests */ nTimeout = pasReqInfo[0].nTimeout; - for (i=0; i nTimeout) nTimeout = pasReqInfo[i].nTimeout; if (pasReqInfo[i].debug) - debug = MS_TRUE; /* For the download loop */ + debug = MS_TRUE; /* For the download loop */ } if (nTimeout <= 0) @@ -484,6 +466,8 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, msDebug("Using CURL_CA_BUNDLE=%s\n", pszCurlCABundle); } + const char *pszHttpVersion = CPLGetConfigOption("CURL_HTTP_VERSION", NULL); + /* Alloc a curl-multi handle, and add a curl-easy handle to it for each * file to download. */ @@ -491,22 +475,22 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, if (multi_handle == NULL) { msSetError(MS_HTTPERR, "curl_multi_init() failed.", "msHTTPExecuteRequests()"); - return(MS_FAILURE); + return (MS_FAILURE); } - for (i=0; iversion_num/0x10000 & 0xff, - psCurlVInfo->version_num/0x100 & 0xff, - psCurlVInfo->version_num & 0xff ); + sprintf(pasReqInfo[i].pszUserAgent, "MapServer/%s libcurl/%d.%d.%d", + MS_VERSION, psCurlVInfo->version_num / 0x10000 & 0xff, + psCurlVInfo->version_num / 0x100 & 0xff, + psCurlVInfo->version_num & 0xff); } } if (pasReqInfo[i].pszUserAgent) { - unchecked_curl_easy_setopt(http_handle, - CURLOPT_USERAGENT, pasReqInfo[i].pszUserAgent ); + unchecked_curl_easy_setopt(http_handle, CURLOPT_USERAGENT, + pasReqInfo[i].pszUserAgent); } /* Enable following redirections. Requires libcurl 7.10.1 at least */ - unchecked_curl_easy_setopt(http_handle, CURLOPT_FOLLOWLOCATION, 1 ); - unchecked_curl_easy_setopt(http_handle, CURLOPT_MAXREDIRS, 10 ); + unchecked_curl_easy_setopt(http_handle, CURLOPT_FOLLOWLOCATION, 1); + unchecked_curl_easy_setopt(http_handle, CURLOPT_MAXREDIRS, 10); /* Set timeout.*/ - unchecked_curl_easy_setopt(http_handle, CURLOPT_TIMEOUT, nTimeout ); + unchecked_curl_easy_setopt(http_handle, CURLOPT_TIMEOUT, nTimeout); /* Pass CURL_CA_BUNDLE if set */ if (pszCurlCABundle) - unchecked_curl_easy_setopt(http_handle, CURLOPT_CAINFO, pszCurlCABundle ); + unchecked_curl_easy_setopt(http_handle, CURLOPT_CAINFO, pszCurlCABundle); /* Set proxying settings */ - if (pasReqInfo[i].pszProxyAddress != NULL - && strlen(pasReqInfo[i].pszProxyAddress) > 0) { - long nProxyType = CURLPROXY_HTTP; + if (pasReqInfo[i].pszProxyAddress != NULL && + strlen(pasReqInfo[i].pszProxyAddress) > 0) { + long nProxyType = CURLPROXY_HTTP; unchecked_curl_easy_setopt(http_handle, CURLOPT_PROXY, - pasReqInfo[i].pszProxyAddress); + pasReqInfo[i].pszProxyAddress); - if (pasReqInfo[i].nProxyPort > 0 - && pasReqInfo[i].nProxyPort < 65535) { + if (pasReqInfo[i].nProxyPort > 0 && pasReqInfo[i].nProxyPort < 65535) { unchecked_curl_easy_setopt(http_handle, CURLOPT_PROXYPORT, - pasReqInfo[i].nProxyPort); + pasReqInfo[i].nProxyPort); } switch (pasReqInfo[i].eProxyType) { - case MS_HTTP: - nProxyType = CURLPROXY_HTTP; - break; - case MS_SOCKS5: - nProxyType = CURLPROXY_SOCKS5; - break; + case MS_HTTP: + nProxyType = CURLPROXY_HTTP; + break; + case MS_SOCKS5: + nProxyType = CURLPROXY_SOCKS5; + break; } unchecked_curl_easy_setopt(http_handle, CURLOPT_PROXYTYPE, nProxyType); /* If there is proxy authentication information, set it */ - if (pasReqInfo[i].pszProxyUsername != NULL - && pasReqInfo[i].pszProxyPassword != NULL - && strlen(pasReqInfo[i].pszProxyUsername) > 0 - && strlen(pasReqInfo[i].pszProxyPassword) > 0) { - char szUsernamePasswd[128]; + if (pasReqInfo[i].pszProxyUsername != NULL && + pasReqInfo[i].pszProxyPassword != NULL && + strlen(pasReqInfo[i].pszProxyUsername) > 0 && + strlen(pasReqInfo[i].pszProxyPassword) > 0) { + char szUsernamePasswd[128]; #if LIBCURL_VERSION_NUM >= 0x070a07 - long nProxyAuthType = CURLAUTH_BASIC; + long nProxyAuthType = CURLAUTH_BASIC; /* CURLOPT_PROXYAUTH available only in Curl 7.10.7 and up */ nProxyAuthType = msGetCURLAuthType(pasReqInfo[i].eProxyAuthType); - unchecked_curl_easy_setopt(http_handle, CURLOPT_PROXYAUTH, nProxyAuthType); + unchecked_curl_easy_setopt(http_handle, CURLOPT_PROXYAUTH, + nProxyAuthType); #else /* We log an error but don't abort processing */ - msSetError(MS_HTTPERR, "CURLOPT_PROXYAUTH not supported. Requires Curl 7.10.7 and up. *_proxy_auth_type setting ignored.", + msSetError(MS_HTTPERR, + "CURLOPT_PROXYAUTH not supported. Requires Curl 7.10.7 and " + "up. *_proxy_auth_type setting ignored.", "msHTTPExecuteRequests()"); #endif /* LIBCURL_VERSION_NUM */ - snprintf(szUsernamePasswd, 127, "%s:%s", - pasReqInfo[i].pszProxyUsername, + snprintf(szUsernamePasswd, 127, "%s:%s", pasReqInfo[i].pszProxyUsername, pasReqInfo[i].pszProxyPassword); unchecked_curl_easy_setopt(http_handle, CURLOPT_PROXYUSERPWD, - szUsernamePasswd); + szUsernamePasswd); } } /* Set HTTP Authentication settings */ - if (pasReqInfo[i].pszHttpUsername != NULL - && pasReqInfo[i].pszHttpPassword != NULL - && strlen(pasReqInfo[i].pszHttpUsername) > 0 - && strlen(pasReqInfo[i].pszHttpPassword) > 0) { - char szUsernamePasswd[128]; - long nHttpAuthType = CURLAUTH_BASIC; - - snprintf(szUsernamePasswd, 127, "%s:%s", - pasReqInfo[i].pszHttpUsername, + if (pasReqInfo[i].pszHttpUsername != NULL && + pasReqInfo[i].pszHttpPassword != NULL && + strlen(pasReqInfo[i].pszHttpUsername) > 0 && + strlen(pasReqInfo[i].pszHttpPassword) > 0) { + char szUsernamePasswd[128]; + long nHttpAuthType = CURLAUTH_BASIC; + + snprintf(szUsernamePasswd, 127, "%s:%s", pasReqInfo[i].pszHttpUsername, pasReqInfo[i].pszHttpPassword); unchecked_curl_easy_setopt(http_handle, CURLOPT_USERPWD, - szUsernamePasswd); + szUsernamePasswd); nHttpAuthType = msGetCURLAuthType(pasReqInfo[i].eHttpAuthType); unchecked_curl_easy_setopt(http_handle, CURLOPT_HTTPAUTH, nHttpAuthType); @@ -650,73 +641,75 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, * (this force avoiding the use of sgnal handlers) */ #ifdef CURLOPT_NOSIGNAL - unchecked_curl_easy_setopt(http_handle, CURLOPT_NOSIGNAL, 1 ); + unchecked_curl_easy_setopt(http_handle, CURLOPT_NOSIGNAL, 1); #endif /* If we are writing file to disk, open the file now. */ - if( pasReqInfo[i].pszOutputFile != NULL ) { - if ( (fp = fopen(pasReqInfo[i].pszOutputFile, "wb")) == NULL) { + if (pasReqInfo[i].pszOutputFile != NULL) { + if ((fp = fopen(pasReqInfo[i].pszOutputFile, "wb")) == NULL) { msSetError(MS_HTTPERR, "Can't open output file %s.", "msHTTPExecuteRequests()", pasReqInfo[i].pszOutputFile); - return(MS_FAILURE); + return (MS_FAILURE); } pasReqInfo[i].fp = fp; } /* coverity[bad_sizeof] */ - unchecked_curl_easy_setopt(http_handle, CURLOPT_WRITEDATA, &(pasReqInfo[i])); - unchecked_curl_easy_setopt(http_handle, CURLOPT_WRITEFUNCTION, msHTTPWriteFct); + unchecked_curl_easy_setopt(http_handle, CURLOPT_WRITEDATA, + &(pasReqInfo[i])); + unchecked_curl_easy_setopt(http_handle, CURLOPT_WRITEFUNCTION, + msHTTPWriteFct); /* Provide a buffer where libcurl can write human readable error msgs */ if (pasReqInfo[i].pszErrBuf == NULL) - pasReqInfo[i].pszErrBuf = (char *)msSmallMalloc((CURL_ERROR_SIZE+1)* - sizeof(char)); + pasReqInfo[i].pszErrBuf = + (char *)msSmallMalloc((CURL_ERROR_SIZE + 1) * sizeof(char)); pasReqInfo[i].pszErrBuf[0] = '\0'; unchecked_curl_easy_setopt(http_handle, CURLOPT_ERRORBUFFER, - pasReqInfo[i].pszErrBuf); + pasReqInfo[i].pszErrBuf); - if(pasReqInfo[i].pszPostRequest != NULL ) { + if (pasReqInfo[i].pszPostRequest != NULL) { char szBuf[100]; - struct curl_slist *headers=NULL; - snprintf(szBuf, 100, - "Content-Type: %s", pasReqInfo[i].pszPostContentType); + struct curl_slist *headers = NULL; + snprintf(szBuf, 100, "Content-Type: %s", + pasReqInfo[i].pszPostContentType); headers = curl_slist_append(headers, szBuf); - unchecked_curl_easy_setopt(http_handle, CURLOPT_POST, 1 ); + unchecked_curl_easy_setopt(http_handle, CURLOPT_POST, 1); unchecked_curl_easy_setopt(http_handle, CURLOPT_POSTFIELDS, - pasReqInfo[i].pszPostRequest); - if( debug ) - { - msDebug("HTTP: POST = %s", pasReqInfo[i].pszPostRequest); + pasReqInfo[i].pszPostRequest); + if (debug) { + msDebug("HTTP: POST = %s", pasReqInfo[i].pszPostRequest); } unchecked_curl_easy_setopt(http_handle, CURLOPT_HTTPHEADER, headers); /* curl_slist_free_all(headers); */ /* free the header list */ } /* Added by RFC-42 HTTP Cookie Forwarding */ - if(pasReqInfo[i].pszHTTPCookieData != NULL) { + if (pasReqInfo[i].pszHTTPCookieData != NULL) { /* Check if there's no end of line in the Cookie string */ /* This could break the HTTP Header */ - for(size_t nPos=0; nPosmsg == CURLMSG_DONE && - curl_msg->data.result != CURLE_OK) { + if (curl_msg->msg == CURLMSG_DONE && curl_msg->data.result != CURLE_OK) { /* Something went wrong with this transfer... report error */ - for (i=0; ieasy_handle) { psReq = &(pasReqInfo[i]); break; @@ -801,38 +794,37 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, if (debug) { /* Print a msDebug header for timings reported in the loop below */ - msDebug("msHTTPExecuteRequests() timing summary per layer (connect_time + time_to_first_packet + download_time = total_time in seconds)\n"); + msDebug("msHTTPExecuteRequests() timing summary per layer (connect_time + " + "time_to_first_packet + download_time = total_time in seconds)\n"); } /* Check status of all requests, close files, report errors and cleanup * handles */ - for (i=0; inStatus == 242) - continue; /* Nothing to do here, this file was in cache already */ + continue; /* Nothing to do here, this file was in cache already */ if (psReq->fp) fclose(psReq->fp); psReq->fp = NULL; - http_handle = (CURL*)(psReq->curl_handle); + http_handle = (CURL *)(psReq->curl_handle); if (psReq->nStatus == 0 && - curl_easy_getinfo(http_handle, - CURLINFO_HTTP_CODE, &lVal) == CURLE_OK) { + curl_easy_getinfo(http_handle, CURLINFO_HTTP_CODE, &lVal) == CURLE_OK) { char *pszContentType = NULL; psReq->nStatus = lVal; /* Fetch content type of response */ - if (curl_easy_getinfo(http_handle, - CURLINFO_CONTENT_TYPE, + if (curl_easy_getinfo(http_handle, CURLINFO_CONTENT_TYPE, &pszContentType) == CURLE_OK && pszContentType != NULL) { psReq->pszContentType = msStrdup(pszContentType); @@ -847,33 +839,29 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, if (psReq->nStatus == -(CURLE_OPERATION_TIMEOUTED)) { /* Timeout isn't a fatal error */ if (psReq->debug) - msDebug("HTTP: TIMEOUT of %d seconds exceeded for %s\n", - nTimeout, psReq->pszGetUrl ); + msDebug("HTTP: TIMEOUT of %d seconds exceeded for %s\n", nTimeout, + psReq->pszGetUrl); - msSetError(MS_HTTPERR, - "HTTP: TIMEOUT of %d seconds exceeded for %s\n", - "msHTTPExecuteRequests()", - nTimeout, psReq->pszGetUrl); + msSetError(MS_HTTPERR, "HTTP: TIMEOUT of %d seconds exceeded for %s\n", + "msHTTPExecuteRequests()", nTimeout, psReq->pszGetUrl); /* Rewrite error message, the curl timeout message isn't * of much use to our users. */ - sprintf(psReq->pszErrBuf, - "TIMEOUT of %d seconds exceeded.", nTimeout); + sprintf(psReq->pszErrBuf, "TIMEOUT of %d seconds exceeded.", nTimeout); } else if (psReq->nStatus > 0) { /* Got an HTTP Error, e.g. 404, etc. */ if (psReq->debug) msDebug("HTTP: HTTP GET request failed with status %d (%s)" " for %s\n", - psReq->nStatus, psReq->pszErrBuf, - psReq->pszGetUrl); + psReq->nStatus, psReq->pszErrBuf, psReq->pszGetUrl); msSetError(MS_HTTPERR, "HTTP GET request failed with status %d (%s) " "for %s", - "msHTTPExecuteRequests()", psReq->nStatus, - psReq->pszErrBuf, psReq->pszGetUrl); + "msHTTPExecuteRequests()", psReq->nStatus, psReq->pszErrBuf, + psReq->pszGetUrl); } else { /* Got a curl error */ @@ -881,45 +869,42 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, if (psReq->debug) msDebug("HTTP: request failed with curl error " "code %d (%s) for %s", - -psReq->nStatus, psReq->pszErrBuf, - psReq->pszGetUrl); + -psReq->nStatus, psReq->pszErrBuf, psReq->pszGetUrl); - if(!error || error->code == MS_NOERR) /* only set error if one hasn't already been set */ + if (!error || + error->code == + MS_NOERR) /* only set error if one hasn't already been set */ msSetError(MS_HTTPERR, - "HTTP: request failed with curl error " - "code %d (%s) for %s", - "msHTTPExecuteRequests()", - -psReq->nStatus, psReq->pszErrBuf, - psReq->pszGetUrl); + "HTTP: request failed with curl error " + "code %d (%s) for %s", + "msHTTPExecuteRequests()", -psReq->nStatus, + psReq->pszErrBuf, psReq->pszGetUrl); } } /* Report download times foreach handle, in debug mode */ if (psReq->debug) { - double dConnectTime=0.0, dTotalTime=0.0, dStartTfrTime=0.0; - - curl_easy_getinfo(http_handle, - CURLINFO_CONNECT_TIME, &dConnectTime); - curl_easy_getinfo(http_handle, - CURLINFO_STARTTRANSFER_TIME, &dStartTfrTime); - curl_easy_getinfo(http_handle, - CURLINFO_TOTAL_TIME, &dTotalTime); + double dConnectTime = 0.0, dTotalTime = 0.0, dStartTfrTime = 0.0; + + curl_easy_getinfo(http_handle, CURLINFO_CONNECT_TIME, &dConnectTime); + curl_easy_getinfo(http_handle, CURLINFO_STARTTRANSFER_TIME, + &dStartTfrTime); + curl_easy_getinfo(http_handle, CURLINFO_TOTAL_TIME, &dTotalTime); /* STARTTRANSFER_TIME includes CONNECT_TIME, but TOTAL_TIME * doesn't, so we need to add it. */ dTotalTime += dConnectTime; msDebug("Layer %d: %.3f + %.3f + %.3f = %.3fs\n", psReq->nLayerId, - dConnectTime, dStartTfrTime-dConnectTime, - dTotalTime-dStartTfrTime, dTotalTime); + dConnectTime, dStartTfrTime - dConnectTime, + dTotalTime - dStartTfrTime, dTotalTime); } /* Cleanup this handle */ - unchecked_curl_easy_setopt(http_handle, CURLOPT_URL, "" ); + unchecked_curl_easy_setopt(http_handle, CURLOPT_URL, ""); curl_multi_remove_handle(multi_handle, http_handle); curl_easy_cleanup(http_handle); psReq->curl_handle = NULL; - } /* Cleanup multi handle, each handle had to be cleaned up individually */ @@ -935,17 +920,16 @@ int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, **********************************************************************/ int msHTTPGetFile(const char *pszGetUrl, const char *pszOutputFile, int *pnHTTPStatus, int nTimeout, int bCheckLocalCache, - int bDebug, int nMaxBytes) -{ + int bDebug, int nMaxBytes) { httpRequestObj *pasReqInfo; /* Alloc httpRequestInfo structs through which status of each request * will be returned. * We need to alloc 2 instance of requestobj so that the last * object in the array can be set to NULL. - */ - pasReqInfo = (httpRequestObj*)calloc(2, sizeof(httpRequestObj)); - MS_CHECK_ALLOC(pasReqInfo, 2*sizeof(httpRequestObj), MS_FAILURE); + */ + pasReqInfo = (httpRequestObj *)calloc(2, sizeof(httpRequestObj)); + MS_CHECK_ALLOC(pasReqInfo, 2 * sizeof(httpRequestObj), MS_FAILURE); msHTTPInitRequestObj(pasReqInfo, 2); @@ -972,5 +956,4 @@ int msHTTPGetFile(const char *pszGetUrl, const char *pszOutputFile, return MS_SUCCESS; } - #endif /* defined(USE_WMS_LYR) || defined(USE_WMS_SVR) */ diff --git a/maphttp.h b/maphttp.h index 5164cdd483..cde5376d6c 100644 --- a/maphttp.h +++ b/maphttp.h @@ -30,8 +30,6 @@ #ifndef MAPHTTP_H #define MAPHTTP_H - - #include "mapprimitive.h" #include @@ -39,86 +37,73 @@ extern "C" { #endif -#define MS_HTTP_SUCCESS(status) (status == 200 || status == 242) - - enum MS_HTTP_PROXY_TYPE - { - MS_HTTP, - MS_SOCKS5 - }; - - enum MS_HTTP_AUTH_TYPE { - MS_BASIC, - MS_DIGEST, - MS_NTLM, - MS_ANY, - MS_ANYSAFE - }; - - typedef struct http_request_info { - int nLayerId; - char *pszGetUrl; - char *pszOutputFile; - int nTimeout; - int nMaxBytes; - rectObj bbox; - int width; - int height; - int nStatus; /* 200=success, value < 0 if request failed */ - char *pszContentType; /* Content-Type of the response */ - char *pszErrBuf; /* Buffer where curl can write errors */ - char *pszPostRequest; /* post request content (NULL for GET) */ - char *pszPostContentType;/* post request MIME type */ - char *pszUserAgent; /* User-Agent, auto-generated if not set */ - char *pszHTTPCookieData; /* HTTP Cookie data */ - - char *pszProxyAddress; /* The address (IP or hostname) of proxy svr */ - long nProxyPort; /* The proxy's port */ - enum MS_HTTP_PROXY_TYPE eProxyType; /* The type of proxy */ - enum MS_HTTP_AUTH_TYPE eProxyAuthType; /* Auth method against proxy */ - char *pszProxyUsername; /* Proxy authentication username */ - char *pszProxyPassword; /* Proxy authentication password */ - - enum MS_HTTP_AUTH_TYPE eHttpAuthType; /* HTTP Authentication type */ - char *pszHttpUsername; /* HTTP Authentication username */ - char *pszHttpPassword; /* HTTP Authentication password */ - - /* For debugging/profiling */ - int debug; /* Debug mode? MS_TRUE/MS_FALSE */ - - /* Private members */ - void * curl_handle; /* CURLM * handle */ - FILE * fp; /* FILE * used during download */ - - char * result_data; /* output if pszOutputFile is NULL */ - int result_size; - int result_buf_size; - - } httpRequestObj; +#define MS_HTTP_SUCCESS(status) (status == 200 || status == 242) + +enum MS_HTTP_PROXY_TYPE { MS_HTTP, MS_SOCKS5 }; + +enum MS_HTTP_AUTH_TYPE { MS_BASIC, MS_DIGEST, MS_NTLM, MS_ANY, MS_ANYSAFE }; + +typedef struct http_request_info { + int nLayerId; + char *pszGetUrl; + char *pszOutputFile; + int nTimeout; + int nMaxBytes; + rectObj bbox; + int width; + int height; + int nStatus; /* 200=success, value < 0 if request failed */ + char *pszContentType; /* Content-Type of the response */ + char *pszErrBuf; /* Buffer where curl can write errors */ + char *pszPostRequest; /* post request content (NULL for GET) */ + char *pszPostContentType; /* post request MIME type */ + char *pszUserAgent; /* User-Agent, auto-generated if not set */ + char *pszHTTPCookieData; /* HTTP Cookie data */ + + char *pszProxyAddress; /* The address (IP or hostname) of proxy svr */ + long nProxyPort; /* The proxy's port */ + enum MS_HTTP_PROXY_TYPE eProxyType; /* The type of proxy */ + enum MS_HTTP_AUTH_TYPE eProxyAuthType; /* Auth method against proxy */ + char *pszProxyUsername; /* Proxy authentication username */ + char *pszProxyPassword; /* Proxy authentication password */ + + enum MS_HTTP_AUTH_TYPE eHttpAuthType; /* HTTP Authentication type */ + char *pszHttpUsername; /* HTTP Authentication username */ + char *pszHttpPassword; /* HTTP Authentication password */ + + /* For debugging/profiling */ + int debug; /* Debug mode? MS_TRUE/MS_FALSE */ + + /* Private members */ + void *curl_handle; /* CURLM * handle */ + FILE *fp; /* FILE * used during download */ + + char *result_data; /* output if pszOutputFile is NULL */ + int result_size; + int result_buf_size; + +} httpRequestObj; #ifdef USE_CURL - int msHTTPInit(void); - void msHTTPCleanup(void); +int msHTTPInit(void); +void msHTTPCleanup(void); - void msHTTPInitRequestObj(httpRequestObj *pasReqInfo, int numRequests); - void msHTTPFreeRequestObj(httpRequestObj *pasReqInfo, int numRequests); - int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, - int bCheckLocalCache); - int msHTTPGetFile(const char *pszGetUrl, const char *pszOutputFile, - int *pnHTTPStatus, int nTimeout, int bCheckLocalCache, - int bDebug, int nMaxBytes); +void msHTTPInitRequestObj(httpRequestObj *pasReqInfo, int numRequests); +void msHTTPFreeRequestObj(httpRequestObj *pasReqInfo, int numRequests); +int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, + int bCheckLocalCache); +int msHTTPGetFile(const char *pszGetUrl, const char *pszOutputFile, + int *pnHTTPStatus, int nTimeout, int bCheckLocalCache, + int bDebug, int nMaxBytes); - int msHTTPAuthProxySetup(hashTableObj *mapmd, hashTableObj *lyrmd, - httpRequestObj *pasReqInfo, int numRequests, - mapObj *map, const char* namespaces); +int msHTTPAuthProxySetup(hashTableObj *mapmd, hashTableObj *lyrmd, + httpRequestObj *pasReqInfo, int numRequests, + mapObj *map, const char *namespaces); #endif /*USE_CURL*/ #ifdef __cplusplus } #endif - - - #endif /* MAPHTTP_H */ diff --git a/mapiconv.c b/mapiconv.c index b0d9de7430..96512e4c2c 100644 --- a/mapiconv.c +++ b/mapiconv.c @@ -28,9 +28,7 @@ #include "mapiconv.h" -size_t msIconv(iconv_t cd, - char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) -{ - return iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft); +size_t msIconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, + size_t *outbytesleft) { + return iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft); } diff --git a/mapiconv.h b/mapiconv.h index cbc25b5dff..4eb752c74e 100644 --- a/mapiconv.h +++ b/mapiconv.h @@ -36,9 +36,8 @@ extern "C" { #include /* Wrapper of iconv() to be used from C++ */ -size_t msIconv(iconv_t cd, - char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft); +size_t msIconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, + size_t *outbytesleft); #ifdef __cplusplus } diff --git a/mapimageio.c b/mapimageio.c index 215a0f9146..f962dd28e1 100644 --- a/mapimageio.c +++ b/mapimageio.c @@ -38,30 +38,24 @@ #include #endif - - typedef struct _streamInfo { FILE *fp; bufferObj *buffer; } streamInfo; -static -void png_write_data_to_stream(png_structp png_ptr, png_bytep data, png_size_t length) -{ - FILE *fp = ((streamInfo*)png_get_io_ptr(png_ptr))->fp; - msIO_fwrite(data,length,1,fp); +static void png_write_data_to_stream(png_structp png_ptr, png_bytep data, + png_size_t length) { + FILE *fp = ((streamInfo *)png_get_io_ptr(png_ptr))->fp; + msIO_fwrite(data, length, 1, fp); } -static -void png_write_data_to_buffer(png_structp png_ptr, png_bytep data, png_size_t length) -{ - bufferObj *buffer = ((streamInfo*)png_get_io_ptr(png_ptr))->buffer; - msBufferAppend(buffer,data,length); +static void png_write_data_to_buffer(png_structp png_ptr, png_bytep data, + png_size_t length) { + bufferObj *buffer = ((streamInfo *)png_get_io_ptr(png_ptr))->buffer; + msBufferAppend(buffer, data, length); } -static -void png_flush_data(png_structp png_ptr) -{ +static void png_flush_data(png_structp png_ptr) { (void)png_ptr; /* do nothing */ } @@ -83,123 +77,116 @@ typedef struct { #define OUTPUT_BUF_SIZE 4096 -static void -jpeg_init_destination (j_compress_ptr cinfo) -{ - ms_destination_mgr *dest = (ms_destination_mgr*) cinfo->dest; +static void jpeg_init_destination(j_compress_ptr cinfo) { + ms_destination_mgr *dest = (ms_destination_mgr *)cinfo->dest; /* Allocate the output buffer --- it will be released when done with image */ - dest->data = (unsigned char *) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - OUTPUT_BUF_SIZE * sizeof (unsigned char)); + dest->data = (unsigned char *)(*cinfo->mem->alloc_small)( + (j_common_ptr)cinfo, JPOOL_IMAGE, + OUTPUT_BUF_SIZE * sizeof(unsigned char)); dest->pub.next_output_byte = dest->data; dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; } -static -void jpeg_stream_term_destination (j_compress_ptr cinfo) -{ - ms_stream_destination_mgr *dest = (ms_stream_destination_mgr*) cinfo->dest; - msIO_fwrite(dest->mgr.data, OUTPUT_BUF_SIZE-dest->mgr.pub.free_in_buffer, 1, dest->stream); +static void jpeg_stream_term_destination(j_compress_ptr cinfo) { + ms_stream_destination_mgr *dest = (ms_stream_destination_mgr *)cinfo->dest; + msIO_fwrite(dest->mgr.data, OUTPUT_BUF_SIZE - dest->mgr.pub.free_in_buffer, 1, + dest->stream); dest->mgr.pub.next_output_byte = dest->mgr.data; dest->mgr.pub.free_in_buffer = OUTPUT_BUF_SIZE; } -static -void jpeg_buffer_term_destination (j_compress_ptr cinfo) -{ - ms_buffer_destination_mgr *dest = (ms_buffer_destination_mgr*) cinfo->dest; - msBufferAppend(dest->buffer, dest->mgr.data, OUTPUT_BUF_SIZE-dest->mgr.pub.free_in_buffer); +static void jpeg_buffer_term_destination(j_compress_ptr cinfo) { + ms_buffer_destination_mgr *dest = (ms_buffer_destination_mgr *)cinfo->dest; + msBufferAppend(dest->buffer, dest->mgr.data, + OUTPUT_BUF_SIZE - dest->mgr.pub.free_in_buffer); dest->mgr.pub.next_output_byte = dest->mgr.data; dest->mgr.pub.free_in_buffer = OUTPUT_BUF_SIZE; } -static -boolean jpeg_stream_empty_output_buffer (j_compress_ptr cinfo) -{ - ms_stream_destination_mgr *dest = (ms_stream_destination_mgr*) cinfo->dest; +static boolean jpeg_stream_empty_output_buffer(j_compress_ptr cinfo) { + ms_stream_destination_mgr *dest = (ms_stream_destination_mgr *)cinfo->dest; msIO_fwrite(dest->mgr.data, OUTPUT_BUF_SIZE, 1, dest->stream); dest->mgr.pub.next_output_byte = dest->mgr.data; dest->mgr.pub.free_in_buffer = OUTPUT_BUF_SIZE; return TRUE; } -static -boolean jpeg_buffer_empty_output_buffer (j_compress_ptr cinfo) -{ - ms_buffer_destination_mgr *dest = (ms_buffer_destination_mgr*) cinfo->dest; +static boolean jpeg_buffer_empty_output_buffer(j_compress_ptr cinfo) { + ms_buffer_destination_mgr *dest = (ms_buffer_destination_mgr *)cinfo->dest; msBufferAppend(dest->buffer, dest->mgr.data, OUTPUT_BUF_SIZE); dest->mgr.pub.next_output_byte = dest->mgr.data; dest->mgr.pub.free_in_buffer = OUTPUT_BUF_SIZE; return TRUE; } -static void msJPEGErrorExit(j_common_ptr cinfo) -{ - jmp_buf* pJmpBuffer = (jmp_buf* ) cinfo->client_data; - char buffer[JMSG_LENGTH_MAX]; +static void msJPEGErrorExit(j_common_ptr cinfo) { + jmp_buf *pJmpBuffer = (jmp_buf *)cinfo->client_data; + char buffer[JMSG_LENGTH_MAX]; - /* Create the message */ - (*cinfo->err->format_message) (cinfo, buffer); + /* Create the message */ + (*cinfo->err->format_message)(cinfo, buffer); - msSetError(MS_MISCERR,"libjpeg: %s","jpeg_ErrorExit()", buffer); + msSetError(MS_MISCERR, "libjpeg: %s", "jpeg_ErrorExit()", buffer); - /* Return control to the setjmp point */ - longjmp(*pJmpBuffer, 1); + /* Return control to the setjmp point */ + longjmp(*pJmpBuffer, 1); } int saveAsJPEG(mapObj *map, rasterBufferObj *rb, streamInfo *info, - outputFormatObj *format) -{ + outputFormatObj *format) { struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; int quality; - const char* pszOptimized; + const char *pszOptimized; int optimized; int arithmetic; ms_destination_mgr *dest; JSAMPLE *rowdata = NULL; unsigned int row; jmp_buf setjmp_buffer; - - quality = atoi(msGetOutputFormatOption( format, "QUALITY", "75")); - pszOptimized = msGetOutputFormatOption( format, "OPTIMIZED", "YES"); + + quality = atoi(msGetOutputFormatOption(format, "QUALITY", "75")); + pszOptimized = msGetOutputFormatOption(format, "OPTIMIZED", "YES"); optimized = EQUAL(pszOptimized, "YES") || EQUAL(pszOptimized, "ON") || EQUAL(pszOptimized, "TRUE"); arithmetic = EQUAL(pszOptimized, "ARITHMETIC"); - if (setjmp(setjmp_buffer)) - { - jpeg_destroy_compress(&cinfo); - free(rowdata); - return MS_FAILURE; + if (setjmp(setjmp_buffer)) { + jpeg_destroy_compress(&cinfo); + free(rowdata); + return MS_FAILURE; } cinfo.err = jpeg_std_error(&jerr); jerr.error_exit = msJPEGErrorExit; - cinfo.client_data = (void *) &(setjmp_buffer); + cinfo.client_data = (void *)&(setjmp_buffer); jpeg_create_compress(&cinfo); if (cinfo.dest == NULL) { - if(info->fp) { - cinfo.dest = (struct jpeg_destination_mgr *) - (*cinfo.mem->alloc_small) ((j_common_ptr) &cinfo, JPOOL_PERMANENT, - sizeof (ms_stream_destination_mgr)); - ((ms_stream_destination_mgr*)cinfo.dest)->mgr.pub.empty_output_buffer = jpeg_stream_empty_output_buffer; - ((ms_stream_destination_mgr*)cinfo.dest)->mgr.pub.term_destination = jpeg_stream_term_destination; - ((ms_stream_destination_mgr*)cinfo.dest)->stream = info->fp; + if (info->fp) { + cinfo.dest = (struct jpeg_destination_mgr *)(*cinfo.mem->alloc_small)( + (j_common_ptr)&cinfo, JPOOL_PERMANENT, + sizeof(ms_stream_destination_mgr)); + ((ms_stream_destination_mgr *)cinfo.dest)->mgr.pub.empty_output_buffer = + jpeg_stream_empty_output_buffer; + ((ms_stream_destination_mgr *)cinfo.dest)->mgr.pub.term_destination = + jpeg_stream_term_destination; + ((ms_stream_destination_mgr *)cinfo.dest)->stream = info->fp; } else { - cinfo.dest = (struct jpeg_destination_mgr *) - (*cinfo.mem->alloc_small) ((j_common_ptr) &cinfo, JPOOL_PERMANENT, - sizeof (ms_buffer_destination_mgr)); - ((ms_buffer_destination_mgr*)cinfo.dest)->mgr.pub.empty_output_buffer = jpeg_buffer_empty_output_buffer; - ((ms_buffer_destination_mgr*)cinfo.dest)->mgr.pub.term_destination = jpeg_buffer_term_destination; - ((ms_buffer_destination_mgr*)cinfo.dest)->buffer = info->buffer; + cinfo.dest = (struct jpeg_destination_mgr *)(*cinfo.mem->alloc_small)( + (j_common_ptr)&cinfo, JPOOL_PERMANENT, + sizeof(ms_buffer_destination_mgr)); + ((ms_buffer_destination_mgr *)cinfo.dest)->mgr.pub.empty_output_buffer = + jpeg_buffer_empty_output_buffer; + ((ms_buffer_destination_mgr *)cinfo.dest)->mgr.pub.term_destination = + jpeg_buffer_term_destination; + ((ms_buffer_destination_mgr *)cinfo.dest)->buffer = info->buffer; } } - dest = (ms_destination_mgr*) cinfo.dest; + dest = (ms_destination_mgr *)cinfo.dest; dest->pub.init_destination = jpeg_init_destination; cinfo.image_width = rb->width; @@ -208,43 +195,47 @@ int saveAsJPEG(mapObj *map, rasterBufferObj *rb, streamInfo *info, cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, quality, TRUE); - if( arithmetic ) + if (arithmetic) cinfo.arith_code = TRUE; - else if( optimized ) + else if (optimized) cinfo.optimize_coding = TRUE; - if( arithmetic || optimized ) { + if (arithmetic || optimized) { /* libjpeg turbo 1.5.2 honours max_memory_to_use, but has no backing */ /* store implementation, so better not set max_memory_to_use ourselves. */ /* See https://github.com/libjpeg-turbo/libjpeg-turbo/issues/162 */ - if( cinfo.mem->max_memory_to_use > 0 ) { + if (cinfo.mem->max_memory_to_use > 0) { if (map == NULL || msGetConfigOption(map, "JPEGMEM") == NULL) { - /* If the user doesn't provide a value for JPEGMEM, we want to be sure */ - /* that at least the image size will be used before creating the temporary file */ + /* If the user doesn't provide a value for JPEGMEM, we want to be sure + */ + /* that at least the image size will be used before creating the + * temporary file */ cinfo.mem->max_memory_to_use = - MS_MAX(cinfo.mem->max_memory_to_use, cinfo.input_components * rb->width * rb->height); + MS_MAX(cinfo.mem->max_memory_to_use, + cinfo.input_components * rb->width * rb->height); } } } jpeg_start_compress(&cinfo, TRUE); - rowdata = (JSAMPLE*)malloc(rb->width*cinfo.input_components*sizeof(JSAMPLE)); + rowdata = + (JSAMPLE *)malloc(rb->width * cinfo.input_components * sizeof(JSAMPLE)); - for(row=0; rowheight; row++) { + for (row = 0; row < rb->height; row++) { JSAMPLE *pixptr = rowdata; - unsigned char *r,*g,*b; - r=rb->data.rgba.r+row*rb->data.rgba.row_step; - g=rb->data.rgba.g+row*rb->data.rgba.row_step; - b=rb->data.rgba.b+row*rb->data.rgba.row_step; - for(unsigned col=0; colwidth; col++) { + unsigned char *r, *g, *b; + r = rb->data.rgba.r + row * rb->data.rgba.row_step; + g = rb->data.rgba.g + row * rb->data.rgba.row_step; + b = rb->data.rgba.b + row * rb->data.rgba.row_step; + for (unsigned col = 0; col < rb->width; col++) { *(pixptr++) = *r; *(pixptr++) = *g; *(pixptr++) = *b; - r+=rb->data.rgba.pixel_step; - g+=rb->data.rgba.pixel_step; - b+=rb->data.rgba.pixel_step; + r += rb->data.rgba.pixel_step; + g += rb->data.rgba.pixel_step; + b += rb->data.rgba.pixel_step; } - (void) jpeg_write_scanlines(&cinfo, &rowdata, 1); + (void)jpeg_write_scanlines(&cinfo, &rowdata, 1); } /* Step 6: Finish compression */ @@ -256,10 +247,11 @@ int saveAsJPEG(mapObj *map, rasterBufferObj *rb, streamInfo *info, } /* - * sort a given list of rgba entries so that all the opaque pixels are at the end + * sort a given list of rgba entries so that all the opaque pixels are at the + * end */ -int remapPaletteForPNG(rasterBufferObj *rb, rgbPixel *rgb, unsigned char *a, int *num_a) -{ +int remapPaletteForPNG(rasterBufferObj *rb, rgbPixel *rgb, unsigned char *a, + int *num_a) { int bot_idx, top_idx; unsigned x; int remap[256]; @@ -275,7 +267,8 @@ int remapPaletteForPNG(rasterBufferObj *rb, rgbPixel *rgb, unsigned char *a, int ** --not that this should matter to anyone. */ - for (top_idx = (int)rb->data.palette.num_entries-1, bot_idx = x = 0; x < rb->data.palette.num_entries; ++x) { + for (top_idx = (int)rb->data.palette.num_entries - 1, bot_idx = x = 0; + x < rb->data.palette.num_entries; ++x) { if (rb->data.palette.palette[x].a == maxval) remap[x] = top_idx--; else @@ -283,50 +276,53 @@ int remapPaletteForPNG(rasterBufferObj *rb, rgbPixel *rgb, unsigned char *a, int } /* sanity check: top and bottom indices should have just crossed paths */ if (bot_idx != top_idx + 1) { - msSetError(MS_MISCERR,"quantization sanity check failed","createPNGPalette()"); + msSetError(MS_MISCERR, "quantization sanity check failed", + "createPNGPalette()"); return MS_FAILURE; } *num_a = bot_idx; - for(x=0; xwidth*rb->height; x++) + for (x = 0; x < rb->width * rb->height; x++) rb->data.palette.pixels[x] = remap[rb->data.palette.pixels[x]]; - for (x = 0; x < rb->data.palette.num_entries; ++x) { - if(maxval == 255) { + if (maxval == 255) { a[remap[x]] = rb->data.palette.palette[x].a; rgb[remap[x]].r = rb->data.palette.palette[x].r; rgb[remap[x]].g = rb->data.palette.palette[x].g; rgb[remap[x]].b = rb->data.palette.palette[x].b; } else { /* rescale palette */ - rgb[remap[x]].r = (rb->data.palette.palette[x].r * 255 + (maxval >> 1)) / maxval; - rgb[remap[x]].g = (rb->data.palette.palette[x].g * 255 + (maxval >> 1)) / maxval; - rgb[remap[x]].b = (rb->data.palette.palette[x].b * 255 + (maxval >> 1)) / maxval; - a[remap[x]] = (rb->data.palette.palette[x].a * 255 + (maxval >> 1)) / maxval; + rgb[remap[x]].r = + (rb->data.palette.palette[x].r * 255 + (maxval >> 1)) / maxval; + rgb[remap[x]].g = + (rb->data.palette.palette[x].g * 255 + (maxval >> 1)) / maxval; + rgb[remap[x]].b = + (rb->data.palette.palette[x].b * 255 + (maxval >> 1)) / maxval; + a[remap[x]] = + (rb->data.palette.palette[x].a * 255 + (maxval >> 1)) / maxval; } - if(a[remap[x]] != 255) { + if (a[remap[x]] != 255) { /* un-premultiply pixels */ - double da = 255.0/a[remap[x]]; - rgb[remap[x]].r *= da; - rgb[remap[x]].g *= da; - rgb[remap[x]].b *= da; + double da = 255.0 / a[remap[x]]; + rgb[remap[x]].r *= da; + rgb[remap[x]].g *= da; + rgb[remap[x]].b *= da; } } return MS_SUCCESS; } -int savePalettePNG(rasterBufferObj *rb, streamInfo *info, int compression) -{ +int savePalettePNG(rasterBufferObj *rb, streamInfo *info, int compression) { png_infop info_ptr; rgbPixel rgb[256]; unsigned char a[256]; int num_a; int sample_depth; - png_structp png_ptr = png_create_write_struct( - PNG_LIBPNG_VER_STRING, NULL,NULL,NULL); + png_structp png_ptr = + png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); assert(rb->type == MS_BUFFER_BYTE_PALETTE); @@ -334,12 +330,11 @@ int savePalettePNG(rasterBufferObj *rb, streamInfo *info, int compression) return (MS_FAILURE); png_set_compression_level(png_ptr, compression); - png_set_filter (png_ptr,0, PNG_FILTER_NONE); + png_set_filter(png_ptr, 0, PNG_FILTER_NONE); info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { - png_destroy_write_struct(&png_ptr, - (png_infopp)NULL); + png_destroy_write_struct(&png_ptr, (png_infopp)NULL); return (MS_FAILURE); } @@ -347,11 +342,10 @@ int savePalettePNG(rasterBufferObj *rb, streamInfo *info, int compression) png_destroy_write_struct(&png_ptr, &info_ptr); return (MS_FAILURE); } - if(info->fp) - png_set_write_fn(png_ptr,info, png_write_data_to_stream, png_flush_data); + if (info->fp) + png_set_write_fn(png_ptr, info, png_write_data_to_stream, png_flush_data); else - png_set_write_fn(png_ptr,info, png_write_data_to_buffer, png_flush_data); - + png_set_write_fn(png_ptr, info, png_write_data_to_buffer, png_flush_data); if (rb->data.palette.num_entries <= 2) sample_depth = 1; @@ -362,22 +356,22 @@ int savePalettePNG(rasterBufferObj *rb, streamInfo *info, int compression) else sample_depth = 8; - png_set_IHDR(png_ptr, info_ptr, rb->width, rb->height, - sample_depth, PNG_COLOR_TYPE_PALETTE, - 0, PNG_COMPRESSION_TYPE_DEFAULT, + png_set_IHDR(png_ptr, info_ptr, rb->width, rb->height, sample_depth, + PNG_COLOR_TYPE_PALETTE, 0, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - remapPaletteForPNG(rb,rgb,a,&num_a); + remapPaletteForPNG(rb, rgb, a, &num_a); - png_set_PLTE(png_ptr, info_ptr, (png_colorp)(rgb),rb->data.palette.num_entries); - if(num_a) - png_set_tRNS(png_ptr, info_ptr, a,num_a, NULL); + png_set_PLTE(png_ptr, info_ptr, (png_colorp)(rgb), + rb->data.palette.num_entries); + if (num_a) + png_set_tRNS(png_ptr, info_ptr, a, num_a, NULL); png_write_info(png_ptr, info_ptr); png_set_packing(png_ptr); - for(unsigned row=0; rowheight; row++) { - unsigned char *rowptr = &(rb->data.palette.pixels[row*rb->width]); + for (unsigned row = 0; row < rb->height; row++) { + unsigned char *rowptr = &(rb->data.palette.pixels[row * rb->width]); png_write_row(png_ptr, rowptr); } png_write_end(png_ptr, info_ptr); @@ -385,38 +379,45 @@ int savePalettePNG(rasterBufferObj *rb, streamInfo *info, int compression) return MS_SUCCESS; } -int readPalette(const char *palette, rgbaPixel *entries, unsigned int *nEntries, int useAlpha) -{ +int readPalette(const char *palette, rgbaPixel *entries, unsigned int *nEntries, + int useAlpha) { FILE *stream = NULL; char buffer[MS_BUFFER_LENGTH]; *nEntries = 0; stream = fopen(palette, "r"); - if(!stream) { - msSetError(MS_IOERR, "Error opening palette file %s.", "readPalette()", palette); + if (!stream) { + msSetError(MS_IOERR, "Error opening palette file %s.", "readPalette()", + palette); return MS_FAILURE; } - while(fgets(buffer, MS_BUFFER_LENGTH, stream) && *nEntries<256) { - int r,g,b,a = 0; + while (fgets(buffer, MS_BUFFER_LENGTH, stream) && *nEntries < 256) { + int r, g, b, a = 0; /* while there are colors to load */ - if(buffer[0] == '#' || buffer[0] == '\n' || buffer[0] == '\r') + if (buffer[0] == '#' || buffer[0] == '\n' || buffer[0] == '\r') continue; /* skip comments and blank lines */ - if(!useAlpha) { - if(3 != sscanf(buffer,"%d,%d,%d\n",&r,&g,&b)) { + if (!useAlpha) { + if (3 != sscanf(buffer, "%d,%d,%d\n", &r, &g, &b)) { fclose(stream); - msSetError(MS_MISCERR,"failed to parse color %d r,g,b triplet in line \"%s\" from file %s","readPalette()",*nEntries+1,buffer,palette); + msSetError(MS_MISCERR, + "failed to parse color %d r,g,b triplet in line \"%s\" from " + "file %s", + "readPalette()", *nEntries + 1, buffer, palette); return MS_FAILURE; } } else { - if(4 != sscanf(buffer,"%d,%d,%d,%d\n",&r,&g,&b,&a)) { + if (4 != sscanf(buffer, "%d,%d,%d,%d\n", &r, &g, &b, &a)) { fclose(stream); - msSetError(MS_MISCERR,"failed to parse color %d r,g,b,a quadruplet in line \"%s\" from file %s","readPalette()",*nEntries+1,buffer,palette); + msSetError(MS_MISCERR, + "failed to parse color %d r,g,b,a quadruplet in line \"%s\" " + "from file %s", + "readPalette()", *nEntries + 1, buffer, palette); return MS_FAILURE; } } - if(useAlpha && a != 255) { - double da = a/255.0; + if (useAlpha && a != 255) { + double da = a / 255.0; entries[*nEntries].r = r * da; entries[*nEntries].g = g * da; entries[*nEntries].b = b * da; @@ -433,100 +434,113 @@ int readPalette(const char *palette, rgbaPixel *entries, unsigned int *nEntries, return MS_SUCCESS; } -int saveAsPNG(mapObj *map,rasterBufferObj *rb, streamInfo *info, outputFormatObj *format) -{ +int saveAsPNG(mapObj *map, rasterBufferObj *rb, streamInfo *info, + outputFormatObj *format) { int force_pc256 = MS_FALSE; int force_palette = MS_FALSE; - const char *force_string,*zlib_compression; + const char *force_string, *zlib_compression; int compression = -1; - zlib_compression = msGetOutputFormatOption( format, "COMPRESSION", NULL); - if(zlib_compression && *zlib_compression) { + zlib_compression = msGetOutputFormatOption(format, "COMPRESSION", NULL); + if (zlib_compression && *zlib_compression) { char *endptr; - compression = strtol(zlib_compression,&endptr,10); - if(*endptr || compression<-1 || compression>9) { - msSetError(MS_MISCERR,"failed to parse FORMATOPTION \"COMPRESSION=%s\", expecting integer from 0 to 9.","saveAsPNG()",zlib_compression); + compression = strtol(zlib_compression, &endptr, 10); + if (*endptr || compression < -1 || compression > 9) { + msSetError(MS_MISCERR, + "failed to parse FORMATOPTION \"COMPRESSION=%s\", expecting " + "integer from 0 to 9.", + "saveAsPNG()", zlib_compression); return MS_FAILURE; } } - - force_string = msGetOutputFormatOption( format, "QUANTIZE_FORCE", NULL ); - if( force_string && (strcasecmp(force_string,"on") == 0 || strcasecmp(force_string,"yes") == 0 || strcasecmp(force_string,"true") == 0) ) + force_string = msGetOutputFormatOption(format, "QUANTIZE_FORCE", NULL); + if (force_string && (strcasecmp(force_string, "on") == 0 || + strcasecmp(force_string, "yes") == 0 || + strcasecmp(force_string, "true") == 0)) force_pc256 = MS_TRUE; - force_string = msGetOutputFormatOption( format, "PALETTE_FORCE", NULL ); - if( force_string && (strcasecmp(force_string,"on") == 0 || strcasecmp(force_string,"yes") == 0 || strcasecmp(force_string,"true") == 0) ) + force_string = msGetOutputFormatOption(format, "PALETTE_FORCE", NULL); + if (force_string && (strcasecmp(force_string, "on") == 0 || + strcasecmp(force_string, "yes") == 0 || + strcasecmp(force_string, "true") == 0)) force_palette = MS_TRUE; - if(force_pc256 || force_palette) { + if (force_pc256 || force_palette) { rasterBufferObj qrb; rgbaPixel palette[256], paletteGiven[256]; unsigned int numPaletteGivenEntries; - memset(&qrb,0,sizeof(rasterBufferObj)); + memset(&qrb, 0, sizeof(rasterBufferObj)); qrb.type = MS_BUFFER_BYTE_PALETTE; qrb.width = rb->width; qrb.height = rb->height; - qrb.data.palette.pixels = (unsigned char*)malloc(qrb.width*qrb.height*sizeof(unsigned char)); + qrb.data.palette.pixels = + (unsigned char *)malloc(qrb.width * qrb.height * sizeof(unsigned char)); qrb.data.palette.scaling_maxval = 255; int ret; - if(force_pc256) { + if (force_pc256) { qrb.data.palette.palette = palette; - qrb.data.palette.num_entries = atoi(msGetOutputFormatOption( format, "QUANTIZE_COLORS", "256")); - ret = msQuantizeRasterBuffer(rb,&(qrb.data.palette.num_entries),qrb.data.palette.palette, - NULL, 0, + qrb.data.palette.num_entries = + atoi(msGetOutputFormatOption(format, "QUANTIZE_COLORS", "256")); + ret = msQuantizeRasterBuffer(rb, &(qrb.data.palette.num_entries), + qrb.data.palette.palette, NULL, 0, &qrb.data.palette.scaling_maxval); } else { - unsigned colorsWanted = (unsigned)atoi(msGetOutputFormatOption( format, "QUANTIZE_COLORS", "0")); - const char *palettePath = msGetOutputFormatOption( format, "PALETTE", "palette.txt"); + unsigned colorsWanted = (unsigned)atoi( + msGetOutputFormatOption(format, "QUANTIZE_COLORS", "0")); + const char *palettePath = + msGetOutputFormatOption(format, "PALETTE", "palette.txt"); char szPath[MS_MAXPATHLEN]; - if(map) { + if (map) { msBuildPath(szPath, map->mappath, palettePath); palettePath = szPath; } - if(readPalette(palettePath,paletteGiven,&numPaletteGivenEntries,format->transparent) != MS_SUCCESS) { + if (readPalette(palettePath, paletteGiven, &numPaletteGivenEntries, + format->transparent) != MS_SUCCESS) { return MS_FAILURE; } - if(numPaletteGivenEntries == 256 || colorsWanted == 0) { + if (numPaletteGivenEntries == 256 || colorsWanted == 0) { qrb.data.palette.palette = paletteGiven; qrb.data.palette.num_entries = numPaletteGivenEntries; ret = MS_SUCCESS; - /* we have a full palette and don't want an additional quantization step */ + /* we have a full palette and don't want an additional quantization step + */ } else { /* quantize the image, and mix our colours in the resulting palette */ qrb.data.palette.palette = palette; - qrb.data.palette.num_entries = MS_MAX(colorsWanted,numPaletteGivenEntries); - ret = msQuantizeRasterBuffer(rb,&(qrb.data.palette.num_entries),qrb.data.palette.palette, - paletteGiven,numPaletteGivenEntries, + qrb.data.palette.num_entries = + MS_MAX(colorsWanted, numPaletteGivenEntries); + ret = msQuantizeRasterBuffer(rb, &(qrb.data.palette.num_entries), + qrb.data.palette.palette, paletteGiven, + numPaletteGivenEntries, &qrb.data.palette.scaling_maxval); } } - if(ret != MS_FAILURE) { - msClassifyRasterBuffer(rb,&qrb); - ret = savePalettePNG(&qrb,info,compression); + if (ret != MS_FAILURE) { + msClassifyRasterBuffer(rb, &qrb); + ret = savePalettePNG(&qrb, info, compression); } msFree(qrb.data.palette.pixels); return ret; - } else if(rb->type == MS_BUFFER_BYTE_RGBA) { + } else if (rb->type == MS_BUFFER_BYTE_RGBA) { png_infop info_ptr; int color_type; unsigned int *rowdata; - png_structp png_ptr = png_create_write_struct( - PNG_LIBPNG_VER_STRING, NULL,NULL,NULL); + png_structp png_ptr = + png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) return (MS_FAILURE); png_set_compression_level(png_ptr, compression); - png_set_filter (png_ptr,0, PNG_FILTER_NONE); + png_set_filter(png_ptr, 0, PNG_FILTER_NONE); info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { - png_destroy_write_struct(&png_ptr, - (png_infopp)NULL); + png_destroy_write_struct(&png_ptr, (png_infopp)NULL); return (MS_FAILURE); } @@ -534,73 +548,72 @@ int saveAsPNG(mapObj *map,rasterBufferObj *rb, streamInfo *info, outputFormatObj png_destroy_write_struct(&png_ptr, &info_ptr); return (MS_FAILURE); } - if(info->fp) - png_set_write_fn(png_ptr,info, png_write_data_to_stream, png_flush_data); + if (info->fp) + png_set_write_fn(png_ptr, info, png_write_data_to_stream, png_flush_data); else - png_set_write_fn(png_ptr,info, png_write_data_to_buffer, png_flush_data); + png_set_write_fn(png_ptr, info, png_write_data_to_buffer, png_flush_data); - if(rb->data.rgba.a) + if (rb->data.rgba.a) color_type = PNG_COLOR_TYPE_RGB_ALPHA; else color_type = PNG_COLOR_TYPE_RGB; - png_set_IHDR(png_ptr, info_ptr, rb->width, rb->height, - 8, color_type, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + png_set_IHDR(png_ptr, info_ptr, rb->width, rb->height, 8, color_type, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); png_write_info(png_ptr, info_ptr); - if(!rb->data.rgba.a && rb->data.rgba.pixel_step==4) + if (!rb->data.rgba.a && rb->data.rgba.pixel_step == 4) png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); - rowdata = (unsigned int*)malloc(rb->width*sizeof(unsigned int)); - for(unsigned row=0; rowheight; row++) { + rowdata = (unsigned int *)malloc(rb->width * sizeof(unsigned int)); + for (unsigned row = 0; row < rb->height; row++) { unsigned int *pixptr = rowdata; - unsigned char *a,*r,*g,*b; - r=rb->data.rgba.r+row*rb->data.rgba.row_step; - g=rb->data.rgba.g+row*rb->data.rgba.row_step; - b=rb->data.rgba.b+row*rb->data.rgba.row_step; - if(rb->data.rgba.a) { - a=rb->data.rgba.a+row*rb->data.rgba.row_step; - for(unsigned col=0; colwidth; col++) { - if(*a) { - double da = *a/255.0; - unsigned char *pix = (unsigned char*)pixptr; - pix[0] = *r/da; - pix[1] = *g/da; - pix[2] = *b/da; + unsigned char *a, *r, *g, *b; + r = rb->data.rgba.r + row * rb->data.rgba.row_step; + g = rb->data.rgba.g + row * rb->data.rgba.row_step; + b = rb->data.rgba.b + row * rb->data.rgba.row_step; + if (rb->data.rgba.a) { + a = rb->data.rgba.a + row * rb->data.rgba.row_step; + for (unsigned col = 0; col < rb->width; col++) { + if (*a) { + double da = *a / 255.0; + unsigned char *pix = (unsigned char *)pixptr; + pix[0] = *r / da; + pix[1] = *g / da; + pix[2] = *b / da; pix[3] = *a; } else { - *pixptr=0; + *pixptr = 0; } pixptr++; - a+=rb->data.rgba.pixel_step; - r+=rb->data.rgba.pixel_step; - g+=rb->data.rgba.pixel_step; - b+=rb->data.rgba.pixel_step; + a += rb->data.rgba.pixel_step; + r += rb->data.rgba.pixel_step; + g += rb->data.rgba.pixel_step; + b += rb->data.rgba.pixel_step; } } else { - for(unsigned col=0; colwidth; col++) { - unsigned char *pix = (unsigned char*)pixptr; + for (unsigned col = 0; col < rb->width; col++) { + unsigned char *pix = (unsigned char *)pixptr; pix[0] = *r; pix[1] = *g; pix[2] = *b; pixptr++; - r+=rb->data.rgba.pixel_step; - g+=rb->data.rgba.pixel_step; - b+=rb->data.rgba.pixel_step; + r += rb->data.rgba.pixel_step; + g += rb->data.rgba.pixel_step; + b += rb->data.rgba.pixel_step; } } - png_write_row(png_ptr,(png_bytep)rowdata); - + png_write_row(png_ptr, (png_bytep)rowdata); } png_write_end(png_ptr, info_ptr); free(rowdata); png_destroy_write_struct(&png_ptr, &info_ptr); return MS_SUCCESS; } else { - msSetError(MS_MISCERR,"Unknown buffer type","saveAsPNG()"); + msSetError(MS_MISCERR, "Unknown buffer type", "saveAsPNG()"); return MS_FAILURE; } } @@ -612,60 +625,58 @@ int saveAsPNG(mapObj *map,rasterBufferObj *rb, streamInfo *info, outputFormatObj #define SEEK_SET 0 #endif /* SEEK_SET */ - -int readPNG(char *path, rasterBufferObj *rb) -{ - png_uint_32 width,height; - unsigned char *a,*r,*g,*b; - int bit_depth,color_type; +int readPNG(char *path, rasterBufferObj *rb) { + png_uint_32 width, height; + unsigned char *a, *r, *g, *b; + int bit_depth, color_type; unsigned char **row_pointers; png_structp png_ptr = NULL; png_infop info_ptr = NULL; - FILE *stream = fopen(path,"rb"); - if(!stream) + FILE *stream = fopen(path, "rb"); + if (!stream) return MS_FAILURE; /* could pass pointers to user-defined error handlers instead of NULLs: */ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { fclose(stream); - return MS_FAILURE; /* out of memory */ + return MS_FAILURE; /* out of memory */ } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, NULL, NULL); fclose(stream); - return MS_FAILURE; /* out of memory */ + return MS_FAILURE; /* out of memory */ } - if(setjmp(png_jmpbuf(png_ptr))) { - png_destroy_read_struct(&png_ptr,&info_ptr,NULL); + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); fclose(stream); return MS_FAILURE; } - png_init_io(png_ptr,stream); - png_read_info(png_ptr,info_ptr); - png_get_IHDR(png_ptr, info_ptr, &width, &height, - &bit_depth, &color_type, - NULL,NULL,NULL); + png_init_io(png_ptr, stream); + png_read_info(png_ptr, info_ptr); + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, + NULL, NULL, NULL); rb->width = width; rb->height = height; rb->type = MS_BUFFER_BYTE_RGBA; - rb->data.rgba.pixels = (unsigned char*)malloc(width*height*4*sizeof(unsigned char)); - row_pointers = (unsigned char**)malloc(height*sizeof(unsigned char*)); - rb->data.rgba.pixel_step=4; - rb->data.rgba.row_step = width*4; + rb->data.rgba.pixels = + (unsigned char *)malloc(width * height * 4 * sizeof(unsigned char)); + row_pointers = (unsigned char **)malloc(height * sizeof(unsigned char *)); + rb->data.rgba.pixel_step = 4; + rb->data.rgba.row_step = width * 4; b = rb->data.rgba.b = &rb->data.rgba.pixels[0]; g = rb->data.rgba.g = &rb->data.rgba.pixels[1]; r = rb->data.rgba.r = &rb->data.rgba.pixels[2]; a = rb->data.rgba.a = &rb->data.rgba.pixels[3]; - for(unsigned i=0; idata.rgba.pixels[i*rb->data.rgba.row_step]); + for (unsigned i = 0; i < height; i++) { + row_pointers[i] = &(rb->data.rgba.pixels[i * rb->data.rgba.row_step]); } if (color_type == PNG_COLOR_TYPE_PALETTE) @@ -695,68 +706,67 @@ int readPNG(char *path, rasterBufferObj *rb) png_read_image(png_ptr, row_pointers); free(row_pointers); - row_pointers=NULL; - png_read_end(png_ptr,NULL); + row_pointers = NULL; + png_read_end(png_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); /*premultiply data*/ - for(unsigned i=0; i> 8; *g = (*g * *a + 255) >> 8; *b = (*b * *a + 255) >> 8; } } - a+=4; - b+=4; - g+=4; - r+=4; + a += 4; + b += 4; + g += 4; + r += 4; } fclose(stream); return MS_SUCCESS; - } int msSaveRasterBuffer(mapObj *map, rasterBufferObj *rb, FILE *stream, - outputFormatObj *format) -{ - if(strcasestr(format->driver,"/png")) { + outputFormatObj *format) { + if (strcasestr(format->driver, "/png")) { streamInfo info; info.fp = stream; info.buffer = NULL; - return saveAsPNG(map, rb,&info,format); - } else if(strcasestr(format->driver,"/jpeg")) { + return saveAsPNG(map, rb, &info, format); + } else if (strcasestr(format->driver, "/jpeg")) { streamInfo info; info.fp = stream; - info.buffer=NULL; - - return saveAsJPEG(map, rb,&info,format); + info.buffer = NULL; + + return saveAsJPEG(map, rb, &info, format); } else { - msSetError(MS_MISCERR,"unsupported image format\n", "msSaveRasterBuffer()"); + msSetError(MS_MISCERR, "unsupported image format\n", + "msSaveRasterBuffer()"); return MS_FAILURE; } } int msSaveRasterBufferToBuffer(rasterBufferObj *data, bufferObj *buffer, - outputFormatObj *format) -{ - if(strcasestr(format->driver,"/png")) { + outputFormatObj *format) { + if (strcasestr(format->driver, "/png")) { streamInfo info; info.fp = NULL; info.buffer = buffer; - return saveAsPNG(NULL, data,&info,format); - } else if(strcasestr(format->driver,"/jpeg")) { + return saveAsPNG(NULL, data, &info, format); + } else if (strcasestr(format->driver, "/jpeg")) { streamInfo info; info.fp = NULL; - info.buffer=buffer; - return saveAsJPEG(NULL, data,&info,format); + info.buffer = buffer; + return saveAsJPEG(NULL, data, &info, format); } else { - msSetError(MS_MISCERR,"unsupported image format\n", "msSaveRasterBuffer()"); + msSetError(MS_MISCERR, "unsupported image format\n", + "msSaveRasterBuffer()"); return MS_FAILURE; } } @@ -774,112 +784,111 @@ static char const *gif_error_msg() int code = GifLastError(); #endif switch (code) { - case E_GIF_ERR_OPEN_FAILED: /* should not see this */ - return "Failed to open given file"; + case E_GIF_ERR_OPEN_FAILED: /* should not see this */ + return "Failed to open given file"; - case E_GIF_ERR_WRITE_FAILED: - return "Write failed"; + case E_GIF_ERR_WRITE_FAILED: + return "Write failed"; - case E_GIF_ERR_HAS_SCRN_DSCR: /* should not see this */ - return "Screen descriptor already passed to giflib"; + case E_GIF_ERR_HAS_SCRN_DSCR: /* should not see this */ + return "Screen descriptor already passed to giflib"; - case E_GIF_ERR_HAS_IMAG_DSCR: /* should not see this */ - return "Image descriptor already passed to giflib"; + case E_GIF_ERR_HAS_IMAG_DSCR: /* should not see this */ + return "Image descriptor already passed to giflib"; - case E_GIF_ERR_NO_COLOR_MAP: /* should not see this */ - return "Neither global nor local color map set"; + case E_GIF_ERR_NO_COLOR_MAP: /* should not see this */ + return "Neither global nor local color map set"; - case E_GIF_ERR_DATA_TOO_BIG: /* should not see this */ - return "Too much pixel data passed to giflib"; + case E_GIF_ERR_DATA_TOO_BIG: /* should not see this */ + return "Too much pixel data passed to giflib"; - case E_GIF_ERR_NOT_ENOUGH_MEM: - return "Out of memory"; + case E_GIF_ERR_NOT_ENOUGH_MEM: + return "Out of memory"; - case E_GIF_ERR_DISK_IS_FULL: - return "Disk is full"; + case E_GIF_ERR_DISK_IS_FULL: + return "Disk is full"; - case E_GIF_ERR_CLOSE_FAILED: /* should not see this */ - return "File close failed"; + case E_GIF_ERR_CLOSE_FAILED: /* should not see this */ + return "File close failed"; - case E_GIF_ERR_NOT_WRITEABLE: /* should not see this */ - return "File not writable"; + case E_GIF_ERR_NOT_WRITEABLE: /* should not see this */ + return "File not writable"; - case D_GIF_ERR_OPEN_FAILED: - return "Failed to open file"; + case D_GIF_ERR_OPEN_FAILED: + return "Failed to open file"; - case D_GIF_ERR_READ_FAILED: - return "Failed to read from file"; + case D_GIF_ERR_READ_FAILED: + return "Failed to read from file"; - case D_GIF_ERR_NOT_GIF_FILE: - return "File is not a GIF file"; + case D_GIF_ERR_NOT_GIF_FILE: + return "File is not a GIF file"; - case D_GIF_ERR_NO_SCRN_DSCR: - return "No screen descriptor detected - invalid file"; + case D_GIF_ERR_NO_SCRN_DSCR: + return "No screen descriptor detected - invalid file"; - case D_GIF_ERR_NO_IMAG_DSCR: - return "No image descriptor detected - invalid file"; + case D_GIF_ERR_NO_IMAG_DSCR: + return "No image descriptor detected - invalid file"; - case D_GIF_ERR_NO_COLOR_MAP: - return "No global or local color map found"; + case D_GIF_ERR_NO_COLOR_MAP: + return "No global or local color map found"; - case D_GIF_ERR_WRONG_RECORD: - return "Wrong record type detected - invalid file?"; + case D_GIF_ERR_WRONG_RECORD: + return "Wrong record type detected - invalid file?"; - case D_GIF_ERR_DATA_TOO_BIG: - return "Data in file too big for image"; + case D_GIF_ERR_DATA_TOO_BIG: + return "Data in file too big for image"; - case D_GIF_ERR_NOT_ENOUGH_MEM: - return "Out of memory"; + case D_GIF_ERR_NOT_ENOUGH_MEM: + return "Out of memory"; - case D_GIF_ERR_CLOSE_FAILED: - return "Close failed"; + case D_GIF_ERR_CLOSE_FAILED: + return "Close failed"; - case D_GIF_ERR_NOT_READABLE: - return "File not opened for read"; + case D_GIF_ERR_NOT_READABLE: + return "File not opened for read"; - case D_GIF_ERR_IMAGE_DEFECT: - return "Defective image"; + case D_GIF_ERR_IMAGE_DEFECT: + return "Defective image"; - case D_GIF_ERR_EOF_TOO_SOON: - return "Unexpected EOF - invalid file"; + case D_GIF_ERR_EOF_TOO_SOON: + return "Unexpected EOF - invalid file"; - default: - sprintf(msg, "Unknown giflib error code %d", code); - return msg; + default: + sprintf(msg, "Unknown giflib error code %d", code); + return msg; } } - /* not fully implemented and tested */ /* missing: set the first pointer to a,r,g,b */ -int readGIF(char *path, rasterBufferObj *rb) -{ +int readGIF(char *path, rasterBufferObj *rb) { int codeSize, extCode, firstImageRead = MS_FALSE; - unsigned char *r,*g,*b,*a; + unsigned char *r, *g, *b, *a; int transIdx = -1; GifFileType *image; GifPixelType *line; GifRecordType recordType; GifByteType *codeBlock, *extension; ColorMapObject *cmap; - int interlacedOffsets[] = {0,4,2,1}; - int interlacedJumps[] = {8,8,4,2}; + int interlacedOffsets[] = {0, 4, 2, 1}; + int interlacedJumps[] = {8, 8, 4, 2}; #if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 int errcode; #endif - rb->type = MS_BUFFER_BYTE_RGBA; #if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 - image = DGifOpenFileName(path, &errcode); + image = DGifOpenFileName(path, &errcode); if (image == NULL) { - msSetError(MS_MISCERR,"failed to load gif image: %s","readGIF()", gif_error_msg(errcode)); + msSetError(MS_MISCERR, "failed to load gif image: %s", "readGIF()", + gif_error_msg(errcode)); return MS_FAILURE; } #else - image = DGifOpenFileName(path); + image = DGifOpenFileName(path); if (image == NULL) { - msSetError(MS_MISCERR,"failed to load gif image: %s","readGIF()", gif_error_msg()); + msSetError(MS_MISCERR, "failed to load gif image: %s", "readGIF()", + gif_error_msg()); return MS_FAILURE; } #endif @@ -887,114 +896,93 @@ int readGIF(char *path, rasterBufferObj *rb) rb->height = image->SHeight; rb->data.rgba.row_step = rb->width * 4; rb->data.rgba.pixel_step = 4; - rb->data.rgba.pixels = (unsigned char*)malloc(rb->width*rb->height*4*sizeof(unsigned char)); + rb->data.rgba.pixels = (unsigned char *)malloc(rb->width * rb->height * 4 * + sizeof(unsigned char)); b = rb->data.rgba.b = &rb->data.rgba.pixels[0]; g = rb->data.rgba.g = &rb->data.rgba.pixels[1]; r = rb->data.rgba.r = &rb->data.rgba.pixels[2]; a = rb->data.rgba.a = &rb->data.rgba.pixels[3]; - cmap = (image->Image.ColorMap)?image->Image.ColorMap:image->SColorMap; - for(unsigned i=0; iwidth*rb->height; i++) { + cmap = (image->Image.ColorMap) ? image->Image.ColorMap : image->SColorMap; + for (unsigned i = 0; i < rb->width * rb->height; i++) { *a = 255; *r = cmap->Colors[image->SBackGroundColor].Red; *g = cmap->Colors[image->SBackGroundColor].Green; *b = cmap->Colors[image->SBackGroundColor].Blue; - a+=rb->data.rgba.pixel_step; - r+=rb->data.rgba.pixel_step; - g+=rb->data.rgba.pixel_step; - b+=rb->data.rgba.pixel_step; + a += rb->data.rgba.pixel_step; + r += rb->data.rgba.pixel_step; + g += rb->data.rgba.pixel_step; + b += rb->data.rgba.pixel_step; } do { if (DGifGetRecordType(image, &recordType) == GIF_ERROR) { #if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg(image->Error)); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg(image->Error)); #else - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg()); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg()); #endif return MS_FAILURE; } switch (recordType) { - case SCREEN_DESC_RECORD_TYPE: - DGifGetScreenDesc(image); - break; - case IMAGE_DESC_RECORD_TYPE: - if (DGifGetImageDesc(image) == GIF_ERROR) { + case SCREEN_DESC_RECORD_TYPE: + DGifGetScreenDesc(image); + break; + case IMAGE_DESC_RECORD_TYPE: + if (DGifGetImageDesc(image) == GIF_ERROR) { #if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg(image->Error)); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg(image->Error)); #else - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg()); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg()); #endif + return MS_FAILURE; + } + if (!firstImageRead) { + + unsigned row = image->Image.Top; + unsigned col = image->Image.Left; + unsigned width = image->Image.Width; + unsigned height = image->Image.Height; + + /* sanity check: */ + if (col + width > rb->width || row + height > rb->height) { + msSetError(MS_MISCERR, + "corrupted gif image, img size exceeds screen size", + "readGIF()"); return MS_FAILURE; } - if (!firstImageRead) { - unsigned row = image->Image.Top; - unsigned col = image->Image.Left; - unsigned width = image->Image.Width; - unsigned height = image->Image.Height; - - /* sanity check: */ - if(col+width>rb->width || row+height>rb->height) { - msSetError(MS_MISCERR,"corrupted gif image, img size exceeds screen size","readGIF()"); - return MS_FAILURE; - } - - line = (GifPixelType *) malloc(width * sizeof(GifPixelType)); - if(image->Image.Interlace) { - int count; - for(count=0; count<4; count++) { - for(unsigned i=row+interlacedOffsets[count]; idata.rgba.row_step + col * rb->data.rgba.pixel_step; - a = rb->data.rgba.a + offset; - r = rb->data.rgba.r + offset; - g = rb->data.rgba.g + offset; - b = rb->data.rgba.b + offset; - if (DGifGetLine(image, line, width) == GIF_ERROR) { -#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()",gif_error_msg(image->Error)); -#else - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()",gif_error_msg()); -#endif - return MS_FAILURE; - } - - for(unsigned j=0; jColors[pix].Red; - *g = cmap->Colors[pix].Green; - *b = cmap->Colors[pix].Blue; - } else { - *a = *r = *g = *b = 0; - } - a+=rb->data.rgba.pixel_step; - r+=rb->data.rgba.pixel_step; - g+=rb->data.rgba.pixel_step; - b+=rb->data.rgba.pixel_step; - } - } - } - } else { - for (unsigned i = 0; i < height; i++) { - int offset = i * rb->data.rgba.row_step + col * rb->data.rgba.pixel_step; + line = (GifPixelType *)malloc(width * sizeof(GifPixelType)); + if (image->Image.Interlace) { + int count; + for (count = 0; count < 4; count++) { + for (unsigned i = row + interlacedOffsets[count]; i < row + height; + i += interlacedJumps[count]) { + int offset = + i * rb->data.rgba.row_step + col * rb->data.rgba.pixel_step; a = rb->data.rgba.a + offset; r = rb->data.rgba.r + offset; g = rb->data.rgba.g + offset; b = rb->data.rgba.b + offset; if (DGifGetLine(image, line, width) == GIF_ERROR) { #if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()",gif_error_msg(image->Error)); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg(image->Error)); #else - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()",gif_error_msg()); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg()); #endif return MS_FAILURE; } - for(unsigned j=0; jColors[pix].Red; *g = cmap->Colors[pix].Green; @@ -1002,86 +990,132 @@ int readGIF(char *path, rasterBufferObj *rb) } else { *a = *r = *g = *b = 0; } - a+=rb->data.rgba.pixel_step; - r+=rb->data.rgba.pixel_step; - g+=rb->data.rgba.pixel_step; - b+=rb->data.rgba.pixel_step; + a += rb->data.rgba.pixel_step; + r += rb->data.rgba.pixel_step; + g += rb->data.rgba.pixel_step; + b += rb->data.rgba.pixel_step; } } } - free((char *) line); - firstImageRead = MS_TRUE; } else { - /* Skip all next images */ - if (DGifGetCode(image, &codeSize, &codeBlock) == GIF_ERROR) { -#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg(image->Error)); -#else - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg()); -#endif - return MS_FAILURE; - } - while (codeBlock != NULL) { - if (DGifGetCodeNext(image, &codeBlock) == GIF_ERROR) { + for (unsigned i = 0; i < height; i++) { + int offset = + i * rb->data.rgba.row_step + col * rb->data.rgba.pixel_step; + a = rb->data.rgba.a + offset; + r = rb->data.rgba.r + offset; + g = rb->data.rgba.g + offset; + b = rb->data.rgba.b + offset; + if (DGifGetLine(image, line, width) == GIF_ERROR) { #if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg(image->Error)); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg(image->Error)); #else - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg()); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg()); #endif return MS_FAILURE; } + for (unsigned j = 0; j < width; j++) { + GifPixelType pix = line[j]; + if (transIdx == -1 || pix != transIdx) { + *a = 255; + *r = cmap->Colors[pix].Red; + *g = cmap->Colors[pix].Green; + *b = cmap->Colors[pix].Blue; + } else { + *a = *r = *g = *b = 0; + } + a += rb->data.rgba.pixel_step; + r += rb->data.rgba.pixel_step; + g += rb->data.rgba.pixel_step; + b += rb->data.rgba.pixel_step; + } } } - break; - case EXTENSION_RECORD_TYPE: - /* skip all extension blocks */ - if (DGifGetExtension(image, &extCode, &extension) == GIF_ERROR) { + free((char *)line); + firstImageRead = MS_TRUE; + } else { + /* Skip all next images */ + if (DGifGetCode(image, &codeSize, &codeBlock) == GIF_ERROR) { #if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg(image->Error)); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg(image->Error)); #else - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg()); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg()); #endif return MS_FAILURE; } - if(extCode == 249 && (extension[1] & 1)) - transIdx = extension[4]; - for (;;) { - if (DGifGetExtensionNext(image, &extension) == GIF_ERROR) { + while (codeBlock != NULL) { + if (DGifGetCodeNext(image, &codeBlock) == GIF_ERROR) { #if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg(image->Error)); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg(image->Error)); #else - msSetError(MS_MISCERR,"corrupted gif image?: %s","readGIF()", gif_error_msg()); + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg()); #endif return MS_FAILURE; } - if (extension == NULL) - break; - if(extension[1] & 1) - transIdx = extension[4]; } - break; - case UNDEFINED_RECORD_TYPE: - break; - case TERMINATE_RECORD_TYPE: - break; - default: - break; + } + break; + case EXTENSION_RECORD_TYPE: + /* skip all extension blocks */ + if (DGifGetExtension(image, &extCode, &extension) == GIF_ERROR) { +#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg(image->Error)); +#else + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg()); +#endif + return MS_FAILURE; + } + if (extCode == 249 && (extension[1] & 1)) + transIdx = extension[4]; + for (;;) { + if (DGifGetExtensionNext(image, &extension) == GIF_ERROR) { +#if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg(image->Error)); +#else + msSetError(MS_MISCERR, "corrupted gif image?: %s", "readGIF()", + gif_error_msg()); +#endif + return MS_FAILURE; + } + if (extension == NULL) + break; + if (extension[1] & 1) + transIdx = extension[4]; + } + break; + case UNDEFINED_RECORD_TYPE: + break; + case TERMINATE_RECORD_TYPE: + break; + default: + break; } } while (recordType != TERMINATE_RECORD_TYPE); - -#if defined GIFLIB_MAJOR && GIFLIB_MINOR && ((GIFLIB_MAJOR == 5 && GIFLIB_MINOR >= 1) || (GIFLIB_MAJOR > 5)) +#if defined GIFLIB_MAJOR && GIFLIB_MINOR && \ + ((GIFLIB_MAJOR == 5 && GIFLIB_MINOR >= 1) || (GIFLIB_MAJOR > 5)) if (DGifCloseFile(image, &errcode) == GIF_ERROR) { - msSetError(MS_MISCERR,"failed to close gif after loading: %s","readGIF()", gif_error_msg(errcode)); + msSetError(MS_MISCERR, "failed to close gif after loading: %s", "readGIF()", + gif_error_msg(errcode)); return MS_FAILURE; } #else if (DGifCloseFile(image) == GIF_ERROR) { #if defined GIFLIB_MAJOR && GIFLIB_MAJOR >= 5 - msSetError(MS_MISCERR,"failed to close gif after loading: %s","readGIF()", gif_error_msg(image->Error)); + msSetError(MS_MISCERR, "failed to close gif after loading: %s", "readGIF()", + gif_error_msg(image->Error)); #else - msSetError(MS_MISCERR,"failed to close gif after loading: %s","readGIF()", gif_error_msg()); + msSetError(MS_MISCERR, "failed to close gif after loading: %s", "readGIF()", + gif_error_msg()); #endif return MS_FAILURE; } @@ -1091,33 +1125,37 @@ int readGIF(char *path, rasterBufferObj *rb) } #endif -int msLoadMSRasterBufferFromFile(char *path, rasterBufferObj *rb) -{ +int msLoadMSRasterBufferFromFile(char *path, rasterBufferObj *rb) { FILE *stream; unsigned char signature[8]; int ret = MS_FAILURE; - stream = fopen(path,"rb"); - if(!stream) { - msSetError(MS_MISCERR, "unable to open file %s for reading", "msLoadMSRasterBufferFromFile()", path); + stream = fopen(path, "rb"); + if (!stream) { + msSetError(MS_MISCERR, "unable to open file %s for reading", + "msLoadMSRasterBufferFromFile()", path); return MS_FAILURE; } - if(1 != fread(signature,8,1,stream)) { + if (1 != fread(signature, 8, 1, stream)) { fclose(stream); - msSetError(MS_MISCERR, "Unable to read header from image file %s", "msLoadMSRasterBufferFromFile()",path); + msSetError(MS_MISCERR, "Unable to read header from image file %s", + "msLoadMSRasterBufferFromFile()", path); return MS_FAILURE; } fclose(stream); - if(png_sig_cmp(signature,0,8) == 0) { - ret = readPNG(path,rb); - } else if (!strncmp((char*)signature,"GIF",3)) { + if (png_sig_cmp(signature, 0, 8) == 0) { + ret = readPNG(path, rb); + } else if (!strncmp((char *)signature, "GIF", 3)) { #ifdef USE_GIF - ret = readGIF(path,rb); + ret = readGIF(path, rb); #else - msSetError(MS_MISCERR,"pixmap %s seems to be GIF formatted, but this server is compiled without GIF support","readImage()",path); + msSetError(MS_MISCERR, + "pixmap %s seems to be GIF formatted, but this server is " + "compiled without GIF support", + "readImage()", path); return MS_FAILURE; #endif } else { - msSetError(MS_MISCERR,"unsupported pixmap format","readImage()"); + msSetError(MS_MISCERR, "unsupported pixmap format", "readImage()"); return MS_FAILURE; } return ret; diff --git a/mapimagemap.c b/mapimagemap.c index 0d378d6f64..f37bb2d138 100644 --- a/mapimagemap.c +++ b/mapimagemap.c @@ -38,8 +38,6 @@ #include #endif - - #define MYDEBUG 0 #define DEBUG_IF if (MYDEBUG > 2) @@ -107,46 +105,45 @@ typedef struct pString { * imagemap/dxf file; parts of this live in another data structure and * are only referenced indirectly here. The other contains layer-specific * information for the dxf output. */ -static char *layerlist=NULL; -static int layersize=0; -static pString imgStr, layerStr= { &layerlist, &layersize, 0 }; +static char *layerlist = NULL; +static int layersize = 0; +static pString imgStr, layerStr = {&layerlist, &layersize, 0}; /* Format strings for the various bits of a client-side imagemap. */ static const char *polyHrefFmt, *polyMOverFmt, *polyMOutFmt; static const char *symbolHrefFmt, *symbolMOverFmt, *symbolMOutFmt; static const char *mapName; /* Should we suppress AREA declarations in imagemaps with no title? */ -static int suppressEmpty=0; +static int suppressEmpty = 0; /* Prevent buffer-overrun and format-string attacks by "sanitizing" any * provided format string to fit the number of expected string arguments * (MAX) exactly. */ -static const char *makeFmtSafe(const char *fmt, int MAX) -{ +static const char *makeFmtSafe(const char *fmt, int MAX) { /* format string should have exactly 'MAX' %s */ - char *result = msSmallMalloc(strlen(fmt)+1+3*MAX), *cp; - int numstr=0, saw_percent=0; + char *result = msSmallMalloc(strlen(fmt) + 1 + 3 * MAX), *cp; + int numstr = 0, saw_percent = 0; strcpy(result, fmt); - for (cp=result; *cp; cp++) { + for (cp = result; *cp; cp++) { if (saw_percent) { - if (*cp=='%') { + if (*cp == '%') { /* safe */ - } else if (*cp=='s' && numstralloc_size) - ps->string_len; va_start(ap, fmt); #if defined(HAVE_VSNPRINTF) - n = vsnprintf((*(ps->string)) + ps->string_len, - remaining, fmt, ap); + n = vsnprintf((*(ps->string)) + ps->string_len, remaining, fmt, ap); #else /* If vsnprintf() is not available then require a minimum * of 512 bytes of free space to prevent a buffer overflow @@ -177,35 +172,33 @@ static void im_iprintf(pString *ps, const char *fmt, ...) #endif va_end(ap); /* if that worked, we're done! */ - if (-1string_len += n; return; - } else { /* double allocated string size */ - *(ps->alloc_size) *= 2;/* these keeps realloc linear.*/ + } else { /* double allocated string size */ + *(ps->alloc_size) *= 2; /* these keeps realloc linear.*/ if (*(ps->alloc_size) < 1024) /* careful: initial size can be 0 */ - *(ps->alloc_size)=1024; - if (n>-1 && *(ps->alloc_size) <= (n + ps->string_len)) + *(ps->alloc_size) = 1024; + if (n > -1 && *(ps->alloc_size) <= (n + ps->string_len)) /* ensure at least as much as what is needed */ - *(ps->alloc_size) = n+ps->string_len+1; - *(ps->string) = (char *) msSmallRealloc - (*(ps->string), *(ps->alloc_size)); + *(ps->alloc_size) = n + ps->string_len + 1; + *(ps->string) = (char *)msSmallRealloc(*(ps->string), *(ps->alloc_size)); /* if realloc doesn't work, we're screwed! */ } } while (1); /* go back and try again. */ } - - -static int lastcolor=-1; -static int matchdxfcolor(colorObj col) -{ - int best=7; - int delta=128*255; +static int lastcolor = -1; +static int matchdxfcolor(colorObj col) { + int best = 7; + int delta = 128 * 255; int tcolor = 0; if (lastcolor != -1) return lastcolor; - while (tcolor < 256 && (ctable[tcolor].r != col.red || ctable[tcolor].g != col.green || ctable[tcolor].b != col.blue)) { + while (tcolor < 256 && + (ctable[tcolor].r != col.red || ctable[tcolor].g != col.green || + ctable[tcolor].b != col.blue)) { const int dr = ctable[tcolor].r - col.red; const int dg = ctable[tcolor].g - col.green; const int db = ctable[tcolor].b - col.blue; @@ -216,17 +209,19 @@ static int matchdxfcolor(colorObj col) } tcolor++; } - if (tcolor >= 256) tcolor = best; - /* DEBUG_IF printf("%d/%d/%d (%d/%d - %d), %d : %d/%d/%d
\n", ctable[tcolor].r, ctable[tcolor].g, ctable[tcolor].b, tcolor, best, delta, lastcolor, col.red, col.green, col.blue); */ + if (tcolor >= 256) + tcolor = best; + /* DEBUG_IF printf("%d/%d/%d (%d/%d - %d), %d : %d/%d/%d
\n", + * ctable[tcolor].r, ctable[tcolor].g, ctable[tcolor].b, tcolor, best, delta, + * lastcolor, col.red, col.green, col.blue); */ lastcolor = tcolor; return tcolor; } -static char* lname; +static char *lname; static int dxf; -void msImageStartLayerIM(mapObj *map, layerObj *layer, imageObj *image) -{ +void msImageStartLayerIM(mapObj *map, layerObj *layer, imageObj *image) { (void)map; (void)image; DEBUG_IF printf("ImageStartLayerIM\n
"); @@ -240,7 +235,8 @@ void msImageStartLayerIM(mapObj *map, layerObj *layer, imageObj *image) } else if (dxf) { im_iprintf(&layerStr, " 0\nLAYER\n 2\n%s\n" - " 70\n 64\n 6\nCONTINUOUS\n", lname); + " 70\n 64\n 6\nCONTINUOUS\n", + lname); } lastcolor = -1; } @@ -250,15 +246,15 @@ void msImageStartLayerIM(mapObj *map, layerObj *layer, imageObj *image) * a pointer to an imageObj structure. */ imageObj *msImageCreateIM(int width, int height, outputFormatObj *format, - char *imagepath, char *imageurl, double resolution, double defresolution) -{ - imageObj *image=NULL; - if (setvbuf(stdout, NULL, _IONBF , 0)) { + char *imagepath, char *imageurl, double resolution, + double defresolution) { + imageObj *image = NULL; + if (setvbuf(stdout, NULL, _IONBF, 0)) { printf("Whoops..."); }; DEBUG_IF printf("msImageCreateIM
\n"); if (width > 0 && height > 0) { - image = (imageObj *)msSmallCalloc(1,sizeof(imageObj)); + image = (imageObj *)msSmallCalloc(1, sizeof(imageObj)); imgStr.string = &(image->img.imagemap); imgStr.alloc_size = &(image->size); @@ -270,48 +266,51 @@ imageObj *msImageCreateIM(int width, int height, outputFormatObj *format, image->imagepath = NULL; image->imageurl = NULL; image->resolution = resolution; - image->resolutionfactor = resolution/defresolution; + image->resolutionfactor = resolution / defresolution; - if( strcasecmp("ON",msGetOutputFormatOption( format, "DXF", "OFF" )) == 0) { + if (strcasecmp("ON", msGetOutputFormatOption(format, "DXF", "OFF")) == 0) { dxf = 1; im_iprintf(&layerStr, " 2\nLAYER\n 70\n 10\n"); } else dxf = 0; - if( strcasecmp("ON",msGetOutputFormatOption( format, "SCRIPT", "OFF" )) == 0) { + if (strcasecmp("ON", msGetOutputFormatOption(format, "SCRIPT", "OFF")) == + 0) { dxf = 2; im_iprintf(&layerStr, ""); } /* get href formation string options */ - polyHrefFmt = makeFmtSafe(msGetOutputFormatOption - ( format, "POLYHREF", "javascript:Clicked('%s');"), 1); - polyMOverFmt = makeFmtSafe(msGetOutputFormatOption - ( format, "POLYMOUSEOVER", ""), 1); - polyMOutFmt = makeFmtSafe(msGetOutputFormatOption - ( format, "POLYMOUSEOUT", ""), 1); - symbolHrefFmt = makeFmtSafe(msGetOutputFormatOption - ( format, "SYMBOLHREF", "javascript:SymbolClicked();"), 1); - symbolMOverFmt = makeFmtSafe(msGetOutputFormatOption - ( format, "SYMBOLMOUSEOVER", ""), 1); - symbolMOutFmt = makeFmtSafe(msGetOutputFormatOption - ( format, "SYMBOLMOUSEOUT", ""), 1); + polyHrefFmt = + makeFmtSafe(msGetOutputFormatOption(format, "POLYHREF", + "javascript:Clicked('%s');"), + 1); + polyMOverFmt = + makeFmtSafe(msGetOutputFormatOption(format, "POLYMOUSEOVER", ""), 1); + polyMOutFmt = + makeFmtSafe(msGetOutputFormatOption(format, "POLYMOUSEOUT", ""), 1); + symbolHrefFmt = + makeFmtSafe(msGetOutputFormatOption(format, "SYMBOLHREF", + "javascript:SymbolClicked();"), + 1); + symbolMOverFmt = + makeFmtSafe(msGetOutputFormatOption(format, "SYMBOLMOUSEOVER", ""), 1); + symbolMOutFmt = + makeFmtSafe(msGetOutputFormatOption(format, "SYMBOLMOUSEOUT", ""), 1); /* get name of client-side image map */ - mapName = msGetOutputFormatOption - ( format, "MAPNAME", "map1" ); + mapName = msGetOutputFormatOption(format, "MAPNAME", "map1"); /* should we suppress area declarations with no title? */ - if( strcasecmp("YES",msGetOutputFormatOption( format, "SUPPRESS", "NO" )) == 0) { - suppressEmpty=1; + if (strcasecmp("YES", msGetOutputFormatOption(format, "SUPPRESS", "NO")) == + 0) { + suppressEmpty = 1; } lname = msStrdup("NONE"); *(imgStr.string) = msStrdup(""); if (*(imgStr.string)) { - *(imgStr.alloc_size) = - imgStr.string_len = strlen(*(imgStr.string)); + *(imgStr.alloc_size) = imgStr.string_len = strlen(*(imgStr.string)); } else { - *(imgStr.alloc_size) = - imgStr.string_len = 0; + *(imgStr.alloc_size) = imgStr.string_len = 0; } if (imagepath) { image->imagepath = msStrdup(imagepath); @@ -322,9 +321,8 @@ imageObj *msImageCreateIM(int width, int height, outputFormatObj *format, return image; } else { - msSetError(MS_IMGERR, - "Cannot create IM image of size %d x %d.", - "msImageCreateIM()", width, height ); + msSetError(MS_IMGERR, "Cannot create IM image of size %d x %d.", + "msImageCreateIM()", width, height); } return image; } @@ -332,8 +330,8 @@ imageObj *msImageCreateIM(int width, int height, outputFormatObj *format, /* ------------------------------------------------------------------------- */ /* Draw a single marker symbol of the specified size and color */ /* ------------------------------------------------------------------------- */ -void msDrawMarkerSymbolIM(mapObj *map, imageObj* img, pointObj *p, styleObj *style, double scalefactor) -{ +void msDrawMarkerSymbolIM(mapObj *map, imageObj *img, pointObj *p, + styleObj *style, double scalefactor) { symbolObj *symbol; int ox, oy; double size; @@ -342,56 +340,57 @@ void msDrawMarkerSymbolIM(mapObj *map, imageObj* img, pointObj *p, styleObj *sty /* skip this, we don't do text */ + if (!p) + return; - - if(!p) return; - - - if(style->symbol > map->symbolset.numsymbols || style->symbol < 0) return; /* no such symbol, 0 is OK */ + if (style->symbol > map->symbolset.numsymbols || style->symbol < 0) + return; /* no such symbol, 0 is OK */ symbol = map->symbolset.symbol[style->symbol]; - ox = style->offsetx*scalefactor; - oy = style->offsety*scalefactor; - if(style->size == -1) { - size = msSymbolGetDefaultSize( symbol ); - size = MS_NINT(size*scalefactor); + ox = style->offsetx * scalefactor; + oy = style->offsety * scalefactor; + if (style->size == -1) { + size = msSymbolGetDefaultSize(symbol); + size = MS_NINT(size * scalefactor); } else - size = MS_NINT(style->size*scalefactor); - size = MS_MAX(size, style->minsize*img->resolutionfactor); - size = MS_MIN(size, style->maxsize*img->resolutionfactor); + size = MS_NINT(style->size * scalefactor); + size = MS_MAX(size, style->minsize * img->resolutionfactor); + size = MS_MIN(size, style->maxsize * img->resolutionfactor); - if(size < 1) return; /* size too small */ + if (size < 1) + return; /* size too small */ /* DEBUG_IF printf(".%d.%d.%d.", symbol->type, style->symbol, fc); */ - if(style->symbol == 0) { /* simply draw a single pixel of the specified color */ + if (style->symbol == + 0) { /* simply draw a single pixel of the specified color */ if (dxf) { - if (dxf==2) - im_iprintf (&imgStr, "POINT\n%.0f %.0f\n%d\n", - p->x + ox, p->y + oy, matchdxfcolor(style->color)); + if (dxf == 2) + im_iprintf(&imgStr, "POINT\n%.0f %.0f\n%d\n", p->x + ox, p->y + oy, + matchdxfcolor(style->color)); else - im_iprintf (&imgStr, - " 0\nPOINT\n 10\n%f\n 20\n%f\n 30\n0.0\n" - " 62\n%6d\n 8\n%s\n", - p->x + ox, p->y + oy, matchdxfcolor(style->color), lname); + im_iprintf(&imgStr, + " 0\nPOINT\n 10\n%f\n 20\n%f\n 30\n0.0\n" + " 62\n%6d\n 8\n%s\n", + p->x + ox, p->y + oy, matchdxfcolor(style->color), lname); } else { - im_iprintf (&imgStr, "\n", - p->x + ox, p->y + oy); + im_iprintf(&imgStr, "shape=\"circle\" coords=\"%.0f,%.0f, 3\" />\n", + p->x + ox, p->y + oy); } /* point2 = &( p->line[j].point[i] ); */ @@ -399,61 +398,61 @@ void msDrawMarkerSymbolIM(mapObj *map, imageObj* img, pointObj *p, styleObj *sty return; } DEBUG_IF printf("A"); - switch(symbol->type) { - case(MS_SYMBOL_TRUETYPE): - DEBUG_IF printf("T"); - break; - case(MS_SYMBOL_PIXMAP): - DEBUG_IF printf("P"); - break; - case(MS_SYMBOL_VECTOR): - DEBUG_IF printf("V"); - { - double d, offset_x, offset_y; - - d = size/symbol->sizey; - offset_x = MS_NINT(p->x - d*.5*symbol->sizex + ox); - offset_y = MS_NINT(p->y - d*.5*symbol->sizey + oy); - - /* For now I only render filled vector symbols in imagemap, and no */ - /* dxf support available yet. */ - if(symbol->filled && !dxf /* && fc >= 0 */ ) { - /* char *title=(p->numvalues) ? p->values[0] : ""; */ - char *title = ""; - int j; - - im_iprintf (&imgStr, "numpoints; j++) { - im_iprintf (&imgStr, "%s %d,%d", j == 0 ? "": ",", - (int)MS_NINT(d*symbol->points[j].x + offset_x), - (int)MS_NINT(d*symbol->points[j].y + offset_y) ); - } - im_iprintf (&imgStr, "\" />\n"); - } /* end of imagemap, filled case. */ - } - break; + switch (symbol->type) { + case (MS_SYMBOL_TRUETYPE): + DEBUG_IF printf("T"); + break; + case (MS_SYMBOL_PIXMAP): + DEBUG_IF printf("P"); + break; + case (MS_SYMBOL_VECTOR): + DEBUG_IF printf("V"); + { + double d, offset_x, offset_y; + + d = size / symbol->sizey; + offset_x = MS_NINT(p->x - d * .5 * symbol->sizex + ox); + offset_y = MS_NINT(p->y - d * .5 * symbol->sizey + oy); + + /* For now I only render filled vector symbols in imagemap, and no */ + /* dxf support available yet. */ + if (symbol->filled && !dxf /* && fc >= 0 */) { + /* char *title=(p->numvalues) ? p->values[0] : ""; */ + char *title = ""; + int j; + + im_iprintf(&imgStr, "numpoints; j++) { + im_iprintf(&imgStr, "%s %d,%d", j == 0 ? "" : ",", + (int)MS_NINT(d * symbol->points[j].x + offset_x), + (int)MS_NINT(d * symbol->points[j].y + offset_y)); + } + im_iprintf(&imgStr, "\" />\n"); + } /* end of imagemap, filled case. */ + } + break; - default: - DEBUG_IF printf("DEF"); - break; + default: + DEBUG_IF printf("DEF"); + break; } /* end switch statement */ return; @@ -462,174 +461,197 @@ void msDrawMarkerSymbolIM(mapObj *map, imageObj* img, pointObj *p, styleObj *sty /* ------------------------------------------------------------------------- */ /* Draw a line symbol of the specified size and color */ /* ------------------------------------------------------------------------- */ -void msDrawLineSymbolIM(mapObj *map, imageObj* img, shapeObj *p, styleObj *style, double scalefactor_ignored) -{ +void msDrawLineSymbolIM(mapObj *map, imageObj *img, shapeObj *p, + styleObj *style, double scalefactor_ignored) { (void)img; (void)scalefactor_ignored; symbolObj *symbol; - int i,j,l; + int i, j, l; char first = 1; DEBUG_IF printf("msDrawLineSymbolIM
\n"); + if (!p) + return; + if (p->numlines <= 0) + return; - if(!p) return; - if(p->numlines <= 0) return; - - if(style->symbol > map->symbolset.numsymbols || style->symbol < 0) return; /* no such symbol, 0 is OK */ + if (style->symbol > map->symbolset.numsymbols || style->symbol < 0) + return; /* no such symbol, 0 is OK */ symbol = map->symbolset.symbol[style->symbol]; - if (suppressEmpty && p->numvalues==0) return;/* suppress area with empty title */ - if(style->symbol == 0) { /* just draw a single width line */ - for(l=0,j=0; jnumlines; j++) { + if (suppressEmpty && p->numvalues == 0) + return; /* suppress area with empty title */ + if (style->symbol == 0) { /* just draw a single width line */ + for (l = 0, j = 0; j < p->numlines; j++) { if (dxf == 2) { - im_iprintf (&imgStr, "LINE\n%d\n", matchdxfcolor(style->color)); + im_iprintf(&imgStr, "LINE\n%d\n", matchdxfcolor(style->color)); } else if (dxf) { - im_iprintf (&imgStr, " 0\nPOLYLINE\n 70\n 0\n 62\n%6d\n 8\n%s\n", matchdxfcolor(style->color), lname); + im_iprintf(&imgStr, " 0\nPOLYLINE\n 70\n 0\n 62\n%6d\n 8\n%s\n", + matchdxfcolor(style->color), lname); } else { char *title; first = 1; - title=(p->numvalues) ? p->values[0] : ""; - im_iprintf (&imgStr, "numvalues) ? p->values[0] : ""; + im_iprintf(&imgStr, "line[j].point[p->line[j].numpoints-1] ); */ - for(i=0; i < p->line[j].numpoints; i++,l++) { + for (i = 0; i < p->line[j].numpoints; i++, l++) { if (dxf == 2) { - im_iprintf (&imgStr, "%.0f %.0f\n", p->line[j].point[i].x, p->line[j].point[i].y); + im_iprintf(&imgStr, "%.0f %.0f\n", p->line[j].point[i].x, + p->line[j].point[i].y); } else if (dxf) { - im_iprintf (&imgStr, " 0\nVERTEX\n 10\n%f\n 20\n%f\n 30\n%f\n", p->line[j].point[i].x, p->line[j].point[i].y, 0.0); + im_iprintf(&imgStr, " 0\nVERTEX\n 10\n%f\n 20\n%f\n 30\n%f\n", + p->line[j].point[i].x, p->line[j].point[i].y, 0.0); } else { - im_iprintf (&imgStr, "%s %.0f,%.0f", first ? "": ",", p->line[j].point[i].x, p->line[j].point[i].y); + im_iprintf(&imgStr, "%s %.0f,%.0f", first ? "" : ",", + p->line[j].point[i].x, p->line[j].point[i].y); } first = 0; /* point2 = &( p->line[j].point[i] ); */ /* if(point1->y == point2->y) {} */ } - im_iprintf (&imgStr, dxf ? (dxf == 2 ? "": " 0\nSEQEND\n") : "\" />\n"); + im_iprintf(&imgStr, dxf ? (dxf == 2 ? "" : " 0\nSEQEND\n") : "\" />\n"); } /* DEBUG_IF printf ("%d, ",strlen(img->img.imagemap) ); */ return; } - DEBUG_IF printf("-%d-",symbol->type); + DEBUG_IF printf("-%d-", symbol->type); return; } - /* ------------------------------------------------------------------------- */ /* Draw a shade symbol of the specified size and color */ /* ------------------------------------------------------------------------- */ -void msDrawShadeSymbolIM(mapObj *map, imageObj* img, shapeObj *p, styleObj *style, double scalefactor_ignored) -{ +void msDrawShadeSymbolIM(mapObj *map, imageObj *img, shapeObj *p, + styleObj *style, double scalefactor_ignored) { (void)img; (void)scalefactor_ignored; symbolObj *symbol; - int i,j,l; + int i, j, l; char first = 1; DEBUG_IF printf("msDrawShadeSymbolIM\n
"); - if(!p) return; - if(p->numlines <= 0) return; + if (!p) + return; + if (p->numlines <= 0) + return; symbol = map->symbolset.symbol[style->symbol]; - if (suppressEmpty && p->numvalues==0) return;/* suppress area with empty title */ - if(style->symbol == 0) { /* simply draw a single pixel of the specified color // */ - for(l=0,j=0; jnumlines; j++) { + if (suppressEmpty && p->numvalues == 0) + return; /* suppress area with empty title */ + if (style->symbol == + 0) { /* simply draw a single pixel of the specified color // */ + for (l = 0, j = 0; j < p->numlines; j++) { if (dxf == 2) { - im_iprintf (&imgStr, "POLY\n%d\n", matchdxfcolor(style->color)); + im_iprintf(&imgStr, "POLY\n%d\n", matchdxfcolor(style->color)); } else if (dxf) { - im_iprintf (&imgStr, " 0\nPOLYLINE\n 73\n 1\n 62\n%6d\n 8\n%s\n", matchdxfcolor(style->color), lname); + im_iprintf(&imgStr, " 0\nPOLYLINE\n 73\n 1\n 62\n%6d\n 8\n%s\n", + matchdxfcolor(style->color), lname); } else { - char *title=(p->numvalues) ? p->values[0] : ""; + char *title = (p->numvalues) ? p->values[0] : ""; first = 1; - im_iprintf (&imgStr, "line[j].point[p->line[j].numpoints-1] ); */ - for(i=0; i < p->line[j].numpoints; i++,l++) { + for (i = 0; i < p->line[j].numpoints; i++, l++) { if (dxf == 2) { - im_iprintf (&imgStr, "%.0f %.0f\n", p->line[j].point[i].x, p->line[j].point[i].y); + im_iprintf(&imgStr, "%.0f %.0f\n", p->line[j].point[i].x, + p->line[j].point[i].y); } else if (dxf) { - im_iprintf (&imgStr, " 0\nVERTEX\n 10\n%f\n 20\n%f\n 30\n%f\n", p->line[j].point[i].x, p->line[j].point[i].y, 0.0); + im_iprintf(&imgStr, " 0\nVERTEX\n 10\n%f\n 20\n%f\n 30\n%f\n", + p->line[j].point[i].x, p->line[j].point[i].y, 0.0); } else { - im_iprintf (&imgStr, "%s %.0f,%.0f", first ? "": ",", p->line[j].point[i].x, p->line[j].point[i].y); + im_iprintf(&imgStr, "%s %.0f,%.0f", first ? "" : ",", + p->line[j].point[i].x, p->line[j].point[i].y); } first = 0; /* point2 = &( p->line[j].point[i] ); */ /* if(point1->y == point2->y) {} */ } - im_iprintf (&imgStr, dxf ? (dxf == 2 ? "": " 0\nSEQEND\n") : "\" />\n"); + im_iprintf(&imgStr, dxf ? (dxf == 2 ? "" : " 0\nSEQEND\n") : "\" />\n"); } return; } /* DEBUG_IF printf ("d"); */ - DEBUG_IF printf("-%d-",symbol->type); + DEBUG_IF printf("-%d-", symbol->type); return; } /* * Simply draws a label based on the label point and the supplied label object. */ -int msDrawTextIM(mapObj *map, imageObj* img, pointObj labelPnt, char *string, labelObj *label, double scalefactor) -{ +int msDrawTextIM(mapObj *map, imageObj *img, pointObj labelPnt, char *string, + labelObj *label, double scalefactor) { (void)map; (void)img; DEBUG_IF printf("msDrawText
\n"); - if(!string) return(0); /* not errors, just don't want to do anything */ - if(strlen(string) == 0) return(0); - if(!dxf) return (0); + if (!string) + return (0); /* not errors, just don't want to do anything */ + if (strlen(string) == 0) + return (0); + if (!dxf) + return (0); if (dxf == 2) { - im_iprintf (&imgStr, "TEXT\n%d\n%s\n%.0f\n%.0f\n%.0f\n" , matchdxfcolor(label->color), string, labelPnt.x, labelPnt.y, -label->angle); + im_iprintf(&imgStr, "TEXT\n%d\n%s\n%.0f\n%.0f\n%.0f\n", + matchdxfcolor(label->color), string, labelPnt.x, labelPnt.y, + -label->angle); } else { - im_iprintf (&imgStr, " 0\nTEXT\n 1\n%s\n 10\n%f\n 20\n%f\n 30\n0.0\n 40\n%f\n 50\n%f\n 62\n%6d\n 8\n%s\n 73\n 2\n 72\n 1\n" , string, labelPnt.x, labelPnt.y, label->size * scalefactor *100, -label->angle, matchdxfcolor(label->color), lname); + im_iprintf(&imgStr, + " 0\nTEXT\n 1\n%s\n 10\n%f\n 20\n%f\n 30\n0.0\n 40\n%f\n " + "50\n%f\n 62\n%6d\n 8\n%s\n 73\n 2\n 72\n 1\n", + string, labelPnt.x, labelPnt.y, label->size * scalefactor * 100, + -label->angle, matchdxfcolor(label->color), lname); } - return(0); + return (0); } /* * Save an image to a file named filename, if filename is NULL it goes to stdout */ -int msSaveImageIM(imageObj* img, const char *filename, outputFormatObj *format ) +int msSaveImageIM(imageObj *img, const char *filename, outputFormatObj *format) { FILE *stream_to_free = NULL; @@ -638,11 +660,11 @@ int msSaveImageIM(imageObj* img, const char *filename, outputFormatObj *format ) DEBUG_IF printf("msSaveImageIM\n
"); - if(filename != NULL && strlen(filename) > 0) { + if (filename != NULL && strlen(filename) > 0) { stream_to_free = fopen(filename, "wb"); - if(!stream_to_free) { + if (!stream_to_free) { msSetError(MS_IOERR, "(%s)", "msSaveImage()", filename); - return(MS_FAILURE); + return (MS_FAILURE); } stream = stream_to_free; } else { /* use stdout */ @@ -651,24 +673,31 @@ int msSaveImageIM(imageObj* img, const char *filename, outputFormatObj *format ) /* * Change stdout mode to binary on win32 platforms */ - if(_setmode( _fileno(stdout), _O_BINARY) == -1) { - msSetError(MS_IOERR, "Unable to change stdout to binary mode.", "msSaveImage()"); - return(MS_FAILURE); + if (_setmode(_fileno(stdout), _O_BINARY) == -1) { + msSetError(MS_IOERR, "Unable to change stdout to binary mode.", + "msSaveImage()"); + return (MS_FAILURE); } #endif stream = stdout; } - if( strcasecmp(format->driver,"imagemap") == 0 ) { + if (strcasecmp(format->driver, "imagemap") == 0) { DEBUG_IF printf("ALLOCD %d
\n", img->size); /* DEBUG_IF printf("F %s
\n", img->img.imagemap); */ DEBUG_IF printf("FLEN %d
\n", (int)strlen(img->img.imagemap)); if (dxf == 2) { msIO_fprintf(stream, "%s", layerlist); } else if (dxf) { - msIO_fprintf(stream, " 0\nSECTION\n 2\nHEADER\n 9\n$ACADVER\n 1\nAC1009\n0\nENDSEC\n 0\nSECTION\n 2\nTABLES\n 0\nTABLE\n%s0\nENDTAB\n0\nENDSEC\n 0\nSECTION\n 2\nBLOCKS\n0\nENDSEC\n 0\nSECTION\n 2\nENTITIES\n", layerlist); + msIO_fprintf( + stream, + " 0\nSECTION\n 2\nHEADER\n 9\n$ACADVER\n 1\nAC1009\n0\nENDSEC\n " + "0\nSECTION\n 2\nTABLES\n 0\nTABLE\n%s0\nENDTAB\n0\nENDSEC\n " + "0\nSECTION\n 2\nBLOCKS\n0\nENDSEC\n 0\nSECTION\n 2\nENTITIES\n", + layerlist); } else { - msIO_fprintf(stream, "\n", mapName, img->width, img->height); + msIO_fprintf(stream, "\n", + mapName, img->width, img->height); } const int nSize = sizeof(workbuffer); @@ -676,18 +705,20 @@ int msSaveImageIM(imageObj* img, const char *filename, outputFormatObj *format ) if (size > nSize) { int iIndice = 0; while ((iIndice + nSize) <= size) { - snprintf(workbuffer, sizeof(workbuffer), "%s", img->img.imagemap+iIndice ); - workbuffer[nSize-1] = '\0'; + snprintf(workbuffer, sizeof(workbuffer), "%s", + img->img.imagemap + iIndice); + workbuffer[nSize - 1] = '\0'; msIO_fwrite(workbuffer, strlen(workbuffer), 1, stream); - iIndice +=nSize-1; + iIndice += nSize - 1; } if (iIndice < size) { - sprintf(workbuffer, "%s", img->img.imagemap+iIndice ); + sprintf(workbuffer, "%s", img->img.imagemap + iIndice); msIO_fprintf(stream, "%s", workbuffer); } } else msIO_fwrite(img->img.imagemap, size, 1, stream); - if( strcasecmp("OFF",msGetOutputFormatOption( format, "SKIPENDTAG", "OFF" )) == 0) { + if (strcasecmp("OFF", + msGetOutputFormatOption(format, "SKIPENDTAG", "OFF")) == 0) { if (dxf == 2) msIO_fprintf(stream, "END"); else if (dxf) @@ -697,21 +728,18 @@ int msSaveImageIM(imageObj* img, const char *filename, outputFormatObj *format ) } } else { msSetError(MS_MISCERR, "Unknown output image type driver: %s.", - "msSaveImage()", format->driver ); - if(stream_to_free != NULL) fclose(stream_to_free); - return(MS_FAILURE); + "msSaveImage()", format->driver); + if (stream_to_free != NULL) + fclose(stream_to_free); + return (MS_FAILURE); } - if(stream_to_free != NULL) fclose(stream_to_free); - return(MS_SUCCESS); + if (stream_to_free != NULL) + fclose(stream_to_free); + return (MS_SUCCESS); } - /* * Free gdImagePtr */ -void msFreeImageIM(imageObj* img) -{ - free(img->img.imagemap); -} - +void msFreeImageIM(imageObj *img) { free(img->img.imagemap); } diff --git a/mapio.c b/mapio.c index 85912f015c..8d31c04b7a 100644 --- a/mapio.c +++ b/mapio.c @@ -38,13 +38,10 @@ #endif #ifdef MOD_WMS_ENABLED -# include "httpd.h" -# include "apr_strings.h" +#include "httpd.h" +#include "apr_strings.h" #endif - - - static int is_msIO_initialized = MS_FALSE; static int is_msIO_header_enabled = MS_TRUE; @@ -53,20 +50,20 @@ typedef struct msIOContextGroup_t { msIOContext stdout_context; msIOContext stderr_context; - void* thread_id; + void *thread_id; struct msIOContextGroup_t *next; } msIOContextGroup; static msIOContextGroup default_contexts; static msIOContextGroup *io_context_list = NULL; -static void msIO_Initialize( void ); +static void msIO_Initialize(void); #ifdef msIO_printf -# undef msIO_printf -# undef msIO_fprintf -# undef msIO_fwrite -# undef msIO_fread -# undef msIO_vfprintf +#undef msIO_printf +#undef msIO_fprintf +#undef msIO_fwrite +#undef msIO_fread +#undef msIO_vfprintf #endif /************************************************************************/ @@ -76,14 +73,14 @@ static void msIO_Initialize( void ); void msIO_Cleanup() { - if( is_msIO_initialized ) + if (is_msIO_initialized) { is_msIO_initialized = MS_FALSE; - while( io_context_list != NULL ) { + while (io_context_list != NULL) { msIOContextGroup *last = io_context_list; io_context_list = io_context_list->next; - free( last ); + free(last); } } } @@ -95,20 +92,20 @@ void msIO_Cleanup() static msIOContextGroup *msIO_GetContextGroup() { - void* nThreadId = msGetThreadId(); + void *nThreadId = msGetThreadId(); msIOContextGroup *prev = NULL, *group = io_context_list; - if( group != NULL && group->thread_id == nThreadId ) + if (group != NULL && group->thread_id == nThreadId) return group; /* -------------------------------------------------------------------- */ /* Search for group for this thread */ /* -------------------------------------------------------------------- */ - msAcquireLock( TLOCK_IOCONTEXT ); + msAcquireLock(TLOCK_IOCONTEXT); msIO_Initialize(); group = io_context_list; - while( group != NULL && group->thread_id != nThreadId ) { + while (group != NULL && group->thread_id != nThreadId) { prev = group; group = group->next; } @@ -117,21 +114,21 @@ static msIOContextGroup *msIO_GetContextGroup() /* If we found it, make sure it is pushed to the front of the */ /* link for faster finding next time, and return it. */ /* -------------------------------------------------------------------- */ - if( group != NULL ) { - if( prev != NULL ) { + if (group != NULL) { + if (prev != NULL) { prev->next = group->next; group->next = io_context_list; io_context_list = group; } - msReleaseLock( TLOCK_IOCONTEXT ); + msReleaseLock(TLOCK_IOCONTEXT); return group; } /* -------------------------------------------------------------------- */ /* Create a new context group for this thread. */ /* -------------------------------------------------------------------- */ - group = (msIOContextGroup *) calloc(sizeof(msIOContextGroup),1); + group = (msIOContextGroup *)calloc(sizeof(msIOContextGroup), 1); group->stdin_context = default_contexts.stdin_context; group->stdout_context = default_contexts.stdout_context; @@ -141,7 +138,7 @@ static msIOContextGroup *msIO_GetContextGroup() group->next = io_context_list; io_context_list = group; - msReleaseLock( TLOCK_IOCONTEXT ); + msReleaseLock(TLOCK_IOCONTEXT); return group; } @@ -149,16 +146,16 @@ static msIOContextGroup *msIO_GetContextGroup() /* returns MS_TRUE if the msIO standard output hasn't been redirected */ int msIO_isStdContext() { msIOContextGroup *group = io_context_list; - void* nThreadId = msGetThreadId(); - if(!group || group->thread_id != nThreadId) { + void *nThreadId = msGetThreadId(); + if (!group || group->thread_id != nThreadId) { group = msIO_GetContextGroup(); - if(!group) { + if (!group) { return MS_FALSE; /* probably a bug */ } } - if(group->stderr_context.cbData == (void*)stderr && - group->stdin_context.cbData == (void*)stdin && - group->stdout_context.cbData == (void*)stdout) + if (group->stderr_context.cbData == (void *)stderr && + group->stdin_context.cbData == (void *)stdin && + group->stdout_context.cbData == (void *)stdout) return MS_TRUE; return MS_FALSE; } @@ -167,25 +164,25 @@ int msIO_isStdContext() { /* msIO_getHandler() */ /************************************************************************/ -msIOContext *msIO_getHandler( FILE * fp ) +msIOContext *msIO_getHandler(FILE *fp) { - void* nThreadId = msGetThreadId(); + void *nThreadId = msGetThreadId(); msIOContextGroup *group = io_context_list; msIO_Initialize(); - if( group == NULL || group->thread_id != nThreadId ) { + if (group == NULL || group->thread_id != nThreadId) { group = msIO_GetContextGroup(); - if( group == NULL ) + if (group == NULL) return NULL; } - if( fp == stdin || fp == NULL || strcmp((const char *)fp,"stdin") == 0 ) + if (fp == stdin || fp == NULL || strcmp((const char *)fp, "stdin") == 0) return &(group->stdin_context); - else if( fp == stdout || strcmp((const char *)fp,"stdout") == 0 ) + else if (fp == stdout || strcmp((const char *)fp, "stdout") == 0) return &(group->stdout_context); - else if( fp == stderr || strcmp((const char *)fp,"stderr") == 0 ) + else if (fp == stderr || strcmp((const char *)fp, "stderr") == 0) return &(group->stderr_context); else return NULL; @@ -195,68 +192,60 @@ msIOContext *msIO_getHandler( FILE * fp ) /* msIO_setHeaderEnabled() */ /************************************************************************/ -void msIO_setHeaderEnabled(int bFlag) -{ - is_msIO_header_enabled = bFlag; -} +void msIO_setHeaderEnabled(int bFlag) { is_msIO_header_enabled = bFlag; } /************************************************************************/ /* msIO_setHeader() */ /************************************************************************/ -void msIO_setHeader (const char *header, const char* value, ...) -{ +void msIO_setHeader(const char *header, const char *value, ...) { va_list args; - va_start( args, value ); + va_start(args, value); #ifdef MOD_WMS_ENABLED - msIOContext *ioctx = msIO_getHandler (stdout); - if(ioctx && !strcmp(ioctx->label,"apache")) { + msIOContext *ioctx = msIO_getHandler(stdout); + if (ioctx && !strcmp(ioctx->label, "apache")) { - request_rec *r = (request_rec*) (ioctx->cbData); - char *fullvalue = apr_pvsprintf(r->pool, value,args); - if (strcasecmp (header, "Content-Type") == 0) { + request_rec *r = (request_rec *)(ioctx->cbData); + char *fullvalue = apr_pvsprintf(r->pool, value, args); + if (strcasecmp(header, "Content-Type") == 0) { r->content_type = fullvalue; - } else if (strcasecmp (header, "Status") == 0) { - r->status = atoi (fullvalue); + } else if (strcasecmp(header, "Status") == 0) { + r->status = atoi(fullvalue); } else { - apr_table_setn (r->headers_out, - apr_pstrdup (r->pool, header), - fullvalue - ); + apr_table_setn(r->headers_out, apr_pstrdup(r->pool, header), fullvalue); } } else { #endif // MOD_WMS_ENABLED - if( is_msIO_header_enabled ) { - msIO_fprintf(stdout,"%s: ",header); - msIO_vfprintf(stdout,value,args); - msIO_fprintf(stdout,"\r\n"); - } + if (is_msIO_header_enabled) { + msIO_fprintf(stdout, "%s: ", header); + msIO_vfprintf(stdout, value, args); + msIO_fprintf(stdout, "\r\n"); + } #ifdef MOD_WMS_ENABLED } #endif - va_end( args ); + va_end(args); } -void msIO_sendHeaders () -{ +void msIO_sendHeaders() { #ifdef MOD_WMS_ENABLED - msIOContext *ioctx = msIO_getHandler (stdout); - if(ioctx && !strcmp(ioctx->label,"apache")) return; + msIOContext *ioctx = msIO_getHandler(stdout); + if (ioctx && !strcmp(ioctx->label, "apache")) + return; #endif // !MOD_WMS_ENABLED - if( is_msIO_header_enabled ) { - msIO_printf ("\r\n"); - fflush (stdout); + if (is_msIO_header_enabled) { + msIO_printf("\r\n"); + fflush(stdout); } } - /************************************************************************/ /* msIO_installHandlers() */ /************************************************************************/ -int msIO_installHandlers( msIOContext *stdin_context, - msIOContext *stdout_context, - msIOContext *stderr_context ) +int msIO_installHandlers(msIOContext *stdin_context, + msIOContext *stdout_context, + msIOContext *stderr_context) { msIOContextGroup *group; @@ -265,19 +254,19 @@ int msIO_installHandlers( msIOContext *stdin_context, group = msIO_GetContextGroup(); - if( stdin_context == NULL ) + if (stdin_context == NULL) group->stdin_context = default_contexts.stdin_context; - else if( stdin_context != &group->stdin_context ) + else if (stdin_context != &group->stdin_context) group->stdin_context = *stdin_context; - if( stdout_context == NULL ) + if (stdout_context == NULL) group->stdout_context = default_contexts.stdout_context; - else if( stdout_context != &group->stdout_context ) + else if (stdout_context != &group->stdout_context) group->stdout_context = *stdout_context; - if( stderr_context == NULL ) + if (stderr_context == NULL) group->stderr_context = default_contexts.stderr_context; - else if( stderr_context != &group->stderr_context ) + else if (stderr_context != &group->stderr_context) group->stderr_context = *stderr_context; return MS_TRUE; @@ -287,27 +276,26 @@ int msIO_installHandlers( msIOContext *stdin_context, /* msIO_contextRead() */ /************************************************************************/ -int msIO_contextRead( msIOContext *context, void *data, int byteCount ) +int msIO_contextRead(msIOContext *context, void *data, int byteCount) { - if( context->write_channel == MS_TRUE ) + if (context->write_channel == MS_TRUE) return 0; else - return context->readWriteFunc( context->cbData, data, byteCount ); + return context->readWriteFunc(context->cbData, data, byteCount); } /************************************************************************/ /* msIO_contextWrite() */ /************************************************************************/ -int msIO_contextWrite( msIOContext *context, const void *data, int byteCount ) +int msIO_contextWrite(msIOContext *context, const void *data, int byteCount) { - if( context->write_channel == MS_FALSE ) + if (context->write_channel == MS_FALSE) return 0; else - return context->readWriteFunc( context->cbData, (void *) data, - byteCount ); + return context->readWriteFunc(context->cbData, (void *)data, byteCount); } /* ==================================================================== */ @@ -320,15 +308,15 @@ int msIO_contextWrite( msIOContext *context, const void *data, int byteCount ) /* _ms_vsprintf() */ /************************************************************************/ -static int _ms_vsprintf(char **workBufPtr, const char *format, va_list ap ) +static int _ms_vsprintf(char **workBufPtr, const char *format, va_list ap) { - int ret_val; - int workBufSize = 16000; + int ret_val; + int workBufSize = 16000; - *workBufPtr = (char*)malloc(workBufSize * sizeof(char)); + *workBufPtr = (char *)malloc(workBufSize * sizeof(char)); if (*workBufPtr == NULL) { - msSetError( MS_MEMERR, NULL, "_ms_vsprintf()"); + msSetError(MS_MEMERR, NULL, "_ms_vsprintf()"); return -1; } @@ -338,35 +326,35 @@ static int _ms_vsprintf(char **workBufPtr, const char *format, va_list ap ) va_list wrk_args; #ifdef va_copy - va_copy( wrk_args, ap ); + va_copy(wrk_args, ap); #else wrk_args = ap; #endif - while( (ret_val = vsnprintf( *workBufPtr, workBufSize, - format, wrk_args)) >= workBufSize-1 - || ret_val == -1 ) { + while ((ret_val = vsnprintf(*workBufPtr, workBufSize, format, wrk_args)) >= + workBufSize - 1 || + ret_val == -1) { workBufSize *= 4; - *workBufPtr = (char *) realloc(*workBufPtr, workBufSize ); + *workBufPtr = (char *)realloc(*workBufPtr, workBufSize); if (*workBufPtr == NULL) { - msSetError( MS_MEMERR, NULL, "_ms_vsprintf()"); - va_end( wrk_args ); + msSetError(MS_MEMERR, NULL, "_ms_vsprintf()"); + va_end(wrk_args); return -1; } #ifdef va_copy - va_end( wrk_args ); - va_copy( wrk_args, ap ); + va_end(wrk_args); + va_copy(wrk_args, ap); #else wrk_args = ap; #endif } - va_end( wrk_args ); + va_end(wrk_args); } #else /* We do not have vsnprintf()... there is a risk of buffer overrun */ - ret_val = vsprintf( *workBufPtr, format, ap ); + ret_val = vsprintf(*workBufPtr, format, ap); - if( ret_val < 0 || ret_val >= workBufSize ) { + if (ret_val < 0 || ret_val >= workBufSize) { msSetError(MS_MISCERR, "Possible buffer overrun.", "_ms_vsprintf()"); msFree(*workBufPtr); *workBufPtr = NULL; @@ -377,18 +365,17 @@ static int _ms_vsprintf(char **workBufPtr, const char *format, va_list ap ) return ret_val; } - /************************************************************************/ /* msIO_printf() */ /************************************************************************/ -int msIO_printf( const char *format, ... ) +int msIO_printf(const char *format, ...) { va_list args; int ret; - va_start( args, format ); - ret = msIO_vfprintf(stdout,format,args); + va_start(args, format); + ret = msIO_vfprintf(stdout, format, args); va_end(args); return ret; } @@ -397,13 +384,13 @@ int msIO_printf( const char *format, ... ) /* msIO_fprintf() */ /************************************************************************/ -int msIO_fprintf( FILE *fp, const char *format, ... ) +int msIO_fprintf(FILE *fp, const char *format, ...) { va_list args; int ret; - va_start( args, format ); - ret = msIO_vfprintf(fp,format,args); + va_start(args, format); + ret = msIO_vfprintf(fp, format, args); va_end(args); return ret; } @@ -412,53 +399,51 @@ int msIO_fprintf( FILE *fp, const char *format, ... ) /* msIO_vfprintf() */ /************************************************************************/ -int msIO_vfprintf( FILE *fp, const char *format, va_list ap ) +int msIO_vfprintf(FILE *fp, const char *format, va_list ap) { - int return_val; + int return_val; msIOContext *context; char workBuf[8000]; #if !defined(HAVE_VSNPRINTF) - return_val = vsprintf( workBuf, format, ap); + return_val = vsprintf(workBuf, format, ap); - if( return_val < 0 || return_val >= sizeof(workBuf) ) { + if (return_val < 0 || return_val >= sizeof(workBuf)) { msSetError(MS_MISCERR, "Possible buffer overrun.", "msIO_vfprintf()"); return -1; } - char* outbuf = workBuf; + char *outbuf = workBuf; #else va_list args_copy; #ifdef va_copy - va_copy( args_copy, ap ); + va_copy(args_copy, ap); #else args_copy = ap; #endif /* va_copy */ - char* largerBuf = NULL; - return_val = vsnprintf( workBuf, sizeof(workBuf), format, ap ); - if (return_val == -1 || return_val >= (int)sizeof(workBuf)-1) { - return_val = _ms_vsprintf(&largerBuf, format, args_copy ); + char *largerBuf = NULL; + return_val = vsnprintf(workBuf, sizeof(workBuf), format, ap); + if (return_val == -1 || return_val >= (int)sizeof(workBuf) - 1) { + return_val = _ms_vsprintf(&largerBuf, format, args_copy); } va_end(args_copy); if (return_val < 0) return -1; - char* outbuf = largerBuf?largerBuf:workBuf; + char *outbuf = largerBuf ? largerBuf : workBuf; #endif /* HAVE_VSNPRINTF */ - context = msIO_getHandler( fp ); - if( context == NULL ) - return_val = fwrite(outbuf , 1, return_val, fp ); + context = msIO_getHandler(fp); + if (context == NULL) + return_val = fwrite(outbuf, 1, return_val, fp); else - return_val = msIO_contextWrite( context, - outbuf, - return_val ); + return_val = msIO_contextWrite(context, outbuf, return_val); #if defined(HAVE_VSNPRINTF) msFree(largerBuf); @@ -471,38 +456,38 @@ int msIO_vfprintf( FILE *fp, const char *format, va_list ap ) /* msIO_fwrite() */ /************************************************************************/ -int msIO_fwrite( const void *data, size_t size, size_t nmemb, FILE *fp ) +int msIO_fwrite(const void *data, size_t size, size_t nmemb, FILE *fp) { msIOContext *context; - if( size == 0 || nmemb == 0 ) + if (size == 0 || nmemb == 0) return 0; - context = msIO_getHandler( fp ); - if( context == NULL ) - return fwrite( data, size, nmemb, fp ); + context = msIO_getHandler(fp); + if (context == NULL) + return fwrite(data, size, nmemb, fp); else - return msIO_contextWrite( context, data, size * nmemb ) / size; + return msIO_contextWrite(context, data, size * nmemb) / size; } /************************************************************************/ /* msIO_fread() */ /************************************************************************/ -int msIO_fread( void *data, size_t size, size_t nmemb, FILE *fp ) +int msIO_fread(void *data, size_t size, size_t nmemb, FILE *fp) { msIOContext *context; - if( size == 0 || nmemb == 0 ) + if (size == 0 || nmemb == 0) return 0; - context = msIO_getHandler( fp ); - if( context == NULL ) - return fread( data, size, nmemb, fp ); + context = msIO_getHandler(fp); + if (context == NULL) + return fread(data, size, nmemb, fp); else - return msIO_contextRead( context, data, size * nmemb ) / size; + return msIO_contextRead(context, data, size * nmemb) / size; } /* ==================================================================== */ @@ -518,10 +503,10 @@ int msIO_fread( void *data, size_t size, size_t nmemb, FILE *fp ) /* This is the default implementation via stdio. */ /************************************************************************/ -static int msIO_stdioRead( void *cbData, void *data, int byteCount ) +static int msIO_stdioRead(void *cbData, void *data, int byteCount) { - return fread( data, 1, byteCount, (FILE *) cbData ); + return fread(data, 1, byteCount, (FILE *)cbData); } /************************************************************************/ @@ -530,36 +515,36 @@ static int msIO_stdioRead( void *cbData, void *data, int byteCount ) /* This is the default implementation via stdio. */ /************************************************************************/ -static int msIO_stdioWrite( void *cbData, void *data, int byteCount ) +static int msIO_stdioWrite(void *cbData, void *data, int byteCount) { - return fwrite( data, 1, byteCount, (FILE *) cbData ); + return fwrite(data, 1, byteCount, (FILE *)cbData); } /************************************************************************/ /* msIO_Initialize() */ /************************************************************************/ -static void msIO_Initialize( void ) +static void msIO_Initialize(void) { - if( is_msIO_initialized == MS_TRUE ) + if (is_msIO_initialized == MS_TRUE) return; default_contexts.stdin_context.label = "stdio"; default_contexts.stdin_context.write_channel = MS_FALSE; default_contexts.stdin_context.readWriteFunc = msIO_stdioRead; - default_contexts.stdin_context.cbData = (void *) stdin; + default_contexts.stdin_context.cbData = (void *)stdin; default_contexts.stdout_context.label = "stdio"; default_contexts.stdout_context.write_channel = MS_TRUE; default_contexts.stdout_context.readWriteFunc = msIO_stdioWrite; - default_contexts.stdout_context.cbData = (void *) stdout; + default_contexts.stdout_context.cbData = (void *)stdout; default_contexts.stderr_context.label = "stdio"; default_contexts.stderr_context.write_channel = MS_TRUE; default_contexts.stderr_context.readWriteFunc = msIO_stdioWrite; - default_contexts.stderr_context.cbData = (void *) stderr; + default_contexts.stderr_context.cbData = (void *)stderr; default_contexts.next = NULL; default_contexts.thread_id = 0; @@ -567,15 +552,12 @@ static void msIO_Initialize( void ) is_msIO_initialized = MS_TRUE; } - /* ==================================================================== */ /* ==================================================================== */ /* FastCGI output redirection functions. */ /* ==================================================================== */ /* ==================================================================== */ - - /************************************************************************/ /* msIO_needBinaryStdout() */ /* */ @@ -592,11 +574,10 @@ int msIO_needBinaryStdout() { #if defined(_WIN32) && !defined(USE_FASTCGI) - if(_setmode( _fileno(stdout), _O_BINARY) == -1) { - msSetError(MS_IOERR, - "Unable to change stdout to binary mode.", - "msIO_needBinaryStdout()" ); - return(MS_FAILURE); + if (_setmode(_fileno(stdout), _O_BINARY) == -1) { + msSetError(MS_IOERR, "Unable to change stdout to binary mode.", + "msIO_needBinaryStdout()"); + return (MS_FAILURE); } #endif @@ -619,11 +600,10 @@ int msIO_needBinaryStdin() { #if defined(_WIN32) && !defined(USE_FASTCGI) - if(_setmode( _fileno(stdin), _O_BINARY) == -1) { - msSetError(MS_IOERR, - "Unable to change stdin to binary mode.", - "msIO_needBinaryStdin()" ); - return(MS_FAILURE); + if (_setmode(_fileno(stdin), _O_BINARY) == -1) { + msSetError(MS_IOERR, "Unable to change stdin to binary mode.", + "msIO_needBinaryStdin()"); + return (MS_FAILURE); } #endif @@ -643,34 +623,34 @@ void msIO_resetHandlers() { msIOContextGroup *group = msIO_GetContextGroup(); - if( group == NULL ) + if (group == NULL) return; - if( strcmp(group->stdin_context.label,"buffer") == 0 ) { - msIOBuffer *buf = (msIOBuffer *) group->stdin_context.cbData; + if (strcmp(group->stdin_context.label, "buffer") == 0) { + msIOBuffer *buf = (msIOBuffer *)group->stdin_context.cbData; - if( buf->data != NULL ) - free( buf->data ); - free( buf ); + if (buf->data != NULL) + free(buf->data); + free(buf); } - if( strcmp(group->stdout_context.label,"buffer") == 0 ) { - msIOBuffer *buf = (msIOBuffer *) group->stdout_context.cbData; + if (strcmp(group->stdout_context.label, "buffer") == 0) { + msIOBuffer *buf = (msIOBuffer *)group->stdout_context.cbData; - if( buf->data != NULL ) - free( buf->data ); - free( buf ); + if (buf->data != NULL) + free(buf->data); + free(buf); } - if( strcmp(group->stderr_context.label,"buffer") == 0 ) { - msIOBuffer *buf = (msIOBuffer *) group->stderr_context.cbData; + if (strcmp(group->stderr_context.label, "buffer") == 0) { + msIOBuffer *buf = (msIOBuffer *)group->stderr_context.cbData; - if( buf->data != NULL ) - free( buf->data ); - free( buf ); + if (buf->data != NULL) + free(buf->data); + free(buf); } - msIO_installHandlers( NULL, NULL, NULL ); + msIO_installHandlers(NULL, NULL, NULL); } /************************************************************************/ @@ -681,19 +661,16 @@ void msIO_installStdoutToBuffer() { msIOContextGroup *group = msIO_GetContextGroup(); - msIOContext context; + msIOContext context; context.label = "buffer"; context.write_channel = MS_TRUE; context.readWriteFunc = msIO_bufferWrite; - context.cbData = calloc(sizeof(msIOBuffer),1); + context.cbData = calloc(sizeof(msIOBuffer), 1); - msIO_installHandlers( &group->stdin_context, - &context, - &group->stderr_context ); + msIO_installHandlers(&group->stdin_context, &context, &group->stderr_context); } - /************************************************************************/ /* msIO_pushStdoutToBufferAndGetOldContext() */ /* */ @@ -704,14 +681,14 @@ void msIO_installStdoutToBuffer() /* libxml objects XML generated by msIO_fprintf() */ /************************************************************************/ -msIOContext* msIO_pushStdoutToBufferAndGetOldContext() +msIOContext *msIO_pushStdoutToBufferAndGetOldContext() { msIOContextGroup *group = msIO_GetContextGroup(); msIOContext *old_context; /* Backup current context */ - old_context = (msIOContext*) msSmallMalloc(sizeof(msIOContext)); + old_context = (msIOContext *)msSmallMalloc(sizeof(msIOContext)); memcpy(old_context, &group->stdout_context, sizeof(msIOContext)); msIO_installStdoutToBuffer(); @@ -723,23 +700,21 @@ msIOContext* msIO_pushStdoutToBufferAndGetOldContext() /* msIO_restoreOldStdoutContext() */ /************************************************************************/ -void msIO_restoreOldStdoutContext(msIOContext *context_to_restore) -{ +void msIO_restoreOldStdoutContext(msIOContext *context_to_restore) { msIOContextGroup *group = msIO_GetContextGroup(); msIOContext *prev_context = &group->stdout_context; - msIOBuffer* buffer; - + msIOBuffer *buffer; + /* Free memory associated to our temporary context */ - assert( strcmp(prev_context->label, "buffer") == 0 ); + assert(strcmp(prev_context->label, "buffer") == 0); - buffer = (msIOBuffer* )prev_context->cbData; + buffer = (msIOBuffer *)prev_context->cbData; msFree(buffer->data); msFree(buffer); /* Restore old context */ - msIO_installHandlers( &group->stdin_context, - context_to_restore, - &group->stderr_context ); + msIO_installHandlers(&group->stdin_context, context_to_restore, + &group->stderr_context); msFree(context_to_restore); } @@ -752,16 +727,15 @@ void msIO_installStdinFromBuffer() { msIOContextGroup *group = msIO_GetContextGroup(); - msIOContext context; + msIOContext context; context.label = "buffer"; context.write_channel = MS_FALSE; context.readWriteFunc = msIO_bufferRead; - context.cbData = calloc(sizeof(msIOBuffer),1); + context.cbData = calloc(sizeof(msIOBuffer), 1); - msIO_installHandlers( &context, - &group->stdout_context, - &group->stderr_context ); + msIO_installHandlers(&context, &group->stdout_context, + &group->stderr_context); } /************************************************************************/ @@ -769,24 +743,23 @@ void msIO_installStdinFromBuffer() /* */ /************************************************************************/ -hashTableObj* msIO_getAndStripStdoutBufferMimeHeaders() -{ +hashTableObj *msIO_getAndStripStdoutBufferMimeHeaders() { /* -------------------------------------------------------------------- */ /* Find stdout buffer. */ /* -------------------------------------------------------------------- */ - msIOContext *ctx = msIO_getHandler( (FILE *) "stdout" ); - msIOBuffer *buf; + msIOContext *ctx = msIO_getHandler((FILE *)"stdout"); + msIOBuffer *buf; int start_of_mime_header, current_pos; - hashTableObj* hashTable; + hashTableObj *hashTable; - if( ctx == NULL || ctx->write_channel == MS_FALSE - || strcmp(ctx->label,"buffer") != 0 ) { - msSetError( MS_MISCERR, "Can't identify msIO buffer.", - "msIO_getAndStripStdoutBufferMimeHeaders" ); + if (ctx == NULL || ctx->write_channel == MS_FALSE || + strcmp(ctx->label, "buffer") != 0) { + msSetError(MS_MISCERR, "Can't identify msIO buffer.", + "msIO_getAndStripStdoutBufferMimeHeaders"); return NULL; } - buf = (msIOBuffer *) ctx->cbData; + buf = (msIOBuffer *)ctx->cbData; hashTable = msCreateHashTable(); @@ -794,90 +767,82 @@ hashTableObj* msIO_getAndStripStdoutBufferMimeHeaders() /* Loop over all headers. */ /* -------------------------------------------------------------------- */ current_pos = 0; - while( MS_TRUE ) { + while (MS_TRUE) { int pos_of_column = -1; - char* key, *value; + char *key, *value; start_of_mime_header = current_pos; - while( current_pos < buf->data_offset ) - { - if( buf->data[current_pos] == '\r' ) - { - if( current_pos + 1 == buf->data_offset || - buf->data[current_pos + 1] != '\n' ) - { - pos_of_column = -1; - break; - } - break; + while (current_pos < buf->data_offset) { + if (buf->data[current_pos] == '\r') { + if (current_pos + 1 == buf->data_offset || + buf->data[current_pos + 1] != '\n') { + pos_of_column = -1; + break; } - if( buf->data[current_pos] == ':' ) - { - pos_of_column = current_pos; - if( current_pos + 1 == buf->data_offset || - buf->data[current_pos + 1] != ' ' ) - { - pos_of_column = -1; - break; - } + break; + } + if (buf->data[current_pos] == ':') { + pos_of_column = current_pos; + if (current_pos + 1 == buf->data_offset || + buf->data[current_pos + 1] != ' ') { + pos_of_column = -1; + break; } - current_pos++; + } + current_pos++; } - if( pos_of_column < 0 || current_pos == buf->data_offset ) { - msSetError( MS_MISCERR, "Corrupt mime headers.", - "msIO_getAndStripStdoutBufferMimeHeaders" ); + if (pos_of_column < 0 || current_pos == buf->data_offset) { + msSetError(MS_MISCERR, "Corrupt mime headers.", + "msIO_getAndStripStdoutBufferMimeHeaders"); msFreeHashTable(hashTable); return NULL; } - key = (char*) malloc( pos_of_column - start_of_mime_header + 1 ); - memcpy( key, buf->data+start_of_mime_header, pos_of_column - start_of_mime_header); + key = (char *)malloc(pos_of_column - start_of_mime_header + 1); + memcpy(key, buf->data + start_of_mime_header, + pos_of_column - start_of_mime_header); key[pos_of_column - start_of_mime_header] = '\0'; - value = (char*) malloc( current_pos - (pos_of_column+2) + 1 ); - memcpy( value, buf->data+pos_of_column+2, current_pos - (pos_of_column+2)); - value[current_pos - (pos_of_column+2)] = '\0'; + value = (char *)malloc(current_pos - (pos_of_column + 2) + 1); + memcpy(value, buf->data + pos_of_column + 2, + current_pos - (pos_of_column + 2)); + value[current_pos - (pos_of_column + 2)] = '\0'; - msInsertHashTable( hashTable, key, value ); + msInsertHashTable(hashTable, key, value); - msFree( key ); - msFree( value ); + msFree(key); + msFree(value); /* -------------------------------------------------------------------- */ /* Go to next line. */ /* -------------------------------------------------------------------- */ current_pos += 2; - if( current_pos == buf->data_offset ) - { - msSetError( MS_MISCERR, "Corrupt mime headers.", - "msIO_getAndStripStdoutBufferMimeHeaders" ); + if (current_pos == buf->data_offset) { + msSetError(MS_MISCERR, "Corrupt mime headers.", + "msIO_getAndStripStdoutBufferMimeHeaders"); msFreeHashTable(hashTable); return NULL; } /* If next line is a '\r', this is the end of mime headers. */ - if( buf->data[current_pos] == '\r' ) - { - current_pos ++; - if( current_pos == buf->data_offset || - buf->data[current_pos] != '\n' ) - { - msSetError( MS_MISCERR, "Corrupt mime headers.", - "msIO_getAndStripStdoutBufferMimeHeaders" ); - msFreeHashTable(hashTable); - return NULL; - } - current_pos ++; - break; + if (buf->data[current_pos] == '\r') { + current_pos++; + if (current_pos == buf->data_offset || buf->data[current_pos] != '\n') { + msSetError(MS_MISCERR, "Corrupt mime headers.", + "msIO_getAndStripStdoutBufferMimeHeaders"); + msFreeHashTable(hashTable); + return NULL; + } + current_pos++; + break; } } /* -------------------------------------------------------------------- */ /* Move data to front of buffer, and reset length. */ /* -------------------------------------------------------------------- */ - memmove( buf->data, buf->data+current_pos, - buf->data_offset - current_pos ); + memmove(buf->data, buf->data + current_pos, buf->data_offset - current_pos); buf->data[buf->data_offset - current_pos] = '\0'; buf->data_offset -= current_pos; @@ -899,38 +864,37 @@ char *msIO_stripStdoutBufferContentType() /* -------------------------------------------------------------------- */ /* Find stdout buffer. */ /* -------------------------------------------------------------------- */ - msIOContext *ctx = msIO_getHandler( (FILE *) "stdout" ); - msIOBuffer *buf; + msIOContext *ctx = msIO_getHandler((FILE *)"stdout"); + msIOBuffer *buf; char *content_type = NULL; int end_of_ct, start_of_data; - if( ctx == NULL || ctx->write_channel == MS_FALSE - || strcmp(ctx->label,"buffer") != 0 ) { - msSetError( MS_MISCERR, "Can't identify msIO buffer.", - "msIO_stripStdoutBufferContentType" ); + if (ctx == NULL || ctx->write_channel == MS_FALSE || + strcmp(ctx->label, "buffer") != 0) { + msSetError(MS_MISCERR, "Can't identify msIO buffer.", + "msIO_stripStdoutBufferContentType"); return NULL; } - buf = (msIOBuffer *) ctx->cbData; + buf = (msIOBuffer *)ctx->cbData; /* -------------------------------------------------------------------- */ /* Return NULL if we don't have a Content-Type header. */ /* -------------------------------------------------------------------- */ - if( buf->data_offset < 14 - || strncasecmp((const char*) buf->data,"Content-Type: ",14) != 0 ) + if (buf->data_offset < 14 || + strncasecmp((const char *)buf->data, "Content-Type: ", 14) != 0) return NULL; /* -------------------------------------------------------------------- */ /* Find newline marker at end of content type argument. */ /* -------------------------------------------------------------------- */ end_of_ct = 13; - while( end_of_ct+1 < buf->data_offset - && buf->data[end_of_ct+1] != '\r' ) + while (end_of_ct + 1 < buf->data_offset && buf->data[end_of_ct + 1] != '\r') end_of_ct++; - if( end_of_ct+1 == buf->data_offset ) { - msSetError( MS_MISCERR, "Corrupt Content-Type header.", - "msIO_stripStdoutBufferContentType" ); + if (end_of_ct + 1 == buf->data_offset) { + msSetError(MS_MISCERR, "Corrupt Content-Type header.", + "msIO_stripStdoutBufferContentType"); return NULL; } @@ -938,14 +902,13 @@ char *msIO_stripStdoutBufferContentType() /* Continue on to the start of data ... */ /* Go to next line and skip if empty. */ /* -------------------------------------------------------------------- */ - start_of_data = end_of_ct+3; - if( start_of_data < buf->data_offset - && buf->data[start_of_data] == '\r' ) - start_of_data +=2; - - if( start_of_data == buf->data_offset ) { - msSetError( MS_MISCERR, "Corrupt Content-Type header.", - "msIO_stripStdoutBufferContentType" ); + start_of_data = end_of_ct + 3; + if (start_of_data < buf->data_offset && buf->data[start_of_data] == '\r') + start_of_data += 2; + + if (start_of_data == buf->data_offset) { + msSetError(MS_MISCERR, "Corrupt Content-Type header.", + "msIO_stripStdoutBufferContentType"); return NULL; } @@ -955,15 +918,15 @@ char *msIO_stripStdoutBufferContentType() /* buffer may not be NULL terminated - strlcpy() requires NULL */ /* terminated sources (see issue #4672). */ /* -------------------------------------------------------------------- */ - content_type = (char *) malloc(end_of_ct-14+2); - strncpy( content_type, (const char *) buf->data + 14, end_of_ct - 14 + 2); - content_type[end_of_ct-14+1] = '\0'; + content_type = (char *)malloc(end_of_ct - 14 + 2); + strncpy(content_type, (const char *)buf->data + 14, end_of_ct - 14 + 2); + content_type[end_of_ct - 14 + 1] = '\0'; /* -------------------------------------------------------------------- */ /* Move data to front of buffer, and reset length. */ /* -------------------------------------------------------------------- */ - memmove( buf->data, buf->data+start_of_data, - buf->data_offset - start_of_data ); + memmove(buf->data, buf->data + start_of_data, + buf->data_offset - start_of_data); buf->data[buf->data_offset - start_of_data] = '\0'; buf->data_offset -= start_of_data; @@ -976,75 +939,74 @@ char *msIO_stripStdoutBufferContentType() /* Strip off Content-* headers from buffer. */ /************************************************************************/ -void msIO_stripStdoutBufferContentHeaders() -{ +void msIO_stripStdoutBufferContentHeaders() { /* -------------------------------------------------------------------- */ /* Find stdout buffer. */ /* -------------------------------------------------------------------- */ - msIOContext *ctx = msIO_getHandler( (FILE *) "stdout" ); - msIOBuffer *buf; + msIOContext *ctx = msIO_getHandler((FILE *)"stdout"); + msIOBuffer *buf; int start_of_data; - if( ctx == NULL || ctx->write_channel == MS_FALSE - || strcmp(ctx->label,"buffer") != 0 ) { - msSetError( MS_MISCERR, "Can't identify msIO buffer.", - "msIO_stripStdoutBufferContentHeaders" ); + if (ctx == NULL || ctx->write_channel == MS_FALSE || + strcmp(ctx->label, "buffer") != 0) { + msSetError(MS_MISCERR, "Can't identify msIO buffer.", + "msIO_stripStdoutBufferContentHeaders"); return; } - buf = (msIOBuffer *) ctx->cbData; + buf = (msIOBuffer *)ctx->cbData; /* -------------------------------------------------------------------- */ /* Exit if we don't have any content-* header. */ /* -------------------------------------------------------------------- */ - if( buf->data_offset < 8 - || strncasecmp((const char*) buf->data,"Content-",8) != 0 ) + if (buf->data_offset < 8 || + strncasecmp((const char *)buf->data, "Content-", 8) != 0) return; /* -------------------------------------------------------------------- */ /* Loop over all content-* headers. */ /* -------------------------------------------------------------------- */ start_of_data = 0; - while( buf->data_offset > start_of_data - && strncasecmp((const char*) buf->data+start_of_data,"Content-",8) == 0 ) { + while (buf->data_offset > start_of_data && + strncasecmp((const char *)buf->data + start_of_data, "Content-", 8) == + 0) { /* -------------------------------------------------------------------- */ /* Find newline marker at end of content-* header argument. */ /* -------------------------------------------------------------------- */ - start_of_data +=7; - while( start_of_data+1 < buf->data_offset - && buf->data[start_of_data+1] != '\r' ) + start_of_data += 7; + while (start_of_data + 1 < buf->data_offset && + buf->data[start_of_data + 1] != '\r') start_of_data++; - if( start_of_data+1 == buf->data_offset ) { - msSetError( MS_MISCERR, "Corrupt Content-* header.", - "msIO_stripStdoutBufferContentHeaders" ); + if (start_of_data + 1 == buf->data_offset) { + msSetError(MS_MISCERR, "Corrupt Content-* header.", + "msIO_stripStdoutBufferContentHeaders"); return; } /* -------------------------------------------------------------------- */ /* Go to next line. */ /* -------------------------------------------------------------------- */ - start_of_data +=3; + start_of_data += 3; } /* -------------------------------------------------------------------- */ /* Continue on to the start of data ... */ /* Skip next line if empty. */ /* -------------------------------------------------------------------- */ - if( start_of_data < buf->data_offset - && buf->data[start_of_data] == '\r' ) - start_of_data +=2; + if (start_of_data < buf->data_offset && buf->data[start_of_data] == '\r') + start_of_data += 2; - if( start_of_data == buf->data_offset ) { - msSetError( MS_MISCERR, "Corrupt Content-* header.", - "msIO_stripStdoutBufferContentHeaders" ); + if (start_of_data == buf->data_offset) { + msSetError(MS_MISCERR, "Corrupt Content-* header.", + "msIO_stripStdoutBufferContentHeaders"); return; } /* -------------------------------------------------------------------- */ /* Move data to front of buffer, and reset length. */ /* -------------------------------------------------------------------- */ - memmove( buf->data, buf->data+start_of_data, - buf->data_offset - start_of_data ); + memmove(buf->data, buf->data + start_of_data, + buf->data_offset - start_of_data); buf->data[buf->data_offset - start_of_data] = '\0'; buf->data_offset -= start_of_data; @@ -1055,25 +1017,24 @@ void msIO_stripStdoutBufferContentHeaders() /* msIO_bufferWrite() */ /************************************************************************/ -int msIO_bufferWrite( void *cbData, void *data, int byteCount ) +int msIO_bufferWrite(void *cbData, void *data, int byteCount) { - msIOBuffer *buf = (msIOBuffer *) cbData; + msIOBuffer *buf = (msIOBuffer *)cbData; /* ** Grow buffer if needed (reserve one extra byte to put nul character) */ - if( buf->data_offset + byteCount >= buf->data_len ) { + if (buf->data_offset + byteCount >= buf->data_len) { buf->data_len = buf->data_len * 2 + byteCount + 100; - if( buf->data == NULL ) - buf->data = (unsigned char *) malloc(buf->data_len); + if (buf->data == NULL) + buf->data = (unsigned char *)malloc(buf->data_len); else - buf->data = (unsigned char *) realloc(buf->data, buf->data_len); + buf->data = (unsigned char *)realloc(buf->data, buf->data_len); - if( buf->data == NULL ) { - msSetError( MS_MEMERR, - "Failed to allocate %d bytes for capture buffer.", - "msIO_bufferWrite()", buf->data_len ); + if (buf->data == NULL) { + msSetError(MS_MEMERR, "Failed to allocate %d bytes for capture buffer.", + "msIO_bufferWrite()", buf->data_len); buf->data_len = 0; return 0; } @@ -1083,7 +1044,7 @@ int msIO_bufferWrite( void *cbData, void *data, int byteCount ) ** Copy result into buffer. */ - memcpy( buf->data + buf->data_offset, data, byteCount ); + memcpy(buf->data + buf->data_offset, data, byteCount); buf->data_offset += byteCount; buf->data[buf->data_offset] = '\0'; @@ -1094,7 +1055,7 @@ int msIO_bufferWrite( void *cbData, void *data, int byteCount ) /* msIO_bufferRead() */ /************************************************************************/ -int msIO_bufferRead( void *cbData, void *data, int byteCount ) +int msIO_bufferRead(void *cbData, void *data, int byteCount) { (void)cbData; diff --git a/mapio.h b/mapio.h index e0499150a2..2e45d376d4 100644 --- a/mapio.h +++ b/mapio.h @@ -45,79 +45,85 @@ extern "C" { #ifndef MS_PRINT_FUNC_FORMAT #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP) -#define MS_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx))) +#define MS_PRINT_FUNC_FORMAT(format_idx, arg_idx) \ + __attribute__((__format__(__printf__, format_idx, arg_idx))) #else -#define MS_PRINT_FUNC_FORMAT( format_idx, arg_idx ) +#define MS_PRINT_FUNC_FORMAT(format_idx, arg_idx) #endif #endif - /* stdio analogs */ - int MS_DLL_EXPORT msIO_printf( const char *format, ... ) MS_PRINT_FUNC_FORMAT(1,2); - int MS_DLL_EXPORT msIO_fprintf( FILE *stream, const char *format, ... ) MS_PRINT_FUNC_FORMAT(2,3); - int MS_DLL_EXPORT msIO_fwrite( const void *ptr, size_t size, size_t nmemb, FILE *stream ); - int MS_DLL_EXPORT msIO_fread( void *ptr, size_t size, size_t nmemb, FILE *stream ); - int MS_DLL_EXPORT msIO_vfprintf( FILE *fp, const char *format, va_list ap ) MS_PRINT_FUNC_FORMAT(2,0); - - /* - ** Definitions for the callback function and the details of the IO - ** channel contexts. - */ - - typedef int (*msIO_llReadWriteFunc)( void *cbData, void *data, int byteCount ); - - typedef struct msIOContext_t { - const char *label; - int write_channel; /* 1 for stdout/stderr, 0 for stdin */ - msIO_llReadWriteFunc readWriteFunc; - void *cbData; - } msIOContext; - - int MS_DLL_EXPORT msIO_installHandlers( msIOContext *stdin_context, - msIOContext *stdout_context, - msIOContext *stderr_context ); - msIOContext MS_DLL_EXPORT *msIO_getHandler( FILE * ); - void MS_DLL_EXPORT msIO_setHeaderEnabled(int bFlag); - void msIO_setHeader (const char *header, const char* value, ...) MS_PRINT_FUNC_FORMAT(2,3); - void msIO_sendHeaders(void); - - /* - ** These can be used instead of the stdio style functions if you have - ** msIOContext's for the channel in question. - */ - int msIO_contextRead( msIOContext *context, void *data, int byteCount ); - int msIO_contextWrite( msIOContext *context, const void *data, int byteCount ); - - /* - ** For redirecting IO to a memory buffer. - */ - - typedef struct { - unsigned char *data; - int data_len; /* really buffer length */ - int data_offset; /* really buffer used */ - } msIOBuffer; - - int MS_DLL_EXPORT msIO_bufferRead( void *, void *, int ); - int MS_DLL_EXPORT msIO_bufferWrite( void *, void *, int ); - - void MS_DLL_EXPORT msIO_resetHandlers(void); - void MS_DLL_EXPORT msIO_installStdoutToBuffer(void); - void MS_DLL_EXPORT msIO_installStdinFromBuffer(void); - void MS_DLL_EXPORT msIO_Cleanup(void); - char MS_DLL_EXPORT *msIO_stripStdoutBufferContentType(void); - void MS_DLL_EXPORT msIO_stripStdoutBufferContentHeaders(void); - hashTableObj MS_DLL_EXPORT *msIO_getAndStripStdoutBufferMimeHeaders(void); - - msIOContext *msIO_pushStdoutToBufferAndGetOldContext(void); - void msIO_restoreOldStdoutContext(msIOContext *context_to_restore); - - int MS_DLL_EXPORT msIO_isStdContext(void); - - - /* this is just for setting normal stdout's to binary mode on windows */ - - int msIO_needBinaryStdout( void ); - int msIO_needBinaryStdin( void ); +/* stdio analogs */ +int MS_DLL_EXPORT msIO_printf(const char *format, ...) + MS_PRINT_FUNC_FORMAT(1, 2); +int MS_DLL_EXPORT msIO_fprintf(FILE *stream, const char *format, ...) + MS_PRINT_FUNC_FORMAT(2, 3); +int MS_DLL_EXPORT msIO_fwrite(const void *ptr, size_t size, size_t nmemb, + FILE *stream); +int MS_DLL_EXPORT msIO_fread(void *ptr, size_t size, size_t nmemb, + FILE *stream); +int MS_DLL_EXPORT msIO_vfprintf(FILE *fp, const char *format, va_list ap) + MS_PRINT_FUNC_FORMAT(2, 0); + +/* +** Definitions for the callback function and the details of the IO +** channel contexts. +*/ + +typedef int (*msIO_llReadWriteFunc)(void *cbData, void *data, int byteCount); + +typedef struct msIOContext_t { + const char *label; + int write_channel; /* 1 for stdout/stderr, 0 for stdin */ + msIO_llReadWriteFunc readWriteFunc; + void *cbData; +} msIOContext; + +int MS_DLL_EXPORT msIO_installHandlers(msIOContext *stdin_context, + msIOContext *stdout_context, + msIOContext *stderr_context); +msIOContext MS_DLL_EXPORT *msIO_getHandler(FILE *); +void MS_DLL_EXPORT msIO_setHeaderEnabled(int bFlag); +void msIO_setHeader(const char *header, const char *value, ...) + MS_PRINT_FUNC_FORMAT(2, 3); +void msIO_sendHeaders(void); + +/* +** These can be used instead of the stdio style functions if you have +** msIOContext's for the channel in question. +*/ +int msIO_contextRead(msIOContext *context, void *data, int byteCount); +int msIO_contextWrite(msIOContext *context, const void *data, int byteCount); + +/* +** For redirecting IO to a memory buffer. +*/ + +typedef struct { + unsigned char *data; + int data_len; /* really buffer length */ + int data_offset; /* really buffer used */ +} msIOBuffer; + +int MS_DLL_EXPORT msIO_bufferRead(void *, void *, int); +int MS_DLL_EXPORT msIO_bufferWrite(void *, void *, int); + +void MS_DLL_EXPORT msIO_resetHandlers(void); +void MS_DLL_EXPORT msIO_installStdoutToBuffer(void); +void MS_DLL_EXPORT msIO_installStdinFromBuffer(void); +void MS_DLL_EXPORT msIO_Cleanup(void); +char MS_DLL_EXPORT *msIO_stripStdoutBufferContentType(void); +void MS_DLL_EXPORT msIO_stripStdoutBufferContentHeaders(void); +hashTableObj MS_DLL_EXPORT *msIO_getAndStripStdoutBufferMimeHeaders(void); + +msIOContext *msIO_pushStdoutToBufferAndGetOldContext(void); +void msIO_restoreOldStdoutContext(msIOContext *context_to_restore); + +int MS_DLL_EXPORT msIO_isStdContext(void); + +/* this is just for setting normal stdout's to binary mode on windows */ + +int msIO_needBinaryStdout(void); +int msIO_needBinaryStdin(void); #ifdef __cplusplus } diff --git a/mapjoin.c b/mapjoin.c index 8d1a09af95..eceb7a96a5 100644 --- a/mapjoin.c +++ b/mapjoin.c @@ -29,11 +29,8 @@ #include "mapserver.h" - - #define ROW_ALLOCATION_SIZE 10 - /* DBF/XBase function prototypes */ int msDBFJoinConnect(layerObj *layer, joinObj *join); int msDBFJoinPrepare(joinObj *join, shapeObj *shape); @@ -62,92 +59,90 @@ int msPOSTGRESQLJoinNext(joinObj *join); int msPOSTGRESQLJoinClose(joinObj *join); /* wrapper function for DB specific join functions */ -int msJoinConnect(layerObj *layer, joinObj *join) -{ - switch(join->connectiontype) { - case(MS_DB_XBASE): - return msDBFJoinConnect(layer, join); - break; - case(MS_DB_CSV): - return msCSVJoinConnect(layer, join); - break; - case(MS_DB_MYSQL): - return msMySQLJoinConnect(layer, join); - break; - case(MS_DB_POSTGRES): - return msPOSTGRESQLJoinConnect(layer, join); - break; - default: - break; - } - - msSetError(MS_JOINERR, "Unsupported join connection type.", "msJoinConnect()"); +int msJoinConnect(layerObj *layer, joinObj *join) { + switch (join->connectiontype) { + case (MS_DB_XBASE): + return msDBFJoinConnect(layer, join); + break; + case (MS_DB_CSV): + return msCSVJoinConnect(layer, join); + break; + case (MS_DB_MYSQL): + return msMySQLJoinConnect(layer, join); + break; + case (MS_DB_POSTGRES): + return msPOSTGRESQLJoinConnect(layer, join); + break; + default: + break; + } + + msSetError(MS_JOINERR, "Unsupported join connection type.", + "msJoinConnect()"); return MS_FAILURE; } -int msJoinPrepare(joinObj *join, shapeObj *shape) -{ - switch(join->connectiontype) { - case(MS_DB_XBASE): - return msDBFJoinPrepare(join, shape); - break; - case(MS_DB_CSV): - return msCSVJoinPrepare(join, shape); - break; - case(MS_DB_MYSQL): - return msMySQLJoinPrepare(join, shape); - break; - case(MS_DB_POSTGRES): - return msPOSTGRESQLJoinPrepare(join, shape); - break; - default: - break; - } - - msSetError(MS_JOINERR, "Unsupported join connection type.", "msJoinPrepare()"); +int msJoinPrepare(joinObj *join, shapeObj *shape) { + switch (join->connectiontype) { + case (MS_DB_XBASE): + return msDBFJoinPrepare(join, shape); + break; + case (MS_DB_CSV): + return msCSVJoinPrepare(join, shape); + break; + case (MS_DB_MYSQL): + return msMySQLJoinPrepare(join, shape); + break; + case (MS_DB_POSTGRES): + return msPOSTGRESQLJoinPrepare(join, shape); + break; + default: + break; + } + + msSetError(MS_JOINERR, "Unsupported join connection type.", + "msJoinPrepare()"); return MS_FAILURE; } -int msJoinNext(joinObj *join) -{ - switch(join->connectiontype) { - case(MS_DB_XBASE): - return msDBFJoinNext(join); - break; - case(MS_DB_CSV): - return msCSVJoinNext(join); - break; - case(MS_DB_MYSQL): - return msMySQLJoinNext(join); - break; - case(MS_DB_POSTGRES): - return msPOSTGRESQLJoinNext(join); - break; - default: - break; +int msJoinNext(joinObj *join) { + switch (join->connectiontype) { + case (MS_DB_XBASE): + return msDBFJoinNext(join); + break; + case (MS_DB_CSV): + return msCSVJoinNext(join); + break; + case (MS_DB_MYSQL): + return msMySQLJoinNext(join); + break; + case (MS_DB_POSTGRES): + return msPOSTGRESQLJoinNext(join); + break; + default: + break; } msSetError(MS_JOINERR, "Unsupported join connection type.", "msJoinNext()"); return MS_FAILURE; } -int msJoinClose(joinObj *join) -{ - switch(join->connectiontype) { - case(MS_DB_XBASE): - return msDBFJoinClose(join); - break; - case(MS_DB_CSV): - return msCSVJoinClose(join); - break; - case(MS_DB_MYSQL): - return msMySQLJoinClose(join); - break; - case(MS_DB_POSTGRES): - return msPOSTGRESQLJoinClose(join); - break; - default: - break; +int msJoinClose(joinObj *join) { + switch (join->connectiontype) { + case (MS_DB_XBASE): + return msDBFJoinClose(join); + break; + case (MS_DB_CSV): + return msCSVJoinClose(join); + break; + case (MS_DB_MYSQL): + return msMySQLJoinClose(join); + break; + case (MS_DB_POSTGRES): + return msPOSTGRESQLJoinClose(join); + break; + default: + break; } msSetError(MS_JOINERR, "Unsupported join connection type.", "msJoinClose()"); @@ -164,23 +159,23 @@ typedef struct { int nextrecord; } msDBFJoinInfo; -int msDBFJoinConnect(layerObj *layer, joinObj *join) -{ +int msDBFJoinConnect(layerObj *layer, joinObj *join) { int i; char szPath[MS_MAXPATHLEN]; msDBFJoinInfo *joininfo; - if(join->joininfo) return(MS_SUCCESS); /* already open */ + if (join->joininfo) + return (MS_SUCCESS); /* already open */ - if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE ) + if (msCheckParentPointer(layer->map, "map") == MS_FAILURE) return MS_FAILURE; - /* allocate a msDBFJoinInfo struct */ - joininfo = (msDBFJoinInfo *) malloc(sizeof(msDBFJoinInfo)); - if(!joininfo) { - msSetError(MS_MEMERR, "Error allocating XBase table info structure.", "msDBFJoinConnect()"); - return(MS_FAILURE); + joininfo = (msDBFJoinInfo *)malloc(sizeof(msDBFJoinInfo)); + if (!joininfo) { + msSetError(MS_MEMERR, "Error allocating XBase table info structure.", + "msDBFJoinConnect()"); + return (MS_FAILURE); } /* initialize any members that won't get set later on in this function */ @@ -190,126 +185,145 @@ int msDBFJoinConnect(layerObj *layer, joinObj *join) join->joininfo = joininfo; /* open the XBase file */ - if((joininfo->hDBF = msDBFOpen( msBuildPath3(szPath, layer->map->mappath, layer->map->shapepath, join->table), "rb" )) == NULL) { - if((joininfo->hDBF = msDBFOpen( msBuildPath(szPath, layer->map->mappath, join->table), "rb" )) == NULL) { + if ((joininfo->hDBF = + msDBFOpen(msBuildPath3(szPath, layer->map->mappath, + layer->map->shapepath, join->table), + "rb")) == NULL) { + if ((joininfo->hDBF = + msDBFOpen(msBuildPath(szPath, layer->map->mappath, join->table), + "rb")) == NULL) { msSetError(MS_IOERR, "(%s)", "msDBFJoinConnect()", join->table); - return(MS_FAILURE); + return (MS_FAILURE); } } /* get "to" item index */ - if((joininfo->toindex = msDBFGetItemIndex(joininfo->hDBF, join->to)) == -1) { - msSetError(MS_DBFERR, "Item %s not found in table %s.", "msDBFJoinConnect()", join->to, join->table); - return(MS_FAILURE); + if ((joininfo->toindex = msDBFGetItemIndex(joininfo->hDBF, join->to)) == -1) { + msSetError(MS_DBFERR, "Item %s not found in table %s.", + "msDBFJoinConnect()", join->to, join->table); + return (MS_FAILURE); } /* get "from" item index */ - for(i=0; inumitems; i++) { - if(strcasecmp(layer->items[i],join->from) == 0) { /* found it */ + for (i = 0; i < layer->numitems; i++) { + if (strcasecmp(layer->items[i], join->from) == 0) { /* found it */ joininfo->fromindex = i; break; } } - if(i == layer->numitems) { - msSetError(MS_JOINERR, "Item %s not found in layer %s.", "msDBFJoinConnect()", join->from, layer->name); - return(MS_FAILURE); + if (i == layer->numitems) { + msSetError(MS_JOINERR, "Item %s not found in layer %s.", + "msDBFJoinConnect()", join->from, layer->name); + return (MS_FAILURE); } /* finally store away the item names in the XBase table */ - join->numitems = msDBFGetFieldCount(joininfo->hDBF); + join->numitems = msDBFGetFieldCount(joininfo->hDBF); join->items = msDBFGetItems(joininfo->hDBF); - if(!join->items) return(MS_FAILURE); + if (!join->items) + return (MS_FAILURE); - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msDBFJoinPrepare(joinObj *join, shapeObj *shape) -{ +int msDBFJoinPrepare(joinObj *join, shapeObj *shape) { msDBFJoinInfo *joininfo = join->joininfo; - if(!joininfo) { - msSetError(MS_JOINERR, "Join connection has not be created.", "msDBFJoinPrepare()"); - return(MS_FAILURE); + if (!joininfo) { + msSetError(MS_JOINERR, "Join connection has not be created.", + "msDBFJoinPrepare()"); + return (MS_FAILURE); } - if(!shape) { - msSetError(MS_JOINERR, "Shape to be joined is empty.", "msDBFJoinPrepare()"); - return(MS_FAILURE); + if (!shape) { + msSetError(MS_JOINERR, "Shape to be joined is empty.", + "msDBFJoinPrepare()"); + return (MS_FAILURE); } - if(!shape->values) { - msSetError(MS_JOINERR, "Shape to be joined has no attributes.", "msDBFJoinPrepare()"); - return(MS_FAILURE); + if (!shape->values) { + msSetError(MS_JOINERR, "Shape to be joined has no attributes.", + "msDBFJoinPrepare()"); + return (MS_FAILURE); } joininfo->nextrecord = 0; /* starting with the first record */ - if(joininfo->target) free(joininfo->target); /* clear last target */ + if (joininfo->target) + free(joininfo->target); /* clear last target */ joininfo->target = msStrdup(shape->values[joininfo->fromindex]); - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msDBFJoinNext(joinObj *join) -{ +int msDBFJoinNext(joinObj *join) { int i, n; msDBFJoinInfo *joininfo = join->joininfo; - if(!joininfo) { - msSetError(MS_JOINERR, "Join connection has not be created.", "msDBFJoinNext()"); - return(MS_FAILURE); + if (!joininfo) { + msSetError(MS_JOINERR, "Join connection has not be created.", + "msDBFJoinNext()"); + return (MS_FAILURE); } - if(!joininfo->target) { - msSetError(MS_JOINERR, "No target specified, run msDBFJoinPrepare() first.", "msDBFJoinNext()"); - return(MS_FAILURE); + if (!joininfo->target) { + msSetError(MS_JOINERR, "No target specified, run msDBFJoinPrepare() first.", + "msDBFJoinNext()"); + return (MS_FAILURE); } /* clear any old data */ - if(join->values) { + if (join->values) { msFreeCharArray(join->values, join->numitems); join->values = NULL; } n = msDBFGetRecordCount(joininfo->hDBF); - for(i=joininfo->nextrecord; itarget, msDBFReadStringAttribute(joininfo->hDBF, i, joininfo->toindex)) == 0) break; + for (i = joininfo->nextrecord; i < n; i++) { /* find a match */ + if (strcmp(joininfo->target, msDBFReadStringAttribute(joininfo->hDBF, i, + joininfo->toindex)) == + 0) + break; } - if(i == n) { /* unable to do the join */ - if((join->values = (char **)malloc(sizeof(char *)*join->numitems)) == NULL) { + if (i == n) { /* unable to do the join */ + if ((join->values = (char **)malloc(sizeof(char *) * join->numitems)) == + NULL) { msSetError(MS_MEMERR, NULL, "msDBFJoinNext()"); - return(MS_FAILURE); + return (MS_FAILURE); } - for(i=0; inumitems; i++) + for (i = 0; i < join->numitems; i++) join->values[i] = msStrdup("\0"); /* intialize to zero length strings */ joininfo->nextrecord = n; - return(MS_DONE); + return (MS_DONE); } - if((join->values = msDBFGetValues(joininfo->hDBF,i)) == NULL) - return(MS_FAILURE); + if ((join->values = msDBFGetValues(joininfo->hDBF, i)) == NULL) + return (MS_FAILURE); - joininfo->nextrecord = i+1; /* so we know where to start looking next time through */ + joininfo->nextrecord = + i + 1; /* so we know where to start looking next time through */ - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msDBFJoinClose(joinObj *join) -{ +int msDBFJoinClose(joinObj *join) { msDBFJoinInfo *joininfo = join->joininfo; - if(!joininfo) return(MS_SUCCESS); /* already closed */ + if (!joininfo) + return (MS_SUCCESS); /* already closed */ - if(joininfo->hDBF) msDBFClose(joininfo->hDBF); - if(joininfo->target) free(joininfo->target); + if (joininfo->hDBF) + msDBFClose(joininfo->hDBF); + if (joininfo->target) + free(joininfo->target); free(joininfo); joininfo = NULL; - return(MS_SUCCESS); + return (MS_SUCCESS); } /* */ @@ -323,23 +337,23 @@ typedef struct { int nextrow; } msCSVJoinInfo; -int msCSVJoinConnect(layerObj *layer, joinObj *join) -{ +int msCSVJoinConnect(layerObj *layer, joinObj *join) { int i; FILE *stream; char szPath[MS_MAXPATHLEN]; msCSVJoinInfo *joininfo; char buffer[MS_BUFFER_LENGTH]; - if(join->joininfo) return(MS_SUCCESS); /* already open */ - if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE ) + if (join->joininfo) + return (MS_SUCCESS); /* already open */ + if (msCheckParentPointer(layer->map, "map") == MS_FAILURE) return MS_FAILURE; - /* allocate a msCSVJoinInfo struct */ - if((joininfo = (msCSVJoinInfo *) malloc(sizeof(msCSVJoinInfo))) == NULL) { - msSetError(MS_MEMERR, "Error allocating CSV table info structure.", "msCSVJoinConnect()"); - return(MS_FAILURE); + if ((joininfo = (msCSVJoinInfo *)malloc(sizeof(msCSVJoinInfo))) == NULL) { + msSetError(MS_MEMERR, "Error allocating CSV table info structure.", + "msCSVJoinConnect()"); + return (MS_FAILURE); } /* initialize any members that won't get set later on in this function */ @@ -349,175 +363,190 @@ int msCSVJoinConnect(layerObj *layer, joinObj *join) join->joininfo = joininfo; /* open the CSV file */ - if((stream = fopen( msBuildPath3(szPath, layer->map->mappath, layer->map->shapepath, join->table), "r" )) == NULL) { - if((stream = fopen( msBuildPath(szPath, layer->map->mappath, join->table), "r" )) == NULL) { + if ((stream = fopen(msBuildPath3(szPath, layer->map->mappath, + layer->map->shapepath, join->table), + "r")) == NULL) { + if ((stream = fopen(msBuildPath(szPath, layer->map->mappath, join->table), + "r")) == NULL) { msSetError(MS_IOERR, "(%s)", "msCSVJoinConnect()", join->table); - return(MS_FAILURE); + return (MS_FAILURE); } } /* once through to get the number of rows */ joininfo->numrows = 0; - while(fgets(buffer, MS_BUFFER_LENGTH, stream) != NULL) joininfo->numrows++; + while (fgets(buffer, MS_BUFFER_LENGTH, stream) != NULL) + joininfo->numrows++; rewind(stream); - if((joininfo->rows = (char ***) malloc(joininfo->numrows*sizeof(char **))) == NULL) { + if ((joininfo->rows = + (char ***)malloc(joininfo->numrows * sizeof(char **))) == NULL) { fclose(stream); msSetError(MS_MEMERR, "Error allocating rows.", "msCSVJoinConnect()"); - return(MS_FAILURE); + return (MS_FAILURE); } /* load the rows */ i = 0; - while(fgets(buffer, MS_BUFFER_LENGTH, stream) != NULL) { + while (fgets(buffer, MS_BUFFER_LENGTH, stream) != NULL) { msStringTrimEOL(buffer); - joininfo->rows[i] = msStringSplitComplex(buffer, ",", &(join->numitems), MS_ALLOWEMPTYTOKENS); + joininfo->rows[i] = msStringSplitComplex(buffer, ",", &(join->numitems), + MS_ALLOWEMPTYTOKENS); i++; } fclose(stream); /* get "from" item index */ - for(i=0; inumitems; i++) { - if(strcasecmp(layer->items[i],join->from) == 0) { /* found it */ + for (i = 0; i < layer->numitems; i++) { + if (strcasecmp(layer->items[i], join->from) == 0) { /* found it */ joininfo->fromindex = i; break; } } - if(i == layer->numitems) { - msSetError(MS_JOINERR, "Item %s not found in layer %s.", "msCSVJoinConnect()", join->from, layer->name); - return(MS_FAILURE); + if (i == layer->numitems) { + msSetError(MS_JOINERR, "Item %s not found in layer %s.", + "msCSVJoinConnect()", join->from, layer->name); + return (MS_FAILURE); } /* get "to" index (for now the user tells us which column, 1..n) */ joininfo->toindex = atoi(join->to) - 1; - if(joininfo->toindex < 0 || joininfo->toindex > join->numitems) { - msSetError(MS_JOINERR, "Invalid column index %s.", "msCSVJoinConnect()", join->to); - return(MS_FAILURE); + if (joininfo->toindex < 0 || joininfo->toindex > join->numitems) { + msSetError(MS_JOINERR, "Invalid column index %s.", "msCSVJoinConnect()", + join->to); + return (MS_FAILURE); } /* store away the column names (1..n) */ - if((join->items = (char **) malloc(sizeof(char *)*join->numitems)) == NULL) { - msSetError(MS_MEMERR, "Error allocating space for join item names.", "msCSVJoinConnect()"); - return(MS_FAILURE); + if ((join->items = (char **)malloc(sizeof(char *) * join->numitems)) == + NULL) { + msSetError(MS_MEMERR, "Error allocating space for join item names.", + "msCSVJoinConnect()"); + return (MS_FAILURE); } - for(i=0; inumitems; i++) { - join->items[i] = (char *) malloc(12); /* plenty of space */ - sprintf(join->items[i], "%d", i+1); + for (i = 0; i < join->numitems; i++) { + join->items[i] = (char *)malloc(12); /* plenty of space */ + sprintf(join->items[i], "%d", i + 1); } - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msCSVJoinPrepare(joinObj *join, shapeObj *shape) -{ +int msCSVJoinPrepare(joinObj *join, shapeObj *shape) { msCSVJoinInfo *joininfo = join->joininfo; - if(!joininfo) { - msSetError(MS_JOINERR, "Join connection has not be created.", "msCSVJoinPrepare()"); - return(MS_FAILURE); + if (!joininfo) { + msSetError(MS_JOINERR, "Join connection has not be created.", + "msCSVJoinPrepare()"); + return (MS_FAILURE); } - if(!shape) { - msSetError(MS_JOINERR, "Shape to be joined is empty.", "msCSVJoinPrepare()"); - return(MS_FAILURE); + if (!shape) { + msSetError(MS_JOINERR, "Shape to be joined is empty.", + "msCSVJoinPrepare()"); + return (MS_FAILURE); } - if(!shape->values) { - msSetError(MS_JOINERR, "Shape to be joined has no attributes.", "msCSVJoinPrepare()"); - return(MS_FAILURE); + if (!shape->values) { + msSetError(MS_JOINERR, "Shape to be joined has no attributes.", + "msCSVJoinPrepare()"); + return (MS_FAILURE); } joininfo->nextrow = 0; /* starting with the first record */ - if(joininfo->target) free(joininfo->target); /* clear last target */ + if (joininfo->target) + free(joininfo->target); /* clear last target */ joininfo->target = msStrdup(shape->values[joininfo->fromindex]); - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msCSVJoinNext(joinObj *join) -{ - int i,j; +int msCSVJoinNext(joinObj *join) { + int i, j; msCSVJoinInfo *joininfo = join->joininfo; - if(!joininfo) { - msSetError(MS_JOINERR, "Join connection has not be created.", "msCSVJoinNext()"); - return(MS_FAILURE); + if (!joininfo) { + msSetError(MS_JOINERR, "Join connection has not be created.", + "msCSVJoinNext()"); + return (MS_FAILURE); } /* clear any old data */ - if(join->values) { + if (join->values) { msFreeCharArray(join->values, join->numitems); join->values = NULL; } - for(i=joininfo->nextrow; inumrows; i++) { /* find a match */ - if(strcmp(joininfo->target, joininfo->rows[i][joininfo->toindex]) == 0) break; + for (i = joininfo->nextrow; i < joininfo->numrows; i++) { /* find a match */ + if (strcmp(joininfo->target, joininfo->rows[i][joininfo->toindex]) == 0) + break; } - if((join->values = (char ** )malloc(sizeof(char *)*join->numitems)) == NULL) { + if ((join->values = (char **)malloc(sizeof(char *) * join->numitems)) == + NULL) { msSetError(MS_MEMERR, NULL, "msCSVJoinNext()"); - return(MS_FAILURE); + return (MS_FAILURE); } - if(i == joininfo->numrows) { /* unable to do the join */ - for(j=0; jnumitems; j++) + if (i == joininfo->numrows) { /* unable to do the join */ + for (j = 0; j < join->numitems; j++) join->values[j] = msStrdup("\0"); /* intialize to zero length strings */ joininfo->nextrow = joininfo->numrows; - return(MS_DONE); + return (MS_DONE); } - for(j=0; jnumitems; j++) + for (j = 0; j < join->numitems; j++) join->values[j] = msStrdup(joininfo->rows[i][j]); - joininfo->nextrow = i+1; /* so we know where to start looking next time through */ + joininfo->nextrow = + i + 1; /* so we know where to start looking next time through */ - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msCSVJoinClose(joinObj *join) -{ +int msCSVJoinClose(joinObj *join) { int i; msCSVJoinInfo *joininfo = join->joininfo; - if(!joininfo) return(MS_SUCCESS); /* already closed */ + if (!joininfo) + return (MS_SUCCESS); /* already closed */ - for(i=0; inumrows; i++) + for (i = 0; i < joininfo->numrows; i++) msFreeCharArray(joininfo->rows[i], join->numitems); free(joininfo->rows); - if(joininfo->target) free(joininfo->target); + if (joininfo->target) + free(joininfo->target); free(joininfo); joininfo = NULL; - return(MS_SUCCESS); + return (MS_SUCCESS); } - #ifdef USE_MYSQL #ifndef _mysql_h #include #endif -char* DB_HOST = NULL; -char* DB_USER = NULL; -char* DB_PASSWD = NULL; -char* DB_DATABASE = NULL; -char* delim; +char *DB_HOST = NULL; +char *DB_USER = NULL; +char *DB_PASSWD = NULL; +char *DB_DATABASE = NULL; +char *delim; #define MYDEBUG if (0) -MYSQL_RES *msMySQLQuery(char *q, MYSQL *conn) -{ - MYSQL_RES *qresult=NULL; - if (mysql_query(conn,q) < 0) { +MYSQL_RES *msMySQLQuery(char *q, MYSQL *conn) { + MYSQL_RES *qresult = NULL; + if (mysql_query(conn, q) < 0) { mysql_close(conn); msSetError(MS_QUERYERR, "Bad mysql query (%s)", "msMySQLQuery()", q); return qresult; } - if (!(qresult=mysql_store_result(conn))) { + if (!(qresult = mysql_store_result(conn))) { mysql_close(conn); msSetError(MS_QUERYERR, "mysql query failed (%s)", "msMySQLQuery()", q); return qresult; @@ -540,30 +569,30 @@ typedef struct { } msMySQLJoinInfo; #endif - -int msMySQLJoinConnect(layerObj *layer, joinObj *join) -{ +int msMySQLJoinConnect(layerObj *layer, joinObj *join) { (void)layer; (void)join; #ifndef USE_MYSQL - msSetError(MS_QUERYERR, "MySQL support not available (compile with --with-mysql)", "msMySQLJoinConnect()"); - return(MS_FAILURE); + msSetError(MS_QUERYERR, + "MySQL support not available (compile with --with-mysql)", + "msMySQLJoinConnect()"); + return (MS_FAILURE); #else int i; char qbuf[4000]; char *conn_decrypted; msMySQLJoinInfo *joininfo; - MYDEBUG if (setvbuf(stdout, NULL, _IONBF , 0)) { - printf("Whoops..."); - }; - if(join->joininfo) return(MS_SUCCESS); /* already open */ + MYDEBUG if (setvbuf(stdout, NULL, _IONBF, 0)) { printf("Whoops..."); }; + if (join->joininfo) + return (MS_SUCCESS); /* already open */ /* allocate a msMySQLJoinInfo struct */ - joininfo = (msMySQLJoinInfo *) malloc(sizeof(msMySQLJoinInfo)); - if(!joininfo) { - msSetError(MS_MEMERR, "Error allocating mysql table info structure.", "msMySQLJoinConnect()"); - return(MS_FAILURE); + joininfo = (msMySQLJoinInfo *)malloc(sizeof(msMySQLJoinInfo)); + if (!joininfo) { + msSetError(MS_MEMERR, "Error allocating mysql table info structure.", + "msMySQLJoinConnect()"); + return (MS_FAILURE); } /* initialize any members that won't get set later on in this function */ @@ -575,18 +604,22 @@ int msMySQLJoinConnect(layerObj *layer, joinObj *join) /* open the mysql connection */ - if( join->connection == NULL ) { - msSetError(MS_QUERYERR, "Error parsing MYSQL JOIN: nothing specified in CONNECTION statement.", - "msMySQLJoinConnect()"); + if (join->connection == NULL) { + msSetError( + MS_QUERYERR, + "Error parsing MYSQL JOIN: nothing specified in CONNECTION statement.", + "msMySQLJoinConnect()"); - return(MS_FAILURE); + return (MS_FAILURE); } conn_decrypted = msDecryptStringTokens(layer->map, join->connection); if (conn_decrypted == NULL) { - msSetError(MS_QUERYERR, "Error parsing MYSQL JOIN: unable to decrypt CONNECTION statement.", - "msMySQLJoinConnect()"); - return(MS_FAILURE); + msSetError( + MS_QUERYERR, + "Error parsing MYSQL JOIN: unable to decrypt CONNECTION statement.", + "msMySQLJoinConnect()"); + return (MS_FAILURE); } delim = msStrdup(":"); @@ -596,29 +629,38 @@ int msMySQLJoinConnect(layerObj *layer, joinObj *join) DB_DATABASE = msStrdup(strtok(NULL, delim)); free(conn_decrypted); - if (DB_HOST == NULL || DB_USER == NULL || DB_PASSWD == NULL || DB_DATABASE == NULL) { - msSetError(MS_QUERYERR, "DB param error: at least one of HOST, USER, PASSWD or DATABASE is null!", "msMySQLJoinConnect()"); + if (DB_HOST == NULL || DB_USER == NULL || DB_PASSWD == NULL || + DB_DATABASE == NULL) { + msSetError(MS_QUERYERR, + "DB param error: at least one of HOST, USER, PASSWD or DATABASE " + "is null!", + "msMySQLJoinConnect()"); return MS_FAILURE; } - if (strcmp(DB_PASSWD, "none") == 0) strcpy(DB_PASSWD, ""); + if (strcmp(DB_PASSWD, "none") == 0) + strcpy(DB_PASSWD, ""); #if MYSQL_VERSION_ID >= 40000 mysql_init(&(joininfo->mysql)); - if (!(joininfo->conn = mysql_real_connect(&(joininfo->mysql),DB_HOST,DB_USER,DB_PASSWD,NULL, 0, NULL, 0))) + if (!(joininfo->conn = mysql_real_connect( + &(joininfo->mysql), DB_HOST, DB_USER, DB_PASSWD, NULL, 0, NULL, 0))) #else - if (!(joininfo->conn = mysql_connect(&(joininfo->mysql),DB_HOST,DB_USER,DB_PASSWD))) + if (!(joininfo->conn = + mysql_connect(&(joininfo->mysql), DB_HOST, DB_USER, DB_PASSWD))) #endif { char tmp[4000]; - snprintf( tmp, sizeof(tmp), "Failed to connect to SQL server: Error: %s\nHost: %s\nUsername:%s\nPassword:%s\n", mysql_error(joininfo->conn), DB_HOST, DB_USER, DB_PASSWD); - msSetError(MS_QUERYERR, "%s", - "msMYSQLLayerOpen()", tmp); + snprintf(tmp, sizeof(tmp), + "Failed to connect to SQL server: Error: %s\nHost: " + "%s\nUsername:%s\nPassword:%s\n", + mysql_error(joininfo->conn), DB_HOST, DB_USER, DB_PASSWD); + msSetError(MS_QUERYERR, "%s", "msMYSQLLayerOpen()", tmp); free(joininfo); return MS_FAILURE; } MYDEBUG printf("msMYSQLLayerOpen2 called
\n"); - if (mysql_select_db(joininfo->conn,DB_DATABASE) < 0) { + if (mysql_select_db(joininfo->conn, DB_DATABASE) < 0) { mysql_close(joininfo->conn); } MYDEBUG printf("msMYSQLLayerOpen3 called
\n"); @@ -627,118 +669,135 @@ int msMySQLJoinConnect(layerObj *layer, joinObj *join) mysql_free_result(joininfo->qresult); } MYDEBUG printf("msMYSQLLayerOpen5 called
\n"); - snprintf(qbuf, sizeof(qbuf), "SELECT count(%s) FROM %s", join->to, join->table); + snprintf(qbuf, sizeof(qbuf), "SELECT count(%s) FROM %s", join->to, + join->table); MYDEBUG printf("%s
\n", qbuf); - if ((joininfo->qresult = msMySQLQuery(qbuf, joininfo->conn))) { /* There were some rows found, write 'em out for debug */ + if ((joininfo->qresult = + msMySQLQuery(qbuf, joininfo->conn))) { /* There were some rows found, + write 'em out for debug */ int numrows = mysql_affected_rows(joininfo->conn); MYDEBUG printf("%d rows
\n", numrows); - for(i=0; iqresult); - MYDEBUG printf("(%s)
\n",row[0]); + MYDEBUG printf("(%s)
\n", row[0]); joininfo->rows = atoi(row[0]); } } else { - msSetError(MS_DBFERR, "Item %s not found in table %s.", "msMySQLJoinConnect()", join->to, join->table); - return(MS_FAILURE); + msSetError(MS_DBFERR, "Item %s not found in table %s.", + "msMySQLJoinConnect()", join->to, join->table); + return (MS_FAILURE); } snprintf(qbuf, sizeof(qbuf), "EXPLAIN %s", join->table); - if ((joininfo->qresult = msMySQLQuery(qbuf, joininfo->conn))) { /* There were some rows found, write 'em out for debug */ + if ((joininfo->qresult = + msMySQLQuery(qbuf, joininfo->conn))) { /* There were some rows found, + write 'em out for debug */ join->numitems = mysql_affected_rows(joininfo->conn); - if((join->items = (char **)malloc(sizeof(char *)*join->numitems)) == NULL) { + if ((join->items = (char **)malloc(sizeof(char *) * join->numitems)) == + NULL) { msSetError(MS_MEMERR, NULL, "msMySQLJoinConnect()"); - return(MS_FAILURE); + return (MS_FAILURE); } MYDEBUG printf("%d rows
\n", join->numitems); - for(i=0; inumitems; i++) { + for (i = 0; i < join->numitems; i++) { MYSQL_ROW row = mysql_fetch_row(joininfo->qresult); - MYDEBUG printf("(%s)
\n",row[0]); + MYDEBUG printf("(%s)
\n", row[0]); join->items[i] = msStrdup(row[0]); } } else { - msSetError(MS_DBFERR, "Item %s not found in table %s.", "msMySQLJoinConnect()", join->to, join->table); - return(MS_FAILURE); + msSetError(MS_DBFERR, "Item %s not found in table %s.", + "msMySQLJoinConnect()", join->to, join->table); + return (MS_FAILURE); } joininfo->tocolumn = msStrdup(join->to); - - /* get "from" item index */ - for(i=0; inumitems; i++) { - if(strcasecmp(layer->items[i],join->from) == 0) { /* found it */ + for (i = 0; i < layer->numitems; i++) { + if (strcasecmp(layer->items[i], join->from) == 0) { /* found it */ joininfo->fromindex = i; break; } } - if(i == layer->numitems) { - msSetError(MS_JOINERR, "Item %s not found in layer %s.", "msMySQLJoinConnect()", join->from, layer->name); - return(MS_FAILURE); + if (i == layer->numitems) { + msSetError(MS_JOINERR, "Item %s not found in layer %s.", + "msMySQLJoinConnect()", join->from, layer->name); + return (MS_FAILURE); } /* finally store away the item names in the XBase table */ - if(!join->items) return(MS_FAILURE); + if (!join->items) + return (MS_FAILURE); - return(MS_SUCCESS); + return (MS_SUCCESS); #endif } -int msMySQLJoinPrepare(joinObj *join, shapeObj *shape) -{ +int msMySQLJoinPrepare(joinObj *join, shapeObj *shape) { (void)join; (void)shape; #ifndef USE_MYSQL - msSetError(MS_QUERYERR, "MySQL support not available (compile with --with-mysql)", "msMySQLJoinPrepare()"); - return(MS_FAILURE); + msSetError(MS_QUERYERR, + "MySQL support not available (compile with --with-mysql)", + "msMySQLJoinPrepare()"); + return (MS_FAILURE); #else msMySQLJoinInfo *joininfo = join->joininfo; - if(!joininfo) { - msSetError(MS_JOINERR, "Join connection has not be created.", "msMySQLJoinPrepare()"); - return(MS_FAILURE); + if (!joininfo) { + msSetError(MS_JOINERR, "Join connection has not be created.", + "msMySQLJoinPrepare()"); + return (MS_FAILURE); } - if(!shape) { - msSetError(MS_JOINERR, "Shape to be joined is empty.", "msMySQLJoinPrepare()"); - return(MS_FAILURE); + if (!shape) { + msSetError(MS_JOINERR, "Shape to be joined is empty.", + "msMySQLJoinPrepare()"); + return (MS_FAILURE); } - if(!shape->values) { - msSetError(MS_JOINERR, "Shape to be joined has no attributes.", "msMySQLJoinPrepare()"); - return(MS_FAILURE); + if (!shape->values) { + msSetError(MS_JOINERR, "Shape to be joined has no attributes.", + "msMySQLJoinPrepare()"); + return (MS_FAILURE); } joininfo->nextrecord = 0; /* starting with the first record */ - if(joininfo->target) free(joininfo->target); /* clear last target */ + if (joininfo->target) + free(joininfo->target); /* clear last target */ joininfo->target = msStrdup(shape->values[joininfo->fromindex]); - return(MS_SUCCESS); + return (MS_SUCCESS); #endif } -int msMySQLJoinNext(joinObj *join) -{ +int msMySQLJoinNext(joinObj *join) { (void)join; #ifndef USE_MYSQL - msSetError(MS_QUERYERR, "MySQL support not available (compile with --with-mysql)", "msMySQLJoinNext()"); - return(MS_FAILURE); + msSetError(MS_QUERYERR, + "MySQL support not available (compile with --with-mysql)", + "msMySQLJoinNext()"); + return (MS_FAILURE); #else int i; char qbuf[4000]; msMySQLJoinInfo *joininfo = join->joininfo; - if(!joininfo) { - msSetError(MS_JOINERR, "Join connection has not be created.", "msMySQLJoinNext()"); - return(MS_FAILURE); + if (!joininfo) { + msSetError(MS_JOINERR, "Join connection has not be created.", + "msMySQLJoinNext()"); + return (MS_FAILURE); } - if(!joininfo->target) { - msSetError(MS_JOINERR, "No target specified, run msMySQLJoinPrepare() first.", "msMySQLJoinNext()"); - return(MS_FAILURE); + if (!joininfo->target) { + msSetError(MS_JOINERR, + "No target specified, run msMySQLJoinPrepare() first.", + "msMySQLJoinNext()"); + return (MS_FAILURE); } /* clear any old data */ - if(join->values) { + if (join->values) { msFreeCharArray(join->values, join->numitems); join->values = NULL; } @@ -746,84 +805,97 @@ int msMySQLJoinNext(joinObj *join) /* int n = joininfo->rows; */ /* for(i=joininfo->nextrecord; itarget, msMySQLReadStringAttribute(joininfo->conn, i, joininfo->toindex)) == 0) break; */ + /* if(strcmp(joininfo->target, msMySQLReadStringAttribute(joininfo->conn, i, + * joininfo->toindex)) == 0) break; */ /* } */ - snprintf(qbuf, sizeof(qbuf), "SELECT * FROM %s WHERE %s = %s", join->table, joininfo->tocolumn, joininfo->target); + snprintf(qbuf, sizeof(qbuf), "SELECT * FROM %s WHERE %s = %s", join->table, + joininfo->tocolumn, joininfo->target); MYDEBUG printf("%s
\n", qbuf); - if ((joininfo->qresult = msMySQLQuery(qbuf, joininfo->conn))) { /* There were some rows found, write 'em out for debug */ + if ((joininfo->qresult = + msMySQLQuery(qbuf, joininfo->conn))) { /* There were some rows found, + write 'em out for debug */ int numrows = mysql_affected_rows(joininfo->conn); int numfields = mysql_field_count(joininfo->conn); MYDEBUG printf("%d rows
\n", numrows); if (numrows > 0) { MYSQL_ROW row = mysql_fetch_row(joininfo->qresult); - for(i=0; i\n"); free(join->values); - if((join->values = (char **)malloc(sizeof(char *)*join->numitems)) == NULL) { + if ((join->values = (char **)malloc(sizeof(char *) * join->numitems)) == + NULL) { msSetError(MS_MEMERR, NULL, "msMySQLJoinNext()"); - return(MS_FAILURE); + return (MS_FAILURE); } - for(i=0; inumitems; i++) { - /* join->values[i] = msStrdup("\0"); */ /* intialize to zero length strings */ - join->values[i] = msStrdup(row[i]); /* intialize to zero length strings */ + for (i = 0; i < join->numitems; i++) { + /* join->values[i] = msStrdup("\0"); */ /* intialize to zero length + strings */ + join->values[i] = + msStrdup(row[i]); /* intialize to zero length strings */ /* rows = atoi(row[0]); */ } } else { - if((join->values = (char **)malloc(sizeof(char *)*join->numitems)) == NULL) { + if ((join->values = (char **)malloc(sizeof(char *) * join->numitems)) == + NULL) { msSetError(MS_MEMERR, NULL, "msMySQLJoinNext()"); - return(MS_FAILURE); + return (MS_FAILURE); } - for(i=0; inumitems; i++) - join->values[i] = msStrdup("\0"); /* intialize to zero length strings */ + for (i = 0; i < join->numitems; i++) + join->values[i] = msStrdup("\0"); /* intialize to zero length strings */ - return(MS_DONE); + return (MS_DONE); } } else { msSetError(MS_QUERYERR, "Query error (%s)", "msMySQLJoinNext()", qbuf); - return(MS_FAILURE); + return (MS_FAILURE); } #ifdef __NOTDEF__ - if(i == n) { /* unable to do the join */ - if((join->values = (char **)malloc(sizeof(char *)*join->numitems)) == NULL) { + if (i == n) { /* unable to do the join */ + if ((join->values = (char **)malloc(sizeof(char *) * join->numitems)) == + NULL) { msSetError(MS_MEMERR, NULL, "msMySQLJoinNext()"); - return(MS_FAILURE); + return (MS_FAILURE); } - for(i=0; inumitems; i++) + for (i = 0; i < join->numitems; i++) join->values[i] = msStrdup("\0"); /* intialize to zero length strings */ joininfo->nextrecord = n; - return(MS_DONE); + return (MS_DONE); } - if((join->values = msMySQLGetValues(joininfo->conn,i)) == NULL) - return(MS_FAILURE); + if ((join->values = msMySQLGetValues(joininfo->conn, i)) == NULL) + return (MS_FAILURE); - joininfo->nextrecord = i+1; /* so we know where to start looking next time through */ + joininfo->nextrecord = + i + 1; /* so we know where to start looking next time through */ #endif /* __NOTDEF__ */ - return(MS_SUCCESS); + return (MS_SUCCESS); #endif } -int msMySQLJoinClose(joinObj *join) -{ +int msMySQLJoinClose(joinObj *join) { (void)join; #ifndef USE_MYSQL - msSetError(MS_QUERYERR, "MySQL support not available (compile with --with-mysql)", "msMySQLJoinClose()"); - return(MS_FAILURE); + msSetError(MS_QUERYERR, + "MySQL support not available (compile with --with-mysql)", + "msMySQLJoinClose()"); + return (MS_FAILURE); #else msMySQLJoinInfo *joininfo = join->joininfo; - if(!joininfo) return(MS_SUCCESS); /* already closed */ + if (!joininfo) + return (MS_SUCCESS); /* already closed */ mysql_close(joininfo->conn); - if(joininfo->target) free(joininfo->target); + if (joininfo->target) + free(joininfo->target); free(joininfo); joininfo = NULL; - return(MS_SUCCESS); + return (MS_SUCCESS); #endif } diff --git a/mapkml.cpp b/mapkml.cpp index 388bc9f6e9..f7c264f1a7 100644 --- a/mapkml.cpp +++ b/mapkml.cpp @@ -36,183 +36,166 @@ extern "C" { #endif - KmlRenderer* getKmlRenderer(imageObj* img) - { - return (KmlRenderer*) img->img.plugin; - } - - imageObj* msCreateImageKml(int width, int height, outputFormatObj *format, colorObj* bg) - { - imageObj *image = NULL; - - image = (imageObj*)malloc(sizeof(imageObj)); - MS_CHECK_ALLOC(image, sizeof(imageObj), NULL); - memset(image, 0, sizeof(imageObj)); +KmlRenderer *getKmlRenderer(imageObj *img) { + return (KmlRenderer *)img->img.plugin; +} - KmlRenderer *ren = new KmlRenderer(width, height, format, bg); - image->img.plugin = (void *) ren; +imageObj *msCreateImageKml(int width, int height, outputFormatObj *format, + colorObj *bg) { + imageObj *image = NULL; - return image; - } + image = (imageObj *)malloc(sizeof(imageObj)); + MS_CHECK_ALLOC(image, sizeof(imageObj), NULL); + memset(image, 0, sizeof(imageObj)); - int msSaveImageKml(imageObj *img, mapObj* /*map*/, FILE *fp, outputFormatObj *format) - { - KmlRenderer* renderer = getKmlRenderer(img); - return renderer->saveImage(img, fp, format); - } + KmlRenderer *ren = new KmlRenderer(width, height, format, bg); + image->img.plugin = (void *)ren; - int msRenderLineKml(imageObj *img, shapeObj *p, strokeStyleObj *style) - { - KmlRenderer* renderer = getKmlRenderer(img); - renderer->renderLine(img, p, style); - return MS_SUCCESS; - } + return image; +} - int msRenderPolygonKml(imageObj *img, shapeObj *p, colorObj *color) - { - KmlRenderer* renderer = getKmlRenderer(img); - renderer->renderPolygon(img, p, color); - return MS_SUCCESS; - } +int msSaveImageKml(imageObj *img, mapObj * /*map*/, FILE *fp, + outputFormatObj *format) { + KmlRenderer *renderer = getKmlRenderer(img); + return renderer->saveImage(img, fp, format); +} - int msRenderPolygonTiledKml(imageObj * /*img*/, shapeObj * /*p*/, imageObj * /*tile*/) - { - /*KmlRenderer* renderer = getKmlRenderer(img);*/ - return MS_SUCCESS; - } +int msRenderLineKml(imageObj *img, shapeObj *p, strokeStyleObj *style) { + KmlRenderer *renderer = getKmlRenderer(img); + renderer->renderLine(img, p, style); + return MS_SUCCESS; +} - int msRenderLineTiledKml(imageObj * /*img*/, shapeObj * /*p*/, imageObj * /*tile*/) - { - return MS_SUCCESS; - } +int msRenderPolygonKml(imageObj *img, shapeObj *p, colorObj *color) { + KmlRenderer *renderer = getKmlRenderer(img); + renderer->renderPolygon(img, p, color); + return MS_SUCCESS; +} - int msRenderGlyphsKml(imageObj *img, const textSymbolObj *ts, colorObj *c, colorObj *oc, int ow, int /*isMarker*/) - { - KmlRenderer* renderer = getKmlRenderer(img); - renderer->renderGlyphs(img, ts, c, oc, ow); - return MS_SUCCESS; - } +int msRenderPolygonTiledKml(imageObj * /*img*/, shapeObj * /*p*/, + imageObj * /*tile*/) { + /*KmlRenderer* renderer = getKmlRenderer(img);*/ + return MS_SUCCESS; +} - int msRenderVectorSymbolKml(imageObj *img, double x, double y, - symbolObj *symbol, symbolStyleObj *style) - { - KmlRenderer* renderer = getKmlRenderer(img); - renderer->renderVectorSymbol(img, x, y, symbol, style); - return MS_SUCCESS; - } +int msRenderLineTiledKml(imageObj * /*img*/, shapeObj * /*p*/, + imageObj * /*tile*/) { + return MS_SUCCESS; +} - int msRenderPixmapSymbolKml(imageObj *img, double x, double y, - symbolObj *symbol, symbolStyleObj *style) - { - KmlRenderer* renderer = getKmlRenderer(img); - renderer->renderPixmapSymbol(img, x, y, symbol, style); - return MS_SUCCESS; - } +int msRenderGlyphsKml(imageObj *img, const textSymbolObj *ts, colorObj *c, + colorObj *oc, int ow, int /*isMarker*/) { + KmlRenderer *renderer = getKmlRenderer(img); + renderer->renderGlyphs(img, ts, c, oc, ow); + return MS_SUCCESS; +} - int msRenderEllipseSymbolKml(imageObj *image, double x, double y, - symbolObj *symbol, symbolStyleObj *style) - { - KmlRenderer* renderer = getKmlRenderer(image); - renderer->renderEllipseSymbol(image, x, y, symbol, style); - return MS_SUCCESS; - } +int msRenderVectorSymbolKml(imageObj *img, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { + KmlRenderer *renderer = getKmlRenderer(img); + renderer->renderVectorSymbol(img, x, y, symbol, style); + return MS_SUCCESS; +} - int msRenderTruetypeSymbolKml(imageObj *image, double x, double y, - symbolObj *symbol, symbolStyleObj *style) - { - KmlRenderer* renderer = getKmlRenderer(image); - renderer->renderTruetypeSymbol(image, x, y, symbol, style); - return MS_SUCCESS; - } +int msRenderPixmapSymbolKml(imageObj *img, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { + KmlRenderer *renderer = getKmlRenderer(img); + renderer->renderPixmapSymbol(img, x, y, symbol, style); + return MS_SUCCESS; +} +int msRenderEllipseSymbolKml(imageObj *image, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { + KmlRenderer *renderer = getKmlRenderer(image); + renderer->renderEllipseSymbol(image, x, y, symbol, style); + return MS_SUCCESS; +} - int msRenderTileKml(imageObj * /*img*/, imageObj * /*tile*/, double /*x*/, double /*y*/) - { - return MS_SUCCESS; - } +int msRenderTruetypeSymbolKml(imageObj *image, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { + KmlRenderer *renderer = getKmlRenderer(image); + renderer->renderTruetypeSymbol(image, x, y, symbol, style); + return MS_SUCCESS; +} - int msGetRasterBufferKml(imageObj * /*img*/,rasterBufferObj * /*rb*/) - { - return MS_FAILURE; //not supported for kml - } +int msRenderTileKml(imageObj * /*img*/, imageObj * /*tile*/, double /*x*/, + double /*y*/) { + return MS_SUCCESS; +} +int msGetRasterBufferKml(imageObj * /*img*/, rasterBufferObj * /*rb*/) { + return MS_FAILURE; // not supported for kml +} - int msGetTruetypeTextBBoxKml(rendererVTableObj * /*r*/,char** /*fonts*/, int /*numfonts*/, double size, char *string, - rectObj *rect, double **advances, int /*bAdjustBaseline*/) - { - rect->minx=0.0; - rect->maxx=0.0; - rect->miny=0.0; - rect->maxy=0.0; - if (advances) { - int numglyphs = msGetNumGlyphs(string); - *advances = (double*) msSmallMalloc(numglyphs * sizeof (double)); - for(int i=0; iminx = 0.0; + rect->maxx = 0.0; + rect->miny = 0.0; + rect->maxy = 0.0; + if (advances) { + int numglyphs = msGetNumGlyphs(string); + *advances = (double *)msSmallMalloc(numglyphs * sizeof(double)); + for (int i = 0; i < numglyphs; i++) { + (*advances)[i] = size; } - return MS_SUCCESS; } + return MS_SUCCESS; +} - int msStartNewLayerKml(imageObj *img, mapObj * /*map*/, layerObj *layer) - { - KmlRenderer* renderer = getKmlRenderer(img); - return renderer->startNewLayer(img, layer); - } +int msStartNewLayerKml(imageObj *img, mapObj * /*map*/, layerObj *layer) { + KmlRenderer *renderer = getKmlRenderer(img); + return renderer->startNewLayer(img, layer); +} - int msCloseNewLayerKml(imageObj *img, mapObj * /*map*/, layerObj *layer) - { - KmlRenderer* renderer = getKmlRenderer(img); - return renderer->closeNewLayer(img, layer); - } +int msCloseNewLayerKml(imageObj *img, mapObj * /*map*/, layerObj *layer) { + KmlRenderer *renderer = getKmlRenderer(img); + return renderer->closeNewLayer(img, layer); +} - int msFreeImageKml(imageObj *image) - { - KmlRenderer* renderer = getKmlRenderer(image); - if (renderer) { - delete renderer; - } - image->img.plugin=NULL; - return MS_SUCCESS; +int msFreeImageKml(imageObj *image) { + KmlRenderer *renderer = getKmlRenderer(image); + if (renderer) { + delete renderer; } + image->img.plugin = NULL; + return MS_SUCCESS; +} - int msFreeSymbolKml(symbolObj * /*symbol*/) - { - return MS_SUCCESS; - } +int msFreeSymbolKml(symbolObj * /*symbol*/) { return MS_SUCCESS; } - int msStartShapeKml(imageObj *img, shapeObj *shape) - { - KmlRenderer* renderer = getKmlRenderer(img); - renderer->startShape(img, shape); - return MS_SUCCESS; - } +int msStartShapeKml(imageObj *img, shapeObj *shape) { + KmlRenderer *renderer = getKmlRenderer(img); + renderer->startShape(img, shape); + return MS_SUCCESS; +} - int msEndShapeKml(imageObj *img, shapeObj *shape) - { - KmlRenderer* renderer = getKmlRenderer(img); - renderer->endShape(img, shape); - return MS_SUCCESS; - } +int msEndShapeKml(imageObj *img, shapeObj *shape) { + KmlRenderer *renderer = getKmlRenderer(img); + renderer->endShape(img, shape); + return MS_SUCCESS; +} - int msMergeRasterBufferKml(imageObj *dest, rasterBufferObj *overlay, double /*opacity*/, int /*srcX*/, - int /*srcY*/, int /*dstX*/, int /*dstY*/, int /*width*/, int /*height*/) - { - KmlRenderer* renderer = getKmlRenderer(dest); - return renderer->mergeRasterBuffer(dest,overlay); - } +int msMergeRasterBufferKml(imageObj *dest, rasterBufferObj *overlay, + double /*opacity*/, int /*srcX*/, int /*srcY*/, + int /*dstX*/, int /*dstY*/, int /*width*/, + int /*height*/) { + KmlRenderer *renderer = getKmlRenderer(dest); + return renderer->mergeRasterBuffer(dest, overlay); +} #ifdef __cplusplus } #endif - #endif /*USE_KML*/ -int aggInitializeRasterBuffer(rasterBufferObj *rb, int width, int height, int mode); +int aggInitializeRasterBuffer(rasterBufferObj *rb, int width, int height, + int mode); -int msPopulateRendererVTableKML( rendererVTableObj *renderer ) -{ +int msPopulateRendererVTableKML(rendererVTableObj *renderer) { #ifdef USE_KML renderer->supports_pixel_buffer = 0; renderer->supports_clipping = 0; @@ -221,11 +204,11 @@ int msPopulateRendererVTableKML( rendererVTableObj *renderer ) renderer->startLayer = msStartNewLayerKml; renderer->endLayer = msCloseNewLayerKml; - renderer->renderLine=&msRenderLineKml; - renderer->createImage=&msCreateImageKml; - renderer->saveImage=&msSaveImageKml; - renderer->renderPolygon=&msRenderPolygonKml; - renderer->renderGlyphs=&msRenderGlyphsKml; + renderer->renderLine = &msRenderLineKml; + renderer->createImage = &msCreateImageKml; + renderer->saveImage = &msSaveImageKml; + renderer->renderPolygon = &msRenderPolygonKml; + renderer->renderGlyphs = &msRenderGlyphsKml; renderer->renderEllipseSymbol = &msRenderEllipseSymbolKml; renderer->renderVectorSymbol = &msRenderVectorSymbolKml; renderer->renderPixmapSymbol = &msRenderPixmapSymbolKml; @@ -236,12 +219,12 @@ int msPopulateRendererVTableKML( rendererVTableObj *renderer ) renderer->renderPolygonTiled = &msRenderPolygonTiledKml; renderer->renderLineTiled = NULL; renderer->freeSymbol = &msFreeSymbolKml; - renderer->freeImage=&msFreeImageKml; + renderer->freeImage = &msFreeImageKml; renderer->mergeRasterBuffer = msMergeRasterBufferKml; renderer->compositeRasterBuffer = NULL; - renderer->startShape=&msStartShapeKml; - renderer->endShape=&msEndShapeKml; + renderer->startShape = &msStartShapeKml; + renderer->endShape = &msEndShapeKml; return MS_SUCCESS; #else @@ -250,4 +233,3 @@ int msPopulateRendererVTableKML( rendererVTableObj *renderer ) return MS_FAILURE; #endif } - diff --git a/mapkmlrenderer.cpp b/mapkmlrenderer.cpp index 360a51f6f5..feaaf62e67 100644 --- a/mapkmlrenderer.cpp +++ b/mapkmlrenderer.cpp @@ -39,22 +39,25 @@ #include "cpl_conv.h" #include "cpl_vsi.h" -#define KML_MAXFEATURES_TODRAW 1000 +#define KML_MAXFEATURES_TODRAW 1000 -KmlRenderer::KmlRenderer(int width, int height, outputFormatObj * /*format*/, colorObj* /*color*/) - : Width(width), Height(height), MapCellsize(1.0), XmlDoc(NULL), LayerNode(NULL), GroundOverlayNode(NULL), - PlacemarkNode(NULL), GeomNode(NULL), - Items(NULL), NumItems(0), FirstLayer(MS_TRUE), map(NULL), currentLayer(NULL), - mElevationFromAttribute( false ), mElevationAttributeIndex( -1 ), mCurrentElevationValue(0.0) +KmlRenderer::KmlRenderer(int width, int height, outputFormatObj * /*format*/, + colorObj * /*color*/) + : Width(width), Height(height), MapCellsize(1.0), XmlDoc(NULL), + LayerNode(NULL), GroundOverlayNode(NULL), PlacemarkNode(NULL), + GeomNode(NULL), Items(NULL), NumItems(0), FirstLayer(MS_TRUE), map(NULL), + currentLayer(NULL), mElevationFromAttribute(false), + mElevationAttributeIndex(-1), mCurrentElevationValue(0.0) { /*private variables*/ pszLayerDescMetadata = NULL; papszLayerIncludeItems = NULL; - nIncludeItems=0; + nIncludeItems = 0; papszLayerExcludeItems = NULL; - nExcludeItems=0; - pszLayerNameAttributeMetadata = NULL; /*metadata to use for a name for each feature*/ + nExcludeItems = 0; + pszLayerNameAttributeMetadata = + NULL; /*metadata to use for a name for each feature*/ LineStyle = NULL; numLineStyle = 0; @@ -67,7 +70,8 @@ KmlRenderer::KmlRenderer(int width, int height, outputFormatObj * /*format*/, co xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST "kml"); /* Name spaces*/ - xmlSetNs(rootNode, xmlNewNs(rootNode, BAD_CAST "http://www.opengis.net/kml/2.2", NULL)); + xmlSetNs(rootNode, + xmlNewNs(rootNode, BAD_CAST "http://www.opengis.net/kml/2.2", NULL)); xmlDocSetRootElement(XmlDoc, rootNode); @@ -79,46 +83,45 @@ KmlRenderer::KmlRenderer(int width, int height, outputFormatObj * /*format*/, co xmlNewChild(listStyleNode, NULL, BAD_CAST "listItemType", BAD_CAST "check"); styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL); - xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST "LayerFolder_checkHideChildren"); + xmlNewProp(styleNode, BAD_CAST "id", + BAD_CAST "LayerFolder_checkHideChildren"); listStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "ListStyle", NULL); - xmlNewChild(listStyleNode, NULL, BAD_CAST "listItemType", BAD_CAST "checkHideChildren"); + xmlNewChild(listStyleNode, NULL, BAD_CAST "listItemType", + BAD_CAST "checkHideChildren"); styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL); xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST "LayerFolder_checkOffOnly"); listStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "ListStyle", NULL); - xmlNewChild(listStyleNode, NULL, BAD_CAST "listItemType", BAD_CAST "checkOffOnly"); + xmlNewChild(listStyleNode, NULL, BAD_CAST "listItemType", + BAD_CAST "checkOffOnly"); styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL); xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST "LayerFolder_radioFolder"); listStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "ListStyle", NULL); - xmlNewChild(listStyleNode, NULL, BAD_CAST "listItemType", BAD_CAST "radioFolder"); - + xmlNewChild(listStyleNode, NULL, BAD_CAST "listItemType", + BAD_CAST "radioFolder"); StyleHashTable = msCreateHashTable(); - } -KmlRenderer::~KmlRenderer() -{ +KmlRenderer::~KmlRenderer() { if (XmlDoc) xmlFreeDoc(XmlDoc); if (StyleHashTable) msFreeHashTable(StyleHashTable); - if(LineStyle) + if (LineStyle) msFree(LineStyle); xmlCleanupParser(); } -imageObj* KmlRenderer::createImage(int, int, outputFormatObj*, colorObj*) -{ +imageObj *KmlRenderer::createImage(int, int, outputFormatObj *, colorObj *) { return NULL; } -int KmlRenderer::saveImage(imageObj *, FILE *fp, outputFormatObj *format) -{ +int KmlRenderer::saveImage(imageObj *, FILE *fp, outputFormatObj *format) { /* -------------------------------------------------------------------- */ /* Write out the document. */ /* -------------------------------------------------------------------- */ @@ -129,7 +132,7 @@ int KmlRenderer::saveImage(imageObj *, FILE *fp, outputFormatObj *format) int chunkSize = 4096; int bZip = MS_FALSE; - if( msIO_needBinaryStdout() == MS_FAILURE ) + if (msIO_needBinaryStdout() == MS_FAILURE) return MS_FAILURE; xmlDocDumpFormatMemoryEnc(XmlDoc, &buf, &bufSize, "UTF-8", 1); @@ -142,63 +145,60 @@ int KmlRenderer::saveImage(imageObj *, FILE *fp, outputFormatObj *format) VSILFILE *fpZip; int bytes_read; char buffer[1024]; - char *zip_filename =NULL; - void *hZip=NULL; + char *zip_filename = NULL; + void *hZip = NULL; - zip_filename = msTmpFile(NULL, NULL, "/vsimem/kmlzip/", "kmz" ); - hZip = CPLCreateZip( zip_filename, NULL ); - CPLCreateFileInZip( hZip, "mapserver.kml", NULL ); - for (int i=0; i bufSize) size = bufSize - i; - CPLWriteFileInZip( hZip, buf+i, size); + CPLWriteFileInZip(hZip, buf + i, size); } - CPLCloseFileInZip( hZip ); - CPLCloseZip( hZip ); + CPLCloseFileInZip(hZip); + CPLCloseZip(hZip); context = msIO_getHandler(fp); - fpZip = VSIFOpenL( zip_filename, "r" ); + fpZip = VSIFOpenL(zip_filename, "r"); - while( (bytes_read = VSIFReadL( buffer, 1, sizeof(buffer), fpZip )) > 0 ) { + while ((bytes_read = VSIFReadL(buffer, 1, sizeof(buffer), fpZip)) > 0) { if (context) msIO_contextWrite(context, buffer, bytes_read); else - msIO_fwrite( buffer, 1, bytes_read, fp ); + msIO_fwrite(buffer, 1, bytes_read, fp); } - VSIFCloseL( fpZip ); - msFree( zip_filename); + VSIFCloseL(fpZip); + msFree(zip_filename); xmlFree(buf); - return(MS_SUCCESS); + return (MS_SUCCESS); } context = msIO_getHandler(fp); - - for (int i=0; i bufSize) size = bufSize - i; if (context) - msIO_contextWrite(context, buf+i, size); + msIO_contextWrite(context, buf + i, size); else - msIO_fwrite(buf+i, 1, size, fp); + msIO_fwrite(buf + i, 1, size, fp); } xmlFree(buf); - return(MS_SUCCESS); + return (MS_SUCCESS); } - /************************************************************************/ /* processLayer */ /* */ /* Set parameters that make sense to a kml output. */ /************************************************************************/ -void KmlRenderer::processLayer(layerObj *layer, outputFormatObj *format) -{ +void KmlRenderer::processLayer(layerObj *layer, outputFormatObj *format) { int i; const char *asRaster = NULL; int nMaxFeatures = -1; @@ -213,29 +213,30 @@ void KmlRenderer::processLayer(layerObj *layer, outputFormatObj *format) /*if there are labels we want the coordinates to be the center of the element.*/ - for(i=0; inumclasses; i++) - if(layer->_class[i]->numlabels > 0) layer->_class[i]->labels[0]->position = MS_XY; + for (i = 0; i < layer->numclasses; i++) + if (layer->_class[i]->numlabels > 0) + layer->_class[i]->labels[0]->position = MS_XY; /*we do not want to draw multiple styles. the new rendering architecture does not allow to know if we are dealing with a multi-style. So here we remove all styles beside the first one*/ - for(i=0; inumclasses; i++) { + for (i = 0; i < layer->numclasses; i++) { while (layer->_class[i]->numstyles > 1) - msDeleteStyle(layer->_class[i], layer->_class[i]->numstyles-1); + msDeleteStyle(layer->_class[i], layer->_class[i]->numstyles - 1); } - /*if layer has a metadata KML_OUTPUTASRASTER set to true, add a processing directive - to use an agg driver*/ + /*if layer has a metadata KML_OUTPUTASRASTER set to true, add a processing + directive to use an agg driver*/ asRaster = msLookupHashTable(&layer->metadata, "kml_outputasraster"); if (!asRaster) - asRaster = msLookupHashTable(&(layer->map->web.metadata), "kml_outputasraster"); - if (asRaster && (strcasecmp(asRaster, "true") == 0 || - strcasecmp(asRaster, "yes") == 0)) + asRaster = + msLookupHashTable(&(layer->map->web.metadata), "kml_outputasraster"); + if (asRaster && + (strcasecmp(asRaster, "true") == 0 || strcasecmp(asRaster, "yes") == 0)) msLayerAddProcessing(layer, "RENDERER=png24"); - /*set a maxfeaturestodraw, if not already set*/ pszTmp = msLookupHashTable(&layer->metadata, "maxfeaturestodraw"); @@ -247,13 +248,13 @@ void KmlRenderer::processLayer(layerObj *layer, outputFormatObj *format) nMaxFeatures = atoi(pszTmp); } if (nMaxFeatures < 0 && format) - nMaxFeatures = atoi(msGetOutputFormatOption( format, "maxfeaturestodraw", "-1")); + nMaxFeatures = + atoi(msGetOutputFormatOption(format, "maxfeaturestodraw", "-1")); if (nMaxFeatures < 0 && format) { snprintf(szTmp, sizeof(szTmp), "%d", KML_MAXFEATURES_TODRAW); - msSetOutputFormatOption( format, "maxfeaturestodraw", szTmp); + msSetOutputFormatOption(format, "maxfeaturestodraw", szTmp); } - } /************************************************************************/ @@ -261,15 +262,14 @@ void KmlRenderer::processLayer(layerObj *layer, outputFormatObj *format) /* */ /* Internal utility function to build name used fo rthe layer. */ /************************************************************************/ -char* KmlRenderer::getLayerName(layerObj *layer) -{ +char *KmlRenderer::getLayerName(layerObj *layer) { char stmp[20]; - const char *name=NULL;; + const char *name = NULL; + ; if (!layer) return NULL; - name = msLookupHashTable(&layer->metadata, "ows_name"); if (name && strlen(name) > 0) return msStrdup(name); @@ -277,13 +277,12 @@ char* KmlRenderer::getLayerName(layerObj *layer) if (layer->name && strlen(layer->name) > 0) return msStrdup(layer->name); - sprintf(stmp, "Layer%d",layer->index); + sprintf(stmp, "Layer%d", layer->index); return msStrdup(stmp); - } -const char* KmlRenderer::getAliasName(layerObj *lp, char *pszItemName, const char *namespaces) -{ +const char *KmlRenderer::getAliasName(layerObj *lp, char *pszItemName, + const char *namespaces) { const char *pszAlias = NULL; if (lp && pszItemName && strlen(pszItemName) > 0) { char szTmp[256]; @@ -293,10 +292,9 @@ const char* KmlRenderer::getAliasName(layerObj *lp, char *pszItemName, const cha return pszAlias; } -int KmlRenderer::startNewLayer(imageObj *img, layerObj *layer) -{ - char *layerName=NULL; - const char *value=NULL; +int KmlRenderer::startNewLayer(imageObj *img, layerObj *layer) { + char *layerName = NULL; + const char *value = NULL; LayerNode = xmlNewNode(NULL, BAD_CAST "Folder"); @@ -307,25 +305,31 @@ int KmlRenderer::startNewLayer(imageObj *img, layerObj *layer) const char *layerVisibility = layer->status != MS_OFF ? "1" : "0"; xmlNewChild(LayerNode, NULL, BAD_CAST "visibility", BAD_CAST layerVisibility); - const char *layerDsiplayFolder = msLookupHashTable(&(layer->metadata), "kml_folder_display"); + const char *layerDsiplayFolder = + msLookupHashTable(&(layer->metadata), "kml_folder_display"); if (layerDsiplayFolder == NULL) - layerDsiplayFolder = msLookupHashTable(&(layer->map->web.metadata), "kml_folder_display"); - if (!layerDsiplayFolder || strlen(layerDsiplayFolder)<=0) { - xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_check"); + layerDsiplayFolder = + msLookupHashTable(&(layer->map->web.metadata), "kml_folder_display"); + if (!layerDsiplayFolder || strlen(layerDsiplayFolder) <= 0) { + xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", + BAD_CAST "#LayerFolder_check"); } else { if (strcasecmp(layerDsiplayFolder, "checkHideChildren") == 0) - xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_checkHideChildren"); + xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", + BAD_CAST "#LayerFolder_checkHideChildren"); else if (strcasecmp(layerDsiplayFolder, "checkOffOnly") == 0) - xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_checkOffOnly"); + xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", + BAD_CAST "#LayerFolder_checkOffOnly"); else if (strcasecmp(layerDsiplayFolder, "radioFolder") == 0) - xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_radioFolder"); + xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", + BAD_CAST "#LayerFolder_radioFolder"); else - xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_check"); + xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", + BAD_CAST "#LayerFolder_check"); } - /*Init few things on the first layer*/ if (FirstLayer) { FirstLayer = MS_FALSE; @@ -338,9 +342,10 @@ int KmlRenderer::startNewLayer(imageObj *img, layerObj *layer) checkProjection(layer->map); /*check for image path and image url*/ - if (layer->map->debug && (layer->map->web.imageurl == NULL || layer->map->web.imagepath == NULL)) - msDebug("KmlRenderer::startNewLayer: imagepath and imageurl should be set in the web object\n"); - + if (layer->map->debug && + (layer->map->web.imageurl == NULL || layer->map->web.imagepath == NULL)) + msDebug("KmlRenderer::startNewLayer: imagepath and imageurl should be " + "set in the web object\n"); /*map rect for ground overlay*/ MapExtent = layer->map->extent; @@ -348,16 +353,16 @@ int KmlRenderer::startNewLayer(imageObj *img, layerObj *layer) BgColor = layer->map->imagecolor; xmlNewChild(DocNode, NULL, BAD_CAST "name", BAD_CAST layer->map->name); - aggFormat = msSelectOutputFormat( layer->map, "png24"); + aggFormat = msSelectOutputFormat(layer->map, "png24"); aggFormat->transparent = MS_TRUE; - } currentLayer = layer; if (!msLayerIsOpen(layer)) { if (msLayerOpen(layer) != MS_SUCCESS) { - msSetError(MS_MISCERR, "msLayerOpen failed", "KmlRenderer::startNewLayer" ); + msSetError(MS_MISCERR, "msLayerOpen failed", + "KmlRenderer::startNewLayer"); return MS_FAILURE; } } @@ -369,45 +374,46 @@ int KmlRenderer::startNewLayer(imageObj *img, layerObj *layer) processLayer(layer, NULL); if (msLookupHashTable(&layer->metadata, "kml_description")) - pszLayerDescMetadata = msLookupHashTable(&layer->metadata, "kml_description"); + pszLayerDescMetadata = + msLookupHashTable(&layer->metadata, "kml_description"); else if (msLookupHashTable(&layer->metadata, "ows_description")) - pszLayerDescMetadata = msLookupHashTable(&layer->metadata, "ows_description"); + pszLayerDescMetadata = + msLookupHashTable(&layer->metadata, "ows_description"); - value=msLookupHashTable(&layer->metadata, "kml_include_items"); + value = msLookupHashTable(&layer->metadata, "kml_include_items"); if (!value) - value=msLookupHashTable(&layer->metadata, "ows_include_items"); + value = msLookupHashTable(&layer->metadata, "ows_include_items"); if (value) papszLayerIncludeItems = msStringSplit(value, ',', &nIncludeItems); - value=msLookupHashTable(&layer->metadata, "kml_exclude_items"); + value = msLookupHashTable(&layer->metadata, "kml_exclude_items"); if (!value) - value=msLookupHashTable(&layer->metadata, "ows_exclude_items"); + value = msLookupHashTable(&layer->metadata, "ows_exclude_items"); if (value) papszLayerExcludeItems = msStringSplit(value, ',', &nExcludeItems); - if (msLookupHashTable(&layer->metadata, "kml_name_item")) - pszLayerNameAttributeMetadata = msLookupHashTable(&layer->metadata, "kml_name_item"); + pszLayerNameAttributeMetadata = + msLookupHashTable(&layer->metadata, "kml_name_item"); /*get all attributes*/ - if(msLayerWhichItems(layer, MS_TRUE, NULL) != MS_SUCCESS) { + if (msLayerWhichItems(layer, MS_TRUE, NULL) != MS_SUCCESS) { return MS_FAILURE; } - NumItems = layer->numitems; if (NumItems) { Items = (char **)msSmallCalloc(NumItems, sizeof(char *)); - for (int i=0; iitems[i]); } - - const char* elevationAttribute = msLookupHashTable(&layer->metadata, "kml_elevation_attribute"); - if( elevationAttribute ) { + const char *elevationAttribute = + msLookupHashTable(&layer->metadata, "kml_elevation_attribute"); + if (elevationAttribute) { mElevationFromAttribute = true; - for( int i = 0; i < layer->numitems; ++i ) { - if( strcasecmp( layer->items[i], elevationAttribute ) == 0 ) { + for (int i = 0; i < layer->numitems; ++i) { + if (strcasecmp(layer->items[i], elevationAttribute) == 0) { mElevationAttributeIndex = i; } } @@ -417,13 +423,12 @@ int KmlRenderer::startNewLayer(imageObj *img, layerObj *layer) return MS_SUCCESS; } -int KmlRenderer::closeNewLayer(imageObj *, layerObj *) -{ +int KmlRenderer::closeNewLayer(imageObj *, layerObj *) { flushPlacemark(); xmlAddChild(DocNode, LayerNode); - if(Items) { + if (Items) { msFreeCharArray(Items, NumItems); Items = NULL; NumItems = 0; @@ -434,33 +439,32 @@ int KmlRenderer::closeNewLayer(imageObj *, layerObj *) if (pszLayerNameAttributeMetadata) pszLayerNameAttributeMetadata = NULL; - if (papszLayerIncludeItems && nIncludeItems>0) + if (papszLayerIncludeItems && nIncludeItems > 0) msFreeCharArray(papszLayerIncludeItems, nIncludeItems); - papszLayerIncludeItems=NULL; + papszLayerIncludeItems = NULL; - if (papszLayerExcludeItems && nExcludeItems>0) + if (papszLayerExcludeItems && nExcludeItems > 0) msFreeCharArray(papszLayerExcludeItems, nExcludeItems); - papszLayerExcludeItems=NULL; + papszLayerExcludeItems = NULL; return MS_SUCCESS; } -int KmlRenderer::mergeRasterBuffer(imageObj *image, rasterBufferObj *rb) -{ +int KmlRenderer::mergeRasterBuffer(imageObj *image, rasterBufferObj *rb) { assert(rb && rb->type == MS_BUFFER_BYTE_RGBA); char *tmpFileName = NULL; char *tmpUrl = NULL; FILE *tmpFile = NULL; tmpFileName = msTmpFile(NULL, MapPath, image->imagepath, "png"); - tmpFile = fopen(tmpFileName,"wb"); + tmpFile = fopen(tmpFileName, "wb"); if (tmpFile) { if (!aggFormat->vtable) msInitializeRendererVTable(aggFormat); - msSaveRasterBuffer(map,rb,tmpFile,aggFormat); - tmpUrl = msStrdup( image->imageurl); + msSaveRasterBuffer(map, rb, tmpFile, aggFormat); + tmpUrl = msStrdup(image->imageurl); tmpUrl = msStringConcatenate(tmpUrl, (char *)(msGetBasename(tmpFileName))); tmpUrl = msStringConcatenate(tmpUrl, ".png"); @@ -470,24 +474,25 @@ int KmlRenderer::mergeRasterBuffer(imageObj *image, rasterBufferObj *rb) fclose(tmpFile); return MS_SUCCESS; } else { - msSetError(MS_IOERR,"Failed to create file for kml overlay","KmlRenderer::mergeRasterBuffer()"); + msSetError(MS_IOERR, "Failed to create file for kml overlay", + "KmlRenderer::mergeRasterBuffer()"); return MS_FAILURE; } } -void KmlRenderer::setupRenderingParams(hashTableObj *layerMetadata) -{ +void KmlRenderer::setupRenderingParams(hashTableObj *layerMetadata) { AltitudeMode = 0; Extrude = 0; Tessellate = 0; - const char *altitudeModeVal = msLookupHashTable(layerMetadata, "kml_altitudeMode"); + const char *altitudeModeVal = + msLookupHashTable(layerMetadata, "kml_altitudeMode"); if (altitudeModeVal) { - if(strcasecmp(altitudeModeVal, "absolute") == 0) + if (strcasecmp(altitudeModeVal, "absolute") == 0) AltitudeMode = absolute; - else if(strcasecmp(altitudeModeVal, "relativeToGround") == 0) + else if (strcasecmp(altitudeModeVal, "relativeToGround") == 0) AltitudeMode = relativeToGround; - else if(strcasecmp(altitudeModeVal, "clampToGround") == 0) + else if (strcasecmp(altitudeModeVal, "clampToGround") == 0) AltitudeMode = clampToGround; } @@ -496,31 +501,31 @@ void KmlRenderer::setupRenderingParams(hashTableObj *layerMetadata) Extrude = atoi(extrudeVal); } - const char *tessellateVal = msLookupHashTable(layerMetadata, "kml_tessellate"); + const char *tessellateVal = + msLookupHashTable(layerMetadata, "kml_tessellate"); if (tessellateVal) { Tessellate = atoi(tessellateVal); } - } -int KmlRenderer::checkProjection(mapObj *map) -{ - projectionObj *projection= &map->projection; - if (projection && projection->numargs > 0 && msProjIsGeographicCRS(projection)) { +int KmlRenderer::checkProjection(mapObj *map) { + projectionObj *projection = &map->projection; + if (projection && projection->numargs > 0 && + msProjIsGeographicCRS(projection)) { return MS_SUCCESS; } else { char epsg_string[100]; rectObj sRect; projectionObj out; - /* for layer the do not have any projection set, set them with the current map - projection*/ + /* for layer the do not have any projection set, set them with the current + map projection*/ if (projection && projection->numargs > 0) { layerObj *lp = NULL; - int i =0; + int i = 0; char *pszMapProjectString = msGetProjectionString(projection); if (pszMapProjectString) { - for(i=0; inumlayers; i++) { + for (i = 0; i < map->numlayers; i++) { lp = GET_LAYER(map, i); if (lp->projection.numargs == 0 && lp->transform == MS_TRUE) { msFreeProjection(&lp->projection); @@ -530,7 +535,7 @@ int KmlRenderer::checkProjection(mapObj *map) msFree(pszMapProjectString); } } - strcpy(epsg_string, "epsg:4326" ); + strcpy(epsg_string, "epsg:4326"); msInitProjection(&out); msProjectionInheritContextFrom(&out, projection); msLoadProjectionString(&out, epsg_string); @@ -544,22 +549,24 @@ int KmlRenderer::checkProjection(mapObj *map) map->extent = sRect; map->units = MS_DD; - if (map->debug) - msDebug("KmlRenderer::checkProjection: Mapfile projection set to epsg:4326\n"); + msDebug("KmlRenderer::checkProjection: Mapfile projection set to " + "epsg:4326\n"); return MS_SUCCESS; } } -xmlNodePtr KmlRenderer::createPlacemarkNode(xmlNodePtr parentNode, char *styleUrl) -{ - xmlNodePtr placemarkNode = xmlNewChild(parentNode, NULL, BAD_CAST "Placemark", NULL); +xmlNodePtr KmlRenderer::createPlacemarkNode(xmlNodePtr parentNode, + char *styleUrl) { + xmlNodePtr placemarkNode = + xmlNewChild(parentNode, NULL, BAD_CAST "Placemark", NULL); /*always add a name. It will be replaced by a text value if available*/ char tmpid[100]; - char *stmp=NULL, *layerName=NULL; - if (CurrentShapeName && strlen(CurrentShapeName)>0) { - xmlNewChild(placemarkNode, NULL, BAD_CAST "name", BAD_CAST CurrentShapeName); + char *stmp = NULL, *layerName = NULL; + if (CurrentShapeName && strlen(CurrentShapeName) > 0) { + xmlNewChild(placemarkNode, NULL, BAD_CAST "name", + BAD_CAST CurrentShapeName); } else { sprintf(tmpid, ".%d", CurrentShapeIndex); layerName = getLayerName(currentLayer); @@ -575,8 +582,7 @@ xmlNodePtr KmlRenderer::createPlacemarkNode(xmlNodePtr parentNode, char *styleUr return placemarkNode; } -void KmlRenderer::renderLine(imageObj*, shapeObj *p, strokeStyleObj *style) -{ +void KmlRenderer::renderLine(imageObj *, shapeObj *p, strokeStyleObj *style) { if (p->numlines == 0) return; @@ -599,8 +605,9 @@ void KmlRenderer::renderLine(imageObj*, shapeObj *p, strokeStyleObj *style) /* more than one line => MultiGeometry*/ if (p->numlines > 1) { geomNode = getGeomParentNode("LineString"); // returns MultiGeom Node - for (int i=1; inumlines; i++) { - xmlNodePtr lineStringNode = xmlNewChild(geomNode, NULL, BAD_CAST "LineString", NULL); + for (int i = 1; i < p->numlines; i++) { + xmlNodePtr lineStringNode = + xmlNewChild(geomNode, NULL, BAD_CAST "LineString", NULL); addAddRenderingSpecifications(lineStringNode); addCoordsNode(lineStringNode, p->line[i].point, p->line[i].numpoints); } @@ -608,11 +615,9 @@ void KmlRenderer::renderLine(imageObj*, shapeObj *p, strokeStyleObj *style) CurrentDrawnShapeIndex = p->index; } - } -void KmlRenderer::renderPolygon(imageObj*, shapeObj *p, colorObj *color) -{ +void KmlRenderer::renderPolygon(imageObj *, shapeObj *p, colorObj *color) { if (PlacemarkNode == NULL) PlacemarkNode = createPlacemarkNode(LayerNode, NULL); @@ -622,40 +627,42 @@ void KmlRenderer::renderPolygon(imageObj*, shapeObj *p, colorObj *color) memcpy(&PolygonColor, color, sizeof(colorObj)); SymbologyFlag[Polygon] = 1; - if (p->index != CurrentDrawnShapeIndex) { xmlNodePtr geomParentNode = getGeomParentNode("Polygon"); - for (int i=0; inumlines; i++) { + for (int i = 0; i < p->numlines; i++) { xmlNodePtr bdryNode = NULL; - if (i==0) /* __TODO__ check ring order*/ - bdryNode = xmlNewChild(geomParentNode, NULL, BAD_CAST "outerBoundaryIs", NULL); + if (i == 0) /* __TODO__ check ring order*/ + bdryNode = + xmlNewChild(geomParentNode, NULL, BAD_CAST "outerBoundaryIs", NULL); else - bdryNode = xmlNewChild(geomParentNode, NULL, BAD_CAST "innerBoundaryIs", NULL); + bdryNode = + xmlNewChild(geomParentNode, NULL, BAD_CAST "innerBoundaryIs", NULL); - xmlNodePtr ringNode = xmlNewChild(bdryNode, NULL, BAD_CAST "LinearRing", NULL); + xmlNodePtr ringNode = + xmlNewChild(bdryNode, NULL, BAD_CAST "LinearRing", NULL); addAddRenderingSpecifications(ringNode); addCoordsNode(ringNode, p->line[i].point, p->line[i].numpoints); } CurrentDrawnShapeIndex = p->index; - } - } -void KmlRenderer::addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts) -{ +void KmlRenderer::addCoordsNode(xmlNodePtr parentNode, pointObj *pts, + int numPts) { char lineBuf[128]; - xmlNodePtr coordsNode = xmlNewChild(parentNode, NULL, BAD_CAST "coordinates", NULL); + xmlNodePtr coordsNode = + xmlNewChild(parentNode, NULL, BAD_CAST "coordinates", NULL); xmlNodeAddContent(coordsNode, BAD_CAST "\n"); - for (int i=0; iannotext == NULL || ts->textpath->numglyphs == 0 ) +void KmlRenderer::renderGlyphs(imageObj *, const textSymbolObj *ts, + colorObj *clr, colorObj * /*oc*/, int /*ow*/) { + if (ts->annotext == NULL || ts->textpath->numglyphs == 0) return; if (PlacemarkNode == NULL) @@ -686,7 +693,7 @@ void KmlRenderer::renderGlyphs(imageObj *, const textSymbolObj *ts, colorObj *cl continue; if (strcmp((char *)node->name, "name") == 0) { - xmlNodeSetContent(node, BAD_CAST ts->annotext); + xmlNodeSetContent(node, BAD_CAST ts->annotext); break; } } @@ -702,8 +709,7 @@ void KmlRenderer::renderGlyphs(imageObj *, const textSymbolObj *ts, colorObj *cl addCoordsNode(geomNode, &pt, 1); } -void KmlRenderer::addAddRenderingSpecifications(xmlNodePtr node) -{ +void KmlRenderer::addAddRenderingSpecifications(xmlNodePtr node) { /* 0 0 @@ -719,48 +725,50 @@ void KmlRenderer::addAddRenderingSpecifications(xmlNodePtr node) if (AltitudeMode == absolute) xmlNewChild(node, NULL, BAD_CAST "altitudeMode", BAD_CAST "absolute"); else if (AltitudeMode == relativeToGround) - xmlNewChild(node, NULL, BAD_CAST "altitudeMode", BAD_CAST "relativeToGround"); + xmlNewChild(node, NULL, BAD_CAST "altitudeMode", + BAD_CAST "relativeToGround"); else if (AltitudeMode == clampToGround) xmlNewChild(node, NULL, BAD_CAST "altitudeMode", BAD_CAST "clampToGround"); } +imageObj *agg2CreateImage(int width, int height, outputFormatObj *format, + colorObj *bg); -imageObj *agg2CreateImage(int width, int height, outputFormatObj *format, colorObj * bg); - -int KmlRenderer::createIconImage(char *fileName, symbolObj *symbol, symbolStyleObj *symstyle) -{ +int KmlRenderer::createIconImage(char *fileName, symbolObj *symbol, + symbolStyleObj *symstyle) { pointObj p; int status; imageObj *tmpImg = NULL; - tmpImg = agg2CreateImage((int)(symbol->sizex*symstyle->scale), - (int)(symbol->sizey*symstyle->scale), - aggFormat, NULL); + tmpImg = + agg2CreateImage((int)(symbol->sizex * symstyle->scale), + (int)(symbol->sizey * symstyle->scale), aggFormat, NULL); tmpImg->format = aggFormat; if (!aggFormat->vtable) msInitializeRendererVTable(aggFormat); p.x = symbol->sizex * symstyle->scale / 2; - p.y = symbol->sizey *symstyle->scale / 2; + p.y = symbol->sizey * symstyle->scale / 2; p.z = 0.0; - status = msDrawMarkerSymbol(map,tmpImg, &p, symstyle->style, 1); - if( status != MS_SUCCESS ) + status = msDrawMarkerSymbol(map, tmpImg, &p, symstyle->style, 1); + if (status != MS_SUCCESS) return status; return msSaveImage(map, tmpImg, fileName); } -void KmlRenderer::renderSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style) -{ +void KmlRenderer::renderSymbol(imageObj *img, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { if (PlacemarkNode == NULL) PlacemarkNode = createPlacemarkNode(LayerNode, NULL); if (!PlacemarkNode) return; - snprintf(SymbolUrl, sizeof(SymbolUrl), "%s", lookupSymbolUrl(img, symbol, style)); + snprintf(SymbolUrl, sizeof(SymbolUrl), "%s", + lookupSymbolUrl(img, symbol, style)); SymbologyFlag[Symbol] = 1; xmlNodePtr geomNode = getGeomParentNode("Point"); @@ -772,32 +780,31 @@ void KmlRenderer::renderSymbol(imageObj *img, double x, double y, symbolObj *sym addCoordsNode(geomNode, &pt, 1); } -void KmlRenderer::renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, - symbolStyleObj *style) -{ +void KmlRenderer::renderPixmapSymbol(imageObj *img, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { renderSymbol(img, x, y, symbol, style); } -void KmlRenderer::renderVectorSymbol(imageObj *img, double x, double y, symbolObj *symbol, - symbolStyleObj *style) -{ +void KmlRenderer::renderVectorSymbol(imageObj *img, double x, double y, + symbolObj *symbol, symbolStyleObj *style) { renderSymbol(img, x, y, symbol, style); } -void KmlRenderer::renderEllipseSymbol(imageObj *img, double x, double y, symbolObj *symbol, - symbolStyleObj *style) -{ +void KmlRenderer::renderEllipseSymbol(imageObj *img, double x, double y, + symbolObj *symbol, + symbolStyleObj *style) { renderSymbol(img, x, y, symbol, style); } -void KmlRenderer::renderTruetypeSymbol(imageObj *img, double x, double y, symbolObj *symbol, - symbolStyleObj *style) -{ +void KmlRenderer::renderTruetypeSymbol(imageObj *img, double x, double y, + symbolObj *symbol, + symbolStyleObj *style) { renderSymbol(img, x, y, symbol, style); } -xmlNodePtr KmlRenderer::createGroundOverlayNode(xmlNodePtr parentNode, char *imageHref, layerObj *layer) -{ +xmlNodePtr KmlRenderer::createGroundOverlayNode(xmlNodePtr parentNode, + char *imageHref, + layerObj *layer) { /* @@ -821,21 +828,26 @@ xmlNodePtr KmlRenderer::createGroundOverlayNode(xmlNodePtr parentNode, char *ima */ - char layerHexColor[32]; - xmlNodePtr groundOverlayNode = xmlNewChild(parentNode, NULL, BAD_CAST "GroundOverlay", NULL); + char layerHexColor[32]; + xmlNodePtr groundOverlayNode = + xmlNewChild(parentNode, NULL, BAD_CAST "GroundOverlay", NULL); char *layerName = getLayerName(layer); xmlNewChild(groundOverlayNode, NULL, BAD_CAST "name", BAD_CAST layerName); - if (layer->compositer && layer->compositer->opacity > 0 && layer->compositer->opacity < 100) { - sprintf(layerHexColor, "%02xffffff", (unsigned int)MS_NINT(layer->compositer->opacity*2.55)); - xmlNewChild(groundOverlayNode, NULL, BAD_CAST "color", BAD_CAST layerHexColor); + if (layer->compositer && layer->compositer->opacity > 0 && + layer->compositer->opacity < 100) { + sprintf(layerHexColor, "%02xffffff", + (unsigned int)MS_NINT(layer->compositer->opacity * 2.55)); + xmlNewChild(groundOverlayNode, NULL, BAD_CAST "color", + BAD_CAST layerHexColor); } else xmlNewChild(groundOverlayNode, NULL, BAD_CAST "color", BAD_CAST "ffffffff"); char stmp[20]; - sprintf(stmp, "%d",layer->index); + sprintf(stmp, "%d", layer->index); xmlNewChild(groundOverlayNode, NULL, BAD_CAST "drawOrder", BAD_CAST stmp); if (imageHref) { - xmlNodePtr iconNode = xmlNewChild(groundOverlayNode, NULL, BAD_CAST "Icon", NULL); + xmlNodePtr iconNode = + xmlNewChild(groundOverlayNode, NULL, BAD_CAST "Icon", NULL); xmlNewChild(iconNode, NULL, BAD_CAST "href", BAD_CAST imageHref); } @@ -846,7 +858,8 @@ xmlNodePtr KmlRenderer::createGroundOverlayNode(xmlNodePtr parentNode, char *ima else mapextent = currentLayer->map->extent; - xmlNodePtr latLonBoxNode = xmlNewChild(groundOverlayNode, NULL, BAD_CAST "LatLonBox", NULL); + xmlNodePtr latLonBoxNode = + xmlNewChild(groundOverlayNode, NULL, BAD_CAST "LatLonBox", NULL); sprintf(crdStr, "%.8f", mapextent.maxy); xmlNewChild(latLonBoxNode, NULL, BAD_CAST "north", BAD_CAST crdStr); @@ -864,17 +877,17 @@ xmlNodePtr KmlRenderer::createGroundOverlayNode(xmlNodePtr parentNode, char *ima return groundOverlayNode; } -void KmlRenderer::startShape(imageObj *, shapeObj *shape) -{ +void KmlRenderer::startShape(imageObj *, shapeObj *shape) { if (PlacemarkNode) flushPlacemark(); - CurrentShapeIndex=-1; + CurrentShapeIndex = -1; CurrentDrawnShapeIndex = -1; - CurrentShapeName=NULL; + CurrentShapeName = NULL; - /*should be done at endshape but the plugin architecture does not call endshape yet*/ - if(LineStyle) { + /*should be done at endshape but the plugin architecture does not call + * endshape yet*/ + if (LineStyle) { msFree(LineStyle); LineStyle = NULL; @@ -883,8 +896,10 @@ void KmlRenderer::startShape(imageObj *, shapeObj *shape) CurrentShapeIndex = shape->index; if (pszLayerNameAttributeMetadata) { - for (int i=0; inumitems; i++) { - if (strcasecmp(currentLayer->items[i], pszLayerNameAttributeMetadata) == 0 && shape->values[i]) { + for (int i = 0; i < currentLayer->numitems; i++) { + if (strcasecmp(currentLayer->items[i], pszLayerNameAttributeMetadata) == + 0 && + shape->values[i]) { CurrentShapeName = msStrdup(shape->values[i]); break; } @@ -895,33 +910,33 @@ void KmlRenderer::startShape(imageObj *, shapeObj *shape) DescriptionNode = createDescriptionNode(shape); - if( mElevationFromAttribute && shape->numvalues > mElevationAttributeIndex && - mElevationAttributeIndex >= 0 && shape->values[mElevationAttributeIndex]) { - mCurrentElevationValue = atof( shape->values[mElevationAttributeIndex] ); + if (mElevationFromAttribute && shape->numvalues > mElevationAttributeIndex && + mElevationAttributeIndex >= 0 && + shape->values[mElevationAttributeIndex]) { + mCurrentElevationValue = atof(shape->values[mElevationAttributeIndex]); } - memset(SymbologyFlag, 0, NumSymbologyFlag); } -void KmlRenderer::endShape(imageObj*, shapeObj*) -{ +void KmlRenderer::endShape(imageObj *, shapeObj *) { CurrentShapeIndex = -1; if (CurrentShapeName) msFree(CurrentShapeName); CurrentShapeName = NULL; } -xmlNodePtr KmlRenderer::getGeomParentNode(const char *geomName) -{ +xmlNodePtr KmlRenderer::getGeomParentNode(const char *geomName) { /*we do not need a multi-geometry for point layers*/ - if (currentLayer->type != MS_LAYER_POINT && currentLayer->type != MS_LAYER_ANNOTATION && GeomNode) { + if (currentLayer->type != MS_LAYER_POINT && + currentLayer->type != MS_LAYER_ANNOTATION && GeomNode) { /*placemark geometry already defined, we need multigeometry node*/ xmlNodePtr multiGeomNode = xmlNewNode(NULL, BAD_CAST "MultiGeometry"); xmlAddChild(multiGeomNode, GeomNode); GeomNode = multiGeomNode; - xmlNodePtr geomNode = xmlNewChild(multiGeomNode, NULL, BAD_CAST geomName, NULL); + xmlNodePtr geomNode = + xmlNewChild(multiGeomNode, NULL, BAD_CAST geomName, NULL); return geomNode; } else { GeomNode = xmlNewNode(NULL, BAD_CAST geomName); @@ -929,9 +944,9 @@ xmlNodePtr KmlRenderer::getGeomParentNode(const char *geomName) } } -const char* KmlRenderer::lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyleObj *symstyle) -{ - char symbolHexColor[32]; +const char *KmlRenderer::lookupSymbolUrl(imageObj *img, symbolObj *symbol, + symbolStyleObj *symstyle) { + char symbolHexColor[32]; /* */ - sprintf(symbolHexColor,"%02x%02x%02x%02x", symstyle->style->color.alpha, symstyle->style->color.blue, - symstyle->style->color.green, symstyle->style->color.red); - snprintf(SymbolName, sizeof(SymbolName), "symbol_%s_%.1f_%s", symbol->name, symstyle->scale, symbolHexColor); + sprintf(symbolHexColor, "%02x%02x%02x%02x", symstyle->style->color.alpha, + symstyle->style->color.blue, symstyle->style->color.green, + symstyle->style->color.red); + snprintf(SymbolName, sizeof(SymbolName), "symbol_%s_%.1f_%s", symbol->name, + symstyle->scale, symbolHexColor); const char *symbolUrl = msLookupHashTable(StyleHashTable, SymbolName); if (!symbolUrl) { @@ -959,16 +976,19 @@ const char* KmlRenderer::lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbo snprintf(iconFileName, sizeof(iconFileName), "%s", tmpFileName); msFree(tmpFileName); } else { - sprintf(iconFileName, "symbol_%s_%.1f.%s", symbol->name, symstyle->scale, "png"); + sprintf(iconFileName, "symbol_%s_%.1f.%s", symbol->name, symstyle->scale, + "png"); } if (createIconImage(iconFileName, symbol, symstyle) != MS_SUCCESS) { - msSetError(MS_IOERR, "Error creating icon file '%s'", "KmlRenderer::lookupSymbolStyle()", iconFileName); + msSetError(MS_IOERR, "Error creating icon file '%s'", + "KmlRenderer::lookupSymbolStyle()", iconFileName); return NULL; } if (img->imageurl) - sprintf(iconUrl, "%s%s.%s", img->imageurl, msGetBasename(iconFileName), "png"); + sprintf(iconUrl, "%s%s.%s", img->imageurl, msGetBasename(iconFileName), + "png"); else snprintf(iconUrl, sizeof(iconUrl), "%s", iconFileName); @@ -979,12 +999,11 @@ const char* KmlRenderer::lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbo return symbolUrl; } -const char* KmlRenderer::lookupPlacemarkStyle() -{ - char lineHexColor[32]; - char polygonHexColor[32]; - char labelHexColor[32]; - char *styleName=NULL; +const char *KmlRenderer::lookupPlacemarkStyle() { + char lineHexColor[32]; + char polygonHexColor[32]; + char labelHexColor[32]; + char *styleName = NULL; styleName = msStringConcatenate(styleName, "style"); @@ -993,23 +1012,29 @@ const char* KmlRenderer::lookupPlacemarkStyle() ffffffff - normal + normal 1 */ - for (int i=0; icompositer && currentLayer->compositer->opacity > 0 && currentLayer->compositer->opacity < 100 && + for (int i = 0; i < numLineStyle; i++) { + if (currentLayer && currentLayer->compositer && + currentLayer->compositer->opacity > 0 && + currentLayer->compositer->opacity < 100 && LineStyle[i].color->alpha == 255) - LineStyle[i].color->alpha = MS_NINT(currentLayer->compositer->opacity*2.55); + LineStyle[i].color->alpha = + MS_NINT(currentLayer->compositer->opacity * 2.55); - sprintf(lineHexColor,"%02x%02x%02x%02x", LineStyle[i].color->alpha, LineStyle[0].color->blue, - LineStyle[i].color->green, LineStyle[i].color->red); + sprintf(lineHexColor, "%02x%02x%02x%02x", LineStyle[i].color->alpha, + LineStyle[0].color->blue, LineStyle[i].color->green, + LineStyle[i].color->red); char lineStyleName[64]; - snprintf(lineStyleName, sizeof(lineStyleName), "_line_%s_w%.1f", lineHexColor, LineStyle[i].width); + snprintf(lineStyleName, sizeof(lineStyleName), "_line_%s_w%.1f", + lineHexColor, LineStyle[i].width); styleName = msStringConcatenate(styleName, lineStyleName); } } @@ -1019,7 +1044,8 @@ const char* KmlRenderer::lookupPlacemarkStyle() ffffffff - normal + normal 1 @@ -1027,10 +1053,12 @@ const char* KmlRenderer::lookupPlacemarkStyle() */ - if (currentLayer && currentLayer->compositer && currentLayer->compositer->opacity > 0 && currentLayer->compositer->opacity < 100 && - PolygonColor.alpha == 255) - PolygonColor.alpha = MS_NINT(currentLayer->compositer->opacity*2.55); - sprintf(polygonHexColor,"%02x%02x%02x%02x", PolygonColor.alpha, PolygonColor.blue, PolygonColor.green, PolygonColor.red); + if (currentLayer && currentLayer->compositer && + currentLayer->compositer->opacity > 0 && + currentLayer->compositer->opacity < 100 && PolygonColor.alpha == 255) + PolygonColor.alpha = MS_NINT(currentLayer->compositer->opacity * 2.55); + sprintf(polygonHexColor, "%02x%02x%02x%02x", PolygonColor.alpha, + PolygonColor.blue, PolygonColor.green, PolygonColor.red); char polygonStyleName[64]; sprintf(polygonStyleName, "_polygon_%s", polygonHexColor); @@ -1042,17 +1070,20 @@ const char* KmlRenderer::lookupPlacemarkStyle() ffffffff - normal + normal 1 */ - if (currentLayer && currentLayer->compositer && currentLayer->compositer->opacity > 0 && currentLayer->compositer->opacity < 100 && - LabelColor.alpha == 255) - LabelColor.alpha = MS_NINT(currentLayer->compositer->opacity*2.55); - sprintf(labelHexColor,"%02x%02x%02x%02x", LabelColor.alpha, LabelColor.blue, LabelColor.green, LabelColor.red); + if (currentLayer && currentLayer->compositer && + currentLayer->compositer->opacity > 0 && + currentLayer->compositer->opacity < 100 && LabelColor.alpha == 255) + LabelColor.alpha = MS_NINT(currentLayer->compositer->opacity * 2.55); + sprintf(labelHexColor, "%02x%02x%02x%02x", LabelColor.alpha, + LabelColor.blue, LabelColor.green, LabelColor.red); // __TODO__ add label scale @@ -1083,7 +1114,7 @@ const char* KmlRenderer::lookupPlacemarkStyle() const char *styleUrl = msLookupHashTable(StyleHashTable, styleName); if (!styleUrl) { - char *styleValue=NULL; + char *styleValue = NULL; styleValue = msStringConcatenate(styleValue, "#"); styleValue = msStringConcatenate(styleValue, styleName); hashObj *hash = msInsertHashTable(StyleHashTable, styleName, styleValue); @@ -1095,16 +1126,21 @@ const char* KmlRenderer::lookupPlacemarkStyle() xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName); if (SymbologyFlag[Polygon]) { - xmlNodePtr polyStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "PolyStyle", NULL); - xmlNewChild(polyStyleNode, NULL, BAD_CAST "color", BAD_CAST polygonHexColor); + xmlNodePtr polyStyleNode = + xmlNewChild(styleNode, NULL, BAD_CAST "PolyStyle", NULL); + xmlNewChild(polyStyleNode, NULL, BAD_CAST "color", + BAD_CAST polygonHexColor); } if (SymbologyFlag[Line]) { - for (int i=0; ialpha, LineStyle[i].color->blue, - LineStyle[i].color->green, LineStyle[i].color->red); - xmlNewChild(lineStyleNode, NULL, BAD_CAST "color", BAD_CAST lineHexColor); + for (int i = 0; i < numLineStyle; i++) { + xmlNodePtr lineStyleNode = + xmlNewChild(styleNode, NULL, BAD_CAST "LineStyle", NULL); + sprintf(lineHexColor, "%02x%02x%02x%02x", LineStyle[i].color->alpha, + LineStyle[i].color->blue, LineStyle[i].color->green, + LineStyle[i].color->red); + xmlNewChild(lineStyleNode, NULL, BAD_CAST "color", + BAD_CAST lineHexColor); char width[16]; sprintf(width, "%.1f", LineStyle[i].width); @@ -1113,27 +1149,34 @@ const char* KmlRenderer::lookupPlacemarkStyle() } if (SymbologyFlag[Symbol]) { - xmlNodePtr iconStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "IconStyle", NULL); + xmlNodePtr iconStyleNode = + xmlNewChild(styleNode, NULL, BAD_CAST "IconStyle", NULL); - xmlNodePtr iconNode = xmlNewChild(iconStyleNode, NULL, BAD_CAST "Icon", NULL); + xmlNodePtr iconNode = + xmlNewChild(iconStyleNode, NULL, BAD_CAST "Icon", NULL); xmlNewChild(iconNode, NULL, BAD_CAST "href", BAD_CAST SymbolUrl); /*char scale[16]; sprintf(scale, "%.1f", style->scale); xmlNewChild(iconStyleNode, NULL, BAD_CAST "scale", BAD_CAST scale);*/ } else { - const char *value=msLookupHashTable(¤tLayer->metadata, "kml_default_symbol_href"); + const char *value = + msLookupHashTable(¤tLayer->metadata, "kml_default_symbol_href"); if (value && strlen(value) > 0) { - xmlNodePtr iconStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "IconStyle", NULL); + xmlNodePtr iconStyleNode = + xmlNewChild(styleNode, NULL, BAD_CAST "IconStyle", NULL); - xmlNodePtr iconNode = xmlNewChild(iconStyleNode, NULL, BAD_CAST "Icon", NULL); + xmlNodePtr iconNode = + xmlNewChild(iconStyleNode, NULL, BAD_CAST "Icon", NULL); xmlNewChild(iconNode, NULL, BAD_CAST "href", BAD_CAST value); } } if (SymbologyFlag[Label]) { - xmlNodePtr labelStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "LabelStyle", NULL); - xmlNewChild(labelStyleNode, NULL, BAD_CAST "color", BAD_CAST labelHexColor); + xmlNodePtr labelStyleNode = + xmlNewChild(styleNode, NULL, BAD_CAST "LabelStyle", NULL); + xmlNewChild(labelStyleNode, NULL, BAD_CAST "color", + BAD_CAST labelHexColor); /*char scale[16]; sprintf(scale, "%.1f", style->scale); @@ -1147,8 +1190,7 @@ const char* KmlRenderer::lookupPlacemarkStyle() return styleUrl; } -void KmlRenderer::flushPlacemark() -{ +void KmlRenderer::flushPlacemark() { if (PlacemarkNode) { const char *styleUrl = lookupPlacemarkStyle(); xmlNewChild(PlacemarkNode, NULL, BAD_CAST "styleUrl", BAD_CAST styleUrl); @@ -1161,9 +1203,7 @@ void KmlRenderer::flushPlacemark() } } - -xmlNodePtr KmlRenderer::createDescriptionNode(shapeObj *shape) -{ +xmlNodePtr KmlRenderer::createDescriptionNode(shapeObj *shape) { /* */ - /*description nodes for vector layers: - if kml_description is set, use it - if not, dump the attributes */ if (pszLayerDescMetadata) { - char *pszTmp=NULL; + char *pszTmp = NULL; char *pszTmpDesc = NULL; size_t bufferSize = 0; pszTmpDesc = msStrdup(pszLayerDescMetadata); - for (int i=0; inumitems; i++) { + for (int i = 0; i < currentLayer->numitems; i++) { bufferSize = strlen(currentLayer->items[i]) + 3; pszTmp = (char *)msSmallMalloc(bufferSize); - snprintf(pszTmp, bufferSize, "%%%s%%",currentLayer->items[i]); + snprintf(pszTmp, bufferSize, "%%%s%%", currentLayer->items[i]); if (strcasestr(pszTmpDesc, pszTmp)) - pszTmpDesc = msCaseReplaceSubstring(pszTmpDesc, pszTmp, shape->values[i]); + pszTmpDesc = + msCaseReplaceSubstring(pszTmpDesc, pszTmp, shape->values[i]); msFree(pszTmp); } xmlNodePtr descriptionNode = xmlNewNode(NULL, BAD_CAST "description"); @@ -1204,38 +1244,43 @@ xmlNodePtr KmlRenderer::createDescriptionNode(shapeObj *shape) xmlNodePtr extendedDataNode = xmlNewNode(NULL, BAD_CAST "ExtendedData"); xmlNodePtr dataNode = NULL; - const char*pszAlias=NULL; + const char *pszAlias = NULL; int bIncludeAll = MS_FALSE; - if(papszLayerIncludeItems && nIncludeItems == 1 && + if (papszLayerIncludeItems && nIncludeItems == 1 && strcasecmp(papszLayerIncludeItems[0], "all") == 0) bIncludeAll = MS_TRUE; - for (int i=0; inumitems; i++) { - int j=0,k=0; + for (int i = 0; i < currentLayer->numitems; i++) { + int j = 0, k = 0; /*TODO optimize to calculate this only once per layer*/ - for (j=0; jitems[i], papszLayerIncludeItems[j]) == 0) break; } - if (j 0) { - for (k=0; kitems[i], papszLayerExcludeItems[k]) == 0) + for (k = 0; k < nExcludeItems; k++) { + if (strcasecmp(currentLayer->items[i], papszLayerExcludeItems[k]) == + 0) break; } } if (nExcludeItems == 0 || k == nExcludeItems) { dataNode = xmlNewNode(NULL, BAD_CAST "Data"); - xmlNewProp(dataNode, BAD_CAST "name", BAD_CAST currentLayer->items[i]); + xmlNewProp(dataNode, BAD_CAST "name", + BAD_CAST currentLayer->items[i]); pszAlias = getAliasName(currentLayer, currentLayer->items[i], "GO"); if (pszAlias) - xmlNewChild(dataNode, NULL, BAD_CAST "displayName", BAD_CAST pszAlias); + xmlNewChild(dataNode, NULL, BAD_CAST "displayName", + BAD_CAST pszAlias); else - xmlNewChild(dataNode, NULL, BAD_CAST "displayName", BAD_CAST currentLayer->items[i]); + xmlNewChild(dataNode, NULL, BAD_CAST "displayName", + BAD_CAST currentLayer->items[i]); if (shape->values[i] && strlen(shape->values[i])) - xmlNewChild(dataNode, NULL, BAD_CAST "value", BAD_CAST shape->values[i]); + xmlNewChild(dataNode, NULL, BAD_CAST "value", + BAD_CAST shape->values[i]); else xmlNewChild(dataNode, NULL, BAD_CAST "value", NULL); xmlAddChild(extendedDataNode, dataNode); @@ -1244,19 +1289,16 @@ xmlNodePtr KmlRenderer::createDescriptionNode(shapeObj *shape) } return extendedDataNode; - - } return NULL; } -void KmlRenderer::addLineStyleToList(strokeStyleObj *style) -{ +void KmlRenderer::addLineStyleToList(strokeStyleObj *style) { /*actually this is not necessary. kml only uses the last LineStyle so we should not bother keeping them all*/ - int i =0; - for (i=0; iwidth == LineStyle[i].width && LineStyle[i].color->alpha == style->color->alpha && LineStyle[i].color->red == style->color->red && @@ -1269,11 +1311,11 @@ void KmlRenderer::addLineStyleToList(strokeStyleObj *style) if (LineStyle == NULL) LineStyle = (strokeStyleObj *)msSmallMalloc(sizeof(strokeStyleObj)); else - LineStyle = (strokeStyleObj *)msSmallRealloc(LineStyle, sizeof(strokeStyleObj)*numLineStyle); + LineStyle = (strokeStyleObj *)msSmallRealloc( + LineStyle, sizeof(strokeStyleObj) * numLineStyle); - memcpy(&LineStyle[numLineStyle-1], style, sizeof(strokeStyleObj)); + memcpy(&LineStyle[numLineStyle - 1], style, sizeof(strokeStyleObj)); } - } #endif diff --git a/mapkmlrenderer.h b/mapkmlrenderer.h index 59df347e7e..ded9df9f11 100644 --- a/mapkmlrenderer.h +++ b/mapkmlrenderer.h @@ -27,7 +27,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ - #ifndef MAPKMLRENDERER_H #define MAPKMLRENDERER_H @@ -37,9 +36,7 @@ #include "mapserver.h" #include "maplibxml2.h" - -class KmlRenderer -{ +class KmlRenderer { private: const char *pszLayerDescMetadata = nullptr; /*if the kml_description is set*/ char **papszLayerIncludeItems = nullptr; @@ -49,74 +46,78 @@ class KmlRenderer const char *pszLayerNameAttributeMetadata = nullptr; protected: - // map properties - int Width = 0, Height = 0; - rectObj MapExtent = {0,0,0,0}; - double MapCellsize = 0; - colorObj BgColor = {0,0,0,0}; - char MapPath[MS_MAXPATHLEN] = {0}; + int Width = 0, Height = 0; + rectObj MapExtent = {0, 0, 0, 0}; + double MapCellsize = 0; + colorObj BgColor = {0, 0, 0, 0}; + char MapPath[MS_MAXPATHLEN] = {0}; // xml nodes pointers xmlDocPtr XmlDoc = nullptr; - xmlNodePtr DocNode = nullptr; - xmlNodePtr LayerNode = nullptr; - xmlNodePtr GroundOverlayNode = nullptr; + xmlNodePtr DocNode = nullptr; + xmlNodePtr LayerNode = nullptr; + xmlNodePtr GroundOverlayNode = nullptr; - xmlNodePtr PlacemarkNode = nullptr; - xmlNodePtr GeomNode = nullptr; - xmlNodePtr DescriptionNode = nullptr; + xmlNodePtr PlacemarkNode = nullptr; + xmlNodePtr GeomNode = nullptr; + xmlNodePtr DescriptionNode = nullptr; - int CurrentShapeIndex = 0; - int CurrentDrawnShapeIndex = 0; - char *CurrentShapeName = nullptr; - char **Items = nullptr; - int NumItems = 0; - int DumpAttributes = 0; + int CurrentShapeIndex = 0; + int CurrentDrawnShapeIndex = 0; + char *CurrentShapeName = nullptr; + char **Items = nullptr; + int NumItems = 0; + int DumpAttributes = 0; // placemark symbology - hashTableObj *StyleHashTable = nullptr; + hashTableObj *StyleHashTable = nullptr; - colorObj LabelColor = {0,0,0,0}; - strokeStyleObj *LineStyle = nullptr; - int numLineStyle = 0; - colorObj PolygonColor = {0,0,0,0}; + colorObj LabelColor = {0, 0, 0, 0}; + strokeStyleObj *LineStyle = nullptr; + int numLineStyle = 0; + colorObj PolygonColor = {0, 0, 0, 0}; - char SymbolName[128] = {0}; - char SymbolUrl[128] = {0}; + char SymbolName[128] = {0}; + char SymbolUrl[128] = {0}; - enum { NumSymbologyFlag = 4}; - char SymbologyFlag[NumSymbologyFlag] = {0,0,0,0}; + enum { NumSymbologyFlag = 4 }; + char SymbologyFlag[NumSymbologyFlag] = {0, 0, 0, 0}; - enum symbFlagsEnum { Label, Line, Polygon, Symbol }; + enum symbFlagsEnum { Label, Line, Polygon, Symbol }; - int FirstLayer = 0; + int FirstLayer = 0; - mapObj *map = nullptr; - layerObj *currentLayer = nullptr; + mapObj *map = nullptr; + layerObj *currentLayer = nullptr; - int AltitudeMode = 0; - int Tessellate = 0; - int Extrude = 0; + int AltitudeMode = 0; + int Tessellate = 0; + int Extrude = 0; - enum altitudeModeEnum { undefined, clampToGround, relativeToGround, absolute }; + enum altitudeModeEnum { + undefined, + clampToGround, + relativeToGround, + absolute + }; /**True if elevation is taken from a feature attribute*/ bool mElevationFromAttribute = false; /**Attribute index of elevation (or -1 if elevation is not attribute driven*/ int mElevationAttributeIndex = 0; double mCurrentElevationValue = 0; - outputFormatObj *aggFormat = nullptr; protected: - - imageObj* createInternalImage(); + imageObj *createInternalImage(); xmlNodePtr createPlacemarkNode(xmlNodePtr parentNode, char *styleUrl); - xmlNodePtr createGroundOverlayNode(xmlNodePtr parentNode, char *imageHref, layerObj *layer); + xmlNodePtr createGroundOverlayNode(xmlNodePtr parentNode, char *imageHref, + layerObj *layer); xmlNodePtr createDescriptionNode(shapeObj *shape); - const char* lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyleObj *style); + const char *lookupSymbolUrl(imageObj *img, symbolObj *symbol, + symbolStyleObj *style); void addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts); @@ -127,27 +128,30 @@ class KmlRenderer int createIconImage(char *fileName, symbolObj *symbol, symbolStyleObj *style); - void renderSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style); + void renderSymbol(imageObj *img, double x, double y, symbolObj *symbol, + symbolStyleObj *style); ////////////////////////////////////////////////////////////////////////////// void renderLineVector(imageObj *img, shapeObj *p, strokeStyleObj *style); void renderPolygonVector(imageObj *img, shapeObj *p, colorObj *color); - const char* lookupPlacemarkStyle(); + const char *lookupPlacemarkStyle(); void flushPlacemark(); xmlNodePtr getGeomParentNode(const char *geomName); - char* getLayerName(layerObj *layer); + char *getLayerName(layerObj *layer); void processLayer(layerObj *layer, outputFormatObj *format); void addLineStyleToList(strokeStyleObj *style); - const char *getAliasName(layerObj *lp, char *pszItemName, const char *namespaces); + const char *getAliasName(layerObj *lp, char *pszItemName, + const char *namespaces); public: - - KmlRenderer(int width, int height, outputFormatObj *format, colorObj* color = NULL); + KmlRenderer(int width, int height, outputFormatObj *format, + colorObj *color = NULL); virtual ~KmlRenderer(); - imageObj* createImage(int width, int height, outputFormatObj *format, colorObj* bg); + imageObj *createImage(int width, int height, outputFormatObj *format, + colorObj *bg); int saveImage(imageObj *img, FILE *fp, outputFormatObj *format); int startNewLayer(imageObj *img, layerObj *layer); @@ -159,15 +163,22 @@ class KmlRenderer void renderLine(imageObj *img, shapeObj *p, strokeStyleObj *style); void renderPolygon(imageObj *img, shapeObj *p, colorObj *color); - void renderGlyphs(imageObj *img, const textSymbolObj *ts, colorObj *c, colorObj *oc, int ow); + void renderGlyphs(imageObj *img, const textSymbolObj *ts, colorObj *c, + colorObj *oc, int ow); // Symbols - void renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style); - void renderVectorSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style); - void renderEllipseSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style); - void renderTruetypeSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style); - - int getTruetypeTextBBox(imageObj *img,char **fonts, int numfonts, double size, char *string, rectObj *rect, double **advances); + void renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, + symbolStyleObj *style); + void renderVectorSymbol(imageObj *img, double x, double y, symbolObj *symbol, + symbolStyleObj *style); + void renderEllipseSymbol(imageObj *img, double x, double y, symbolObj *symbol, + symbolStyleObj *style); + void renderTruetypeSymbol(imageObj *img, double x, double y, + symbolObj *symbol, symbolStyleObj *style); + + int getTruetypeTextBBox(imageObj *img, char **fonts, int numfonts, + double size, char *string, rectObj *rect, + double **advances); int mergeRasterBuffer(imageObj *image, rasterBufferObj *rb); }; diff --git a/maplabel.c b/maplabel.c index 0e078ae0ac..7780216c2a 100644 --- a/maplabel.c +++ b/maplabel.c @@ -40,24 +40,20 @@ #include "cpl_vsi.h" #include "cpl_string.h" +void initTextPath(textPathObj *ts) { memset(ts, 0, sizeof(*ts)); } - - - -void initTextPath(textPathObj *ts) { - memset(ts,0,sizeof(*ts)); -} - -int WARN_UNUSED msLayoutTextSymbol(mapObj *map, textSymbolObj *ts, textPathObj *tgret); +int WARN_UNUSED msLayoutTextSymbol(mapObj *map, textSymbolObj *ts, + textPathObj *tgret); #if defined(USE_EXTENDED_DEBUG) && 0 static void msDebugTextPath(textSymbolObj *ts) { int i; - msDebug("text: %s\n",ts->annotext); - if(ts->textpath) { - for(i=0;itextpath->numglyphs; i++) { + msDebug("text: %s\n", ts->annotext); + if (ts->textpath) { + for (i = 0; i < ts->textpath->numglyphs; i++) { glyphObj *g = &ts->textpath->glyphs[i]; - msDebug("glyph %d: pos: %f %f\n",g->glyph->key.codepoint,g->pnt.x,g->pnt.y); + msDebug("glyph %d: pos: %f %f\n", g->glyph->key.codepoint, g->pnt.x, + g->pnt.y); } } else { msDebug("no glyphs\n"); @@ -73,39 +69,37 @@ int msComputeTextPath(mapObj *map, textSymbolObj *ts) { ts->textpath = tgret; tgret->absolute = 0; tgret->glyph_size = ts->label->size * ts->scalefactor; - tgret->glyph_size = MS_MAX(tgret->glyph_size, ts->label->minsize * ts->resolutionfactor); - tgret->glyph_size = MS_NINT(MS_MIN(tgret->glyph_size, ts->label->maxsize * ts->resolutionfactor)); + tgret->glyph_size = + MS_MAX(tgret->glyph_size, ts->label->minsize * ts->resolutionfactor); + tgret->glyph_size = MS_NINT( + MS_MIN(tgret->glyph_size, ts->label->maxsize * ts->resolutionfactor)); tgret->line_height = ceil(tgret->glyph_size * 1.33); - return msLayoutTextSymbol(map,ts,tgret); + return msLayoutTextSymbol(map, ts, tgret); } -void initTextSymbol(textSymbolObj *ts) { - memset(ts,0,sizeof(*ts)); -} +void initTextSymbol(textSymbolObj *ts) { memset(ts, 0, sizeof(*ts)); } void freeTextPath(textPathObj *tp) { free(tp->glyphs); - if(tp->bounds.poly) { + if (tp->bounds.poly) { free(tp->bounds.poly->point); free(tp->bounds.poly); } } -void freeTextSymbol(textSymbolObj *ts) { - freeTextSymbolEx(ts, MS_TRUE); -} +void freeTextSymbol(textSymbolObj *ts) { freeTextSymbolEx(ts, MS_TRUE); } void freeTextSymbolEx(textSymbolObj *ts, int doFreeLabel) { - if(ts->textpath) { + if (ts->textpath) { freeTextPath(ts->textpath); free(ts->textpath); } - if(ts->label->numstyles) { - if(ts->style_bounds) { + if (ts->label->numstyles) { + if (ts->style_bounds) { int i; - for(i=0;ilabel->numstyles; i++) { - if(ts->style_bounds[i]) { - if(ts->style_bounds[i]->poly) { + for (i = 0; i < ts->label->numstyles; i++) { + if (ts->style_bounds[i]) { + if (ts->style_bounds[i]->poly) { free(ts->style_bounds[i]->poly->point); free(ts->style_bounds[i]->poly); } @@ -116,7 +110,7 @@ void freeTextSymbolEx(textSymbolObj *ts, int doFreeLabel) { } } free(ts->annotext); - if(doFreeLabel && freeLabel(ts->label) == MS_SUCCESS) { + if (doFreeLabel && freeLabel(ts->label) == MS_SUCCESS) { free(ts->label); } } @@ -124,19 +118,20 @@ void freeTextSymbolEx(textSymbolObj *ts, int doFreeLabel) { void msCopyTextPath(textPathObj *dst, textPathObj *src) { int i; *dst = *src; - if(src->bounds.poly) { + if (src->bounds.poly) { dst->bounds.poly = msSmallMalloc(sizeof(lineObj)); dst->bounds.poly->numpoints = src->bounds.poly->numpoints; - dst->bounds.poly->point = msSmallMalloc(src->bounds.poly->numpoints * sizeof(pointObj)); - for(i=0; ibounds.poly->numpoints; i++) { + dst->bounds.poly->point = + msSmallMalloc(src->bounds.poly->numpoints * sizeof(pointObj)); + for (i = 0; i < src->bounds.poly->numpoints; i++) { dst->bounds.poly->point[i] = src->bounds.poly->point[i]; } } else { dst->bounds.poly = NULL; } - if(dst->numglyphs > 0) { + if (dst->numglyphs > 0) { dst->glyphs = msSmallMalloc(dst->numglyphs * sizeof(glyphObj)); - for(i=0; inumglyphs; i++) + for (i = 0; i < dst->numglyphs; i++) dst->glyphs[i] = src->glyphs[i]; } } @@ -145,15 +140,16 @@ void msCopyTextSymbol(textSymbolObj *dst, textSymbolObj *src) { *dst = *src; MS_REFCNT_INCR(src->label); dst->annotext = msStrdup(src->annotext); - if(src->textpath) { + if (src->textpath) { dst->textpath = msSmallMalloc(sizeof(textPathObj)); - msCopyTextPath(dst->textpath,src->textpath); + msCopyTextPath(dst->textpath, src->textpath); } - if(src->style_bounds) { + if (src->style_bounds) { int i; - dst->style_bounds = msSmallCalloc(src->label->numstyles, sizeof(label_bounds*)); - for(i=0; ilabel->numstyles; i++) { - if(src->style_bounds[i]) { + dst->style_bounds = + msSmallCalloc(src->label->numstyles, sizeof(label_bounds *)); + for (i = 0; i < src->label->numstyles; i++) { + if (src->style_bounds[i]) { dst->style_bounds[i] = msSmallMalloc(sizeof(label_bounds)); copyLabelBounds(dst->style_bounds[i], src->style_bounds[i]); } @@ -163,27 +159,31 @@ void msCopyTextSymbol(textSymbolObj *dst, textSymbolObj *src) { static int labelNeedsDeepCopy(labelObj *label) { int i; - if(label->numbindings > 0) return MS_TRUE; - for(i=0; inumstyles; i++) { - if(label->styles[i]->numbindings>0) { + if (label->numbindings > 0) + return MS_TRUE; + for (i = 0; i < label->numstyles; i++) { + if (label->styles[i]->numbindings > 0) { return MS_TRUE; } } return MS_FALSE; } -void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char *string, double scalefactor, double resolutionfactor, label_cache_mode cache) { - if(cache == duplicate_always) { +void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, + char *string, double scalefactor, + double resolutionfactor, + label_cache_mode cache) { + if (cache == duplicate_always) { ts->label = msSmallMalloc(sizeof(labelObj)); initLabel(ts->label); - msCopyLabel(ts->label,l); - } else if(cache == duplicate_never) { + msCopyLabel(ts->label, l); + } else if (cache == duplicate_never) { ts->label = l; MS_REFCNT_INCR(l); - } else if(cache == duplicate_if_needed && labelNeedsDeepCopy(l)) { + } else if (cache == duplicate_if_needed && labelNeedsDeepCopy(l)) { ts->label = msSmallMalloc(sizeof(labelObj)); initLabel(ts->label); - msCopyLabel(ts->label,l); + msCopyLabel(ts->label, l); } else { ts->label = l; MS_REFCNT_INCR(l); @@ -194,14 +194,15 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char ts->rotation = l->angle * MS_DEG_TO_RAD; } -int msAddLabelGroup(mapObj *map, imageObj *image, layerObj* layer, int classindex, shapeObj *shape, pointObj *point, double featuresize) -{ - int l,s, priority; +int msAddLabelGroup(mapObj *map, imageObj *image, layerObj *layer, + int classindex, shapeObj *shape, pointObj *point, + double featuresize) { + int l, s, priority; labelCacheSlotObj *cacheslot; - labelCacheMemberObj *cachePtr=NULL; - layerObj *layerPtr=NULL; - classObj *classPtr=NULL; + labelCacheMemberObj *cachePtr = NULL; + layerObj *layerPtr = NULL; + classObj *classPtr = NULL; int numtextsymbols = 0; textSymbolObj **textsymbols, *ts; int layerindex = layer->index; @@ -211,69 +212,82 @@ int msAddLabelGroup(mapObj *map, imageObj *image, layerObj* layer, int classinde layerPtr = layer; classPtr = layer->class[classindex]; - if(classPtr->numlabels == 0) return MS_SUCCESS; /* not an error just nothing to do */ + if (classPtr->numlabels == 0) + return MS_SUCCESS; /* not an error just nothing to do */ /* check that the label intersects the layer mask */ - if(layerPtr->mask) { - int maskLayerIdx = msGetLayerIndex(map,layerPtr->mask); - layerObj *maskLayer = GET_LAYER(map,maskLayerIdx); + if (layerPtr->mask) { + int maskLayerIdx = msGetLayerIndex(map, layerPtr->mask); + layerObj *maskLayer = GET_LAYER(map, maskLayerIdx); unsigned char *alphapixptr; - if(maskLayer->maskimage && MS_IMAGE_RENDERER(maskLayer->maskimage)->supports_pixel_buffer) { + if (maskLayer->maskimage && + MS_IMAGE_RENDERER(maskLayer->maskimage)->supports_pixel_buffer) { rasterBufferObj rb; - int x,y; - memset(&rb,0,sizeof(rasterBufferObj)); - if(MS_UNLIKELY(MS_FAILURE == MS_IMAGE_RENDERER(maskLayer->maskimage)->getRasterBufferHandle(maskLayer->maskimage,&rb))) { + int x, y; + memset(&rb, 0, sizeof(rasterBufferObj)); + if (MS_UNLIKELY(MS_FAILURE == + MS_IMAGE_RENDERER(maskLayer->maskimage) + ->getRasterBufferHandle(maskLayer->maskimage, &rb))) { return MS_FAILURE; } x = MS_NINT(point->x); y = MS_NINT(point->y); - /* Using label repeatdistance, we might have a point with x/y below 0. See #4764 */ + /* Using label repeatdistance, we might have a point with x/y below 0. See + * #4764 */ if (x >= 0 && x < (int)rb.width && y >= 0 && y < (int)rb.height) { assert(rb.type == MS_BUFFER_BYTE_RGBA); - alphapixptr = rb.data.rgba.a+rb.data.rgba.row_step*y + rb.data.rgba.pixel_step*x; - if(!*alphapixptr) { + alphapixptr = rb.data.rgba.a + rb.data.rgba.row_step * y + + rb.data.rgba.pixel_step * x; + if (!*alphapixptr) { /* label point does not intersect mask */ return MS_SUCCESS; } } else { - return MS_SUCCESS; /* label point does not intersect image extent, we cannot know if it intersects - mask, so we discard it (#5237)*/ + return MS_SUCCESS; /* label point does not intersect image extent, we + cannot know if it intersects mask, so we discard it + (#5237)*/ } } else { - msSetError(MS_MISCERR, "Layer (%s) references references a mask layer, but the selected renderer does not support them", "msAddLabelGroup()", layerPtr->name); + msSetError(MS_MISCERR, + "Layer (%s) references references a mask layer, but the " + "selected renderer does not support them", + "msAddLabelGroup()", layerPtr->name); return (MS_FAILURE); } } - textsymbols = msSmallMalloc(classPtr->numlabels * sizeof(textSymbolObj*)); + textsymbols = msSmallMalloc(classPtr->numlabels * sizeof(textSymbolObj *)); - for(l=0; lnumlabels; l++) { + for (l = 0; l < classPtr->numlabels; l++) { labelObj *lbl = classPtr->labels[l]; char *annotext; - if(msGetLabelStatus(map,layerPtr,shape,lbl) == MS_OFF) { + if (msGetLabelStatus(map, layerPtr, shape, lbl) == MS_OFF) { continue; } - annotext = msShapeGetLabelAnnotation(layerPtr,shape,lbl); - if(!annotext) { - for(s=0;snumstyles;s++) { - if(lbl->styles[s]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) - break; /* we have a "symbol only label, so we shouldn't skip this label */ + annotext = msShapeGetLabelAnnotation(layerPtr, shape, lbl); + if (!annotext) { + for (s = 0; s < lbl->numstyles; s++) { + if (lbl->styles[s]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) + break; /* we have a "symbol only label, so we shouldn't skip this + label */ } - if(s == lbl->numstyles) { + if (s == lbl->numstyles) { continue; /* no anno text, and no label symbols */ } } ts = msSmallMalloc(sizeof(textSymbolObj)); initTextSymbol(ts); - msPopulateTextSymbolForLabelAndString(ts,lbl,annotext,layerPtr->scalefactor,image->resolutionfactor, 1); + msPopulateTextSymbolForLabelAndString( + ts, lbl, annotext, layerPtr->scalefactor, image->resolutionfactor, 1); - if(annotext && *annotext && lbl->autominfeaturesize && featuresize > 0) { - if(MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map,ts))) { + if (annotext && *annotext && lbl->autominfeaturesize && featuresize > 0) { + if (MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map, ts))) { freeTextSymbol(ts); free(ts); return MS_FAILURE; } - if(featuresize < (ts->textpath->bounds.bbox.maxx - ts->textpath->bounds.bbox.minx)) { + if (featuresize < + (ts->textpath->bounds.bbox.maxx - ts->textpath->bounds.bbox.minx)) { /* feature is too big to be drawn, skip it */ freeTextSymbol(ts); free(ts); @@ -284,29 +298,37 @@ int msAddLabelGroup(mapObj *map, imageObj *image, layerObj* layer, int classinde numtextsymbols++; } - if(numtextsymbols == 0) { + if (numtextsymbols == 0) { free(textsymbols); return MS_SUCCESS; } /* Validate label priority value and get ref on label cache for it */ - priority = classPtr->labels[0]->priority; /* take priority from the first label */ + priority = + classPtr->labels[0]->priority; /* take priority from the first label */ if (priority < 1) priority = 1; else if (priority > MS_MAX_LABEL_PRIORITY) priority = MS_MAX_LABEL_PRIORITY; - cacheslot = &(map->labelcache.slots[priority-1]); - - if(cacheslot->numlabels == cacheslot->cachesize) { /* just add it to the end */ - cacheslot->labels = (labelCacheMemberObj *) realloc(cacheslot->labels, sizeof(labelCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT)); - MS_CHECK_ALLOC(cacheslot->labels, sizeof(labelCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT), MS_FAILURE); + cacheslot = &(map->labelcache.slots[priority - 1]); + + if (cacheslot->numlabels == + cacheslot->cachesize) { /* just add it to the end */ + cacheslot->labels = (labelCacheMemberObj *)realloc( + cacheslot->labels, sizeof(labelCacheMemberObj) * + (cacheslot->cachesize + MS_LABELCACHEINCREMENT)); + MS_CHECK_ALLOC(cacheslot->labels, + sizeof(labelCacheMemberObj) * + (cacheslot->cachesize + MS_LABELCACHEINCREMENT), + MS_FAILURE); cacheslot->cachesize += MS_LABELCACHEINCREMENT; } cachePtr = &(cacheslot->labels[cacheslot->numlabels]); - cachePtr->layerindex = layerindex; /* so we can get back to this *raw* data if necessary */ + cachePtr->layerindex = + layerindex; /* so we can get back to this *raw* data if necessary */ cachePtr->classindex = classindex; @@ -319,24 +341,35 @@ int msAddLabelGroup(mapObj *map, imageObj *image, layerObj* layer, int classinde cachePtr->status = MS_FALSE; - if(layerPtr->type == MS_LAYER_POINT && classPtr->numstyles > 0) { + if (layerPtr->type == MS_LAYER_POINT && classPtr->numstyles > 0) { /* cache the marker placement, it's already on the map */ - /* TO DO: at the moment only checks the bottom style, perhaps should check all of them */ + /* TO DO: at the moment only checks the bottom style, perhaps should check + * all of them */ /* #2347: after RFC-24 classPtr->styles could be NULL so we check it */ double w, h; - if(msGetMarkerSize(map, classPtr->styles[0], &w, &h, layerPtr->scalefactor) != MS_SUCCESS) - return(MS_FAILURE); + if (msGetMarkerSize(map, classPtr->styles[0], &w, &h, + layerPtr->scalefactor) != MS_SUCCESS) + return (MS_FAILURE); - if(cacheslot->nummarkers == cacheslot->markercachesize) { /* just add it to the end */ - cacheslot->markers = (markerCacheMemberObj *) realloc(cacheslot->markers, sizeof(markerCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT)); - MS_CHECK_ALLOC(cacheslot->markers, sizeof(markerCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT), MS_FAILURE); - cacheslot->markercachesize+=MS_LABELCACHEINCREMENT; + if (cacheslot->nummarkers == + cacheslot->markercachesize) { /* just add it to the end */ + cacheslot->markers = (markerCacheMemberObj *)realloc( + cacheslot->markers, + sizeof(markerCacheMemberObj) * + (cacheslot->cachesize + MS_LABELCACHEINCREMENT)); + MS_CHECK_ALLOC(cacheslot->markers, + sizeof(markerCacheMemberObj) * + (cacheslot->cachesize + MS_LABELCACHEINCREMENT), + MS_FAILURE); + cacheslot->markercachesize += MS_LABELCACHEINCREMENT; } cacheslot->markers[cacheslot->nummarkers].bounds.minx = (point->x - .5 * w); cacheslot->markers[cacheslot->nummarkers].bounds.miny = (point->y - .5 * h); - cacheslot->markers[cacheslot->nummarkers].bounds.maxx = cacheslot->markers[cacheslot->nummarkers].bounds.minx + (w-1); - cacheslot->markers[cacheslot->nummarkers].bounds.maxy = cacheslot->markers[cacheslot->nummarkers].bounds.miny + (h-1); + cacheslot->markers[cacheslot->nummarkers].bounds.maxx = + cacheslot->markers[cacheslot->nummarkers].bounds.minx + (w - 1); + cacheslot->markers[cacheslot->nummarkers].bounds.maxy = + cacheslot->markers[cacheslot->nummarkers].bounds.miny + (h - 1); cacheslot->markers[cacheslot->nummarkers].id = cacheslot->numlabels; cachePtr->markerid = cacheslot->nummarkers; @@ -347,20 +380,21 @@ int msAddLabelGroup(mapObj *map, imageObj *image, layerObj* layer, int classinde cacheslot->numlabels++; - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, int classindex, - shapeObj *shape, pointObj *point, double featuresize, textSymbolObj *ts) -{ +int msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, + int classindex, shapeObj *shape, pointObj *point, + double featuresize, textSymbolObj *ts) { int i; labelCacheSlotObj *cacheslot; - labelCacheMemberObj *cachePtr=NULL; - char *annotext = NULL; + labelCacheMemberObj *cachePtr = NULL; + const char *annotext = NULL; + char *annotextToFree = NULL; layerObj *layerPtr; classObj *classPtr; - layerPtr=GET_LAYER(map,layerindex); + layerPtr = GET_LAYER(map, layerindex); assert(layerPtr); assert(classindex < layerPtr->numclasses); @@ -368,20 +402,22 @@ int msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, in assert(label); - if(ts) + if (ts) annotext = ts->annotext; - else if(shape) - annotext = msShapeGetLabelAnnotation(layerPtr,shape,label); + else if (shape) { + annotextToFree = msShapeGetLabelAnnotation(layerPtr, shape, label); + annotext = annotextToFree; + } - if(!annotext) { + if (!annotext) { /* check if we have a labelpnt style */ - for(i=0; inumstyles; i++) { - if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) + for (i = 0; i < label->numstyles; i++) { + if (label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) break; } - if(i==label->numstyles) { + if (i == label->numstyles) { /* label has no text or marker symbols */ - if(ts) { + if (ts) { freeTextSymbol(ts); free(ts); } @@ -389,9 +425,10 @@ int msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, in } } - if(classPtr->leader) { - if(ts && ts->textpath && ts->textpath->absolute) { - msSetError(MS_MISCERR, "LEADERs are not supported on ANGLE FOLLOW labels", "msAddLabel()"); + if (classPtr->leader) { + if (ts && ts->textpath && ts->textpath->absolute) { + msSetError(MS_MISCERR, "LEADERs are not supported on ANGLE FOLLOW labels", + "msAddLabel()"); return MS_FAILURE; } } @@ -401,30 +438,39 @@ int msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, in int maskLayerIdx = msGetLayerIndex(map, layerPtr->mask); layerObj *maskLayer = GET_LAYER(map, maskLayerIdx); unsigned char *alphapixptr; - if (maskLayer->maskimage && MS_IMAGE_RENDERER(maskLayer->maskimage)->supports_pixel_buffer) { + if (maskLayer->maskimage && + MS_IMAGE_RENDERER(maskLayer->maskimage)->supports_pixel_buffer) { rasterBufferObj rb; - memset(&rb, 0, sizeof (rasterBufferObj)); - if(MS_UNLIKELY(MS_FAILURE == MS_IMAGE_RENDERER(maskLayer->maskimage)->getRasterBufferHandle(maskLayer->maskimage, &rb))) { + memset(&rb, 0, sizeof(rasterBufferObj)); + if (MS_UNLIKELY(MS_FAILURE == + MS_IMAGE_RENDERER(maskLayer->maskimage) + ->getRasterBufferHandle(maskLayer->maskimage, &rb))) { + msFree(annotextToFree); return MS_FAILURE; } assert(rb.type == MS_BUFFER_BYTE_RGBA); if (point) { int x = MS_NINT(point->x); int y = MS_NINT(point->y); - /* Using label repeatdistance, we might have a point with x/y below 0. See #4764 */ + /* Using label repeatdistance, we might have a point with x/y below 0. + * See #4764 */ if (x >= 0 && x < (int)rb.width && y >= 0 && y < (int)rb.height) { - alphapixptr = rb.data.rgba.a+rb.data.rgba.row_step*y + rb.data.rgba.pixel_step*x; - if(!*alphapixptr) { + alphapixptr = rb.data.rgba.a + rb.data.rgba.row_step * y + + rb.data.rgba.pixel_step * x; + if (!*alphapixptr) { /* label point does not intersect mask */ - if(ts) { + if (ts) { freeTextSymbol(ts); free(ts); } + msFree(annotextToFree); return MS_SUCCESS; } } else { - return MS_SUCCESS; /* label point does not intersect image extent, we cannot know if it intersects - mask, so we discard it (#5237)*/ + msFree(annotextToFree); + return MS_SUCCESS; /* label point does not intersect image extent, we + cannot know if it intersects mask, so we discard + it (#5237)*/ } } else if (ts && ts->textpath) { int i = 0; @@ -432,41 +478,53 @@ int msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, in int x = MS_NINT(ts->textpath->glyphs[i].pnt.x); int y = MS_NINT(ts->textpath->glyphs[i].pnt.y); if (x >= 0 && x < (int)rb.width && y >= 0 && y < (int)rb.height) { - alphapixptr = rb.data.rgba.a + rb.data.rgba.row_step * y + rb.data.rgba.pixel_step*x; + alphapixptr = rb.data.rgba.a + rb.data.rgba.row_step * y + + rb.data.rgba.pixel_step * x; if (!*alphapixptr) { freeTextSymbol(ts); free(ts); + msFree(annotextToFree); return MS_SUCCESS; } } else { freeTextSymbol(ts); free(ts); - return MS_SUCCESS; /* label point does not intersect image extent, we cannot know if it intersects - mask, so we discard it (#5237)*/ + msFree(annotextToFree); + return MS_SUCCESS; /* label point does not intersect image extent, + we cannot know if it intersects mask, so we + discard it (#5237)*/ } } } } else { - msSetError(MS_MISCERR, "Layer (%s) references references a mask layer, but the selected renderer does not support them", "msAddLabel()", layerPtr->name); + msSetError(MS_MISCERR, + "Layer (%s) references references a mask layer, but the " + "selected renderer does not support them", + "msAddLabel()", layerPtr->name); + msFree(annotextToFree); return (MS_FAILURE); } } - if(!ts) { + if (!ts) { ts = msSmallMalloc(sizeof(textSymbolObj)); initTextSymbol(ts); - msPopulateTextSymbolForLabelAndString(ts,label,annotext,layerPtr->scalefactor,image->resolutionfactor, 1); + msPopulateTextSymbolForLabelAndString(ts, label, annotextToFree, + layerPtr->scalefactor, + image->resolutionfactor, 1); + // annotextToFree = NULL; } - if(annotext && label->autominfeaturesize && featuresize > 0) { - if(!ts->textpath) { - if(MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map,ts))) + if (annotext && label->autominfeaturesize && featuresize > 0) { + if (!ts->textpath) { + if (MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map, ts))) return MS_FAILURE; } - if(!ts->textpath) { + if (!ts->textpath) { return MS_FAILURE; } - if(featuresize > (ts->textpath->bounds.bbox.maxx - ts->textpath->bounds.bbox.minx)) { + if (featuresize > + (ts->textpath->bounds.bbox.maxx - ts->textpath->bounds.bbox.minx)) { /* feature is too big to be drawn, skip it */ freeTextSymbol(ts); free(ts); @@ -474,67 +532,89 @@ int msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, in } } - - /* Validate label priority value and get ref on label cache for it */ if (label->priority < 1) label->priority = 1; else if (label->priority > MS_MAX_LABEL_PRIORITY) label->priority = MS_MAX_LABEL_PRIORITY; - cacheslot = &(map->labelcache.slots[label->priority-1]); - - if(cacheslot->numlabels == cacheslot->cachesize) { /* just add it to the end */ - cacheslot->labels = (labelCacheMemberObj *) realloc(cacheslot->labels, sizeof(labelCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT)); - MS_CHECK_ALLOC(cacheslot->labels, sizeof(labelCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT), MS_FAILURE); + cacheslot = &(map->labelcache.slots[label->priority - 1]); + + if (cacheslot->numlabels == + cacheslot->cachesize) { /* just add it to the end */ + cacheslot->labels = (labelCacheMemberObj *)realloc( + cacheslot->labels, sizeof(labelCacheMemberObj) * + (cacheslot->cachesize + MS_LABELCACHEINCREMENT)); + MS_CHECK_ALLOC(cacheslot->labels, + sizeof(labelCacheMemberObj) * + (cacheslot->cachesize + MS_LABELCACHEINCREMENT), + MS_FAILURE); cacheslot->cachesize += MS_LABELCACHEINCREMENT; } cachePtr = &(cacheslot->labels[cacheslot->numlabels]); - cachePtr->layerindex = layerindex; /* so we can get back to this *raw* data if necessary */ + cachePtr->layerindex = + layerindex; /* so we can get back to this *raw* data if necessary */ cachePtr->classindex = classindex; cachePtr->leaderline = NULL; cachePtr->leaderbbox = NULL; /* Store the label point or the label path (Bug #1620) */ - if ( point ) { + if (point) { cachePtr->point = *point; /* the actual label point */ } else { - assert(ts && ts->textpath && ts->textpath->absolute && ts->textpath->numglyphs>0); + assert(ts && ts->textpath && ts->textpath->absolute && + ts->textpath->numglyphs > 0); /* Use the middle point of the labelpath for mindistance calculations */ - cachePtr->point = ts->textpath->glyphs[ts->textpath->numglyphs/2].pnt; + cachePtr->point = ts->textpath->glyphs[ts->textpath->numglyphs / 2].pnt; } /* copy the label */ cachePtr->numtextsymbols = 1; - cachePtr->textsymbols = (textSymbolObj **) msSmallMalloc(sizeof(textSymbolObj*)); + cachePtr->textsymbols = + (textSymbolObj **)msSmallMalloc(sizeof(textSymbolObj *)); cachePtr->textsymbols[0] = ts; cachePtr->markerid = -1; cachePtr->status = MS_FALSE; - if(layerPtr->type == MS_LAYER_POINT && classPtr->numstyles > 0) { /* cache the marker placement, it's already on the map */ + if (layerPtr->type == MS_LAYER_POINT && + classPtr->numstyles > + 0) { /* cache the marker placement, it's already on the map */ double w, h; - if(cacheslot->nummarkers == cacheslot->markercachesize) { /* just add it to the end */ - cacheslot->markers = (markerCacheMemberObj *) realloc(cacheslot->markers, sizeof(markerCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT)); - MS_CHECK_ALLOC(cacheslot->markers, sizeof(markerCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT), MS_FAILURE); - cacheslot->markercachesize+=MS_LABELCACHEINCREMENT; + if (cacheslot->nummarkers == + cacheslot->markercachesize) { /* just add it to the end */ + cacheslot->markers = (markerCacheMemberObj *)realloc( + cacheslot->markers, + sizeof(markerCacheMemberObj) * + (cacheslot->cachesize + MS_LABELCACHEINCREMENT)); + MS_CHECK_ALLOC(cacheslot->markers, + sizeof(markerCacheMemberObj) * + (cacheslot->cachesize + MS_LABELCACHEINCREMENT), + MS_FAILURE); + cacheslot->markercachesize += MS_LABELCACHEINCREMENT; } i = cacheslot->nummarkers; - /* TO DO: at the moment only checks the bottom style, perhaps should check all of them */ + /* TO DO: at the moment only checks the bottom style, perhaps should check + * all of them */ /* #2347: after RFC-24 classPtr->styles could be NULL so we check it */ - if(classPtr->styles != NULL) { - if(msGetMarkerSize(map, classPtr->styles[0], &w, &h, layerPtr->scalefactor) != MS_SUCCESS) - return(MS_FAILURE); + if (classPtr->styles != NULL) { + if (msGetMarkerSize(map, classPtr->styles[0], &w, &h, + layerPtr->scalefactor) != MS_SUCCESS) + return (MS_FAILURE); assert(point); - cacheslot->markers[cacheslot->nummarkers].bounds.minx = (point->x - .5 * w); - cacheslot->markers[cacheslot->nummarkers].bounds.miny = (point->y - .5 * h); - cacheslot->markers[cacheslot->nummarkers].bounds.maxx = cacheslot->markers[cacheslot->nummarkers].bounds.minx + (w-1); - cacheslot->markers[cacheslot->nummarkers].bounds.maxy = cacheslot->markers[cacheslot->nummarkers].bounds.miny + (h-1); + cacheslot->markers[cacheslot->nummarkers].bounds.minx = + (point->x - .5 * w); + cacheslot->markers[cacheslot->nummarkers].bounds.miny = + (point->y - .5 * h); + cacheslot->markers[cacheslot->nummarkers].bounds.maxx = + cacheslot->markers[cacheslot->nummarkers].bounds.minx + (w - 1); + cacheslot->markers[cacheslot->nummarkers].bounds.maxy = + cacheslot->markers[cacheslot->nummarkers].bounds.miny + (h - 1); cacheslot->markers[i].id = cacheslot->numlabels; cachePtr->markerid = i; @@ -545,7 +625,7 @@ int msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, in cacheslot->numlabels++; - return(MS_SUCCESS); + return (MS_SUCCESS); } /* @@ -553,80 +633,87 @@ int msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, in ** image for no labels (effectively making image larger. The gutter can be ** negative in cases where a label has a buffer around it. */ -static int labelInImage(int width, int height, lineObj *lpoly, rectObj *bounds, int gutter) -{ +static int labelInImage(int width, int height, lineObj *lpoly, rectObj *bounds, + int gutter) { int j; /* do a bbox test first */ - if(bounds->minx >= gutter && - bounds->miny >= gutter && - bounds->maxx < width-gutter && - bounds->maxy < height-gutter) { + if (bounds->minx >= gutter && bounds->miny >= gutter && + bounds->maxx < width - gutter && bounds->maxy < height - gutter) { return MS_TRUE; } - if(lpoly) { - for(j=1; jnumpoints; j++) { - if(lpoly->point[j].x < gutter) return(MS_FALSE); - if(lpoly->point[j].x >= width-gutter) return(MS_FALSE); - if(lpoly->point[j].y < gutter) return(MS_FALSE); - if(lpoly->point[j].y >= height-gutter) return(MS_FALSE); + if (lpoly) { + for (j = 1; j < lpoly->numpoints; j++) { + if (lpoly->point[j].x < gutter) + return (MS_FALSE); + if (lpoly->point[j].x >= width - gutter) + return (MS_FALSE); + if (lpoly->point[j].y < gutter) + return (MS_FALSE); + if (lpoly->point[j].y >= height - gutter) + return (MS_FALSE); } } else { /* if no poly, then return false as the boundong box intersected */ return MS_FALSE; } - return(MS_TRUE); + return (MS_TRUE); } void insertRenderedLabelMember(mapObj *map, labelCacheMemberObj *cachePtr) { - if(map->labelcache.num_rendered_members == map->labelcache.num_allocated_rendered_members) { - if(map->labelcache.num_rendered_members == 0) { + if (map->labelcache.num_rendered_members == + map->labelcache.num_allocated_rendered_members) { + if (map->labelcache.num_rendered_members == 0) { map->labelcache.num_allocated_rendered_members = 50; } else { map->labelcache.num_allocated_rendered_members *= 2; } - map->labelcache.rendered_text_symbols = msSmallRealloc(map->labelcache.rendered_text_symbols, - map->labelcache.num_allocated_rendered_members * sizeof(labelCacheMemberObj*)); + map->labelcache.rendered_text_symbols = + msSmallRealloc(map->labelcache.rendered_text_symbols, + map->labelcache.num_allocated_rendered_members * + sizeof(labelCacheMemberObj *)); } - map->labelcache.rendered_text_symbols[map->labelcache.num_rendered_members++] = cachePtr; + map->labelcache + .rendered_text_symbols[map->labelcache.num_rendered_members++] = cachePtr; } -static inline int testSegmentLabelBBoxIntersection(const rectObj *leaderbbox, const pointObj *lp1, - const pointObj *lp2, const label_bounds *test) { - if(msRectOverlap(leaderbbox, &test->bbox)) { - if(test->poly) { +static inline int testSegmentLabelBBoxIntersection(const rectObj *leaderbbox, + const pointObj *lp1, + const pointObj *lp2, + const label_bounds *test) { + if (msRectOverlap(leaderbbox, &test->bbox)) { + if (test->poly) { int pp; - for(pp=1; pppoly->numpoints; pp++) { - if(msIntersectSegments( - &(test->poly->point[pp-1]), - &(test->poly->point[pp]), - lp1,lp2) == MS_TRUE) { - return(MS_FALSE); + for (pp = 1; pp < test->poly->numpoints; pp++) { + if (msIntersectSegments(&(test->poly->point[pp - 1]), + &(test->poly->point[pp]), lp1, + lp2) == MS_TRUE) { + return (MS_FALSE); } } } else { - pointObj tp1 = {0},tp2 = {0}; + pointObj tp1 = {0}, tp2 = {0}; tp1.x = test->bbox.minx; tp1.y = test->bbox.miny; tp2.x = test->bbox.minx; tp2.y = test->bbox.maxy; - if(msIntersectSegments(lp1,lp2,&tp1,&tp2)) + if (msIntersectSegments(lp1, lp2, &tp1, &tp2)) return MS_FALSE; tp2.x = test->bbox.maxx; tp2.y = test->bbox.miny; - if(msIntersectSegments(lp1,lp2,&tp1,&tp2)) + if (msIntersectSegments(lp1, lp2, &tp1, &tp2)) return MS_FALSE; tp1.x = test->bbox.maxx; tp1.y = test->bbox.maxy; tp2.x = test->bbox.minx; tp2.y = test->bbox.maxy; - if(msIntersectSegments(lp1,lp2,&tp1,&tp2)) + if (msIntersectSegments(lp1, lp2, &tp1, &tp2)) return MS_FALSE; tp2.x = test->bbox.maxx; tp2.y = test->bbox.miny; - if(msIntersectSegments(lp1,lp2,&tp1,&tp2)) + if (msIntersectSegments(lp1, lp2, &tp1, &tp2)) return MS_FALSE; } } @@ -636,35 +723,41 @@ static inline int testSegmentLabelBBoxIntersection(const rectObj *leaderbbox, co int msTestLabelCacheLeaderCollision(mapObj *map, pointObj *lp1, pointObj *lp2) { int p; rectObj leaderbbox; - leaderbbox.minx = MS_MIN(lp1->x,lp2->x); - leaderbbox.maxx = MS_MAX(lp1->x,lp2->x); - leaderbbox.miny = MS_MIN(lp1->y,lp2->y); - leaderbbox.maxy = MS_MAX(lp1->y,lp2->y); - for(p=0; plabelcache.num_rendered_members; p++) { - labelCacheMemberObj *curCachePtr= map->labelcache.rendered_text_symbols[p]; - if(msRectOverlap(&leaderbbox, &(curCachePtr->bbox))) { - /* leaderbbox interesects with the curCachePtr's global bbox */ + leaderbbox.minx = MS_MIN(lp1->x, lp2->x); + leaderbbox.maxx = MS_MAX(lp1->x, lp2->x); + leaderbbox.miny = MS_MIN(lp1->y, lp2->y); + leaderbbox.maxy = MS_MAX(lp1->y, lp2->y); + for (p = 0; p < map->labelcache.num_rendered_members; p++) { + labelCacheMemberObj *curCachePtr = map->labelcache.rendered_text_symbols[p]; + if (msRectOverlap(&leaderbbox, &(curCachePtr->bbox))) { + /* leaderbbox interesects with the curCachePtr's global bbox */ int t; - for(t=0; tnumtextsymbols; t++) { + for (t = 0; t < curCachePtr->numtextsymbols; t++) { int s; textSymbolObj *ts = curCachePtr->textsymbols[t]; /* check for intersect with textpath */ - if(ts->textpath && testSegmentLabelBBoxIntersection(&leaderbbox, lp1, lp2, &ts->textpath->bounds) == MS_FALSE) { + if (ts->textpath && + testSegmentLabelBBoxIntersection( + &leaderbbox, lp1, lp2, &ts->textpath->bounds) == MS_FALSE) { return MS_FALSE; } /* check for intersect with label's labelpnt styles */ - if(ts->style_bounds) { - for(s=0; slabel->numstyles; s++) { - if(ts->label->styles[s]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { - if(testSegmentLabelBBoxIntersection(&leaderbbox, lp1,lp2, ts->style_bounds[s]) == MS_FALSE) { + if (ts->style_bounds) { + for (s = 0; s < ts->label->numstyles; s++) { + if (ts->label->styles[s]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT) { + if (testSegmentLabelBBoxIntersection( + &leaderbbox, lp1, lp2, ts->style_bounds[s]) == MS_FALSE) { return MS_FALSE; } } } } } - if(curCachePtr->leaderbbox) { - if(msIntersectSegments(lp1,lp2,&(curCachePtr->leaderline->point[0]), &(curCachePtr->leaderline->point[1])) == MS_TRUE) { + if (curCachePtr->leaderbbox) { + if (msIntersectSegments(lp1, lp2, &(curCachePtr->leaderline->point[0]), + &(curCachePtr->leaderline->point[1])) == + MS_TRUE) { return MS_FALSE; } } @@ -675,25 +768,28 @@ int msTestLabelCacheLeaderCollision(mapObj *map, pointObj *lp1, pointObj *lp2) { /* msTestLabelCacheCollisions() ** -** Compares label bounds (in *bounds) against labels already drawn and markers from cache and -** returns MS_FALSE if it collides with another label, or collides with a marker. +** Compares label bounds (in *bounds) against labels already drawn and markers +from cache and +** returns MS_FALSE if it collides with another label, or collides with a +marker. ** ** This function is used by the various msDrawLabelCacheXX() implementations. -int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, label_bounds *bounds, - int current_priority, int current_label); +int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, +label_bounds *bounds, int current_priority, int current_label); */ -int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, label_bounds *lb, - int current_priority, int current_label) -{ +int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, + label_bounds *lb, int current_priority, + int current_label) { labelCacheObj *labelcache = &(map->labelcache); int i, p, ll; /* * Check against image bounds first */ - if(!cachePtr->textsymbols[0]->label->partials) { - if(labelInImage(map->width, map->height, lb->poly, &lb->bbox, labelcache->gutter) == MS_FALSE) { + if (!cachePtr->textsymbols[0]->label->partials) { + if (labelInImage(map->width, map->height, lb->poly, &lb->bbox, + labelcache->gutter) == MS_FALSE) { return MS_FALSE; } } @@ -701,33 +797,43 @@ int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, label /* Compare against all rendered markers from this priority level and higher. ** Labels can overlap their own marker and markers from lower priority levels */ - for (p=current_priority; p < MS_MAX_LABEL_PRIORITY; p++) { + for (p = current_priority; p < MS_MAX_LABEL_PRIORITY; p++) { labelCacheSlotObj *markerslot; markerslot = &(labelcache->slots[p]); - for ( ll = 0; ll < markerslot->nummarkers; ll++ ) { - if ( !(p == current_priority && current_label == markerslot->markers[ll].id ) ) { /* labels can overlap their own marker */ - if ( intersectLabelPolygons(NULL, &markerslot->markers[ll].bounds, lb->poly, &lb->bbox ) == MS_TRUE ) { + for (ll = 0; ll < markerslot->nummarkers; ll++) { + if (!(p == current_priority && + current_label == + markerslot->markers[ll] + .id)) { /* labels can overlap their own marker */ + if (intersectLabelPolygons(NULL, &markerslot->markers[ll].bounds, + lb->poly, &lb->bbox) == MS_TRUE) { return MS_FALSE; } } } } - for(p=0; pnum_rendered_members; p++) { - labelCacheMemberObj *curCachePtr= labelcache->rendered_text_symbols[p]; - if(msRectOverlap(&curCachePtr->bbox,&lb->bbox)) { - for(i=0; inumtextsymbols; i++) { + for (p = 0; p < labelcache->num_rendered_members; p++) { + labelCacheMemberObj *curCachePtr = labelcache->rendered_text_symbols[p]; + if (msRectOverlap(&curCachePtr->bbox, &lb->bbox)) { + for (i = 0; i < curCachePtr->numtextsymbols; i++) { int j; textSymbolObj *ts = curCachePtr->textsymbols[i]; - if(ts->textpath && intersectLabelPolygons(ts->textpath->bounds.poly, &ts->textpath->bounds.bbox, lb->poly, &lb->bbox) == MS_TRUE ) { + if (ts->textpath && + intersectLabelPolygons(ts->textpath->bounds.poly, + &ts->textpath->bounds.bbox, lb->poly, + &lb->bbox) == MS_TRUE) { return MS_FALSE; } - if(ts->style_bounds) { - for(j=0;jlabel->numstyles;j++) { - if(ts->style_bounds[j] && ts->label->styles[j]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { - if(intersectLabelPolygons(ts->style_bounds[j]->poly, &ts->style_bounds[j]->bbox, - lb->poly, &lb->bbox)) { + if (ts->style_bounds) { + for (j = 0; j < ts->label->numstyles; j++) { + if (ts->style_bounds[j] && + ts->label->styles[j]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT) { + if (intersectLabelPolygons(ts->style_bounds[j]->poly, + &ts->style_bounds[j]->bbox, lb->poly, + &lb->bbox)) { return MS_FALSE; } } @@ -735,9 +841,10 @@ int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, label } } } - if(curCachePtr->leaderline) { - if(testSegmentLabelBBoxIntersection(curCachePtr->leaderbbox, &curCachePtr->leaderline->point[0], - &curCachePtr->leaderline->point[1], lb) == MS_FALSE) { + if (curCachePtr->leaderline) { + if (testSegmentLabelBBoxIntersection( + curCachePtr->leaderbbox, &curCachePtr->leaderline->point[0], + &curCachePtr->leaderline->point[1], lb) == MS_FALSE) { return MS_FALSE; } } @@ -745,23 +852,23 @@ int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, label return MS_TRUE; } -/* utility function to get the rect of a string outside of a rendering loop, i.e. - without going through textpath layouts */ -int msGetStringSize(mapObj *map, labelObj *label, int size, char *string, rectObj *r) { +/* utility function to get the rect of a string outside of a rendering loop, + i.e. without going through textpath layouts */ +int msGetStringSize(mapObj *map, labelObj *label, int size, char *string, + rectObj *r) { textSymbolObj ts; double lsize = label->size; initTextSymbol(&ts); label->size = size; - msPopulateTextSymbolForLabelAndString(&ts,label,msStrdup(string),1,1,0); - if(MS_UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&ts,r))) + msPopulateTextSymbolForLabelAndString(&ts, label, msStrdup(string), 1, 1, 0); + if (MS_UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map, &ts, r))) return MS_FAILURE; label->size = lsize; freeTextSymbol(&ts); return MS_SUCCESS; } -int msInitFontSet(fontSetObj *fontset) -{ +int msInitFontSet(fontSetObj *fontset) { fontset->filename = NULL; /* fontset->fonts = NULL; */ @@ -769,11 +876,10 @@ int msInitFontSet(fontSetObj *fontset) fontset->numfonts = 0; fontset->map = NULL; - return( 0 ); + return (0); } -int msFreeFontSet(fontSetObj *fontset) -{ +int msFreeFontSet(fontSetObj *fontset) { if (fontset->filename) free(fontset->filename); fontset->filename = NULL; @@ -782,23 +888,23 @@ int msFreeFontSet(fontSetObj *fontset) /* fontset->fonts = NULL; */ fontset->numfonts = 0; - return( 0 ); + return (0); } -int msLoadFontSet(fontSetObj *fontset, mapObj *map) -{ +int msLoadFontSet(fontSetObj *fontset, mapObj *map) { VSILFILE *stream; - const char* line; + const char *line; char *path; char szPath[MS_MAXPATHLEN]; int i; int bFullPath = 0; + const char *realpath; - if(fontset->numfonts != 0) /* already initialized */ - return(0); + if (fontset->numfonts != 0) /* already initialized */ + return (0); - if(!fontset->filename) - return(0); + if (!fontset->filename) + return (0); fontset->map = (mapObj *)map; @@ -806,35 +912,43 @@ int msLoadFontSet(fontSetObj *fontset, mapObj *map) /* fontset->fonts = msCreateHashTable(); // create font hash */ /* if(!fontset->fonts) { */ - /* msSetError(MS_HASHERR, "Error initializing font hash.", "msLoadFontSet()"); */ + /* msSetError(MS_HASHERR, "Error initializing font hash.", "msLoadFontSet()"); + */ /* return(-1); */ /* } */ - stream = VSIFOpenL( msBuildPath(szPath, fontset->map->mappath, fontset->filename), "rb"); - if(!stream) { + realpath = msBuildPath(szPath, fontset->map->mappath, fontset->filename); + if (!realpath) { + free(path); + return -1; + } + stream = VSIFOpenL(realpath, "rb"); + if (!stream) { msSetError(MS_IOERR, "Error opening fontset %s.", "msLoadFontset()", fontset->filename); - return(-1); + free(path); + return (-1); } i = 0; - while( (line = CPLReadLineL(stream)) != NULL ) { /* while there's something to load */ + while ((line = CPLReadLineL(stream)) != + NULL) { /* while there's something to load */ - if(line[0] == '#' || line[0] == '\n' || line[0] == '\r' || line[0] == ' ') + if (line[0] == '#' || line[0] == '\n' || line[0] == '\r' || line[0] == ' ') continue; /* skip comments and blank lines */ char alias[64]; snprintf(alias, sizeof(alias), "%s", line); - char* ptr = strpbrk(alias, " \t"); - if( !ptr ) - continue; + char *ptr = strpbrk(alias, " \t"); + if (!ptr) + continue; *ptr = '\0'; - const char* file1StartPtr = line + (ptr - alias); - file1StartPtr ++; + const char *file1StartPtr = line + (ptr - alias); + file1StartPtr++; /* Skip leading spaces */ - while( isspace((int)*file1StartPtr) ) - file1StartPtr ++; + while (isspace((int)*file1StartPtr)) + file1StartPtr++; if (!(*file1StartPtr) || !(*alias)) continue; @@ -843,10 +957,9 @@ int msLoadFontSet(fontSetObj *fontset, mapObj *map) snprintf(file1, sizeof(file1), "%s", file1StartPtr); /* Remove trailing spaces */ ptr = file1 + strlen(file1) - 1; - while( ptr >= file1 && isspace((int)*ptr) ) - { - *ptr = '\0'; - --ptr; + while (ptr >= file1 && isspace((int)*ptr)) { + *ptr = '\0'; + --ptr; } bFullPath = 0; @@ -854,11 +967,11 @@ int msLoadFontSet(fontSetObj *fontset, mapObj *map) if (file1[0] == '\\' || (strlen(file1) > 1 && (file1[1] == ':'))) bFullPath = 1; #else - if(file1[0] == '/') + if (file1[0] == '/') bFullPath = 1; #endif - if(bFullPath) { /* already full path */ + if (bFullPath) { /* already full path */ msInsertHashTable(&(fontset->fonts), alias, file1); } else { char file2[MS_PATH_LENGTH]; @@ -872,7 +985,6 @@ int msLoadFontSet(fontSetObj *fontset, mapObj *map) */ msInsertHashTable(&(fontset->fonts), alias, msBuildPath(szPath, fontset->map->mappath, file2)); - } i++; @@ -882,93 +994,94 @@ int msLoadFontSet(fontSetObj *fontset, mapObj *map) VSIFCloseL(stream); /* close the file */ free(path); - return(0); + return (0); } - int msGetTextSymbolSize(mapObj *map, textSymbolObj *ts, rectObj *r) { - if(!ts->textpath) { - if(MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map,ts))) + if (!ts->textpath) { + if (MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map, ts))) return MS_FAILURE; } - if(!ts->textpath) + if (!ts->textpath) return MS_FAILURE; *r = ts->textpath->bounds.bbox; return MS_SUCCESS; } /* -** Note: All these routines assume a reference point at the LL corner of the text. GD's -** bitmapped fonts use UL and this is compensated for. Note the rect is relative to the +** Note: All these routines assume a reference point at the LL corner of the +*text. GD's +** bitmapped fonts use UL and this is compensated for. Note the rect is relative +*to the ** LL corner of the text to be rendered, this is first line for TrueType fonts. */ #define MARKER_SLOP 2 -pointObj get_metrics(pointObj *p, int position, textPathObj *tp, int ox, int oy, double rotation, int buffer, label_bounds *bounds) -{ +pointObj get_metrics(pointObj *p, int position, textPathObj *tp, int ox, int oy, + double rotation, int buffer, label_bounds *bounds) { pointObj q = {0}; // initialize - double x1=0, y1=0, x2=0, y2=0; - double sin_a,cos_a; + double x1 = 0, y1 = 0, x2 = 0, y2 = 0; + double sin_a, cos_a; double w, h, x, y; w = tp->bounds.bbox.maxx - tp->bounds.bbox.minx; h = tp->bounds.bbox.maxy - tp->bounds.bbox.miny; - switch(position) { - case MS_UL: - x1 = -w - ox; - y1 = -oy; - break; - case MS_UC: - x1 = -(w/2.0); - y1 = -oy - MARKER_SLOP; - break; - case MS_UR: - x1 = ox; - y1 = -oy; - break; - case MS_CL: - x1 = -w - ox - MARKER_SLOP; - if(oy > 0 && tp->numlines == 1) - y1 = oy; - else - y1 = (h/2.0); - break; - case MS_CC: - x1 = -(w/2.0) + ox; - y1 = (h/2.0) + oy; - break; - case MS_CR: - x1 = ox + MARKER_SLOP; - if(oy > 0 && tp->numlines == 1) - y1 = oy; - else - y1 = (h/2.0); - break; - case MS_LL: - x1 = -w - ox; - y1 = h + oy; - break; - case MS_LC: - x1 = -(w/2.0); - y1 = h + oy + MARKER_SLOP; - break; - case MS_LR: - x1 = ox; - y1 = h + oy; - break; + switch (position) { + case MS_UL: + x1 = -w - ox; + y1 = -oy; + break; + case MS_UC: + x1 = -(w / 2.0); + y1 = -oy - MARKER_SLOP; + break; + case MS_UR: + x1 = ox; + y1 = -oy; + break; + case MS_CL: + x1 = -w - ox - MARKER_SLOP; + if (oy > 0 && tp->numlines == 1) + y1 = oy; + else + y1 = (h / 2.0); + break; + case MS_CC: + x1 = -(w / 2.0) + ox; + y1 = (h / 2.0) + oy; + break; + case MS_CR: + x1 = ox + MARKER_SLOP; + if (oy > 0 && tp->numlines == 1) + y1 = oy; + else + y1 = (h / 2.0); + break; + case MS_LL: + x1 = -w - ox; + y1 = h + oy; + break; + case MS_LC: + x1 = -(w / 2.0); + y1 = h + oy + MARKER_SLOP; + break; + case MS_LR: + x1 = ox; + y1 = h + oy; + break; } - if(rotation) { + if (rotation) { sin_a = sin(rotation); cos_a = cos(rotation); x = x1 - tp->bounds.bbox.minx; y = tp->bounds.bbox.maxy - y1; - q.x = p->x + (x * cos_a - (y) * sin_a); - q.y = p->y - (x * sin_a + (y) * cos_a); + q.x = p->x + (x * cos_a - (y)*sin_a); + q.y = p->y - (x * sin_a + (y)*cos_a); - if(bounds) { + if (bounds) { x2 = x1 - buffer; /* ll */ y2 = y1 + buffer; bounds->poly->point[0].x = p->x + (x2 * cos_a - (-y2) * sin_a); @@ -991,37 +1104,39 @@ pointObj get_metrics(pointObj *p, int position, textPathObj *tp, int ox, int oy, bounds->poly->point[4].x = bounds->poly->point[0].x; bounds->poly->point[4].y = bounds->poly->point[0].y; - fastComputeBounds(bounds->poly,&bounds->bbox); + fastComputeBounds(bounds->poly, &bounds->bbox); } - } - else { + } else { q.x = p->x + x1 - tp->bounds.bbox.minx; q.y = p->y + y1 - tp->bounds.bbox.maxy; - if(bounds) { + if (bounds) { /* no rotation, we only need to return a bbox */ bounds->poly = NULL; - bounds->bbox.minx = q.x - buffer; bounds->bbox.maxy = q.y + buffer + tp->bounds.bbox.maxy; bounds->bbox.maxx = q.x + w + buffer; - bounds->bbox.miny = bounds->bbox.maxy - h - buffer*2; + bounds->bbox.miny = bounds->bbox.maxy - h - buffer * 2; } } - return(q); + return (q); } int intersectTextSymbol(textSymbolObj *ts, label_bounds *lb) { - if(ts->textpath && ts->textpath->absolute) { - if(intersectLabelPolygons(lb->poly,&lb->bbox,ts->textpath->bounds.poly,&ts->textpath->bounds.bbox)) + if (ts->textpath && ts->textpath->absolute) { + if (intersectLabelPolygons(lb->poly, &lb->bbox, ts->textpath->bounds.poly, + &ts->textpath->bounds.bbox)) return MS_TRUE; } - if(ts->style_bounds) { + if (ts->style_bounds) { int s; - for(s=0; slabel->numstyles; s++) { - if(ts->style_bounds[s] && ts->label->styles[s]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT && - intersectLabelPolygons(lb->poly,&lb->bbox,ts->style_bounds[s]->poly, &ts->style_bounds[s]->bbox)) + for (s = 0; s < ts->label->numstyles; s++) { + if (ts->style_bounds[s] && + ts->label->styles[s]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT && + intersectLabelPolygons(lb->poly, &lb->bbox, ts->style_bounds[s]->poly, + &ts->style_bounds[s]->bbox)) return MS_TRUE; } } @@ -1029,25 +1144,24 @@ int intersectTextSymbol(textSymbolObj *ts, label_bounds *lb) { } /* -** Variation on msIntersectPolygons. Label polygons aren't like shapefile polygons. They +** Variation on msIntersectPolygons. Label polygons aren't like shapefile +*polygons. They ** have no holes, and often do have overlapping parts (i.e. road symbols). */ -int intersectLabelPolygons(lineObj *l1, rectObj *r1, lineObj *l2, rectObj *r2) -{ - int v1,v2; +int intersectLabelPolygons(lineObj *l1, rectObj *r1, lineObj *l2, rectObj *r2) { + int v1, v2; pointObj *point; - lineObj *p1,*p2,sp1,sp2; - pointObj pnts1[5],pnts2[5]; - + lineObj *p1, *p2, sp1, sp2; + pointObj pnts1[5], pnts2[5]; /* STEP 0: check bounding boxes */ - if(!msRectOverlap(r1,r2)) { /* from alans@wunderground.com */ - return(MS_FALSE); + if (!msRectOverlap(r1, r2)) { /* from alans@wunderground.com */ + return (MS_FALSE); } - if(!l1 && !l2) + if (!l1 && !l2) return MS_TRUE; - if(!l1) { + if (!l1) { p1 = &sp1; p1->numpoints = 5; p1->point = pnts1; @@ -1058,7 +1172,7 @@ int intersectLabelPolygons(lineObj *l1, rectObj *r1, lineObj *l2, rectObj *r2) } else { p1 = l1; } - if(!l2) { + if (!l2) { p2 = &sp2; p2->numpoints = 5; p2->point = pnts2; @@ -1069,42 +1183,58 @@ int intersectLabelPolygons(lineObj *l1, rectObj *r1, lineObj *l2, rectObj *r2) } else { p2 = l2; } - (void)pnts1[0].x; (void)pnts1[0].y; - (void)pnts1[1].x; (void)pnts1[1].y; - (void)pnts1[2].x; (void)pnts1[2].y; - (void)pnts1[3].x; (void)pnts1[3].y; - (void)pnts1[4].x; (void)pnts1[4].y; - (void)pnts2[0].x; (void)pnts2[0].y; - (void)pnts2[1].x; (void)pnts2[1].y; - (void)pnts2[2].x; (void)pnts2[2].y; - (void)pnts2[3].x; (void)pnts2[3].y; - (void)pnts2[4].x; (void)pnts2[4].y; + (void)pnts1[0].x; + (void)pnts1[0].y; + (void)pnts1[1].x; + (void)pnts1[1].y; + (void)pnts1[2].x; + (void)pnts1[2].y; + (void)pnts1[3].x; + (void)pnts1[3].y; + (void)pnts1[4].x; + (void)pnts1[4].y; + (void)pnts2[0].x; + (void)pnts2[0].y; + (void)pnts2[1].x; + (void)pnts2[1].y; + (void)pnts2[2].x; + (void)pnts2[2].y; + (void)pnts2[3].x; + (void)pnts2[3].y; + (void)pnts2[4].x; + (void)pnts2[4].y; /* STEP 1: look for intersecting line segments */ - for(v1=1; v1numpoints; v1++) - for(v2=1; v2numpoints; v2++) - if(msIntersectSegments(&(p1->point[v1-1]), &(p1->point[v1]), &(p2->point[v2-1]), &(p2->point[v2])) == MS_TRUE) { - return(MS_TRUE); - } + for (v1 = 1; v1 < p1->numpoints; v1++) + for (v2 = 1; v2 < p2->numpoints; v2++) + if (msIntersectSegments(&(p1->point[v1 - 1]), &(p1->point[v1]), + &(p2->point[v2 - 1]), + &(p2->point[v2])) == MS_TRUE) { + return (MS_TRUE); + } - /* STEP 2: polygon one completely contains two (only need to check one point from each part) */ + /* STEP 2: polygon one completely contains two (only need to check one point + * from each part) */ point = &(p2->point[0]); - if(msPointInPolygon(point, p1) == MS_TRUE) /* ok, the point is in a polygon */ - return(MS_TRUE); + if (msPointInPolygon(point, p1) == + MS_TRUE) /* ok, the point is in a polygon */ + return (MS_TRUE); - /* STEP 3: polygon two completely contains one (only need to check one point from each part) */ + /* STEP 3: polygon two completely contains one (only need to check one point + * from each part) */ point = &(p1->point[0]); - if(msPointInPolygon(point, p2) == MS_TRUE) /* ok, the point is in a polygon */ - return(MS_TRUE); + if (msPointInPolygon(point, p2) == + MS_TRUE) /* ok, the point is in a polygon */ + return (MS_TRUE); - return(MS_FALSE); + return (MS_FALSE); } /* For MapScript, exactly the same the msInsertStyle */ -int msInsertLabelStyle(labelObj *label, styleObj *style, int nStyleIndex) -{ +int msInsertLabelStyle(labelObj *label, styleObj *style, int nStyleIndex) { if (!style) { - msSetError(MS_CHILDERR, "Can't insert a NULL Style", "msInsertLabelStyle()"); + msSetError(MS_CHILDERR, "Can't insert a NULL Style", + "msInsertLabelStyle()"); return -1; } @@ -1114,20 +1244,21 @@ int msInsertLabelStyle(labelObj *label, styleObj *style, int nStyleIndex) } /* Catch attempt to insert past end of styles array */ else if (nStyleIndex >= label->numstyles) { - msSetError(MS_CHILDERR, "Cannot insert style beyond index %d", "insertLabelStyle()", label->numstyles-1); + msSetError(MS_CHILDERR, "Cannot insert style beyond index %d", + "insertLabelStyle()", label->numstyles - 1); return -1; } else if (nStyleIndex < 0) { /* Insert at the end by default */ - label->styles[label->numstyles]=style; + label->styles[label->numstyles] = style; MS_REFCNT_INCR(style); label->numstyles++; - return label->numstyles-1; + return label->numstyles - 1; } else { /* Move styles existing at the specified nStyleIndex or greater */ /* to a higher nStyleIndex */ - for (int i=label->numstyles-1; i>=nStyleIndex; i--) { - label->styles[i+1] = label->styles[i]; + for (int i = label->numstyles - 1; i >= nStyleIndex; i--) { + label->styles[i + 1] = label->styles[i]; } - label->styles[nStyleIndex]=style; + label->styles[nStyleIndex] = style; MS_REFCNT_INCR(style); label->numstyles++; return nStyleIndex; @@ -1137,46 +1268,41 @@ int msInsertLabelStyle(labelObj *label, styleObj *style, int nStyleIndex) /** * Move the style up inside the array of styles. */ -int msMoveLabelStyleUp(labelObj *label, int nStyleIndex) -{ - if (label && nStyleIndex < label->numstyles && nStyleIndex >0) { - styleObj* psTmpStyle = (styleObj *)malloc(sizeof(styleObj)); +int msMoveLabelStyleUp(labelObj *label, int nStyleIndex) { + if (label && nStyleIndex < label->numstyles && nStyleIndex > 0) { + styleObj *psTmpStyle = (styleObj *)malloc(sizeof(styleObj)); initStyle(psTmpStyle); msCopyStyle(psTmpStyle, label->styles[nStyleIndex]); - msCopyStyle(label->styles[nStyleIndex], - label->styles[nStyleIndex-1]); + msCopyStyle(label->styles[nStyleIndex], label->styles[nStyleIndex - 1]); - msCopyStyle(label->styles[nStyleIndex-1], psTmpStyle); + msCopyStyle(label->styles[nStyleIndex - 1], psTmpStyle); - return(MS_SUCCESS); + return (MS_SUCCESS); } msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveLabelStyleUp()", nStyleIndex); return (MS_FAILURE); } - /** * Move the style down inside the array of styles. */ -int msMoveLabelStyleDown(labelObj *label, int nStyleIndex) -{ +int msMoveLabelStyleDown(labelObj *label, int nStyleIndex) { styleObj *psTmpStyle = NULL; - if (label && nStyleIndex < label->numstyles-1 && nStyleIndex >=0) { + if (label && nStyleIndex < label->numstyles - 1 && nStyleIndex >= 0) { psTmpStyle = (styleObj *)malloc(sizeof(styleObj)); initStyle(psTmpStyle); msCopyStyle(psTmpStyle, label->styles[nStyleIndex]); - msCopyStyle(label->styles[nStyleIndex], - label->styles[nStyleIndex+1]); + msCopyStyle(label->styles[nStyleIndex], label->styles[nStyleIndex + 1]); - msCopyStyle(label->styles[nStyleIndex+1], psTmpStyle); + msCopyStyle(label->styles[nStyleIndex + 1], psTmpStyle); - return(MS_SUCCESS); + return (MS_SUCCESS); } msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveLabelStyleDown()", nStyleIndex); @@ -1187,36 +1313,35 @@ int msMoveLabelStyleDown(labelObj *label, int nStyleIndex) * Delete the style identified by the index and shift * styles that follows the deleted style. */ -int msDeleteLabelStyle(labelObj *label, int nStyleIndex) -{ - if (label && nStyleIndex < label->numstyles && nStyleIndex >=0) { +int msDeleteLabelStyle(labelObj *label, int nStyleIndex) { + if (label && nStyleIndex < label->numstyles && nStyleIndex >= 0) { if (freeStyle(label->styles[nStyleIndex]) == MS_SUCCESS) msFree(label->styles[nStyleIndex]); - for (int i=nStyleIndex; i< label->numstyles-1; i++) { - label->styles[i] = label->styles[i+1]; + for (int i = nStyleIndex; i < label->numstyles - 1; i++) { + label->styles[i] = label->styles[i + 1]; } - label->styles[label->numstyles-1] = NULL; + label->styles[label->numstyles - 1] = NULL; label->numstyles--; - return(MS_SUCCESS); + return (MS_SUCCESS); } msSetError(MS_CHILDERR, "Invalid index: %d", "msDeleteLabelStyle()", nStyleIndex); return (MS_FAILURE); } -styleObj *msRemoveLabelStyle(labelObj *label, int nStyleIndex) -{ +styleObj *msRemoveLabelStyle(labelObj *label, int nStyleIndex) { int i; styleObj *style; if (nStyleIndex < 0 || nStyleIndex >= label->numstyles) { - msSetError(MS_CHILDERR, "Cannot remove style, invalid nStyleIndex %d", "removeLabelStyle()", nStyleIndex); + msSetError(MS_CHILDERR, "Cannot remove style, invalid nStyleIndex %d", + "removeLabelStyle()", nStyleIndex); return NULL; } else { - style=label->styles[nStyleIndex]; - for (i=nStyleIndex; inumstyles-1; i++) { - label->styles[i]=label->styles[i+1]; + style = label->styles[nStyleIndex]; + for (i = nStyleIndex; i < label->numstyles - 1; i++) { + label->styles[i] = label->styles[i + 1]; } - label->styles[label->numstyles-1]=NULL; + label->styles[label->numstyles - 1] = NULL; label->numstyles--; MS_REFCNT_DECR(style); return style; diff --git a/maplayer.c b/maplayer.c index 0927a77711..ab219bb6f9 100644 --- a/maplayer.c +++ b/maplayer.c @@ -38,23 +38,29 @@ #include #ifndef cppcheck_assert -#define cppcheck_assert(x) do {} while(0) +#define cppcheck_assert(x) \ + do { \ + } while (0) #endif static int populateVirtualTable(layerVTableObj *vtable); /* -** Iteminfo is a layer parameter that holds information necessary to retrieve an individual item for -** a particular source. It is an array built from a list of items. The type of iteminfo will vary by -** source. For shapefiles and OGR it is simply an array of integers where each value is an index for -** the item. For SDE it's a ESRI specific type that contains index and column type information. Two -** helper functions below initialize and free that structure member which is used locally by layer +** Iteminfo is a layer parameter that holds information necessary to retrieve an +*individual item for +** a particular source. It is an array built from a list of items. The type of +*iteminfo will vary by +** source. For shapefiles and OGR it is simply an array of integers where each +*value is an index for +** the item. For SDE it's a ESRI specific type that contains index and column +*type information. Two +** helper functions below initialize and free that structure member which is +*used locally by layer ** specific functions. */ -int msLayerInitItemInfo(layerObj *layer) -{ - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); +int msLayerInitItemInfo(layerObj *layer) { + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } @@ -62,11 +68,10 @@ int msLayerInitItemInfo(layerObj *layer) return layer->vtable->LayerInitItemInfo(layer); } -void msLayerFreeItemInfo(layerObj *layer) -{ - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); - if( rv != MS_SUCCESS ) +void msLayerFreeItemInfo(layerObj *layer) { + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); + if (rv != MS_SUCCESS) return; } cppcheck_assert(layer->vtable); @@ -80,167 +85,184 @@ void msLayerFreeItemInfo(layerObj *layer) msLayerFreeExpressions(layer); } -int msLayerRestoreFromScaletokens(layerObj *layer) -{ - if(!layer->scaletokens || !layer->orig_st) { +int msLayerRestoreFromScaletokens(layerObj *layer) { + if (!layer->scaletokens || !layer->orig_st) { return MS_SUCCESS; } - if(layer->orig_st->data) { + if (layer->orig_st->data) { msFree(layer->data); layer->data = layer->orig_st->data; } - if(layer->orig_st->tileindex) { + if (layer->orig_st->tileindex) { msFree(layer->tileindex); layer->tileindex = layer->orig_st->tileindex; } - if(layer->orig_st->tileitem) { + if (layer->orig_st->tileitem) { msFree(layer->tileitem); layer->tileitem = layer->orig_st->tileitem; } - if(layer->orig_st->filter) { - msLoadExpressionString(&(layer->filter),layer->orig_st->filter); + if (layer->orig_st->filter) { + msLoadExpressionString(&(layer->filter), layer->orig_st->filter); msFree(layer->orig_st->filter); } - if(layer->orig_st->filteritem) { + if (layer->orig_st->filteritem) { msFree(layer->filteritem); layer->filteritem = layer->orig_st->filteritem; } - if(layer->orig_st->n_processing) { + if (layer->orig_st->n_processing) { int i; - for(i=0;iorig_st->n_processing;i++) { + for (i = 0; i < layer->orig_st->n_processing; i++) { msFree(layer->processing[layer->orig_st->processing_idx[i]]); - layer->processing[layer->orig_st->processing_idx[i]] = layer->orig_st->processing[i]; + layer->processing[layer->orig_st->processing_idx[i]] = + layer->orig_st->processing[i]; } msFree(layer->orig_st->processing); msFree(layer->orig_st->processing_idx); } msFree(layer->orig_st); layer->orig_st = NULL; - return MS_SUCCESS; + return MS_SUCCESS; } -#define check_st_alloc(l) if(!l->orig_st) l->orig_st=msSmallCalloc(1,sizeof(originalScaleTokenStrings)); -int msLayerApplyScaletokens(layerObj *layer, double scale) -{ - int i,p; - if(!layer->scaletokens) { +#define check_st_alloc(l) \ + if (!l->orig_st) \ + l->orig_st = msSmallCalloc(1, sizeof(originalScaleTokenStrings)); +int msLayerApplyScaletokens(layerObj *layer, double scale) { + int i, p; + if (!layer->scaletokens) { return MS_SUCCESS; } msLayerRestoreFromScaletokens(layer); - for(i=0;inumscaletokens;i++) { + for (i = 0; i < layer->numscaletokens; i++) { scaleTokenObj *st = &layer->scaletokens[i]; scaleTokenEntryObj *ste = NULL; - if(scale<=0) { - ste = &(st->tokens[0]); + if (scale <= 0) { + ste = &(st->tokens[0]); /* no scale defined, use first entry */ } else { - int tokenindex=0; - while(tokenindexn_entries) { + int tokenindex = 0; + while (tokenindex < st->n_entries) { ste = &(st->tokens[tokenindex]); - if(scale < ste->maxscale && scale >= ste->minscale) break; /* current token is the correct one */ + if (scale < ste->maxscale && scale >= ste->minscale) + break; /* current token is the correct one */ tokenindex++; ste = NULL; } } assert(ste); - if(layer->data && strstr(layer->data,st->name)) { - if(layer->debug >= MS_DEBUGLEVEL_DEBUG) { - msDebug("replacing scaletoken (%s) with (%s) in layer->data (%s) for scale=%f\n", - st->name,ste->value,layer->name,scale); + if (layer->data && strstr(layer->data, st->name)) { + if (layer->debug >= MS_DEBUGLEVEL_DEBUG) { + msDebug("replacing scaletoken (%s) with (%s) in layer->data (%s) for " + "scale=%f\n", + st->name, ste->value, layer->name, scale); } check_st_alloc(layer); layer->orig_st->data = layer->data; layer->data = msStrdup(layer->data); - layer->data = msReplaceSubstring(layer->data,st->name,ste->value); + layer->data = msReplaceSubstring(layer->data, st->name, ste->value); } - if(layer->tileindex && strstr(layer->tileindex,st->name)) { - if(layer->debug >= MS_DEBUGLEVEL_DEBUG) { - msDebug("replacing scaletoken (%s) with (%s) in layer->tileindex (%s) for scale=%f\n", - st->name,ste->value,layer->name,scale); + if (layer->tileindex && strstr(layer->tileindex, st->name)) { + if (layer->debug >= MS_DEBUGLEVEL_DEBUG) { + msDebug("replacing scaletoken (%s) with (%s) in layer->tileindex (%s) " + "for scale=%f\n", + st->name, ste->value, layer->name, scale); } check_st_alloc(layer); layer->orig_st->tileindex = layer->tileindex; layer->tileindex = msStrdup(layer->tileindex); - layer->tileindex = msReplaceSubstring(layer->tileindex,st->name,ste->value); + layer->tileindex = + msReplaceSubstring(layer->tileindex, st->name, ste->value); } - if(layer->tileitem && strstr(layer->tileitem,st->name)) { - if(layer->debug >= MS_DEBUGLEVEL_DEBUG) { - msDebug("replacing scaletoken (%s) with (%s) in layer->tileitem (%s) for scale=%f\n", - st->name,ste->value,layer->name,scale); + if (layer->tileitem && strstr(layer->tileitem, st->name)) { + if (layer->debug >= MS_DEBUGLEVEL_DEBUG) { + msDebug("replacing scaletoken (%s) with (%s) in layer->tileitem (%s) " + "for scale=%f\n", + st->name, ste->value, layer->name, scale); } check_st_alloc(layer); layer->orig_st->tileitem = layer->tileitem; layer->tileitem = msStrdup(layer->tileitem); - layer->tileitem = msReplaceSubstring(layer->tileitem,st->name,ste->value); + layer->tileitem = + msReplaceSubstring(layer->tileitem, st->name, ste->value); } - if(layer->filteritem && strstr(layer->filteritem,st->name)) { - if(layer->debug >= MS_DEBUGLEVEL_DEBUG) { - msDebug("replacing scaletoken (%s) with (%s) in layer->filteritem (%s) for scale=%f\n", - st->name,ste->value,layer->name,scale); + if (layer->filteritem && strstr(layer->filteritem, st->name)) { + if (layer->debug >= MS_DEBUGLEVEL_DEBUG) { + msDebug("replacing scaletoken (%s) with (%s) in layer->filteritem (%s) " + "for scale=%f\n", + st->name, ste->value, layer->name, scale); } check_st_alloc(layer); layer->orig_st->filteritem = layer->filteritem; layer->filteritem = msStrdup(layer->filteritem); - layer->filteritem = msReplaceSubstring(layer->filteritem,st->name,ste->value); + layer->filteritem = + msReplaceSubstring(layer->filteritem, st->name, ste->value); } - if(layer->filter.string && strstr(layer->filter.string,st->name)) { + if (layer->filter.string && strstr(layer->filter.string, st->name)) { char *tmpval; - if(layer->debug >= MS_DEBUGLEVEL_DEBUG) { - msDebug("replacing scaletoken (%s) with (%s) in layer->filter (%s) for scale=%f\n", - st->name,ste->value,layer->name,scale); + if (layer->debug >= MS_DEBUGLEVEL_DEBUG) { + msDebug("replacing scaletoken (%s) with (%s) in layer->filter (%s) for " + "scale=%f\n", + st->name, ste->value, layer->name, scale); } check_st_alloc(layer); layer->orig_st->filter = msStrdup(layer->filter.string); tmpval = msStrdup(layer->filter.string); - tmpval = msReplaceSubstring(tmpval,st->name,ste->value); - if(msLoadExpressionString(&(layer->filter),tmpval) == -1) return(MS_FAILURE); /* msLoadExpressionString() cleans up previously allocated expression */ + tmpval = msReplaceSubstring(tmpval, st->name, ste->value); + if (msLoadExpressionString(&(layer->filter), tmpval) == -1) + return (MS_FAILURE); /* msLoadExpressionString() cleans up previously + allocated expression */ msFree(tmpval); } - for(p=0;pnumprocessing;p++) { - if(strstr(layer->processing[p],st->name)) { + for (p = 0; p < layer->numprocessing; p++) { + if (strstr(layer->processing[p], st->name)) { check_st_alloc(layer); layer->orig_st->n_processing++; - layer->orig_st->processing = msSmallRealloc(layer->orig_st->processing, layer->orig_st->n_processing * sizeof(char*)); - layer->orig_st->processing_idx = msSmallRealloc(layer->orig_st->processing_idx, layer->orig_st->n_processing * sizeof(int)); - layer->orig_st->processing[layer->orig_st->n_processing-1] = layer->processing[p]; - layer->orig_st->processing_idx[layer->orig_st->n_processing-1] = p; + layer->orig_st->processing = + msSmallRealloc(layer->orig_st->processing, + layer->orig_st->n_processing * sizeof(char *)); + layer->orig_st->processing_idx = + msSmallRealloc(layer->orig_st->processing_idx, + layer->orig_st->n_processing * sizeof(int)); + layer->orig_st->processing[layer->orig_st->n_processing - 1] = + layer->processing[p]; + layer->orig_st->processing_idx[layer->orig_st->n_processing - 1] = p; layer->processing[p] = msStrdup(layer->processing[p]); - layer->processing[p] = msReplaceSubstring(layer->processing[p],st->name,ste->value); + layer->processing[p] = + msReplaceSubstring(layer->processing[p], st->name, ste->value); } } - } return MS_SUCCESS; } - /* ** Does exactly what it implies, readies a layer for processing. */ -int msLayerOpen(layerObj *layer) -{ +int msLayerOpen(layerObj *layer) { int rv; /* RFC-86 Scale dependant token replacements*/ - rv = msLayerApplyScaletokens(layer,(layer->map)?layer->map->scaledenom:-1); - if (rv != MS_SUCCESS) return rv; + rv = msLayerApplyScaletokens(layer, + (layer->map) ? layer->map->scaledenom : -1); + if (rv != MS_SUCCESS) + return rv; /* RFC-69 clustering support */ if (layer->cluster.region) return msClusterLayerOpen(layer); - if(layer->features && layer->connectiontype != MS_GRATICULE ) + if (layer->features && layer->connectiontype != MS_GRATICULE) layer->connectiontype = MS_INLINE; - if(layer->tileindex && layer->connectiontype == MS_SHAPEFILE) + if (layer->tileindex && layer->connectiontype == MS_SHAPEFILE) layer->connectiontype = MS_TILED_SHAPEFILE; - if(layer->type == MS_LAYER_RASTER && layer->connectiontype != MS_WMS - && layer->connectiontype != MS_KERNELDENSITY) + if (layer->type == MS_LAYER_RASTER && layer->connectiontype != MS_WMS && + layer->connectiontype != MS_KERNELDENSITY) layer->connectiontype = MS_RASTER; - if ( ! layer->vtable) { - rv = msInitializeVirtualTable(layer); + if (!layer->vtable) { + rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } @@ -249,12 +271,12 @@ int msLayerOpen(layerObj *layer) } /* -** Returns MS_TRUE if layer has been opened using msLayerOpen(), MS_FALSE otherwise +** Returns MS_TRUE if layer has been opened using msLayerOpen(), MS_FALSE +*otherwise */ -int msLayerIsOpen(layerObj *layer) -{ - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); +int msLayerIsOpen(layerObj *layer) { + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } @@ -263,12 +285,12 @@ int msLayerIsOpen(layerObj *layer) } /* -** Returns MS_TRUE is a layer supports the common expression/filter syntax (RFC 64) and MS_FALSE otherwise. +** Returns MS_TRUE is a layer supports the common expression/filter syntax (RFC +*64) and MS_FALSE otherwise. */ -int msLayerSupportsCommonFilters(layerObj *layer) -{ - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); +int msLayerSupportsCommonFilters(layerObj *layer) { + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } @@ -276,10 +298,10 @@ int msLayerSupportsCommonFilters(layerObj *layer) return layer->vtable->LayerSupportsCommonFilters(layer); } -int msLayerTranslateFilter(layerObj *layer, expressionObj *filter, char *filteritem) -{ +int msLayerTranslateFilter(layerObj *layer, expressionObj *filter, + char *filteritem) { if (!layer->vtable) { - int rv = msInitializeVirtualTable(layer); + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } @@ -288,22 +310,26 @@ int msLayerTranslateFilter(layerObj *layer, expressionObj *filter, char *filteri } /* -** Performs a spatial, and optionally an attribute based feature search. The function basically -** prepares things so that candidate features can be accessed by query or drawing functions. For -** OGR and shapefiles this sets an internal bit vector that indicates whether a particular feature -** is to processed. For SDE it executes an SQL statement on the SDE server. Once run the msLayerNextShape +** Performs a spatial, and optionally an attribute based feature search. The +*function basically +** prepares things so that candidate features can be accessed by query or +*drawing functions. For +** OGR and shapefiles this sets an internal bit vector that indicates whether a +*particular feature +** is to processed. For SDE it executes an SQL statement on the SDE server. Once +*run the msLayerNextShape ** function should be called to actually access the shapes. ** -** Note that for shapefiles we apply any maxfeatures constraint at this point. That may be the only +** Note that for shapefiles we apply any maxfeatures constraint at this point. +*That may be the only ** connection type where this is feasible. */ -int msLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) -{ - if(!msLayerSupportsCommonFilters(layer)) +int msLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) { + if (!msLayerSupportsCommonFilters(layer)) msLayerTranslateFilter(layer, &layer->filter, layer->filteritem); - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } @@ -312,17 +338,17 @@ int msLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) } /* -** Called after msWhichShapes has been called to actually retrieve shapes within a given area +** Called after msWhichShapes has been called to actually retrieve shapes within +*a given area ** and matching a vendor specific filter (i.e. layer FILTER attribute). ** ** Shapefiles: NULL shapes (shapes with attributes but NO vertices are skipped) */ -int msLayerNextShape(layerObj *layer, shapeObj *shape) -{ +int msLayerNextShape(layerObj *layer, shapeObj *shape) { int rv, filter_passed; - - if ( ! layer->vtable) { - rv = msInitializeVirtualTable(layer); + + if (!layer->vtable) { + rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } @@ -330,53 +356,58 @@ int msLayerNextShape(layerObj *layer, shapeObj *shape) #ifdef USE_V8_MAPSCRIPT /* we need to force the GetItems for the geomtransform attributes */ - if(!layer->items && - layer->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION && - strstr(layer->_geomtransform.string, "javascript")) - msLayerGetItems(layer); + if (!layer->items && + layer->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION && + strstr(layer->_geomtransform.string, "javascript")) + msLayerGetItems(layer); #endif /* At the end of switch case (default -> break; -> return MS_FAILURE), * was following TODO ITEM: * * TO DO! This is where dynamic joins will happen. Joined attributes will be - * tagged on to the main attributes with the naming scheme [join name].[item name]. - * We need to leverage the iteminfo (I think) at this point + * tagged on to the main attributes with the naming scheme [join name].[item + * name]. We need to leverage the iteminfo (I think) at this point */ /* RFC 91: MapServer-based filtering is done at a more general level. */ do { rv = layer->vtable->LayerNextShape(layer, shape); - if(rv != MS_SUCCESS) return rv; + if (rv != MS_SUCCESS) + return rv; - /* attributes need to be iconv'd to UTF-8 before any filter logic is applied */ - if(layer->encoding) { - rv = msLayerEncodeShapeAttributes(layer,shape); - if(rv != MS_SUCCESS) + /* attributes need to be iconv'd to UTF-8 before any filter logic is applied + */ + if (layer->encoding) { + rv = msLayerEncodeShapeAttributes(layer, shape); + if (rv != MS_SUCCESS) return rv; } - filter_passed = msEvalExpression(layer, shape, &(layer->filter), layer->filteritemindex); + filter_passed = msEvalExpression(layer, shape, &(layer->filter), + layer->filteritemindex); - if(!filter_passed) msFreeShape(shape); - } while(!filter_passed); + if (!filter_passed) + msFreeShape(shape); + } while (!filter_passed); /* RFC89 Apply Layer GeomTransform */ - if(layer->_geomtransform.type != MS_GEOMTRANSFORM_NONE && rv == MS_SUCCESS) { - rv = msGeomTransformShape(layer->map, layer, shape); - if(rv != MS_SUCCESS) + if (layer->_geomtransform.type != MS_GEOMTRANSFORM_NONE && rv == MS_SUCCESS) { + rv = msGeomTransformShape(layer->map, layer, shape); + if (rv != MS_SUCCESS) return rv; } - return rv; } /* -** Used to retrieve a shape from a result set by index. Result sets are created by the various +** Used to retrieve a shape from a result set by index. Result sets are created +*by the various ** msQueryBy...() functions. The index is assigned by the data source. */ -/* int msLayerResultsGetShape(layerObj *layer, shapeObj *shape, int tile, long record) +/* int msLayerResultsGetShape(layerObj *layer, shapeObj *shape, int tile, long +record) { if ( ! layer->vtable) { int rv = msInitializeVirtualTable(layer); @@ -388,39 +419,40 @@ int msLayerNextShape(layerObj *layer, shapeObj *shape) } */ /* -** Used to retrieve a shape by index. All data sources must be capable of random access using +** Used to retrieve a shape by index. All data sources must be capable of random +*access using ** a record number(s) of some sort. */ -int msLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) -{ +int msLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) { int rv; - - if( ! layer->vtable) { - rv = msInitializeVirtualTable(layer); - if(rv != MS_SUCCESS) + + if (!layer->vtable) { + rv = msInitializeVirtualTable(layer); + if (rv != MS_SUCCESS) return rv; } cppcheck_assert(layer->vtable); /* ** TODO: This is where dynamic joins could happen. Joined attributes would be - ** tagged on to the main attributes with the naming scheme [join name].[item name]. + ** tagged on to the main attributes with the naming scheme [join name].[item + *name]. */ rv = layer->vtable->LayerGetShape(layer, shape, record); - if(rv != MS_SUCCESS) + if (rv != MS_SUCCESS) return rv; /* RFC89 Apply Layer GeomTransform */ - if(layer->_geomtransform.type != MS_GEOMTRANSFORM_NONE) { - rv = msGeomTransformShape(layer->map, layer, shape); - if(rv != MS_SUCCESS) + if (layer->_geomtransform.type != MS_GEOMTRANSFORM_NONE) { + rv = msGeomTransformShape(layer->map, layer, shape); + if (rv != MS_SUCCESS) return rv; } - if(layer->encoding) { - rv = msLayerEncodeShapeAttributes(layer,shape); - if(rv != MS_SUCCESS) + if (layer->encoding) { + rv = msLayerEncodeShapeAttributes(layer, shape); + if (rv != MS_SUCCESS) return rv; } @@ -429,21 +461,21 @@ int msLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) /* ** Returns the number of shapes that match the potential filter and extent. - * rectProjection is the projection in which rect is expressed, or can be NULL if - * rect should be considered in the layer projection. - * This should be equivalent to calling msLayerWhichShapes() and counting the - * number of shapes returned by msLayerNextShape(), honouring layer->maxfeatures - * limitation if layer->maxfeatures>=0, and honouring layer->startindex if - * layer->startindex >= 1 and paging is enabled. - * Returns -1 in case of failure. - */ -int msLayerGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rectProjection) -{ +* rectProjection is the projection in which rect is expressed, or can be NULL if +* rect should be considered in the layer projection. +* This should be equivalent to calling msLayerWhichShapes() and counting the +* number of shapes returned by msLayerNextShape(), honouring layer->maxfeatures +* limitation if layer->maxfeatures>=0, and honouring layer->startindex if +* layer->startindex >= 1 and paging is enabled. +* Returns -1 in case of failure. +*/ +int msLayerGetShapeCount(layerObj *layer, rectObj rect, + projectionObj *rectProjection) { int rv; - if( ! layer->vtable) { + if (!layer->vtable) { rv = msInitializeVirtualTable(layer); - if(rv != MS_SUCCESS) + if (rv != MS_SUCCESS) return -1; } cppcheck_assert(layer->vtable); @@ -451,21 +483,20 @@ int msLayerGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rectProje return layer->vtable->LayerGetShapeCount(layer, rect, rectProjection); } - /* ** Closes resources used by a particular layer. */ -void msLayerClose(layerObj *layer) -{ +void msLayerClose(layerObj *layer) { /* no need for items once the layer is closed */ msLayerFreeItemInfo(layer); - if(layer->items) { + if (layer->items) { msFreeCharArray(layer->items, layer->numitems); layer->items = NULL; layer->numitems = 0; } - /* clear out items used as part of expressions (bug #2702) -- what about the layer filter? */ + /* clear out items used as part of expressions (bug #2702) -- what about the + * layer filter? */ msLayerFreeExpressions(layer); if (layer->vtable) { @@ -477,43 +508,43 @@ void msLayerClose(layerObj *layer) /* ** Clear out items used as part of expressions. */ -void msLayerFreeExpressions(layerObj *layer) -{ - int i,j,k; +void msLayerFreeExpressions(layerObj *layer) { + int i, j, k; msFreeExpressionTokens(&(layer->filter)); msFreeExpressionTokens(&(layer->cluster.group)); msFreeExpressionTokens(&(layer->cluster.filter)); - for(i=0; inumclasses; i++) { - msFreeExpressionTokens(&(layer->class[i]->expression)); - msFreeExpressionTokens(&(layer->class[i]->text)); - for(j=0; jclass[i]->numstyles; j++) - msFreeExpressionTokens(&(layer->class[i]->styles[j]->_geomtransform)); - for(k=0; kclass[i]->numlabels; k++) { - msFreeExpressionTokens(&(layer->class[i]->labels[k]->expression)); - msFreeExpressionTokens(&(layer->class[i]->labels[k]->text)); + for (i = 0; i < layer->numclasses; i++) { + msFreeExpressionTokens(&(layer->class[i] -> expression)); + msFreeExpressionTokens(&(layer->class[i] -> text)); + for (j = 0; j < layer->class[i] -> numstyles; j++) + msFreeExpressionTokens(&(layer->class[i] -> styles[j] -> _geomtransform)); + for (k = 0; k < layer->class[i] -> numlabels; k++) { + msFreeExpressionTokens(&(layer->class[i] -> labels[k] -> expression)); + msFreeExpressionTokens(&(layer->class[i] -> labels[k] -> text)); } } } /* -** Retrieves a list of attributes available for this layer. Most sources also set the iteminfo array -** at this point. This function is used when processing query results to expose attributes to query +** Retrieves a list of attributes available for this layer. Most sources also +*set the iteminfo array +** at this point. This function is used when processing query results to expose +*attributes to query ** templates. At that point all attributes are fair game. */ -int msLayerGetItems(layerObj *layer) -{ +int msLayerGetItems(layerObj *layer) { const char *itemNames; /* clean up any previously allocated instances */ msLayerFreeItemInfo(layer); - if(layer->items) { + if (layer->items) { msFreeCharArray(layer->items, layer->numitems); layer->items = NULL; layer->numitems = 0; } - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } @@ -522,8 +553,9 @@ int msLayerGetItems(layerObj *layer) /* At the end of switch case (default -> break; -> return MS_FAILURE), * was following TODO ITEM: */ - /* TO DO! Need to add any joined itemd on to the core layer items, one long list! */ - itemNames = msLayerGetProcessingKey( layer, "ITEMS" ); + /* TO DO! Need to add any joined itemd on to the core layer items, one long + * list! */ + itemNames = msLayerGetProcessingKey(layer, "ITEMS"); if (itemNames) { layer->items = msStringSplit(itemNames, ',', &layer->numitems); /* populate the iteminfo array */ @@ -543,8 +575,7 @@ int msLayerGetItems(layerObj *layer) ** ** Returns MS_SUCCESS/MS_FAILURE. */ -int msLayerGetExtent(layerObj *layer, rectObj *extent) -{ +int msLayerGetExtent(layerObj *layer, rectObj *extent) { int need_to_close = MS_FALSE, status = MS_SUCCESS; if (MS_VALID_EXTENT(layer->extent)) { @@ -558,8 +589,8 @@ int msLayerGetExtent(layerObj *layer, rectObj *extent) need_to_close = MS_TRUE; } - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) { if (need_to_close) msLayerClose(layer); @@ -570,34 +601,33 @@ int msLayerGetExtent(layerObj *layer, rectObj *extent) status = layer->vtable->LayerGetExtent(layer, extent); if (status == MS_SUCCESS) { - layer->extent = *extent; + layer->extent = *extent; } if (need_to_close) msLayerClose(layer); - return(status); + return (status); } -int msLayerGetItemIndex(layerObj *layer, char *item) -{ +int msLayerGetItemIndex(layerObj *layer, char *item) { int i; - for(i=0; inumitems; i++) { - if(strcasecmp(layer->items[i], item) == 0) return(i); + for (i = 0; i < layer->numitems; i++) { + if (strcasecmp(layer->items[i], item) == 0) + return (i); } return -1; /* item not found */ } -static int string2list(char **list, int *listsize, char *string) -{ +static int string2list(char **list, int *listsize, char *string) { int i; - for(i=0; i<(*listsize); i++) { - if(strcasecmp(list[i], string) == 0) { + for (i = 0; i < (*listsize); i++) { + if (strcasecmp(list[i], string) == 0) { /* printf("string2list (duplicate): %s %d\n", string, i); */ - return(i); + return (i); } } @@ -606,7 +636,7 @@ static int string2list(char **list, int *listsize, char *string) /* printf("string2list: %s %d\n", string, i); */ - return(i); + return (i); } extern int msyylex(void); @@ -619,72 +649,118 @@ extern double msyynumber; /* token containers */ extern char *msyystring_buffer; const char *msExpressionTokenToString(int token) { - switch(token) { - case '(': return "("; - case ')': return ")"; - case ',': return ","; - case '+': return "+"; - case '-': return "-"; - case '/': return "/"; - case '*': return "*"; - case '%': return "%"; - - case MS_TOKEN_LOGICAL_AND: return " and "; - case MS_TOKEN_LOGICAL_OR: return " or "; - case MS_TOKEN_LOGICAL_NOT: return " not "; - - case MS_TOKEN_COMPARISON_EQ: return " = "; - case MS_TOKEN_COMPARISON_NE: return " != "; - case MS_TOKEN_COMPARISON_GT: return " > "; - case MS_TOKEN_COMPARISON_GE: return " >= "; - case MS_TOKEN_COMPARISON_LT: return " < "; - case MS_TOKEN_COMPARISON_LE: return " <= "; - case MS_TOKEN_COMPARISON_IEQ: return ""; - case MS_TOKEN_COMPARISON_RE: return " ~ "; - case MS_TOKEN_COMPARISON_IRE: return " ~* "; - case MS_TOKEN_COMPARISON_IN: return " in "; - case MS_TOKEN_COMPARISON_LIKE: return " like "; - - case MS_TOKEN_COMPARISON_INTERSECTS: return "intersects"; - case MS_TOKEN_COMPARISON_DISJOINT: return "disjoint"; - case MS_TOKEN_COMPARISON_TOUCHES: return "touches"; - case MS_TOKEN_COMPARISON_OVERLAPS: return "overlaps"; - case MS_TOKEN_COMPARISON_CROSSES: return "crosses"; - case MS_TOKEN_COMPARISON_WITHIN: return "within"; - case MS_TOKEN_COMPARISON_CONTAINS: return "contains"; - case MS_TOKEN_COMPARISON_EQUALS: return "equals"; - case MS_TOKEN_COMPARISON_BEYOND: return "beyond"; - case MS_TOKEN_COMPARISON_DWITHIN: return "dwithin"; - - case MS_TOKEN_FUNCTION_LENGTH: return "length"; - case MS_TOKEN_FUNCTION_TOSTRING: return "tostring"; - case MS_TOKEN_FUNCTION_COMMIFY: return "commify"; - case MS_TOKEN_FUNCTION_AREA: return "area"; - case MS_TOKEN_FUNCTION_ROUND: return "round"; - case MS_TOKEN_FUNCTION_BUFFER: return "buffer"; - case MS_TOKEN_FUNCTION_DIFFERENCE: return "difference"; - case MS_TOKEN_FUNCTION_SIMPLIFY: return "simplify"; - // case MS_TOKEN_FUNCTION_SIMPLIFYPT: - case MS_TOKEN_FUNCTION_GENERALIZE: return "generalize"; - default: return NULL; - } -} - -int msTokenizeExpression(expressionObj *expression, char **list, int *listsize) -{ + switch (token) { + case '(': + return "("; + case ')': + return ")"; + case ',': + return ","; + case '+': + return "+"; + case '-': + return "-"; + case '/': + return "/"; + case '*': + return "*"; + case '%': + return "%"; + + case MS_TOKEN_LOGICAL_AND: + return " and "; + case MS_TOKEN_LOGICAL_OR: + return " or "; + case MS_TOKEN_LOGICAL_NOT: + return " not "; + + case MS_TOKEN_COMPARISON_EQ: + return " = "; + case MS_TOKEN_COMPARISON_NE: + return " != "; + case MS_TOKEN_COMPARISON_GT: + return " > "; + case MS_TOKEN_COMPARISON_GE: + return " >= "; + case MS_TOKEN_COMPARISON_LT: + return " < "; + case MS_TOKEN_COMPARISON_LE: + return " <= "; + case MS_TOKEN_COMPARISON_IEQ: + return ""; + case MS_TOKEN_COMPARISON_RE: + return " ~ "; + case MS_TOKEN_COMPARISON_IRE: + return " ~* "; + case MS_TOKEN_COMPARISON_IN: + return " in "; + case MS_TOKEN_COMPARISON_LIKE: + return " like "; + + case MS_TOKEN_COMPARISON_INTERSECTS: + return "intersects"; + case MS_TOKEN_COMPARISON_DISJOINT: + return "disjoint"; + case MS_TOKEN_COMPARISON_TOUCHES: + return "touches"; + case MS_TOKEN_COMPARISON_OVERLAPS: + return "overlaps"; + case MS_TOKEN_COMPARISON_CROSSES: + return "crosses"; + case MS_TOKEN_COMPARISON_WITHIN: + return "within"; + case MS_TOKEN_COMPARISON_CONTAINS: + return "contains"; + case MS_TOKEN_COMPARISON_EQUALS: + return "equals"; + case MS_TOKEN_COMPARISON_BEYOND: + return "beyond"; + case MS_TOKEN_COMPARISON_DWITHIN: + return "dwithin"; + + case MS_TOKEN_FUNCTION_LENGTH: + return "length"; + case MS_TOKEN_FUNCTION_TOSTRING: + return "tostring"; + case MS_TOKEN_FUNCTION_COMMIFY: + return "commify"; + case MS_TOKEN_FUNCTION_AREA: + return "area"; + case MS_TOKEN_FUNCTION_ROUND: + return "round"; + case MS_TOKEN_FUNCTION_BUFFER: + return "buffer"; + case MS_TOKEN_FUNCTION_DIFFERENCE: + return "difference"; + case MS_TOKEN_FUNCTION_SIMPLIFY: + return "simplify"; + // case MS_TOKEN_FUNCTION_SIMPLIFYPT: + case MS_TOKEN_FUNCTION_GENERALIZE: + return "generalize"; + default: + return NULL; + } +} + +int msTokenizeExpression(expressionObj *expression, char **list, + int *listsize) { tokenListNodeObjPtr node; int token; - /* TODO: make sure the constants can't somehow reference invalid expression types */ - /* if(expression->type != MS_EXPRESSION && expression->type != MS_GEOMTRANSFORM_EXPRESSION) return MS_SUCCESS; */ + /* TODO: make sure the constants can't somehow reference invalid expression + * types */ + /* if(expression->type != MS_EXPRESSION && expression->type != + * MS_GEOMTRANSFORM_EXPRESSION) return MS_SUCCESS; */ msAcquireLock(TLOCK_PARSER); msyystate = MS_TOKENIZE_EXPRESSION; msyystring = expression->string; /* the thing we're tokenizing */ - while((token = msyylex()) != 0) { /* keep processing tokens until the end of the string (\0) */ + while ((token = msyylex()) != + 0) { /* keep processing tokens until the end of the string (\0) */ - if((node = (tokenListNodeObjPtr) malloc(sizeof(tokenListNodeObj))) == NULL) { + if ((node = (tokenListNodeObjPtr)malloc(sizeof(tokenListNodeObj))) == + NULL) { msSetError(MS_MEMERR, NULL, "msTokenizeExpression()"); goto parse_error; } @@ -694,86 +770,99 @@ int msTokenizeExpression(expressionObj *expression, char **list, int *listsize) node->tailifhead = NULL; node->next = NULL; - switch(token) { - case MS_TOKEN_LITERAL_BOOLEAN: - case MS_TOKEN_LITERAL_NUMBER: - node->token = token; - node->tokenval.dblval = msyynumber; - break; - case MS_TOKEN_LITERAL_STRING: - node->token = token; - node->tokenval.strval = msStrdup(msyystring_buffer); - break; - case MS_TOKEN_LITERAL_TIME: - node->tokensrc = msStrdup(msyystring_buffer); - node->token = token; - msTimeInit(&(node->tokenval.tmval)); - if(msParseTime(msyystring_buffer, &(node->tokenval.tmval)) != MS_TRUE) { - msSetError(MS_PARSEERR, "Parsing time value failed.", "msTokenizeExpression()"); - free(node); - goto parse_error; - } - break; - case MS_TOKEN_BINDING_DOUBLE: /* we've encountered an attribute (binding) reference */ - case MS_TOKEN_BINDING_INTEGER: - case MS_TOKEN_BINDING_STRING: - case MS_TOKEN_BINDING_TIME: - node->token = token; /* binding type */ - node->tokenval.bindval.item = msStrdup(msyystring_buffer); - if(list) node->tokenval.bindval.index = string2list(list, listsize, msyystring_buffer); - break; - case MS_TOKEN_BINDING_SHAPE: - node->token = token; - break; - case MS_TOKEN_BINDING_MAP_CELLSIZE: - node->token = token; - break; - case MS_TOKEN_BINDING_DATA_CELLSIZE: - node->token = token; - break; - case MS_TOKEN_FUNCTION_FROMTEXT: /* we want to process a shape from WKT once and not for every feature being evaluated */ - if((token = msyylex()) != 40) { /* ( */ - msSetError(MS_PARSEERR, "Parsing fromText function failed.", "msTokenizeExpression()"); - free(node); - goto parse_error; - } + switch (token) { + case MS_TOKEN_LITERAL_BOOLEAN: + case MS_TOKEN_LITERAL_NUMBER: + node->token = token; + node->tokenval.dblval = msyynumber; + break; + case MS_TOKEN_LITERAL_STRING: + node->token = token; + node->tokenval.strval = msStrdup(msyystring_buffer); + break; + case MS_TOKEN_LITERAL_TIME: + node->tokensrc = msStrdup(msyystring_buffer); + node->token = token; + msTimeInit(&(node->tokenval.tmval)); + if (msParseTime(msyystring_buffer, &(node->tokenval.tmval)) != MS_TRUE) { + msSetError(MS_PARSEERR, "Parsing time value failed.", + "msTokenizeExpression()"); + free(node); + goto parse_error; + } + break; + case MS_TOKEN_BINDING_DOUBLE: /* we've encountered an attribute (binding) + reference */ + case MS_TOKEN_BINDING_INTEGER: + case MS_TOKEN_BINDING_STRING: + case MS_TOKEN_BINDING_TIME: + node->token = token; /* binding type */ + node->tokenval.bindval.item = msStrdup(msyystring_buffer); + if (list) + node->tokenval.bindval.index = + string2list(list, listsize, msyystring_buffer); + break; + case MS_TOKEN_BINDING_SHAPE: + node->token = token; + break; + case MS_TOKEN_BINDING_MAP_CELLSIZE: + node->token = token; + break; + case MS_TOKEN_BINDING_DATA_CELLSIZE: + node->token = token; + break; + case MS_TOKEN_FUNCTION_FROMTEXT: /* we want to process a shape from WKT once + and not for every feature being + evaluated */ + if ((token = msyylex()) != 40) { /* ( */ + msSetError(MS_PARSEERR, "Parsing fromText function failed.", + "msTokenizeExpression()"); + free(node); + goto parse_error; + } - if((token = msyylex()) != MS_TOKEN_LITERAL_STRING) { - msSetError(MS_PARSEERR, "Parsing fromText function failed.", "msTokenizeExpression()"); - free(node); - goto parse_error; - } + if ((token = msyylex()) != MS_TOKEN_LITERAL_STRING) { + msSetError(MS_PARSEERR, "Parsing fromText function failed.", + "msTokenizeExpression()"); + free(node); + goto parse_error; + } - node->token = MS_TOKEN_LITERAL_SHAPE; - node->tokenval.shpval = msShapeFromWKT(msyystring_buffer); + node->token = MS_TOKEN_LITERAL_SHAPE; + node->tokenval.shpval = msShapeFromWKT(msyystring_buffer); - if(!node->tokenval.shpval) { - msSetError(MS_PARSEERR, "Parsing fromText function failed, WKT processing failed.", "msTokenizeExpression()"); - free(node); - goto parse_error; - } + if (!node->tokenval.shpval) { + msSetError(MS_PARSEERR, + "Parsing fromText function failed, WKT processing failed.", + "msTokenizeExpression()"); + free(node); + goto parse_error; + } - /* todo: perhaps process optional args (e.g. projection) */ + /* todo: perhaps process optional args (e.g. projection) */ - if((token = msyylex()) != 41) { /* ) */ - msSetError(MS_PARSEERR, "Parsing fromText function failed.", "msTokenizeExpression()"); - msFreeShape(node->tokenval.shpval); - free(node->tokenval.shpval); - free(node); - goto parse_error; - } - break; - default: - node->token = token; /* for everything else */ - break; + if ((token = msyylex()) != 41) { /* ) */ + msSetError(MS_PARSEERR, "Parsing fromText function failed.", + "msTokenizeExpression()"); + msFreeShape(node->tokenval.shpval); + free(node->tokenval.shpval); + free(node); + goto parse_error; + } + break; + default: + node->token = token; /* for everything else */ + break; } /* add node to token list */ - if(expression->tokens == NULL) { + if (expression->tokens == NULL) { expression->tokens = node; } else { - if(expression->tokens->tailifhead != NULL) /* this should never be NULL, but just in case */ - expression->tokens->tailifhead->next = node; /* put the node at the end of the list */ + if (expression->tokens->tailifhead != + NULL) /* this should never be NULL, but just in case */ + expression->tokens->tailifhead->next = + node; /* put the node at the end of the list */ } /* repoint the head of the list to the end - our new element @@ -792,114 +881,166 @@ int msTokenizeExpression(expressionObj *expression, char **list, int *listsize) return MS_FAILURE; } - -static void buildLayerItemList(layerObj *layer) -{ +static void buildLayerItemList(layerObj *layer) { int i, j, k, l; /* - ** build layer item list, compute item indexes for explicity item references (e.g. classitem) or item bindings + ** build layer item list, compute item indexes for explicity item references + *(e.g. classitem) or item bindings */ /* layer items */ - if(layer->classitem) layer->classitemindex = string2list(layer->items, &(layer->numitems), layer->classitem); - if(layer->filteritem) layer->filteritemindex = string2list(layer->items, &(layer->numitems), layer->filteritem); - if(layer->styleitem && (strcasecmp(layer->styleitem, "AUTO") != 0) && (strncasecmp(layer->styleitem, "javascript://",13) != 0)) - layer->styleitemindex = string2list(layer->items, &(layer->numitems), layer->styleitem); - if(layer->labelitem) layer->labelitemindex = string2list(layer->items, &(layer->numitems), layer->labelitem); - if(layer->utfitem) layer->utfitemindex = string2list(layer->items, &(layer->numitems), layer->utfitem); + if (layer->classitem) + layer->classitemindex = + string2list(layer->items, &(layer->numitems), layer->classitem); + if (layer->filteritem) + layer->filteritemindex = + string2list(layer->items, &(layer->numitems), layer->filteritem); + if (layer->styleitem && (strcasecmp(layer->styleitem, "AUTO") != 0) && + (strncasecmp(layer->styleitem, "javascript://", 13) != 0)) + layer->styleitemindex = + string2list(layer->items, &(layer->numitems), layer->styleitem); + if (layer->labelitem) + layer->labelitemindex = + string2list(layer->items, &(layer->numitems), layer->labelitem); + if (layer->utfitem) + layer->utfitemindex = + string2list(layer->items, &(layer->numitems), layer->utfitem); /* layer classes */ - for(i=0; inumclasses; i++) { - - if(layer->class[i]->expression.type == MS_EXPRESSION) /* class expression */ - msTokenizeExpression(&(layer->class[i]->expression), layer->items, &(layer->numitems)); + for (i = 0; i < layer->numclasses; i++) { + + if (layer->class[i] -> expression.type == + MS_EXPRESSION) /* class expression */ + msTokenizeExpression(&(layer->class[i] -> expression), layer->items, + &(layer->numitems)); /* class styles (items, bindings, geomtransform) */ - for(j=0; jclass[i]->numstyles; j++) { - if(layer->class[i]->styles[j]->rangeitem) - layer->class[i]->styles[j]->rangeitemindex = string2list(layer->items, &(layer->numitems), layer->class[i]->styles[j]->rangeitem); - for(k=0; kclass[i]->styles[j]->bindings[k].item) - layer->class[i]->styles[j]->bindings[k].index = string2list(layer->items, &(layer->numitems), layer->class[i]->styles[j]->bindings[k].item); - if (layer->class[i]->styles[j]->exprBindings[k].type == MS_EXPRESSION) - { + for (j = 0; j < layer->class[i] -> numstyles; j++) { + if (layer->class[i] -> styles[j] -> rangeitem) + layer->class[i]->styles[j]->rangeitemindex = + string2list(layer->items, &(layer->numitems), + layer->class[i] -> styles[j] -> rangeitem); + for (k = 0; k < MS_STYLE_BINDING_LENGTH; k++) { + if (layer->class[i] -> styles[j] -> bindings[k].item) + layer->class[i]->styles[j]->bindings[k].index = + string2list(layer->items, &(layer->numitems), + layer->class[i] -> styles[j] -> bindings[k].item); + if (layer->class[i] -> styles[j] -> exprBindings[k].type == + MS_EXPRESSION) { msTokenizeExpression( - &(layer->class[i]->styles[j]->exprBindings[k]), - layer->items, &(layer->numitems)); + &(layer->class[i] -> styles[j] -> exprBindings[k]), layer->items, + &(layer->numitems)); } } - if(layer->class[i]->styles[j]->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) - msTokenizeExpression(&(layer->class[i]->styles[j]->_geomtransform), layer->items, &(layer->numitems)); + if (layer->class[i] -> styles[j] -> _geomtransform.type == + MS_GEOMTRANSFORM_EXPRESSION) + msTokenizeExpression(&(layer->class[i] -> styles[j] -> _geomtransform), + layer->items, &(layer->numitems)); } /* class labels and label styles (items, bindings, geomtransform) */ - for(l=0; lclass[i]->numlabels; l++) { - for(j=0; jclass[i]->labels[l]->numstyles; j++) { - if(layer->class[i]->labels[l]->styles[j]->rangeitem) - layer->class[i]->labels[l]->styles[j]->rangeitemindex = string2list(layer->items, &(layer->numitems), layer->class[i]->labels[l]->styles[j]->rangeitem); - for(k=0; kclass[i]->labels[l]->styles[j]->bindings[k].item) - layer->class[i]->labels[l]->styles[j]->bindings[k].index = string2list(layer->items, &(layer->numitems), layer->class[i]->labels[l]->styles[j]->bindings[k].item); - if(layer->class[i]->labels[l]->styles[j]->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) - msTokenizeExpression(&(layer->class[i]->labels[l]->styles[j]->_geomtransform), layer->items, &(layer->numitems)); + for (l = 0; l < layer->class[i] -> numlabels; l++) { + for (j = 0; j < layer->class[i] -> labels[l] -> numstyles; j++) { + if (layer->class[i] -> labels[l] -> styles[j] -> rangeitem) + layer->class[i]->labels[l]->styles[j]->rangeitemindex = string2list( + layer->items, &(layer->numitems), + layer->class[i] -> labels[l] -> styles[j] -> rangeitem); + for (k = 0; k < MS_STYLE_BINDING_LENGTH; k++) { + if (layer->class[i] -> labels[l] -> styles[j] -> bindings[k].item) + layer->class[i]->labels[l]->styles[j]->bindings[k].index = + string2list(layer->items, &(layer->numitems), + layer->class[i] -> labels[l] -> styles[j] + -> bindings[k].item); + if (layer->class[i] -> labels[l] -> styles[j] + -> _geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) + msTokenizeExpression( + &(layer->class[i] -> labels[l] -> styles[j] -> _geomtransform), + layer->items, &(layer->numitems)); } } - for(k=0; kclass[i]->labels[l]->bindings[k].item) - layer->class[i]->labels[l]->bindings[k].index = string2list(layer->items, &(layer->numitems), layer->class[i]->labels[l]->bindings[k].item); - if (layer->class[i]->labels[l]->exprBindings[k].type == MS_EXPRESSION) - { + for (k = 0; k < MS_LABEL_BINDING_LENGTH; k++) { + if (layer->class[i] -> labels[l] -> bindings[k].item) + layer->class[i]->labels[l]->bindings[k].index = + string2list(layer->items, &(layer->numitems), + layer->class[i] -> labels[l] -> bindings[k].item); + if (layer->class[i] -> labels[l] -> exprBindings[k].type == + MS_EXPRESSION) { msTokenizeExpression( - &(layer->class[i]->labels[l]->exprBindings[k]), - layer->items, &(layer->numitems)); + &(layer->class[i] -> labels[l] -> exprBindings[k]), layer->items, + &(layer->numitems)); } } - /* label expression */ - if(layer->class[i]->labels[l]->expression.type == MS_EXPRESSION) msTokenizeExpression(&(layer->class[i]->labels[l]->expression), layer->items, &(layer->numitems)); + /* label expression */ + if (layer->class[i] -> labels[l] -> expression.type == MS_EXPRESSION) + msTokenizeExpression(&(layer->class[i] -> labels[l] -> expression), + layer->items, &(layer->numitems)); /* label text */ - if(layer->class[i]->labels[l]->text.type == MS_EXPRESSION || (layer->class[i]->labels[l]->text.string && strchr(layer->class[i]->labels[l]->text.string,'[') != NULL && strchr(layer->class[i]->labels[l]->text.string,']') != NULL)) - msTokenizeExpression(&(layer->class[i]->labels[l]->text), layer->items, &(layer->numitems)); + if (layer->class[i] -> labels[l] + -> text.type == MS_EXPRESSION || + (layer->class[i] -> labels[l] + -> text.string &&strchr( + layer->class[i] -> labels[l] -> text.string, '[') != + NULL && + strchr(layer->class[i] -> labels[l] -> text.string, + ']') != NULL)) + msTokenizeExpression(&(layer->class[i] -> labels[l] -> text), + layer->items, &(layer->numitems)); } /* class text */ - if(layer->class[i]->text.type == MS_EXPRESSION || (layer->class[i]->text.string && strchr(layer->class[i]->text.string,'[') != NULL && strchr(layer->class[i]->text.string,']') != NULL)) - msTokenizeExpression(&(layer->class[i]->text), layer->items, &(layer->numitems)); + if (layer->class[i] + -> text.type == MS_EXPRESSION || + (layer->class[i] + -> text.string &&strchr(layer->class[i] -> text.string, '[') != + NULL && + strchr(layer->class[i] -> text.string, ']') != NULL)) + msTokenizeExpression(&(layer->class[i] -> text), layer->items, + &(layer->numitems)); } /* layer filter */ - if(layer->filter.type == MS_EXPRESSION) msTokenizeExpression(&(layer->filter), layer->items, &(layer->numitems)); + if (layer->filter.type == MS_EXPRESSION) + msTokenizeExpression(&(layer->filter), layer->items, &(layer->numitems)); /* cluster expressions */ - if(layer->cluster.group.type == MS_EXPRESSION) msTokenizeExpression(&(layer->cluster.group), layer->items, &(layer->numitems)); - if(layer->cluster.filter.type == MS_EXPRESSION) msTokenizeExpression(&(layer->cluster.filter), layer->items, &(layer->numitems)); + if (layer->cluster.group.type == MS_EXPRESSION) + msTokenizeExpression(&(layer->cluster.group), layer->items, + &(layer->numitems)); + if (layer->cluster.filter.type == MS_EXPRESSION) + msTokenizeExpression(&(layer->cluster.filter), layer->items, + &(layer->numitems)); /* utfdata */ - if(layer->utfdata.type == MS_EXPRESSION || (layer->utfdata.string && strchr(layer->utfdata.string,'[') != NULL && strchr(layer->utfdata.string,']') != NULL)) { + if (layer->utfdata.type == MS_EXPRESSION || + (layer->utfdata.string && strchr(layer->utfdata.string, '[') != NULL && + strchr(layer->utfdata.string, ']') != NULL)) { msTokenizeExpression(&(layer->utfdata), layer->items, &(layer->numitems)); } } /* -** This function builds a list of items necessary to draw or query a particular layer by -** examining the contents of the various xxxxitem parameters and expressions. That list is +** This function builds a list of items necessary to draw or query a particular +*layer by +** examining the contents of the various xxxxitem parameters and expressions. +*That list is ** then used to set the iteminfo variable. */ -int msLayerWhichItems(layerObj *layer, int get_all, const char *metadata) -{ +int msLayerWhichItems(layerObj *layer, int get_all, const char *metadata) { int i, j, k, l, rv; - int nt=0; + int nt = 0; if (!layer->vtable) { - rv = msInitializeVirtualTable(layer); - if (rv != MS_SUCCESS) return rv; + rv = msInitializeVirtualTable(layer); + if (rv != MS_SUCCESS) + return rv; } cppcheck_assert(layer->vtable); /* Cleanup any previous item selection */ msLayerFreeItemInfo(layer); - if(layer->items) { + if (layer->items) { msFreeCharArray(layer->items, layer->numitems); layer->items = NULL; layer->numitems = 0; @@ -916,130 +1057,163 @@ int msLayerWhichItems(layerObj *layer, int get_all, const char *metadata) layer->labelitemindex = -1; layer->utfitemindex = -1; - if(layer->classitem) nt++; - if(layer->filteritem) nt++; - if(layer->styleitem && - (strcasecmp(layer->styleitem, "AUTO") != 0) && - (strncasecmp(layer->styleitem, "javascript://", 13) != 0)) nt++; - - if(layer->filter.type == MS_EXPRESSION) + if (layer->classitem) + nt++; + if (layer->filteritem) + nt++; + if (layer->styleitem && (strcasecmp(layer->styleitem, "AUTO") != 0) && + (strncasecmp(layer->styleitem, "javascript://", 13) != 0)) + nt++; + + if (layer->filter.type == MS_EXPRESSION) nt += msCountChars(layer->filter.string, '['); - if(layer->cluster.group.type == MS_EXPRESSION) + if (layer->cluster.group.type == MS_EXPRESSION) nt += msCountChars(layer->cluster.group.string, '['); - if(layer->cluster.filter.type == MS_EXPRESSION) + if (layer->cluster.filter.type == MS_EXPRESSION) nt += msCountChars(layer->cluster.filter.string, '['); - if(layer->labelitem) nt++; - if(layer->utfitem) nt++; + if (layer->labelitem) + nt++; + if (layer->utfitem) + nt++; - if(layer->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) - msTokenizeExpression(&layer->_geomtransform, layer->items, &(layer->numitems)); + if (layer->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) + msTokenizeExpression(&layer->_geomtransform, layer->items, + &(layer->numitems)); /* class level counts */ - for(i=0; inumclasses; i++) { + for (i = 0; i < layer->numclasses; i++) { - for(j=0; jclass[i]->numstyles; j++) { - if(layer->class[i]->styles[j]->rangeitem) nt++; + for (j = 0; j < layer->class[i] -> numstyles; j++) { + if (layer->class[i] -> styles[j] -> rangeitem) + nt++; nt += layer->class[i]->styles[j]->numbindings; - if(layer->class[i]->styles[j]->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) - nt += msCountChars(layer->class[i]->styles[j]->_geomtransform.string, '['); - for(k=0; kclass[i]->styles[j]->exprBindings[k].type == MS_EXPRESSION) - { - nt += msCountChars(layer->class[i]->styles[j]->exprBindings[k].string, '['); + if (layer->class[i] -> styles[j] -> _geomtransform.type == + MS_GEOMTRANSFORM_EXPRESSION) + nt += msCountChars( + layer->class[i] -> styles[j] -> _geomtransform.string, '['); + for (k = 0; k < MS_STYLE_BINDING_LENGTH; k++) { + if (layer->class[i] -> styles[j] -> exprBindings[k].type == + MS_EXPRESSION) { + nt += msCountChars( + layer->class[i] -> styles[j] -> exprBindings[k].string, '['); } } } - if(layer->class[i]->expression.type == MS_EXPRESSION) - nt += msCountChars(layer->class[i]->expression.string, '['); + if (layer->class[i] -> expression.type == MS_EXPRESSION) + nt += msCountChars(layer->class[i] -> expression.string, '['); - for(l=0; lclass[i]->numlabels; l++) { + for (l = 0; l < layer->class[i] -> numlabels; l++) { nt += layer->class[i]->labels[l]->numbindings; - for(j=0; jclass[i]->labels[l]->numstyles; j++) { - if(layer->class[i]->labels[l]->styles[j]->rangeitem) nt++; + for (j = 0; j < layer->class[i] -> labels[l] -> numstyles; j++) { + if (layer->class[i] -> labels[l] -> styles[j] -> rangeitem) + nt++; nt += layer->class[i]->labels[l]->styles[j]->numbindings; - if(layer->class[i]->labels[l]->styles[j]->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) - nt += msCountChars(layer->class[i]->labels[l]->styles[j]->_geomtransform.string, '['); + if (layer->class[i] -> labels[l] -> styles[j] + -> _geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) + nt += msCountChars(layer->class[i] -> labels[l] -> styles[j] + -> _geomtransform.string, + '['); } - for(k=0; kclass[i]->labels[l]->exprBindings[k].type == MS_EXPRESSION) - { - nt += msCountChars(layer->class[i]->labels[l]->exprBindings[k].string, '['); + for (k = 0; k < MS_LABEL_BINDING_LENGTH; k++) { + if (layer->class[i] -> labels[l] -> exprBindings[k].type == + MS_EXPRESSION) { + nt += msCountChars( + layer->class[i] -> labels[l] -> exprBindings[k].string, '['); } } - if(layer->class[i]->labels[l]->expression.type == MS_EXPRESSION) - nt += msCountChars(layer->class[i]->labels[l]->expression.string, '['); - if(layer->class[i]->labels[l]->text.type == MS_EXPRESSION || (layer->class[i]->labels[l]->text.string && strchr(layer->class[i]->labels[l]->text.string,'[') != NULL && strchr(layer->class[i]->labels[l]->text.string,']') != NULL)) - nt += msCountChars(layer->class[i]->labels[l]->text.string, '['); + if (layer->class[i] -> labels[l] -> expression.type == MS_EXPRESSION) + nt += msCountChars(layer->class[i] -> labels[l] -> expression.string, + '['); + if (layer->class[i] -> labels[l] + -> text.type == MS_EXPRESSION || + (layer->class[i] -> labels[l] + -> text.string &&strchr( + layer->class[i] -> labels[l] -> text.string, '[') != + NULL && + strchr(layer->class[i] -> labels[l] -> text.string, + ']') != NULL)) + nt += msCountChars(layer->class[i] -> labels[l] -> text.string, '['); } - if(layer->class[i]->text.type == MS_EXPRESSION || (layer->class[i]->text.string && strchr(layer->class[i]->text.string,'[') != NULL && strchr(layer->class[i]->text.string,']') != NULL)) - nt += msCountChars(layer->class[i]->text.string, '['); + if (layer->class[i] + -> text.type == MS_EXPRESSION || + (layer->class[i] + -> text.string &&strchr(layer->class[i] -> text.string, '[') != + NULL && + strchr(layer->class[i] -> text.string, ']') != NULL)) + nt += msCountChars(layer->class[i] -> text.string, '['); } /* utfgrid count */ - if(layer->utfdata.type == MS_EXPRESSION || (layer->utfdata.string && strchr(layer->utfdata.string,'[') != NULL && strchr(layer->utfdata.string,']') != NULL)) + if (layer->utfdata.type == MS_EXPRESSION || + (layer->utfdata.string && strchr(layer->utfdata.string, '[') != NULL && + strchr(layer->utfdata.string, ']') != NULL)) nt += msCountChars(layer->utfdata.string, '['); - // if we are using a GetMap request with a WMS filter we don't need to return all items + // if we are using a GetMap request with a WMS filter we don't need to return + // all items if (msOWSLookupMetadata(&(layer->metadata), "G", "wmsfilter_flag") != NULL) { - get_all = MS_FALSE; + get_all = MS_FALSE; } - if(metadata == NULL){ - // check item set by mapwfs.cpp to restrict the number of columns selected - metadata = msOWSLookupMetadata(&(layer->metadata), "G", "select_items"); - if (metadata) { - /* get only selected items */ - get_all = MS_FALSE; - } + if (metadata == NULL) { + // check item set by mapwfs.cpp to restrict the number of columns selected + metadata = msOWSLookupMetadata(&(layer->metadata), "G", "select_items"); + if (metadata) { + /* get only selected items */ + get_all = MS_FALSE; + } } /* always retrieve all items in some cases */ - if(layer->connectiontype == MS_INLINE || - (layer->map->outputformat && layer->map->outputformat->renderer == MS_RENDER_WITH_KML)) { + if (layer->connectiontype == MS_INLINE || + (layer->map->outputformat && + layer->map->outputformat->renderer == MS_RENDER_WITH_KML)) { get_all = MS_TRUE; } /* ** allocate space for the item list (worse case size) */ - if( get_all ) { + if (get_all) { rv = msLayerGetItems(layer); - if(nt > 0) /* need to realloc the array to accept the possible new items*/ - layer->items = (char **)msSmallRealloc(layer->items, sizeof(char *)*(layer->numitems + nt)); + if (nt > 0) /* need to realloc the array to accept the possible new items*/ + layer->items = (char **)msSmallRealloc( + layer->items, sizeof(char *) * (layer->numitems + nt)); } else { rv = layer->vtable->LayerCreateItems(layer, nt); } - if(rv != MS_SUCCESS) + if (rv != MS_SUCCESS) return rv; buildLayerItemList(layer); - if(metadata) { + if (metadata) { char **tokens; int n = 0; int j; tokens = msStringSplit(metadata, ',', &n); - if(tokens) { - for(i=0; inumitems; j++) { - if(strcasecmp(tokens[i], layer->items[j]) == 0) { + for (j = 0; j < layer->numitems; j++) { + if (strcasecmp(tokens[i], layer->items[j]) == 0) { bFound = 1; break; } } - if(!bFound) { + if (!bFound) { layer->numitems++; - layer->items = (char **)msSmallRealloc(layer->items, sizeof(char *)*(layer->numitems)); - layer->items[layer->numitems-1] = msStrdup(tokens[i]); + layer->items = (char **)msSmallRealloc( + layer->items, sizeof(char *) * (layer->numitems)); + layer->items[layer->numitems - 1] = msStrdup(tokens[i]); } } msFreeCharArray(tokens, n); @@ -1049,99 +1223,93 @@ int msLayerWhichItems(layerObj *layer, int get_all, const char *metadata) /* order of the layer->items array is consistent with it. This is */ /* important so that WFS DescribeFeatureType and GetFeature requests */ /* return items in the same order */ - if( !get_all && layer->numitems ) { - char** unsorted_items = layer->items; - int numitems = layer->numitems; - - /* Retrieve all items */ - layer->items = NULL; - layer->numitems = 0; - rv = msLayerGetItems(layer); - if( rv != MS_SUCCESS ) { - msFreeCharArray(unsorted_items, numitems); - return rv; - } + if (!get_all && layer->numitems) { + char **unsorted_items = layer->items; + int numitems = layer->numitems; + + /* Retrieve all items */ + layer->items = NULL; + layer->numitems = 0; + rv = msLayerGetItems(layer); + if (rv != MS_SUCCESS) { + msFreeCharArray(unsorted_items, numitems); + return rv; + } - /* Sort unsorted_items in the order of layer->items */ - char** sorted_items = (char **)msSmallMalloc(sizeof(char*) * numitems); - int num_sorted_items = 0; - for( i = 0; i < layer->numitems; i++ ) - { - if( layer->items[i] ) - { - for( j = 0; j < numitems; j++ ) - { - if( unsorted_items[j] && - strcasecmp(layer->items[i], unsorted_items[j]) == 0 ) - { - sorted_items[num_sorted_items] = layer->items[i]; - num_sorted_items ++; - - layer->items[i] = NULL; - msFree(unsorted_items[j]); - unsorted_items[j] = NULL; - break; - } - } + /* Sort unsorted_items in the order of layer->items */ + char **sorted_items = (char **)msSmallMalloc(sizeof(char *) * numitems); + int num_sorted_items = 0; + for (i = 0; i < layer->numitems; i++) { + if (layer->items[i]) { + for (j = 0; j < numitems; j++) { + if (unsorted_items[j] && + strcasecmp(layer->items[i], unsorted_items[j]) == 0) { + sorted_items[num_sorted_items] = layer->items[i]; + num_sorted_items++; + + layer->items[i] = NULL; + msFree(unsorted_items[j]); + unsorted_items[j] = NULL; + break; } + } } + } - /* Add items that are not returned by msLayerGetItems() (not sure if that can happen) */ - for( j = 0; j < numitems; j++ ) - { - if( unsorted_items[j] ) - { - sorted_items[num_sorted_items] = unsorted_items[j]; - num_sorted_items ++; - } + /* Add items that are not returned by msLayerGetItems() (not sure if that + * can happen) */ + for (j = 0; j < numitems; j++) { + if (unsorted_items[j]) { + sorted_items[num_sorted_items] = unsorted_items[j]; + num_sorted_items++; } + } - if(layer->numitems > 0) { - msFreeCharArray(layer->items, layer->numitems); - } - msFreeCharArray(unsorted_items, numitems); + if (layer->numitems > 0) { + msFreeCharArray(layer->items, layer->numitems); + } + msFreeCharArray(unsorted_items, numitems); - layer->items = sorted_items; - layer->numitems = numitems; + layer->items = sorted_items; + layer->numitems = numitems; - /* Re-run buildLayerItemList() with the now correctly sorted items */ - buildLayerItemList(layer); + /* Re-run buildLayerItemList() with the now correctly sorted items */ + buildLayerItemList(layer); } - } /* populate the iteminfo array */ - if(layer->numitems == 0) - return(MS_SUCCESS); + if (layer->numitems == 0) + return (MS_SUCCESS); - return(msLayerInitItemInfo(layer)); + return (msLayerInitItemInfo(layer)); } /* -** A helper function to set the items to be retrieved with a particular shape. Unused at the moment but will be used +** A helper function to set the items to be retrieved with a particular shape. +*Unused at the moment but will be used ** from within MapScript. Should not need modification. */ -int msLayerSetItems(layerObj *layer, char **items, int numitems) -{ +int msLayerSetItems(layerObj *layer, char **items, int numitems) { int i; /* Cleanup any previous item selection */ msLayerFreeItemInfo(layer); - if(layer->items) { + if (layer->items) { msFreeCharArray(layer->items, layer->numitems); layer->items = NULL; layer->numitems = 0; } /* now allocate and set the layer item parameters */ - layer->items = (char **)malloc(sizeof(char *)*numitems); - MS_CHECK_ALLOC(layer->items, sizeof(char *)*numitems, MS_FAILURE); + layer->items = (char **)malloc(sizeof(char *) * numitems); + MS_CHECK_ALLOC(layer->items, sizeof(char *) * numitems, MS_FAILURE); - for(i=0; iitems[i] = msStrdup(items[i]); layer->numitems = numitems; /* populate the iteminfo array */ - return(msLayerInitItemInfo(layer)); + return (msLayerInitItemInfo(layer)); } /* @@ -1152,10 +1320,10 @@ int msLayerSetItems(layerObj *layer, char **items, int numitems) ** twice. ** */ -int msLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj* shape) -{ - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); +int msLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, + shapeObj *shape) { + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } @@ -1168,37 +1336,38 @@ int msLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj* sha ** with STYLEITEM "attribute" when rendering shapes. ** */ -int msLayerGetFeatureStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj* shape) -{ - char* stylestring = NULL; - if (layer->styleitem && layer->styleitemindex >=0) { +int msLayerGetFeatureStyle(mapObj *map, layerObj *layer, classObj *c, + shapeObj *shape) { + char *stylestring = NULL; + if (layer->styleitem && layer->styleitemindex >= 0) { stylestring = msStrdup(shape->values[layer->styleitemindex]); - } - else if (layer->styleitem && strncasecmp(layer->styleitem,"javascript://",13) == 0) { + } else if (layer->styleitem && + strncasecmp(layer->styleitem, "javascript://", 13) == 0) { #ifdef USE_V8_MAPSCRIPT - char *filename = layer->styleitem+13; + char *filename = layer->styleitem + 13; if (!map->v8context) { msV8CreateContext(map); - if (!map->v8context) - { - msSetError(MS_V8ERR, "Unable to create v8 context.", "msLayerGetFeatureStyle()"); + if (!map->v8context) { + msSetError(MS_V8ERR, "Unable to create v8 context.", + "msLayerGetFeatureStyle()"); return MS_FAILURE; } } if (*filename == '\0') { - msSetError(MS_V8ERR, "Invalid javascript filename: \"%s\".", "msLayerGetFeatureStyle()", layer->styleitem); + msSetError(MS_V8ERR, "Invalid javascript filename: \"%s\".", + "msLayerGetFeatureStyle()", layer->styleitem); return MS_FAILURE; } - + stylestring = msV8GetFeatureStyle(map, filename, layer, shape); #else - msSetError(MS_V8ERR, "V8 Javascript support is not available.", "msLayerGetFeatureStyle()"); - return MS_FAILURE; + msSetError(MS_V8ERR, "V8 Javascript support is not available.", + "msLayerGetFeatureStyle()"); + return MS_FAILURE; #endif - } - else { /* unknown styleitem */ + } else { /* unknown styleitem */ return MS_FAILURE; } @@ -1206,32 +1375,36 @@ int msLayerGetFeatureStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj* if (!stylestring) return MS_FAILURE; - if (strncasecmp(stylestring,"style",5) == 0) { + if (strncasecmp(stylestring, "style", 5) == 0) { resetClassStyle(c); c->layer = layer; if (msMaybeAllocateClassStyle(c, 0)) { free(stylestring); - return(MS_FAILURE); + return (MS_FAILURE); } msUpdateStyleFromString(c->styles[0], stylestring); - if(c->styles[0]->symbolname) { - if((c->styles[0]->symbol = msGetSymbolIndex(&(map->symbolset), c->styles[0]->symbolname, MS_TRUE)) == -1) { - msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class of layer %s.", "msLayerGetFeatureStyle()", - c->styles[0]->symbolname, layer->name); + if (c->styles[0]->symbolname) { + if ((c->styles[0]->symbol = msGetSymbolIndex( + &(map->symbolset), c->styles[0]->symbolname, MS_TRUE)) == -1) { + msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class of layer %s.", + "msLayerGetFeatureStyle()", c->styles[0]->symbolname, + layer->name); free(stylestring); return MS_FAILURE; } } - } else if (strncasecmp(stylestring,"class",5) == 0) { + } else if (strncasecmp(stylestring, "class", 5) == 0) { if (strcasestr(stylestring, " style ") != NULL) { /* reset style if stylestring contains style definitions */ resetClassStyle(c); c->layer = layer; } msUpdateClassFromString(c, stylestring); - } else if (strncasecmp(stylestring,"pen",3) == 0 || strncasecmp(stylestring,"brush",5) == 0 || - strncasecmp(stylestring,"symbol",6) == 0 || strncasecmp(stylestring,"label",5) == 0) { + } else if (strncasecmp(stylestring, "pen", 3) == 0 || + strncasecmp(stylestring, "brush", 5) == 0 || + strncasecmp(stylestring, "symbol", 6) == 0 || + strncasecmp(stylestring, "label", 5) == 0) { msOGRUpdateStyleFromString(map, layer, c, stylestring); } else { resetClassStyle(c); @@ -1241,62 +1414,60 @@ int msLayerGetFeatureStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj* return MS_SUCCESS; } - /* Returns the number of inline feature of a layer */ -int msLayerGetNumFeatures(layerObj *layer) -{ - int need_to_close = MS_FALSE, result = -1; +int msLayerGetNumFeatures(layerObj *layer) { + int need_to_close = MS_FALSE, result = -1; - if (!msLayerIsOpen(layer)) { - if (msLayerOpen(layer) != MS_SUCCESS) - return result; - need_to_close = MS_TRUE; - } + if (!msLayerIsOpen(layer)) { + if (msLayerOpen(layer) != MS_SUCCESS) + return result; + need_to_close = MS_TRUE; + } - if (!layer->vtable) { - int rv = msInitializeVirtualTable(layer); - if (rv != MS_SUCCESS) - return result; - } - cppcheck_assert(layer->vtable); + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); + if (rv != MS_SUCCESS) + return result; + } + cppcheck_assert(layer->vtable); - result = layer->vtable->LayerGetNumFeatures(layer); + result = layer->vtable->LayerGetNumFeatures(layer); - if (need_to_close) - msLayerClose(layer); + if (need_to_close) + msLayerClose(layer); - return(result); + return (result); } -void -msLayerSetProcessingKey( layerObj *layer, const char *key, const char *value) +void msLayerSetProcessingKey(layerObj *layer, const char *key, + const char *value) { int len = strlen(key); int i; char *directive = NULL; - if( value != NULL ) { - directive = (char *) msSmallMalloc(strlen(key)+strlen(value)+2); - sprintf( directive, "%s=%s", key, value ); + if (value != NULL) { + directive = (char *)msSmallMalloc(strlen(key) + strlen(value) + 2); + sprintf(directive, "%s=%s", key, value); } - for( i = 0; i < layer->numprocessing; i++ ) { - if( strncasecmp( key, layer->processing[i], len ) == 0 - && layer->processing[i][len] == '=' ) { - free( layer->processing[i] ); + for (i = 0; i < layer->numprocessing; i++) { + if (strncasecmp(key, layer->processing[i], len) == 0 && + layer->processing[i][len] == '=') { + free(layer->processing[i]); /* ** Either replace the existing entry with a new one or ** clear the entry. */ - if( directive != NULL ) + if (directive != NULL) layer->processing[i] = directive; else { - layer->processing[i] = layer->processing[layer->numprocessing-1]; - layer->processing[layer->numprocessing-1] = NULL; + layer->processing[i] = layer->processing[layer->numprocessing - 1]; + layer->processing[layer->numprocessing - 1] = NULL; layer->numprocessing--; } return; @@ -1305,55 +1476,56 @@ msLayerSetProcessingKey( layerObj *layer, const char *key, const char *value) /* otherwise add the directive at the end. */ - if( directive != NULL ) { - msLayerAddProcessing( layer, directive ); - free( directive ); + if (directive != NULL) { + msLayerAddProcessing(layer, directive); + free(directive); } } -void msLayerSubstituteProcessing( layerObj *layer, const char *from, const char *to ) { +void msLayerSubstituteProcessing(layerObj *layer, const char *from, + const char *to) { int i; - for( i = 0; i < layer->numprocessing; i++ ) { - layer->processing[i] = msCaseReplaceSubstring(layer->processing[i], from, to); + for (i = 0; i < layer->numprocessing; i++) { + layer->processing[i] = + msCaseReplaceSubstring(layer->processing[i], from, to); } } -void msLayerAddProcessing( layerObj *layer, const char *directive ) +void msLayerAddProcessing(layerObj *layer, const char *directive) { layer->numprocessing++; - if( layer->numprocessing == 1 ) - layer->processing = (char **) msSmallMalloc(2*sizeof(char *)); + if (layer->numprocessing == 1) + layer->processing = (char **)msSmallMalloc(2 * sizeof(char *)); else - layer->processing = (char **) msSmallRealloc(layer->processing, sizeof(char*) * (layer->numprocessing+1) ); - layer->processing[layer->numprocessing-1] = msStrdup(directive); + layer->processing = (char **)msSmallRealloc( + layer->processing, sizeof(char *) * (layer->numprocessing + 1)); + layer->processing[layer->numprocessing - 1] = msStrdup(directive); layer->processing[layer->numprocessing] = NULL; } -const char *msLayerGetProcessing( const layerObj *layer, int proc_index) -{ +const char *msLayerGetProcessing(const layerObj *layer, int proc_index) { if (proc_index < 0 || proc_index >= layer->numprocessing) { - msSetError(MS_CHILDERR, "Invalid processing index.", "msLayerGetProcessing()"); + msSetError(MS_CHILDERR, "Invalid processing index.", + "msLayerGetProcessing()"); return NULL; } else { return layer->processing[proc_index]; } } -const char *msLayerGetProcessingKey( const layerObj *layer, const char *key ) -{ +const char *msLayerGetProcessingKey(const layerObj *layer, const char *key) { int i, len = strlen(key); - for( i = 0; i < layer->numprocessing; i++ ) { - if( strncasecmp(layer->processing[i],key,len) == 0 - && layer->processing[i][len] == '=' ) + for (i = 0; i < layer->numprocessing; i++) { + if (strncasecmp(layer->processing[i], key, len) == 0 && + layer->processing[i][len] == '=') return layer->processing[i] + len + 1; } return NULL; } - /************************************************************************/ /* msLayerGetMaxFeaturesToDraw */ /* */ @@ -1361,8 +1533,7 @@ const char *msLayerGetProcessingKey( const layerObj *layer, const char *key ) /* output format option. Used for vector layers to limit the */ /* number of fatures rendered. */ /************************************************************************/ -int msLayerGetMaxFeaturesToDraw(layerObj *layer, outputFormatObj *format) -{ +int msLayerGetMaxFeaturesToDraw(layerObj *layer, outputFormatObj *format) { int nMaxFeatures = -1; const char *pszTmp = NULL; if (layer) { @@ -1371,39 +1542,34 @@ int msLayerGetMaxFeaturesToDraw(layerObj *layer, outputFormatObj *format) if (pszTmp) nMaxFeatures = atoi(pszTmp); else { - pszTmp = msLookupHashTable(&layer->map->web.metadata, "maxfeaturestodraw"); + pszTmp = + msLookupHashTable(&layer->map->web.metadata, "maxfeaturestodraw"); if (pszTmp) nMaxFeatures = atoi(pszTmp); } } - if(format) { + if (format) { if (nMaxFeatures < 0) - nMaxFeatures = atoi(msGetOutputFormatOption( format, "maxfeaturestodraw", "-1")); + nMaxFeatures = + atoi(msGetOutputFormatOption(format, "maxfeaturestodraw", "-1")); } return nMaxFeatures; - } -int msLayerClearProcessing( layerObj *layer ) -{ +int msLayerClearProcessing(layerObj *layer) { if (layer->numprocessing > 0) { - msFreeCharArray( layer->processing, layer->numprocessing ); + msFreeCharArray(layer->processing, layer->numprocessing); layer->processing = NULL; layer->numprocessing = 0; } return layer->numprocessing; } - -int -makeTimeFilter(layerObj *lp, - const char *timestring, - const char *timefield, - const int addtimebacktics) -{ +int makeTimeFilter(layerObj *lp, const char *timestring, const char *timefield, + const int addtimebacktics) { char **atimes, **tokens = NULL; - int numtimes,i, ntmp = 0; + int numtimes, i, ntmp = 0; char *pszBuffer = NULL; int bOnlyExistingFilter = 0; @@ -1426,22 +1592,22 @@ makeTimeFilter(layerObj *lp, /* if the filter is set and it's a sting type, concatenate it with the time. If not just free it */ if (lp->filter.string && lp->filter.type == MS_STRING) { - pszBuffer = msStringConcatenate(pszBuffer, "(("); - pszBuffer = msStringConcatenate(pszBuffer, lp->filter.string); - pszBuffer = msStringConcatenate(pszBuffer, ") and "); + pszBuffer = msStringConcatenate(pszBuffer, "(("); + pszBuffer = msStringConcatenate(pszBuffer, lp->filter.string); + pszBuffer = msStringConcatenate(pszBuffer, ") and "); } else if (lp->filter.string && lp->filter.type == MS_EXPRESSION) { - char* pszExpressionString = msGetExpressionString(&(lp->filter)); - pszBuffer = msStringConcatenate(pszBuffer, "("); - pszBuffer = msStringConcatenate(pszBuffer, pszExpressionString); - pszBuffer = msStringConcatenate(pszBuffer, " and "); - msFree(pszExpressionString); + char *pszExpressionString = msGetExpressionString(&(lp->filter)); + pszBuffer = msStringConcatenate(pszBuffer, "("); + pszBuffer = msStringConcatenate(pszBuffer, pszExpressionString); + pszBuffer = msStringConcatenate(pszBuffer, " and "); + msFree(pszExpressionString); } else { - msFreeExpression(&lp->filter); + msFreeExpression(&lp->filter); } pszBuffer = msStringConcatenate(pszBuffer, "("); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); if (addtimebacktics) pszBuffer = msStringConcatenate(pszBuffer, "["); @@ -1449,29 +1615,28 @@ makeTimeFilter(layerObj *lp, if (addtimebacktics) pszBuffer = msStringConcatenate(pszBuffer, "]"); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); - + pszBuffer = msStringConcatenate(pszBuffer, "`"); pszBuffer = msStringConcatenate(pszBuffer, " = "); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); else - pszBuffer = msStringConcatenate(pszBuffer, "'"); + pszBuffer = msStringConcatenate(pszBuffer, "'"); pszBuffer = msStringConcatenate(pszBuffer, (char *)timestring); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); else - pszBuffer = msStringConcatenate(pszBuffer, "'"); + pszBuffer = msStringConcatenate(pszBuffer, "'"); pszBuffer = msStringConcatenate(pszBuffer, ")"); - /* if there was a filter, It was concatenate with an And ans should be closed*/ + /* if there was a filter, It was concatenate with an And ans should be + * closed*/ if (lp->filter.string && - (lp->filter.type == MS_STRING || lp->filter.type == MS_EXPRESSION)) + (lp->filter.type == MS_STRING || lp->filter.type == MS_EXPRESSION)) pszBuffer = msStringConcatenate(pszBuffer, ")"); - msLoadExpressionString(&lp->filter, pszBuffer); if (pszBuffer) @@ -1481,7 +1646,7 @@ makeTimeFilter(layerObj *lp, atimes = msStringSplit(timestring, ',', &numtimes); if (atimes == NULL || numtimes < 1) { - msFreeCharArray(atimes,numtimes); + msFreeCharArray(atimes, numtimes); return MS_FALSE; } @@ -1494,7 +1659,7 @@ makeTimeFilter(layerObj *lp, added to the buffer */ bOnlyExistingFilter = 1; } else if (lp->filter.string && lp->filter.type == MS_EXPRESSION) { - char* pszExpressionString = msGetExpressionString(&(lp->filter)); + char *pszExpressionString = msGetExpressionString(&(lp->filter)); pszBuffer = msStringConcatenate(pszBuffer, "("); pszBuffer = msStringConcatenate(pszBuffer, pszExpressionString); pszBuffer = msStringConcatenate(pszBuffer, " and "); @@ -1504,11 +1669,11 @@ makeTimeFilter(layerObj *lp, msFreeExpression(&lp->filter); /* check to see if we have ranges by parsing the first entry */ - tokens = msStringSplit(atimes[0], '/', &ntmp); + tokens = msStringSplit(atimes[0], '/', &ntmp); if (ntmp == 2) { /* ranges */ msFreeCharArray(tokens, ntmp); - for (i=0; i 0 && bOnlyExistingFilter == 0) pszBuffer = msStringConcatenate(pszBuffer, " OR "); @@ -1519,7 +1684,7 @@ makeTimeFilter(layerObj *lp, pszBuffer = msStringConcatenate(pszBuffer, "("); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); if (addtimebacktics) pszBuffer = msStringConcatenate(pszBuffer, "["); @@ -1528,23 +1693,23 @@ makeTimeFilter(layerObj *lp, pszBuffer = msStringConcatenate(pszBuffer, "]"); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); pszBuffer = msStringConcatenate(pszBuffer, " >= "); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); else - pszBuffer = msStringConcatenate(pszBuffer, "'"); + pszBuffer = msStringConcatenate(pszBuffer, "'"); pszBuffer = msStringConcatenate(pszBuffer, tokens[0]); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); else - pszBuffer = msStringConcatenate(pszBuffer, "'"); + pszBuffer = msStringConcatenate(pszBuffer, "'"); pszBuffer = msStringConcatenate(pszBuffer, " AND "); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); if (addtimebacktics) pszBuffer = msStringConcatenate(pszBuffer, "["); @@ -1552,19 +1717,19 @@ makeTimeFilter(layerObj *lp, if (addtimebacktics) pszBuffer = msStringConcatenate(pszBuffer, "]"); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); pszBuffer = msStringConcatenate(pszBuffer, " <= "); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); else - pszBuffer = msStringConcatenate(pszBuffer, "'"); + pszBuffer = msStringConcatenate(pszBuffer, "'"); pszBuffer = msStringConcatenate(pszBuffer, tokens[1]); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); else - pszBuffer = msStringConcatenate(pszBuffer, "'"); + pszBuffer = msStringConcatenate(pszBuffer, "'"); pszBuffer = msStringConcatenate(pszBuffer, ")"); } @@ -1575,7 +1740,7 @@ makeTimeFilter(layerObj *lp, } else if (ntmp == 1) { /* multiple times */ msFreeCharArray(tokens, ntmp); pszBuffer = msStringConcatenate(pszBuffer, "("); - for (i=0; i 0) pszBuffer = msStringConcatenate(pszBuffer, " OR "); @@ -1597,12 +1762,12 @@ makeTimeFilter(layerObj *lp, if (addtimebacktics) pszBuffer = msStringConcatenate(pszBuffer, "`"); else - pszBuffer = msStringConcatenate(pszBuffer, "'"); + pszBuffer = msStringConcatenate(pszBuffer, "'"); pszBuffer = msStringConcatenate(pszBuffer, atimes[i]); if (addtimebacktics) - pszBuffer = msStringConcatenate(pszBuffer, "`"); + pszBuffer = msStringConcatenate(pszBuffer, "`"); else - pszBuffer = msStringConcatenate(pszBuffer, "'"); + pszBuffer = msStringConcatenate(pszBuffer, "'"); pszBuffer = msStringConcatenate(pszBuffer, ")"); } pszBuffer = msStringConcatenate(pszBuffer, ")"); @@ -1617,7 +1782,8 @@ makeTimeFilter(layerObj *lp, /* load the string to the filter */ if (pszBuffer && strlen(pszBuffer) > 0) { - if(lp->filter.string && (lp->filter.type == MS_STRING || lp->filter.type == MS_EXPRESSION )) + if (lp->filter.string && + (lp->filter.type == MS_STRING || lp->filter.type == MS_EXPRESSION)) pszBuffer = msStringConcatenate(pszBuffer, ")"); /* if(lp->filteritem) @@ -1626,7 +1792,6 @@ makeTimeFilter(layerObj *lp, */ msLoadExpressionString(&lp->filter, pszBuffer); - } msFree(pszBuffer); return MS_TRUE; @@ -1637,10 +1802,9 @@ makeTimeFilter(layerObj *lp, **/ int msLayerSetTimeFilter(layerObj *layer, const char *timestring, - const char *timefield) -{ - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); + const char *timefield) { + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } @@ -1648,141 +1812,124 @@ int msLayerSetTimeFilter(layerObj *layer, const char *timestring, return layer->vtable->LayerSetTimeFilter(layer, timestring, timefield); } -int -msLayerMakeBackticsTimeFilter(layerObj *lp, const char *timestring, - const char *timefield) -{ +int msLayerMakeBackticsTimeFilter(layerObj *lp, const char *timestring, + const char *timefield) { return makeTimeFilter(lp, timestring, timefield, MS_TRUE); } -int -msLayerMakePlainTimeFilter(layerObj *lp, const char *timestring, - const char *timefield) -{ +int msLayerMakePlainTimeFilter(layerObj *lp, const char *timestring, + const char *timefield) { return makeTimeFilter(lp, timestring, timefield, MS_FALSE); } - /* * Dummies / default actions for layers */ -int LayerDefaultInitItemInfo(layerObj *layer) -{ +int LayerDefaultInitItemInfo(layerObj *layer) { (void)layer; return MS_SUCCESS; } -void LayerDefaultFreeItemInfo(layerObj *layer) -{ - (void)layer; -} +void LayerDefaultFreeItemInfo(layerObj *layer) { (void)layer; } -int LayerDefaultOpen(layerObj *layer) -{ +int LayerDefaultOpen(layerObj *layer) { (void)layer; return MS_FAILURE; } -int LayerDefaultIsOpen(layerObj *layer) -{ +int LayerDefaultIsOpen(layerObj *layer) { (void)layer; return MS_FALSE; } -int LayerDefaultWhichShapes(layerObj *layer, rectObj rect, int isQuery) -{ +int LayerDefaultWhichShapes(layerObj *layer, rectObj rect, int isQuery) { (void)layer; (void)rect; (void)isQuery; return MS_SUCCESS; } -int LayerDefaultNextShape(layerObj *layer, shapeObj *shape) -{ +int LayerDefaultNextShape(layerObj *layer, shapeObj *shape) { (void)layer; (void)shape; return MS_FAILURE; } -int LayerDefaultGetShape(layerObj *layer, shapeObj *shape, resultObj *record) -{ +int LayerDefaultGetShape(layerObj *layer, shapeObj *shape, resultObj *record) { (void)layer; (void)shape; (void)record; return MS_FAILURE; } -int LayerDefaultGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rectProjection) -{ +int LayerDefaultGetShapeCount(layerObj *layer, rectObj rect, + projectionObj *rectProjection) { int status; shapeObj shape, searchshape; int nShapeCount = 0; rectObj searchrect = rect; - reprojectionObj* reprojector = NULL; + reprojectionObj *reprojector = NULL; msInitShape(&searchshape); msRectToPolygon(searchrect, &searchshape); - if( rectProjection != NULL ) - { - if(layer->project && msProjectionsDiffer(&(layer->projection), rectProjection)) - msProjectRect(rectProjection, &(layer->projection), &searchrect); /* project the searchrect to source coords */ + if (rectProjection != NULL) { + if (layer->project && + msProjectionsDiffer(&(layer->projection), rectProjection)) + msProjectRect(rectProjection, &(layer->projection), + &searchrect); /* project the searchrect to source coords */ else layer->project = MS_FALSE; } - status = msLayerWhichShapes(layer, searchrect, MS_TRUE) ; - if( status == MS_FAILURE ) - { + status = msLayerWhichShapes(layer, searchrect, MS_TRUE); + if (status == MS_FAILURE) { msFreeShape(&searchshape); return -1; - } - else if( status == MS_DONE ) - { + } else if (status == MS_DONE) { msFreeShape(&searchshape); return 0; } msInitShape(&shape); - while((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) - { - if( rectProjection != NULL ) - { - if(layer->project && msProjectionsDiffer(&(layer->projection), rectProjection)) - { - if( reprojector == NULL ) - reprojector = msProjectCreateReprojector(&(layer->projection), rectProjection); - if( reprojector ) - msProjectShapeEx(reprojector, &shape); - } - else + while ((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) { + if (rectProjection != NULL) { + if (layer->project && + msProjectionsDiffer(&(layer->projection), rectProjection)) { + if (reprojector == NULL) + reprojector = + msProjectCreateReprojector(&(layer->projection), rectProjection); + if (reprojector) + msProjectShapeEx(reprojector, &shape); + } else layer->project = MS_FALSE; - if(msRectContained(&shape.bounds, &rect) == MS_TRUE) { /* if the whole shape is in, don't intersect */ + if (msRectContained(&shape.bounds, &rect) == + MS_TRUE) { /* if the whole shape is in, don't intersect */ status = MS_TRUE; } else { - switch(shape.type) { /* make sure shape actually intersects the qrect (ADD FUNCTIONS SPECIFIC TO RECTOBJ) */ - case MS_SHAPE_POINT: - status = msIntersectMultipointPolygon(&shape, &searchshape); - break; - case MS_SHAPE_LINE: - status = msIntersectPolylinePolygon(&shape, &searchshape); - break; - case MS_SHAPE_POLYGON: - status = msIntersectPolygons(&shape, &searchshape); - break; - default: - break; + switch (shape.type) { /* make sure shape actually intersects the qrect + (ADD FUNCTIONS SPECIFIC TO RECTOBJ) */ + case MS_SHAPE_POINT: + status = msIntersectMultipointPolygon(&shape, &searchshape); + break; + case MS_SHAPE_LINE: + status = msIntersectPolylinePolygon(&shape, &searchshape); + break; + case MS_SHAPE_POLYGON: + status = msIntersectPolygons(&shape, &searchshape); + break; + default: + break; } } - } - else + } else status = MS_TRUE; - if( status == MS_TRUE ) - nShapeCount++ ; + if (status == MS_TRUE) + nShapeCount++; msFreeShape(&shape); - if(layer->maxfeatures > 0 && layer->maxfeatures == nShapeCount) + if (layer->maxfeatures > 0 && layer->maxfeatures == nShapeCount) break; } @@ -1792,48 +1939,46 @@ int LayerDefaultGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rect return nShapeCount; } -int LayerDefaultClose(layerObj *layer) -{ +int LayerDefaultClose(layerObj *layer) { (void)layer; return MS_SUCCESS; } -int LayerDefaultGetItems(layerObj *layer) -{ +int LayerDefaultGetItems(layerObj *layer) { (void)layer; return MS_SUCCESS; /* returning no items is legit */ } -int -msLayerApplyCondSQLFilterToLayer(FilterEncodingNode *psNode, mapObj *map, - int iLayerIndex) -{ +int msLayerApplyCondSQLFilterToLayer(FilterEncodingNode *psNode, mapObj *map, + int iLayerIndex) { return FLTLayerApplyCondSQLFilterToLayer(psNode, map, iLayerIndex); } -int msLayerSupportsPaging(layerObj *layer) -{ - if (layer && - ((layer->connectiontype == MS_ORACLESPATIAL) || - (layer->connectiontype == MS_POSTGIS)) ) +int msLayerSupportsPaging(layerObj *layer) { + if (layer && ((layer->connectiontype == MS_ORACLESPATIAL) || + (layer->connectiontype == MS_POSTGIS))) return MS_TRUE; return MS_FALSE; } -int msLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, int iLayerIndex); +int msLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, + int iLayerIndex); /* * msLayerSupportsSorting() * * Returns MS_TRUE if the layer supports sorting/ordering. */ -int msLayerSupportsSorting(layerObj *layer) -{ - if (layer && ( - (layer->connectiontype == MS_OGR) || (layer->connectiontype == MS_POSTGIS) || (layer->connectiontype == MS_ORACLESPATIAL) || ((layer->connectiontype == MS_PLUGIN) && (strstr(layer->plugin_library,"msplugin_oracle") != NULL)) || ((layer->connectiontype == MS_PLUGIN) && (strstr(layer->plugin_library,"msplugin_mssql2008") != NULL)) - ) - ) +int msLayerSupportsSorting(layerObj *layer) { + if (layer && + ((layer->connectiontype == MS_OGR) || + (layer->connectiontype == MS_POSTGIS) || + (layer->connectiontype == MS_ORACLESPATIAL) || + ((layer->connectiontype == MS_PLUGIN) && + (strstr(layer->plugin_library, "msplugin_oracle") != NULL)) || + ((layer->connectiontype == MS_PLUGIN) && + (strstr(layer->plugin_library, "msplugin_mssql2008") != NULL)))) return MS_TRUE; return MS_FALSE; @@ -1844,20 +1989,20 @@ int msLayerSupportsSorting(layerObj *layer) * * Copy the sortBy clause passed as an argument into the layer sortBy member. */ -void msLayerSetSort(layerObj *layer, const sortByClause* sortBy) -{ +void msLayerSetSort(layerObj *layer, const sortByClause *sortBy) { int i; - for(i=0;isortBy.nProperties;i++) + for (i = 0; i < layer->sortBy.nProperties; i++) msFree(layer->sortBy.properties[i].item); msFree(layer->sortBy.properties); layer->sortBy.nProperties = sortBy->nProperties; - layer->sortBy.properties = (sortByProperties*) msSmallMalloc(sortBy->nProperties * sizeof(sortByProperties)); - for(i=0;isortBy.nProperties;i++) { + layer->sortBy.properties = (sortByProperties *)msSmallMalloc( + sortBy->nProperties * sizeof(sortByProperties)); + for (i = 0; i < layer->sortBy.nProperties; i++) { layer->sortBy.properties[i].item = msStrdup(sortBy->properties[i].item); layer->sortBy.properties[i].sortOrder = sortBy->properties[i].sortOrder; } - } +} /* * msLayerBuildSQLOrderBy() @@ -1865,17 +2010,17 @@ void msLayerSetSort(layerObj *layer, const sortByClause* sortBy) * Returns the content of a SQL ORDER BY clause from the sortBy member of * the layer. The string does not contain the "ORDER BY" keywords itself. */ -char* msLayerBuildSQLOrderBy(layerObj *layer) -{ - char* strOrderBy = NULL; - if( layer->sortBy.nProperties > 0 ) { +char *msLayerBuildSQLOrderBy(layerObj *layer) { + char *strOrderBy = NULL; + if (layer->sortBy.nProperties > 0) { int i; - for(i=0;isortBy.nProperties;i++) { - char* escaped = msLayerEscapePropertyName(layer, layer->sortBy.properties[i].item); - if( i > 0 ) + for (i = 0; i < layer->sortBy.nProperties; i++) { + char *escaped = + msLayerEscapePropertyName(layer, layer->sortBy.properties[i].item); + if (i > 0) strOrderBy = msStringConcatenate(strOrderBy, ", "); strOrderBy = msStringConcatenate(strOrderBy, escaped); - if( layer->sortBy.properties[i].sortOrder == SORT_DESC ) + if (layer->sortBy.properties[i].sortOrder == SORT_DESC) strOrderBy = msStringConcatenate(strOrderBy, " DESC"); msFree(escaped); } @@ -1883,18 +2028,17 @@ char* msLayerBuildSQLOrderBy(layerObj *layer) return strOrderBy; } -int -msLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, int iLayerIndex) -{ +int msLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, + int iLayerIndex) { return FLTLayerApplyPlainFilterToLayer(psNode, map, iLayerIndex); } -int msLayerGetPaging(layerObj *layer) -{ - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); +int msLayerGetPaging(layerObj *layer) { + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) { - msSetError(MS_MISCERR, "Unable to initialize virtual table", "msLayerGetPaging()"); + msSetError(MS_MISCERR, "Unable to initialize virtual table", + "msLayerGetPaging()"); return MS_FAILURE; } } @@ -1902,12 +2046,12 @@ int msLayerGetPaging(layerObj *layer) return layer->vtable->LayerGetPaging(layer); } -void msLayerEnablePaging(layerObj *layer, int value) -{ - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); +void msLayerEnablePaging(layerObj *layer, int value) { + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) { - msSetError(MS_MISCERR, "Unable to initialize virtual table", "msLayerEnablePaging()"); + msSetError(MS_MISCERR, "Unable to initialize virtual table", + "msLayerEnablePaging()"); return; } } @@ -1915,33 +2059,48 @@ void msLayerEnablePaging(layerObj *layer, int value) layer->vtable->LayerEnablePaging(layer, value); } -int LayerDefaultGetExtent(layerObj *layer, rectObj *extent) -{ +/** Returns a cached reprojector from the layer projection to the map projection + */ +reprojectionObj *msLayerGetReprojectorToMap(layerObj *layer, mapObj *map) { + if (layer->reprojectorLayerToMap != NULL && + !msProjectIsReprojectorStillValid(layer->reprojectorLayerToMap)) { + msProjectDestroyReprojector(layer->reprojectorLayerToMap); + layer->reprojectorLayerToMap = NULL; + } + + if (layer->reprojectorLayerToMap == NULL) { + layer->reprojectorLayerToMap = + msProjectCreateReprojector(&layer->projection, &map->projection); + } + return layer->reprojectorLayerToMap; +} + +int LayerDefaultGetExtent(layerObj *layer, rectObj *extent) { (void)layer; (void)extent; return MS_FAILURE; } -int LayerDefaultGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj *shape) -{ +int LayerDefaultGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, + shapeObj *shape) { (void)map; (void)layer; (void)c; (void)shape; - msSetError(MS_MISCERR, "'STYLEITEM AUTO' not supported for this data source.", "msLayerGetAutoStyle()"); + msSetError(MS_MISCERR, "'STYLEITEM AUTO' not supported for this data source.", + "msLayerGetAutoStyle()"); return MS_FAILURE; } -int LayerDefaultCloseConnection(layerObj *layer) -{ +int LayerDefaultCloseConnection(layerObj *layer) { (void)layer; return MS_SUCCESS; } -int LayerDefaultCreateItems(layerObj *layer, const int nt) -{ +int LayerDefaultCreateItems(layerObj *layer, const int nt) { if (nt > 0) { - layer->items = (char **)calloc(nt, sizeof(char *)); /* should be more than enough space */ + layer->items = (char **)calloc( + nt, sizeof(char *)); /* should be more than enough space */ MS_CHECK_ALLOC(layer->items, sizeof(char *), MS_FAILURE); layer->numitems = 0; @@ -1949,79 +2108,79 @@ int LayerDefaultCreateItems(layerObj *layer, const int nt) return MS_SUCCESS; } -int LayerDefaultGetNumFeatures(layerObj *layer) -{ - rectObj extent; - int status; - int result; - shapeObj shape; - - /* calculate layer extent */ - if (!MS_VALID_EXTENT(layer->extent)) { - if (msLayerGetExtent(layer, &extent) != MS_SUCCESS) { - msSetError(MS_MISCERR, "Unable to get layer extent", "LayerDefaultGetNumFeatures()"); - return -1; - } +int LayerDefaultGetNumFeatures(layerObj *layer) { + rectObj extent; + int status; + int result; + shapeObj shape; + + /* calculate layer extent */ + if (!MS_VALID_EXTENT(layer->extent)) { + if (msLayerGetExtent(layer, &extent) != MS_SUCCESS) { + msSetError(MS_MISCERR, "Unable to get layer extent", + "LayerDefaultGetNumFeatures()"); + return -1; } - else - extent = layer->extent; + } else + extent = layer->extent; - /* Cleanup any previous item selection */ - msLayerFreeItemInfo(layer); - if (layer->items) { - msFreeCharArray(layer->items, layer->numitems); - layer->items = NULL; - layer->numitems = 0; - } + /* Cleanup any previous item selection */ + msLayerFreeItemInfo(layer); + if (layer->items) { + msFreeCharArray(layer->items, layer->numitems); + layer->items = NULL; + layer->numitems = 0; + } - status = msLayerWhichShapes(layer, extent, MS_FALSE); - if (status == MS_DONE) { /* no overlap */ - return 0; - } - else if (status != MS_SUCCESS) { - return -1; - } + status = msLayerWhichShapes(layer, extent, MS_FALSE); + if (status == MS_DONE) { /* no overlap */ + return 0; + } else if (status != MS_SUCCESS) { + return -1; + } - result = 0; - while ((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) { - ++result; - } + result = 0; + while ((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) { + ++result; + msFreeShape(&shape); + } - return result; + return result; } -int LayerDefaultAutoProjection(layerObj *layer, projectionObj* projection) -{ +int LayerDefaultAutoProjection(layerObj *layer, projectionObj *projection) { (void)layer; (void)projection; - msSetError(MS_MISCERR, "This data driver does not implement AUTO projection support", "LayerDefaultAutoProjection()"); + msSetError(MS_MISCERR, + "This data driver does not implement AUTO projection support", + "LayerDefaultAutoProjection()"); return MS_FAILURE; } -int LayerDefaultSupportsCommonFilters(layerObj *layer) -{ +int LayerDefaultSupportsCommonFilters(layerObj *layer) { (void)layer; return MS_FALSE; } -int LayerDefaultTranslateFilter(layerObj *layer, expressionObj *filter, char *filteritem) -{ +int LayerDefaultTranslateFilter(layerObj *layer, expressionObj *filter, + char *filteritem) { (void)layer; (void)filteritem; - if(!filter->string) return MS_SUCCESS; /* nothing to do, not an error */ + if (!filter->string) + return MS_SUCCESS; /* nothing to do, not an error */ - msSetError(MS_MISCERR, "This data driver does not implement filter translation support", "LayerDefaultTranslateFilter()"); + msSetError(MS_MISCERR, + "This data driver does not implement filter translation support", + "LayerDefaultTranslateFilter()"); return MS_FAILURE; } -int msLayerDefaultGetPaging(layerObj *layer) -{ +int msLayerDefaultGetPaging(layerObj *layer) { (void)layer; return MS_FALSE; } -void msLayerDefaultEnablePaging(layerObj *layer, int value) -{ +void msLayerDefaultEnablePaging(layerObj *layer, int value) { (void)layer; (void)value; } @@ -2033,17 +2192,16 @@ void msLayerDefaultEnablePaging(layerObj *layer, int value) /* injection. Specific drivers should redefine if an escaping */ /* function is available in the driver. */ /************************************************************************/ -char *LayerDefaultEscapeSQLParam(layerObj *layer, const char* pszString) -{ +char *LayerDefaultEscapeSQLParam(layerObj *layer, const char *pszString) { (void)layer; - char *pszEscapedStr=NULL; + char *pszEscapedStr = NULL; if (pszString) { int nSrcLen; char c; - int i=0, j=0; + int i = 0, j = 0; nSrcLen = (int)strlen(pszString); - pszEscapedStr = (char*) msSmallMalloc( 2 * nSrcLen + 1); - for(i = 0, j = 0; i < nSrcLen; i++) { + pszEscapedStr = (char *)msSmallMalloc(2 * nSrcLen + 1); + for (i = 0, j = 0; i < nSrcLen; i++) { c = pszString[i]; if (c == '\'') { pszEscapedStr[j++] = '\''; @@ -2064,22 +2222,21 @@ char *LayerDefaultEscapeSQLParam(layerObj *layer, const char* pszString) /* */ /* Return the property name in a properly escaped and quoted form. */ /************************************************************************/ -char *LayerDefaultEscapePropertyName(layerObj *layer, const char* pszString) -{ - char* pszEscapedStr=NULL; +char *LayerDefaultEscapePropertyName(layerObj *layer, const char *pszString) { + char *pszEscapedStr = NULL; int i, j = 0; if (layer && pszString && strlen(pszString) > 0) { int nLength = strlen(pszString); - pszEscapedStr = (char*) msSmallMalloc( 1 + 2 * nLength + 1 + 1); + pszEscapedStr = (char *)msSmallMalloc(1 + 2 * nLength + 1 + 1); pszEscapedStr[j++] = '"'; - for (i=0; iconnectiontype = connectiontype; /* For internal types, library_str is ignored */ if (connectiontype == MS_PLUGIN) { int rv; - msFree(layer->plugin_library); - msFree(layer->plugin_library_original); + msFree(layer->plugin_library_original); layer->plugin_library_original = msStrdup(library_str); + rv = msBuildPluginLibraryPath(&layer->plugin_library, - layer->plugin_library_original, - layer->map); + layer->plugin_library_original, layer->map); if (rv != MS_SUCCESS) { return rv; } } - return msInitializeVirtualTable(layer) ; + return msInitializeVirtualTable(layer); } -static int populateVirtualTable(layerVTableObj *vtable) -{ +static int populateVirtualTable(layerVTableObj *vtable) { assert(vtable != NULL); vtable->LayerSupportsCommonFilters = LayerDefaultSupportsCommonFilters; @@ -2167,94 +2318,92 @@ static int populateVirtualTable(layerVTableObj *vtable) return MS_SUCCESS; } -static int createVirtualTable(layerVTableObj **vtable) -{ +static int createVirtualTable(layerVTableObj **vtable) { *vtable = malloc(sizeof(**vtable)); MS_CHECK_ALLOC(*vtable, sizeof(**vtable), MS_FAILURE); return populateVirtualTable(*vtable); } -static int destroyVirtualTable(layerVTableObj **vtable) -{ +static int destroyVirtualTable(layerVTableObj **vtable) { memset(*vtable, 0, sizeof(**vtable)); msFree(*vtable); *vtable = NULL; return MS_SUCCESS; } -int msInitializeVirtualTable(layerObj *layer) -{ +int msInitializeVirtualTable(layerObj *layer) { if (layer->vtable) { destroyVirtualTable(&layer->vtable); } createVirtualTable(&layer->vtable); - if(layer->features && layer->connectiontype != MS_GRATICULE ) + if (layer->features && layer->connectiontype != MS_GRATICULE) layer->connectiontype = MS_INLINE; - if(layer->tileindex && layer->connectiontype == MS_SHAPEFILE) + if (layer->tileindex && layer->connectiontype == MS_SHAPEFILE) layer->connectiontype = MS_TILED_SHAPEFILE; - if(layer->type == MS_LAYER_RASTER && layer->connectiontype != MS_WMS - && layer->connectiontype != MS_KERNELDENSITY) + if (layer->type == MS_LAYER_RASTER && layer->connectiontype != MS_WMS && + layer->connectiontype != MS_KERNELDENSITY) layer->connectiontype = MS_RASTER; - switch(layer->connectiontype) { - case(MS_INLINE): - return(msINLINELayerInitializeVirtualTable(layer)); - break; - case(MS_SHAPEFILE): - return(msSHPLayerInitializeVirtualTable(layer)); - break; - case(MS_TILED_SHAPEFILE): - return(msTiledSHPLayerInitializeVirtualTable(layer)); - break; - case(MS_OGR): - return(msOGRLayerInitializeVirtualTable(layer)); - break; - case(MS_FLATGEOBUF): - return(msFlatGeobufLayerInitializeVirtualTable(layer)); - break; - case(MS_POSTGIS): - return(msPostGISLayerInitializeVirtualTable(layer)); - break; - case(MS_WMS): - /* WMS should be treated as a raster layer */ - return(msRASTERLayerInitializeVirtualTable(layer)); - break; - case(MS_KERNELDENSITY): - /* KERNELDENSITY should be treated as a raster layer */ - return(msRASTERLayerInitializeVirtualTable(layer)); - break; - case(MS_ORACLESPATIAL): - return(msOracleSpatialLayerInitializeVirtualTable(layer)); - break; - case(MS_WFS): - return(msWFSLayerInitializeVirtualTable(layer)); - break; - case(MS_GRATICULE): - return(msGraticuleLayerInitializeVirtualTable(layer)); - break; - case(MS_RASTER): - return(msRASTERLayerInitializeVirtualTable(layer)); - break; - case(MS_PLUGIN): - return(msPluginLayerInitializeVirtualTable(layer)); - break; - case(MS_UNION): - return(msUnionLayerInitializeVirtualTable(layer)); - break; - case(MS_UVRASTER): - return(msUVRASTERLayerInitializeVirtualTable(layer)); - break; - case(MS_CONTOUR): - return(msContourLayerInitializeVirtualTable(layer)); - break; - default: - msSetError(MS_MISCERR, "Unknown connectiontype, it was %d", "msInitializeVirtualTable()", layer->connectiontype); - return MS_FAILURE; - break; + switch (layer->connectiontype) { + case (MS_INLINE): + return (msINLINELayerInitializeVirtualTable(layer)); + break; + case (MS_SHAPEFILE): + return (msSHPLayerInitializeVirtualTable(layer)); + break; + case (MS_TILED_SHAPEFILE): + return (msTiledSHPLayerInitializeVirtualTable(layer)); + break; + case (MS_OGR): + return (msOGRLayerInitializeVirtualTable(layer)); + break; + case (MS_FLATGEOBUF): + return (msFlatGeobufLayerInitializeVirtualTable(layer)); + break; + case (MS_POSTGIS): + return (msPostGISLayerInitializeVirtualTable(layer)); + break; + case (MS_WMS): + /* WMS should be treated as a raster layer */ + return (msRASTERLayerInitializeVirtualTable(layer)); + break; + case (MS_KERNELDENSITY): + /* KERNELDENSITY should be treated as a raster layer */ + return (msRASTERLayerInitializeVirtualTable(layer)); + break; + case (MS_ORACLESPATIAL): + return (msOracleSpatialLayerInitializeVirtualTable(layer)); + break; + case (MS_WFS): + return (msWFSLayerInitializeVirtualTable(layer)); + break; + case (MS_GRATICULE): + return (msGraticuleLayerInitializeVirtualTable(layer)); + break; + case (MS_RASTER): + return (msRASTERLayerInitializeVirtualTable(layer)); + break; + case (MS_PLUGIN): + return (msPluginLayerInitializeVirtualTable(layer)); + break; + case (MS_UNION): + return (msUnionLayerInitializeVirtualTable(layer)); + break; + case (MS_UVRASTER): + return (msUVRASTERLayerInitializeVirtualTable(layer)); + break; + case (MS_CONTOUR): + return (msContourLayerInitializeVirtualTable(layer)); + break; + default: + msSetError(MS_MISCERR, "Unknown connectiontype, it was %d", + "msInitializeVirtualTable()", layer->connectiontype); + return MS_FAILURE; + break; } /* not reached */ @@ -2268,53 +2417,49 @@ int msInitializeVirtualTable(layerObj *layer) typedef struct { rectObj searchrect; int is_relative; /* relative coordinates? */ -} -msINLINELayerInfo; +} msINLINELayerInfo; -int msINLINELayerIsOpen(layerObj *layer) -{ +int msINLINELayerIsOpen(layerObj *layer) { if (layer->layerinfo) - return(MS_TRUE); + return (MS_TRUE); else - return(MS_FALSE); + return (MS_FALSE); } -msINLINELayerInfo *msINLINECreateLayerInfo(void) -{ +msINLINELayerInfo *msINLINECreateLayerInfo(void) { msINLINELayerInfo *layerinfo = msSmallMalloc(sizeof(msINLINELayerInfo)); layerinfo->searchrect.minx = -1.0; layerinfo->searchrect.miny = -1.0; layerinfo->searchrect.maxx = -1.0; layerinfo->searchrect.maxy = -1.0; layerinfo->is_relative = MS_FALSE; - return layerinfo; + return layerinfo; } -int msINLINELayerOpen(layerObj *layer) -{ - msINLINELayerInfo *layerinfo; +int msINLINELayerOpen(layerObj *layer) { + msINLINELayerInfo *layerinfo; if (layer->layerinfo) { if (layer->debug) { msDebug("msINLINELayerOpen: Layer is already open!\n"); } - return MS_SUCCESS; /* already open */ + return MS_SUCCESS; /* already open */ } - + /* ** Initialize the layerinfo **/ layerinfo = msINLINECreateLayerInfo(); - - layer->currentfeature = layer->features; /* point to the begining of the feature list */ - layer->layerinfo = (void*)layerinfo; - - return(MS_SUCCESS); + layer->currentfeature = + layer->features; /* point to the begining of the feature list */ + + layer->layerinfo = (void *)layerinfo; + + return (MS_SUCCESS); } -int msINLINELayerClose(layerObj *layer) -{ +int msINLINELayerClose(layerObj *layer) { if (layer->layerinfo) { free(layer->layerinfo); layer->layerinfo = NULL; @@ -2323,43 +2468,47 @@ int msINLINELayerClose(layerObj *layer) return MS_SUCCESS; } -int msINLINELayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) -{ +int msINLINELayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) { (void)isQuery; - msINLINELayerInfo *layerinfo = NULL; - layerinfo = (msINLINELayerInfo*) layer->layerinfo; + msINLINELayerInfo *layerinfo = NULL; + layerinfo = (msINLINELayerInfo *)layer->layerinfo; layerinfo->searchrect = rect; - layerinfo->is_relative = (layer->transform != MS_FALSE && layer->transform != MS_TRUE); - + layerinfo->is_relative = + (layer->transform != MS_FALSE && layer->transform != MS_TRUE); + return MS_SUCCESS; } /* Author: Cristoph Spoerri and Sean Gillies */ -int msINLINELayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) -{ - int i=0; +int msINLINELayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) { + int i = 0; featureListNodeObjPtr current; int shapeindex = record->shapeindex; /* only index necessary */ current = layer->features; - while (current!=NULL && i!=shapeindex) { + while (current != NULL && i != shapeindex) { i++; current = current->next; } if (current == NULL) { - msSetError(MS_SHPERR, "No inline feature with this index.", "msINLINELayerGetShape()"); + msSetError(MS_SHPERR, "No inline feature with this index.", + "msINLINELayerGetShape()"); return MS_FAILURE; } if (msCopyShape(&(current->shape), shape) != MS_SUCCESS) { - msSetError(MS_SHPERR, "Cannot retrieve inline shape. There some problem with the shape", "msINLINELayerGetShape()"); + msSetError( + MS_SHPERR, + "Cannot retrieve inline shape. There some problem with the shape", + "msINLINELayerGetShape()"); return MS_FAILURE; } /* check for the expected size of the values array */ if (layer->numitems > shape->numvalues) { - shape->values = (char **)msSmallRealloc(shape->values, sizeof(char *)*(layer->numitems)); + shape->values = (char **)msSmallRealloc(shape->values, + sizeof(char *) * (layer->numitems)); for (i = shape->numvalues; i < layer->numitems; i++) shape->values[i] = msStrdup(""); } @@ -2367,32 +2516,33 @@ int msINLINELayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) return MS_SUCCESS; } -int msINLINELayerNextShape(layerObj *layer, shapeObj *shape) -{ - msINLINELayerInfo *layerinfo = NULL; - shapeObj * s; - - layerinfo = (msINLINELayerInfo*) layer->layerinfo; - +int msINLINELayerNextShape(layerObj *layer, shapeObj *shape) { + msINLINELayerInfo *layerinfo = NULL; + shapeObj *s; + + layerinfo = (msINLINELayerInfo *)layer->layerinfo; + while (1) { - if( ! (layer->currentfeature)) { + if (!(layer->currentfeature)) { /* out of features */ - return(MS_DONE); + return (MS_DONE); } s = &(layer->currentfeature->shape); layer->currentfeature = layer->currentfeature->next; msComputeBounds(s); - if (layerinfo->is_relative || msRectOverlap(&s->bounds, &layerinfo->searchrect)) { - + if (layerinfo->is_relative || + msRectOverlap(&s->bounds, &layerinfo->searchrect)) { + msCopyShape(s, shape); /* check for the expected size of the values array */ if (layer->numitems > shape->numvalues) { int i; - shape->values = (char **)msSmallRealloc(shape->values, sizeof(char *)*(layer->numitems)); + shape->values = (char **)msSmallRealloc( + shape->values, sizeof(char *) * (layer->numitems)); for (i = shape->numvalues; i < layer->numitems; i++) shape->values[i] = msStrdup(""); shape->numvalues = layer->numitems; @@ -2400,14 +2550,12 @@ int msINLINELayerNextShape(layerObj *layer, shapeObj *shape) break; } - } - return(MS_SUCCESS); + return (MS_SUCCESS); } -int msINLINELayerGetNumFeatures(layerObj *layer) -{ +int msINLINELayerGetNumFeatures(layerObj *layer) { int i = 0; featureListNodeObjPtr current; @@ -2419,15 +2567,12 @@ int msINLINELayerGetNumFeatures(layerObj *layer) return i; } - - /* Returns an escaped string */ -char *msLayerEscapeSQLParam(layerObj *layer, const char*pszString) -{ - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); +char *msLayerEscapeSQLParam(layerObj *layer, const char *pszString) { + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return ""; } @@ -2435,10 +2580,9 @@ char *msLayerEscapeSQLParam(layerObj *layer, const char*pszString) return layer->vtable->LayerEscapeSQLParam(layer, pszString); } -char *msLayerEscapePropertyName(layerObj *layer, const char*pszString) -{ - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); +char *msLayerEscapePropertyName(layerObj *layer, const char *pszString) { + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return ""; } @@ -2446,10 +2590,7 @@ char *msLayerEscapePropertyName(layerObj *layer, const char*pszString) return layer->vtable->LayerEscapePropertyName(layer, pszString); } - -int -msINLINELayerInitializeVirtualTable(layerObj *layer) -{ +int msINLINELayerInitializeVirtualTable(layerObj *layer) { assert(layer != NULL); assert(layer->vtable != NULL); @@ -2487,5 +2628,3 @@ msINLINELayerInitializeVirtualTable(layerObj *layer) return MS_SUCCESS; } - - diff --git a/maplegend.c b/maplegend.c index 1f1b84533f..781c082b62 100644 --- a/maplegend.c +++ b/maplegend.c @@ -29,57 +29,51 @@ #include "mapserver.h" - - #define PSF .8 #define VMARGIN 5 /* margin at top and bottom of legend graphic */ #define HMARGIN 5 /* margin at left and right of legend graphic */ - -static int msDrawGradientSymbol(rendererVTableObj* renderer, - imageObj* image_draw, - double x_center, - double y_center, - int width, - int height, - styleObj* style) -{ - unsigned char *r,*g,*b,*a; - symbolObj symbol; - rasterBufferObj* rb; - symbolStyleObj symbolStyle; - int ret; - - initSymbol(&symbol); - rb = (rasterBufferObj*)calloc(1,sizeof(rasterBufferObj)); - symbol.pixmap_buffer = rb; - rb->type = MS_BUFFER_BYTE_RGBA; - rb->width = width; - rb->height = height; - rb->data.rgba.row_step = rb->width * 4; - rb->data.rgba.pixel_step = 4; - rb->data.rgba.pixels = (unsigned char*)malloc( - rb->width*rb->height*4*sizeof(unsigned char)); - b = rb->data.rgba.b = &rb->data.rgba.pixels[0]; - g = rb->data.rgba.g = &rb->data.rgba.pixels[1]; - r = rb->data.rgba.r = &rb->data.rgba.pixels[2]; - a = rb->data.rgba.a = &rb->data.rgba.pixels[3]; - for( unsigned j = 0; j < rb->height; j++ ) - { - for( unsigned i = 0; i < rb->width; i++ ) - { - msValueToRange(style, style->minvalue + - (double)i / rb->width * (style->maxvalue - style->minvalue), MS_COLORSPACE_RGB); - b[4*(j * rb->width + i)] = style->color.blue; - g[4*(j * rb->width + i)] = style->color.green; - r[4*(j * rb->width + i)] = style->color.red; - a[4*(j * rb->width + i)] = style->color.alpha; - } +static int msDrawGradientSymbol(rendererVTableObj *renderer, + imageObj *image_draw, double x_center, + double y_center, int width, int height, + styleObj *style) { + unsigned char *r, *g, *b, *a; + symbolObj symbol; + rasterBufferObj *rb; + symbolStyleObj symbolStyle; + int ret; + + initSymbol(&symbol); + rb = (rasterBufferObj *)calloc(1, sizeof(rasterBufferObj)); + symbol.pixmap_buffer = rb; + rb->type = MS_BUFFER_BYTE_RGBA; + rb->width = width; + rb->height = height; + rb->data.rgba.row_step = rb->width * 4; + rb->data.rgba.pixel_step = 4; + rb->data.rgba.pixels = (unsigned char *)malloc(rb->width * rb->height * 4 * + sizeof(unsigned char)); + b = rb->data.rgba.b = &rb->data.rgba.pixels[0]; + g = rb->data.rgba.g = &rb->data.rgba.pixels[1]; + r = rb->data.rgba.r = &rb->data.rgba.pixels[2]; + a = rb->data.rgba.a = &rb->data.rgba.pixels[3]; + for (unsigned j = 0; j < rb->height; j++) { + for (unsigned i = 0; i < rb->width; i++) { + msValueToRange(style, + style->minvalue + (double)i / rb->width * + (style->maxvalue - style->minvalue), + MS_COLORSPACE_RGB); + b[4 * (j * rb->width + i)] = style->color.blue; + g[4 * (j * rb->width + i)] = style->color.green; + r[4 * (j * rb->width + i)] = style->color.red; + a[4 * (j * rb->width + i)] = style->color.alpha; } - INIT_SYMBOL_STYLE(symbolStyle); - ret = renderer->renderPixmapSymbol(image_draw, x_center, y_center, &symbol, &symbolStyle); - msFreeSymbol(&symbol); - return ret; + } + INIT_SYMBOL_STYLE(symbolStyle); + ret = renderer->renderPixmapSymbol(image_draw, x_center, y_center, &symbol, + &symbolStyle); + msFreeSymbol(&symbol); + return ret; } /* @@ -87,78 +81,84 @@ static int msDrawGradientSymbol(rendererVTableObj* renderer, * renderer specific drawing functions shouldn't be called directly, but through * this function */ -int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass, - int width, int height, imageObj *image, int dstX, int dstY, - int scale_independant, class_hittest *hittest) -{ - int i, type, hasmarkersymbol, ret=MS_SUCCESS; +int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass, int width, + int height, imageObj *image, int dstX, int dstY, + int scale_independant, class_hittest *hittest) { + int i, type, hasmarkersymbol, ret = MS_SUCCESS; double offset; - double polygon_contraction = 0.5; /* used to account for the width of a polygon's outline */ + double polygon_contraction = + 0.5; /* used to account for the width of a polygon's outline */ shapeObj box, zigzag; - lineObj box_line,zigzag_line; + lineObj box_line, zigzag_line; pointObj box_point[5], zigzag_point[4]; pointObj marker; char szPath[MS_MAXPATHLEN]; styleObj outline_style; imageObj *image_draw = image; rendererVTableObj *renderer; - outputFormatObj *transFormat = NULL, *altFormat=NULL; + outputFormatObj *transFormat = NULL, *altFormat = NULL; const char *alternativeFormatString = NULL; - if(!MS_RENDERER_PLUGIN(image->format)) { - msSetError(MS_MISCERR,"unsupported image format","msDrawLegendIcon()"); + if (!MS_RENDERER_PLUGIN(image->format)) { + msSetError(MS_MISCERR, "unsupported image format", "msDrawLegendIcon()"); return MS_FAILURE; } alternativeFormatString = msLayerGetProcessingKey(lp, "RENDERER"); - if (MS_RENDERER_PLUGIN(image_draw->format) && alternativeFormatString!=NULL && - (altFormat= msSelectOutputFormat(map, alternativeFormatString))) { + if (MS_RENDERER_PLUGIN(image_draw->format) && + alternativeFormatString != NULL && + (altFormat = msSelectOutputFormat(map, alternativeFormatString))) { msInitializeRendererVTable(altFormat); - image_draw = msImageCreate(image->width, image->height, - altFormat, image->imagepath, image->imageurl, map->resolution, map->defresolution, &map->imagecolor); + image_draw = msImageCreate( + image->width, image->height, altFormat, image->imagepath, + image->imageurl, map->resolution, map->defresolution, &map->imagecolor); image_draw->map = map; renderer = MS_IMAGE_RENDERER(image_draw); } else { renderer = MS_IMAGE_RENDERER(image_draw); if (lp->compositer && renderer->compositeRasterBuffer) { - image_draw = msImageCreate(image->width, image->height, - image->format, image->imagepath, image->imageurl, map->resolution, map->defresolution, NULL); + image_draw = msImageCreate(image->width, image->height, image->format, + image->imagepath, image->imageurl, + map->resolution, map->defresolution, NULL); if (!image_draw) { - msSetError(MS_MISCERR, "Unable to initialize temporary transparent image.", - "msDrawLegendIcon()"); + msSetError(MS_MISCERR, + "Unable to initialize temporary transparent image.", + "msDrawLegendIcon()"); return (MS_FAILURE); } image_draw->map = map; } } - - if(renderer->supports_clipping && MS_VALID_COLOR(map->legend.outlinecolor)) { + if (renderer->supports_clipping && MS_VALID_COLOR(map->legend.outlinecolor)) { /* keep GD specific code here for now as it supports clipping */ rectObj clip; clip.maxx = dstX + width - 1; - clip.maxy = dstY + height -1; + clip.maxy = dstY + height - 1; clip.minx = dstX; clip.miny = dstY; - renderer->setClip(image_draw,clip); + renderer->setClip(image_draw, clip); } - + /* if the class has a keyimage, treat it as a point layer * (the keyimage will be treated there) */ - if(theclass->keyimage != NULL) { + if (theclass->keyimage != NULL) { type = MS_LAYER_POINT; } else { - /* some polygon layers may be better drawn using zigzag if there is no fill */ + /* some polygon layers may be better drawn using zigzag if there is no fill + */ type = lp->type; - if(type == MS_LAYER_POLYGON) { + if (type == MS_LAYER_POLYGON) { type = MS_LAYER_LINE; - for(i=0; inumstyles; i++) { - if(MS_VALID_COLOR(theclass->styles[i]->color)) { /* there is a fill */ + for (i = 0; i < theclass->numstyles; i++) { + if (MS_VALID_COLOR(theclass->styles[i]->color)) { /* there is a fill */ type = MS_LAYER_POLYGON; } - if(MS_VALID_COLOR(theclass->styles[i]->outlinecolor)) { /* there is an outline */ - polygon_contraction = MS_MAX(polygon_contraction, theclass->styles[i]->width / 2.0); + if (MS_VALID_COLOR( + theclass->styles[i]->outlinecolor)) { /* there is an outline */ + polygon_contraction = + MS_MAX(polygon_contraction, theclass->styles[i]->width / 2.0); } } } @@ -183,180 +183,211 @@ int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass, box.line[0].point[4].x = box.line[0].point[0].x; box.line[0].point[4].y = box.line[0].point[0].y; - - /* ** now draw the appropriate color/symbol/size combination */ /* Scalefactor will be infinity when SIZEUNITS is set in LAYER */ - if(lp->sizeunits != MS_PIXELS) { - lp->scalefactor = 1.0; + if (lp->sizeunits != MS_PIXELS) { + lp->scalefactor = 1.0; } - switch(type) { - case MS_LAYER_POINT: - marker.x = dstX + MS_NINT(width / 2.0); - marker.y = dstY + MS_NINT(height / 2.0); - if(theclass->keyimage != NULL) { - int symbolNum; - styleObj imgStyle; - symbolObj *symbol=NULL; - symbolNum = msAddImageSymbol(&(map->symbolset), msBuildPath(szPath, map->mappath, theclass->keyimage)); - if(symbolNum == -1) { - msSetError(MS_IMGERR, "Failed to open legend key image", "msCreateLegendIcon()"); - return(MS_FAILURE); - } + switch (type) { + case MS_LAYER_POINT: + marker.x = dstX + MS_NINT(width / 2.0); + marker.y = dstY + MS_NINT(height / 2.0); + if (theclass->keyimage != NULL) { + int symbolNum; + styleObj imgStyle; + symbolObj *symbol = NULL; + symbolNum = + msAddImageSymbol(&(map->symbolset), msBuildPath(szPath, map->mappath, + theclass->keyimage)); + if (symbolNum == -1) { + msSetError(MS_IMGERR, "Failed to open legend key image", + "msCreateLegendIcon()"); + return (MS_FAILURE); + } - symbol = map->symbolset.symbol[symbolNum]; + symbol = map->symbolset.symbol[symbolNum]; - initStyle(&imgStyle); - /*set size so that symbol will be scaled properly #3296*/ - if (width/symbol->sizex < height/symbol->sizey) - imgStyle.size = symbol->sizey*(width/symbol->sizex); - else - imgStyle.size = symbol->sizey*(height/symbol->sizey); + initStyle(&imgStyle); + /*set size so that symbol will be scaled properly #3296*/ + if (width / symbol->sizex < height / symbol->sizey) + imgStyle.size = symbol->sizey * (width / symbol->sizex); + else + imgStyle.size = symbol->sizey * (height / symbol->sizey); - if (imgStyle.size > imgStyle.maxsize) - imgStyle.maxsize = imgStyle.size; + if (imgStyle.size > imgStyle.maxsize) + imgStyle.maxsize = imgStyle.size; - imgStyle.symbol = symbolNum; - ret = msDrawMarkerSymbol(map ,image_draw,&marker,&imgStyle, 1.0); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; - /* TO DO: we may want to handle this differently depending on the relative size of the keyimage */ - } else { - for(i=0; inumstyles; i++) { - if(!scale_independant && map->scaledenom > 0) { - styleObj *lp = theclass->styles[i]; - if((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) continue; - if((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) continue; - } - if(hittest && hittest->stylehits[i].status == 0) continue; - ret = msDrawMarkerSymbol(map, image_draw, &marker, theclass->styles[i], lp->scalefactor * image->resolutionfactor); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; + imgStyle.symbol = symbolNum; + ret = msDrawMarkerSymbol(map, image_draw, &marker, &imgStyle, 1.0); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; + /* TO DO: we may want to handle this differently depending on the relative + * size of the keyimage */ + } else { + for (i = 0; i < theclass->numstyles; i++) { + if (!scale_independant && map->scaledenom > 0) { + styleObj *lp = theclass->styles[i]; + if ((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) + continue; + if ((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) + continue; } + if (hittest && hittest->stylehits[i].status == 0) + continue; + ret = msDrawMarkerSymbol(map, image_draw, &marker, theclass->styles[i], + lp->scalefactor * image->resolutionfactor); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; } - break; - case MS_LAYER_LINE: - offset = 1; - /* To set the offset, we only check the size/width parameter of the first style */ - if (theclass->numstyles > 0) { - if (theclass->styles[0]->symbol > 0 && theclass->styles[0]->symbol < map->symbolset.numsymbols && - map->symbolset.symbol[theclass->styles[0]->symbol]->type != MS_SYMBOL_SIMPLE) - offset = theclass->styles[0]->size/2; - else - offset = theclass->styles[0]->width/2; + } + break; + case MS_LAYER_LINE: + offset = 1; + /* To set the offset, we only check the size/width parameter of the first + * style */ + if (theclass->numstyles > 0) { + if (theclass->styles[0]->symbol > 0 && + theclass->styles[0]->symbol < map->symbolset.numsymbols && + map->symbolset.symbol[theclass->styles[0]->symbol]->type != + MS_SYMBOL_SIMPLE) + offset = theclass->styles[0]->size / 2; + else + offset = theclass->styles[0]->width / 2; + } + msInitShape(&zigzag); + zigzag.line = &zigzag_line; + zigzag.numlines = 1; + zigzag.line[0].point = zigzag_point; + zigzag.line[0].numpoints = 4; + zigzag.type = MS_SHAPE_LINE; + + zigzag.line[0].point[0].x = dstX + offset; + zigzag.line[0].point[0].y = dstY + height - offset; + zigzag.line[0].point[1].x = dstX + MS_NINT(width / 3.0) - 1; + zigzag.line[0].point[1].y = dstY + offset; + zigzag.line[0].point[2].x = dstX + MS_NINT(2.0 * width / 3.0) - 1; + zigzag.line[0].point[2].y = dstY + height - offset; + zigzag.line[0].point[3].x = dstX + width - offset; + zigzag.line[0].point[3].y = dstY + offset; + + for (i = 0; i < theclass->numstyles; i++) { + if (!scale_independant && map->scaledenom > 0) { + styleObj *lp = theclass->styles[i]; + if ((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) + continue; + if ((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) + continue; } - msInitShape(&zigzag); - zigzag.line = &zigzag_line; - zigzag.numlines = 1; - zigzag.line[0].point = zigzag_point; - zigzag.line[0].numpoints = 4; - zigzag.type = MS_SHAPE_LINE; - - zigzag.line[0].point[0].x = dstX + offset; - zigzag.line[0].point[0].y = dstY + height - offset; - zigzag.line[0].point[1].x = dstX + MS_NINT(width / 3.0) - 1; - zigzag.line[0].point[1].y = dstY + offset; - zigzag.line[0].point[2].x = dstX + MS_NINT(2.0 * width / 3.0) - 1; - zigzag.line[0].point[2].y = dstY + height - offset; - zigzag.line[0].point[3].x = dstX + width - offset; - zigzag.line[0].point[3].y = dstY + offset; - - for(i=0; inumstyles; i++) { - if(!scale_independant && map->scaledenom > 0) { - styleObj *lp = theclass->styles[i]; - if((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) continue; - if((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) continue; - } - if(hittest && hittest->stylehits[i].status == 0) continue; - if (theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE || - theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT || - theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) { - if (theclass->styles[i]->outlinewidth > 0) { - /* Swap the style contents to render the outline first, - * and then restore the style to render the interior of the line - */ - msOutlineRenderingPrepareStyle(theclass->styles[i], map, lp, image); - ret = msDrawLineSymbol(map, image_draw, &zigzag, theclass->styles[i], lp->scalefactor * image_draw->resolutionfactor); - msOutlineRenderingRestoreStyle(theclass->styles[i], map, lp, image); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; - } - ret = msDrawLineSymbol(map, image_draw, &zigzag, theclass->styles[i], lp->scalefactor * image_draw->resolutionfactor); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; + if (hittest && hittest->stylehits[i].status == 0) + continue; + if (theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE || + theclass->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT || + theclass->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOLY) { + if (theclass->styles[i]->outlinewidth > 0) { + /* Swap the style contents to render the outline first, + * and then restore the style to render the interior of the line + */ + msOutlineRenderingPrepareStyle(theclass->styles[i], map, lp, image); + ret = + msDrawLineSymbol(map, image_draw, &zigzag, theclass->styles[i], + lp->scalefactor * image_draw->resolutionfactor); + msOutlineRenderingRestoreStyle(theclass->styles[i], map, lp, image); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; } - else { - if (theclass->styles[i]->outlinewidth > 0) { - /* Swap the style contents to render the outline first, - * and then restore the style to render the interior of the line - */ - msOutlineRenderingPrepareStyle(theclass->styles[i], map, lp, image); - ret = msDrawTransformedShape(map, image_draw, &zigzag, theclass->styles[i], lp->scalefactor * image_draw->resolutionfactor); - msOutlineRenderingRestoreStyle(theclass->styles[i], map, lp, image); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; - } - ret = msDrawTransformedShape(map, image_draw, &zigzag, theclass->styles[i], lp->scalefactor * image_draw->resolutionfactor); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; + ret = msDrawLineSymbol(map, image_draw, &zigzag, theclass->styles[i], + lp->scalefactor * image_draw->resolutionfactor); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; + } else { + if (theclass->styles[i]->outlinewidth > 0) { + /* Swap the style contents to render the outline first, + * and then restore the style to render the interior of the line + */ + msOutlineRenderingPrepareStyle(theclass->styles[i], map, lp, image); + ret = msDrawTransformedShape( + map, image_draw, &zigzag, theclass->styles[i], + lp->scalefactor * image_draw->resolutionfactor); + msOutlineRenderingRestoreStyle(theclass->styles[i], map, lp, image); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; } + ret = msDrawTransformedShape( + map, image_draw, &zigzag, theclass->styles[i], + lp->scalefactor * image_draw->resolutionfactor); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; } + } - break; - case MS_LAYER_CIRCLE: - case MS_LAYER_RASTER: - case MS_LAYER_CHART: - case MS_LAYER_POLYGON: - for(i=0; inumstyles; i++) { - if(!scale_independant && map->scaledenom > 0) { - styleObj *lp = theclass->styles[i]; - if((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) continue; - if((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) continue; - } - if(hittest && hittest->stylehits[i].status == 0) continue; - if (theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE || - theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT || - theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) { - - if (MS_VALID_COLOR(theclass->styles[i]->mincolor)) - { - ret = msDrawGradientSymbol(renderer, - image_draw, - dstX + width / 2., - dstY + height / 2.0, - width - 2 * polygon_contraction, - height - 2 * polygon_contraction, - theclass->styles[i]); - } - else - { - ret = msDrawShadeSymbol(map, image_draw, &box, theclass->styles[i], lp->scalefactor * image_draw->resolutionfactor); - } - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; - } - else { - ret = msDrawTransformedShape(map, image_draw, &box, - theclass->styles[i], lp->scalefactor); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; + break; + case MS_LAYER_CIRCLE: + case MS_LAYER_RASTER: + case MS_LAYER_CHART: + case MS_LAYER_POLYGON: + for (i = 0; i < theclass->numstyles; i++) { + if (!scale_independant && map->scaledenom > 0) { + styleObj *lp = theclass->styles[i]; + if ((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) + continue; + if ((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) + continue; + } + if (hittest && hittest->stylehits[i].status == 0) + continue; + if (theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE || + theclass->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOINT || + theclass->styles[i]->_geomtransform.type == + MS_GEOMTRANSFORM_LABELPOLY) { + + if (MS_VALID_COLOR(theclass->styles[i]->mincolor)) { + ret = msDrawGradientSymbol( + renderer, image_draw, dstX + width / 2., dstY + height / 2.0, + width - 2 * polygon_contraction, height - 2 * polygon_contraction, + theclass->styles[i]); + } else { + ret = + msDrawShadeSymbol(map, image_draw, &box, theclass->styles[i], + lp->scalefactor * image_draw->resolutionfactor); } + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; + } else { + ret = msDrawTransformedShape(map, image_draw, &box, theclass->styles[i], + lp->scalefactor); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; } - break; - default: - return MS_FAILURE; - break; + } + break; + default: + return MS_FAILURE; + break; } /* end symbol drawing */ /* handle label styles */ - for(i=0; inumlabels; i++) { + for (i = 0; i < theclass->numlabels; i++) { labelObj *l = theclass->labels[i]; - if(!scale_independant && map->scaledenom > 0) { - if(msScaleInBounds(map->scaledenom, l->minscaledenom, l->maxscaledenom)) { + if (!scale_independant && map->scaledenom > 0) { + if (msScaleInBounds(map->scaledenom, l->minscaledenom, + l->maxscaledenom)) { int j; - for(j=0; jnumstyles; j++) { + for (j = 0; j < l->numstyles; j++) { styleObj *s = l->styles[j]; marker.x = dstX + MS_NINT(width / 2.0); marker.y = dstY + MS_NINT(height / 2.0); - if(s->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { - ret = msDrawMarkerSymbol(map, image_draw, &marker, s, lp->scalefactor); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; + if (s->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { + ret = msDrawMarkerSymbol(map, image_draw, &marker, s, + lp->scalefactor); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; } } } @@ -365,15 +396,16 @@ int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass, /* handle "pure" text layers, i.e. layers with no symbology */ hasmarkersymbol = 0; - if(theclass->numstyles == 0) { - for(i=0; inumlabels; i++) { + if (theclass->numstyles == 0) { + for (i = 0; i < theclass->numlabels; i++) { labelObj *l = theclass->labels[i]; - if(!scale_independant && map->scaledenom > 0) { - if(msScaleInBounds(map->scaledenom, l->minscaledenom, l->maxscaledenom)) { + if (!scale_independant && map->scaledenom > 0) { + if (msScaleInBounds(map->scaledenom, l->minscaledenom, + l->maxscaledenom)) { int j; - for(j=0; jnumstyles; j++) { + for (j = 0; j < l->numstyles; j++) { styleObj *s = l->styles[j]; - if(s->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { + if (s->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { hasmarkersymbol = 1; } } @@ -384,33 +416,38 @@ int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass, hasmarkersymbol = 1; } - if(!hasmarkersymbol && theclass->numlabels>0) { + if (!hasmarkersymbol && theclass->numlabels > 0) { textSymbolObj ts; pointObj textstartpt; marker.x = dstX + MS_NINT(width / 2.0); marker.y = dstY + MS_NINT(height / 2.0); initTextSymbol(&ts); - msPopulateTextSymbolForLabelAndString(&ts,theclass->labels[0],msStrdup("Az"),lp->scalefactor*image_draw->resolutionfactor,image_draw->resolutionfactor, duplicate_always); + msPopulateTextSymbolForLabelAndString( + &ts, theclass->labels[0], msStrdup("Az"), + lp->scalefactor * image_draw->resolutionfactor, + image_draw->resolutionfactor, duplicate_always); ts.label->size = height - 1; ts.rotation = 0; - ret = msComputeTextPath(map,&ts); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; - textstartpt = get_metrics(&marker,MS_CC,ts.textpath,0,0,0,0,NULL); - ret = msDrawTextSymbol(map,image_draw, textstartpt, &ts); + ret = msComputeTextPath(map, &ts); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; + textstartpt = get_metrics(&marker, MS_CC, ts.textpath, 0, 0, 0, 0, NULL); + ret = msDrawTextSymbol(map, image_draw, textstartpt, &ts); freeTextSymbol(&ts); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; - + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; } - /* handle an outline if necessary */ - if(MS_VALID_COLOR(map->legend.outlinecolor)) { + if (MS_VALID_COLOR(map->legend.outlinecolor)) { initStyle(&outline_style); outline_style.color = map->legend.outlinecolor; - ret = msDrawLineSymbol(map, image_draw, &box, &outline_style, image_draw->resolutionfactor); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; + ret = msDrawLineSymbol(map, image_draw, &box, &outline_style, + image_draw->resolutionfactor); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; /* reset clipping rectangle */ - if(renderer->supports_clipping) + if (renderer->supports_clipping) renderer->resetClip(image_draw); } @@ -418,74 +455,84 @@ int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass, rendererVTableObj *renderer = MS_IMAGE_RENDERER(image); rendererVTableObj *altrenderer = MS_IMAGE_RENDERER(image_draw); rasterBufferObj rb; - memset(&rb,0,sizeof(rasterBufferObj)); - - ret = altrenderer->getRasterBufferHandle(image_draw,&rb); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; - ret = renderer->mergeRasterBuffer(image,&rb,((lp->compositer)?lp->compositer->opacity*0.01:1.0),0,0,0,0,rb.width,rb.height); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; + memset(&rb, 0, sizeof(rasterBufferObj)); + + ret = altrenderer->getRasterBufferHandle(image_draw, &rb); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; + ret = renderer->mergeRasterBuffer( + image, &rb, ((lp->compositer) ? lp->compositer->opacity * 0.01 : 1.0), + 0, 0, 0, 0, rb.width, rb.height); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; /* - * hack to work around bug #3834: if we have use an alternate renderer, the symbolset may contain - * symbols that reference it. We want to remove those references before the altFormat is destroyed - * to avoid a segfault and/or a leak, and so the the main renderer doesn't pick the cache up thinking + * hack to work around bug #3834: if we have use an alternate renderer, the + * symbolset may contain symbols that reference it. We want to remove those + * references before the altFormat is destroyed to avoid a segfault and/or a + * leak, and so the the main renderer doesn't pick the cache up thinking * it's for him. */ - for(i=0; isymbolset.numsymbols; i++) { - if (map->symbolset.symbol[i]!=NULL) { + for (i = 0; i < map->symbolset.numsymbols; i++) { + if (map->symbolset.symbol[i] != NULL) { symbolObj *s = map->symbolset.symbol[i]; - if(s->renderer == altrenderer) { + if (s->renderer == altrenderer) { altrenderer->freeSymbol(s); s->renderer = NULL; } } } - } else if(image != image_draw) { + } else if (image != image_draw) { rendererVTableObj *renderer = MS_IMAGE_RENDERER(image_draw); rasterBufferObj rb; - memset(&rb,0,sizeof(rasterBufferObj)); + memset(&rb, 0, sizeof(rasterBufferObj)); - ret = renderer->getRasterBufferHandle(image_draw,&rb); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; - ret = renderer->mergeRasterBuffer(image,&rb,((lp->compositer)?lp->compositer->opacity*0.01:1.0),0,0,0,0,rb.width,rb.height); - if(MS_UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup; + ret = renderer->getRasterBufferHandle(image_draw, &rb); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; + ret = renderer->mergeRasterBuffer( + image, &rb, ((lp->compositer) ? lp->compositer->opacity * 0.01 : 1.0), + 0, 0, 0, 0, rb.width, rb.height); + if (MS_UNLIKELY(ret == MS_FAILURE)) + goto legend_icon_cleanup; /* deref and possibly free temporary transparent output format. */ - msApplyOutputFormat( &transFormat, NULL, MS_NOOVERRIDE); - + msApplyOutputFormat(&transFormat, NULL, MS_NOOVERRIDE); } legend_icon_cleanup: - if(image != image_draw) { + if (image != image_draw) { msFreeImage(image_draw); } return ret; } -imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* class, int width, int height, int scale_independant) -{ +imageObj *msCreateLegendIcon(mapObj *map, layerObj *lp, classObj *class, + int width, int height, int scale_independant) { imageObj *image; outputFormatObj *format = NULL; rendererVTableObj *renderer = MS_MAP_RENDERER(map); - if( !renderer ) { + if (!renderer) { msSetError(MS_MISCERR, "invalid map outputformat", "msCreateLegendIcon()"); - return(NULL); + return (NULL); } /* ensure we have an image format representing the options for the legend */ msApplyOutputFormat(&format, map->outputformat, map->legend.transparent); - image = msImageCreate(width,height,format,map->web.imagepath, map->web.imageurl, - map->resolution, map->defresolution, &(map->legend.imagecolor)); + image = msImageCreate(width, height, format, map->web.imagepath, + map->web.imageurl, map->resolution, map->defresolution, + &(map->legend.imagecolor)); /* drop this reference to output format */ - msApplyOutputFormat( &format, NULL, MS_NOOVERRIDE); + msApplyOutputFormat(&format, NULL, MS_NOOVERRIDE); - if(image == NULL) { - msSetError(MS_IMGERR, "Unable to initialize image.","msCreateLegendIcon()"); - return(NULL); + if (image == NULL) { + msSetError(MS_IMGERR, "Unable to initialize image.", + "msCreateLegendIcon()"); + return (NULL); } image->map = map; @@ -495,13 +542,18 @@ imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* class, int wid /* Fev 2004 by AY) */ if (lp) { if (class) { - if(MS_UNLIKELY(MS_FAILURE == msDrawLegendIcon(map, lp, class, width, height, image, 0, 0, scale_independant, NULL))) { + if (MS_UNLIKELY(MS_FAILURE == + msDrawLegendIcon(map, lp, class, width, height, image, 0, + 0, scale_independant, NULL))) { msFreeImage(image); return NULL; } } else { - for (int i=0; inumclasses; i++) { - if(MS_UNLIKELY(MS_FAILURE == msDrawLegendIcon(map, lp, lp->class[i], width, height, image, 0, 0, scale_independant, NULL))) { + for (int i = 0; i < lp->numclasses; i++) { + if (MS_UNLIKELY(MS_FAILURE == msDrawLegendIcon(map, lp, lp->class[i], + width, height, image, 0, + 0, scale_independant, + NULL))) { msFreeImage(image); return NULL; } @@ -521,38 +573,39 @@ imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* class, int wid * MS_SUCCESS * MS_FAILURE */ -int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_y, - int *layer_index, int num_layers, map_hittest *hittest, - double resolutionfactor) -{ +int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, + int *size_y, int *layer_index, int num_layers, + map_hittest *hittest, double resolutionfactor) { int i, j; - int status, maxwidth=0, nLegendItems=0; + int status, maxwidth = 0, nLegendItems = 0; char *text; layerObj *lp; rectObj rect; - int current_layers=0; + int current_layers = 0; /* reset sizes */ *size_x = 0; *size_y = 0; /* enable scale-dependent calculations */ - if(!scale_independent) { + if (!scale_independent) { map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height); - status = msCalculateScale(map->extent, map->units, map->width, map->height, map->resolution, &map->scaledenom); - if(status != MS_SUCCESS) return MS_FAILURE; + status = msCalculateScale(map->extent, map->units, map->width, map->height, + map->resolution, &map->scaledenom); + if (status != MS_SUCCESS) + return MS_FAILURE; } /* * step through all map classes, and for each one that will be displayed * calculate the label size */ - if (layer_index != NULL && num_layers >0) - current_layers = num_layers; + if (layer_index != NULL && num_layers > 0) + current_layers = num_layers; else current_layers = map->numlayers; - for(i=0; i< current_layers; i++) { + for (i = 0; i < current_layers; i++) { int layerindex; if (layer_index != NULL && num_layers > 0) layerindex = layer_index[i]; @@ -561,36 +614,53 @@ int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_ lp = (GET_LAYER(map, layerindex)); - if((lp->status == MS_OFF && (layer_index == NULL || num_layers <= 0)) || (lp->type == MS_LAYER_QUERY)) /* skip it */ + if ((lp->status == MS_OFF && (layer_index == NULL || num_layers <= 0)) || + (lp->type == MS_LAYER_QUERY)) /* skip it */ continue; - if(hittest && hittest->layerhits[layerindex].status == 0) continue; + if (hittest && hittest->layerhits[layerindex].status == 0) + continue; - if(!scale_independent && map->scaledenom > 0) { - if((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) continue; - if((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) continue; + if (!scale_independent && map->scaledenom > 0) { + if ((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) + continue; + if ((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) + continue; } - for(j=lp->numclasses-1; j>=0; j--) { + for (j = lp->numclasses - 1; j >= 0; j--) { textSymbolObj ts; - text = lp->class[j]->title?lp->class[j]->title:lp->class[j]->name; /* point to the right legend text, title takes precedence */ - if(!text) continue; /* skip it */ + text = lp->class[j]->title + ? lp->class[j]->title + : lp->class[j]->name; /* point to the right legend text, title + takes precedence */ + if (!text) + continue; /* skip it */ /* skip the class if the classgroup is defined */ - if(lp->classgroup && (lp->class[j]->group == NULL || strcasecmp(lp->class[j]->group, lp->classgroup) != 0)) + if (lp->classgroup && + (lp->class[j] -> group == NULL || strcasecmp(lp->class[j] -> group, + lp -> classgroup) != 0)) continue; /* verify class scale */ - if(!scale_independent && map->scaledenom > 0) { - if((lp->class[j]->maxscaledenom > 0) && (map->scaledenom > lp->class[j]->maxscaledenom)) continue; - if((lp->class[j]->minscaledenom > 0) && (map->scaledenom <= lp->class[j]->minscaledenom)) continue; + if (!scale_independent && map->scaledenom > 0) { + if ((lp->class[j] -> maxscaledenom > 0) && + (map->scaledenom > lp->class[j] -> maxscaledenom)) + continue; + if ((lp->class[j] -> minscaledenom > 0) && + (map->scaledenom <= lp->class[j] -> minscaledenom)) + continue; } - if(hittest && hittest->layerhits[layerindex].classhits[j].status == 0) continue; + if (hittest && hittest->layerhits[layerindex].classhits[j].status == 0) + continue; - if(*text) { + if (*text) { initTextSymbol(&ts); - msPopulateTextSymbolForLabelAndString(&ts,&map->legend.label,msStrdup(text),resolutionfactor,resolutionfactor, 0); - if(MS_UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&ts,&rect))) { + msPopulateTextSymbolForLabelAndString(&ts, &map->legend.label, + msStrdup(text), resolutionfactor, + resolutionfactor, 0); + if (MS_UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map, &ts, &rect))) { freeTextSymbol(&ts); return MS_FAILURE; } @@ -607,11 +677,12 @@ int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_ /* Calculate the size of the legend: */ /* - account for the Y keyspacing */ - *size_y += (2*VMARGIN) + ((nLegendItems-1) * map->legend.keyspacingy); + *size_y += (2 * VMARGIN) + ((nLegendItems - 1) * map->legend.keyspacingy); /* - determine the legend width */ - *size_x = (2*HMARGIN) + maxwidth + map->legend.keyspacingx + map->legend.keysizex; + *size_x = + (2 * HMARGIN) + maxwidth + map->legend.keyspacingx + map->legend.keysizex; - if(*size_y <=0 || *size_x <=0) + if (*size_y <= 0 || *size_x <= 0) return MS_FAILURE; return MS_SUCCESS; @@ -627,11 +698,11 @@ int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_ ** and maxscale are ignored and layers that are currently out of scale still ** show up in the legend. */ -imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest) -{ - int i,j,ret=MS_SUCCESS; /* loop counters */ +imageObj *msDrawLegend(mapObj *map, int scale_independent, + map_hittest *hittest) { + int i, j, ret = MS_SUCCESS; /* loop counters */ pointObj pnt; - int size_x, size_y=0; + int size_x, size_y = 0; layerObj *lp; rectObj rect; imageObj *image = NULL; @@ -642,78 +713,110 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest) int height; textSymbolObj ts; int layerindex, classindex; - struct legend_struct* pred; + struct legend_struct *pred; }; typedef struct legend_struct legendlabel; - legendlabel *head=NULL,*cur=NULL; + legendlabel *head = NULL, *cur = NULL; - if(!MS_RENDERER_PLUGIN(map->outputformat)) { - msSetError(MS_MISCERR,"unsupported output format","msDrawLegend()"); + if (!MS_RENDERER_PLUGIN(map->outputformat)) { + msSetError(MS_MISCERR, "unsupported output format", "msDrawLegend()"); return NULL; } - if(msValidateContexts(map) != MS_SUCCESS) return NULL; /* make sure there are no recursive REQUIRES or LABELREQUIRES expressions */ - if(msLegendCalcSize(map, scale_independent, &size_x, &size_y, NULL, 0, hittest, map->resolution/map->defresolution) != MS_SUCCESS) return NULL; + if (msValidateContexts(map) != MS_SUCCESS) + return NULL; /* make sure there are no recursive REQUIRES or LABELREQUIRES + expressions */ + if (msLegendCalcSize(map, scale_independent, &size_x, &size_y, NULL, 0, + hittest, + map->resolution / map->defresolution) != MS_SUCCESS) + return NULL; /* * step through all map classes, and for each one that will be displayed * keep a reference to its label size and text */ - - for(i=0; inumlayers; i++) { + + for (i = 0; i < map->numlayers; i++) { lp = (GET_LAYER(map, map->layerorder[i])); - if((lp->status == MS_OFF) || (lp->type == MS_LAYER_QUERY)) /* skip it */ + if ((lp->status == MS_OFF) || (lp->type == MS_LAYER_QUERY)) /* skip it */ continue; - if(hittest && hittest->layerhits[map->layerorder[i]].status == 0) + if (hittest && hittest->layerhits[map->layerorder[i]].status == 0) continue; - if(!scale_independent && map->scaledenom > 0) { - if((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) continue; - if((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) continue; + if (!scale_independent && map->scaledenom > 0) { + if ((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) + continue; + if ((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) + continue; } - if(!scale_independent && lp->maxscaledenom <=0 && lp->minscaledenom <=0) { - if((lp->maxgeowidth > 0) && ((map->extent.maxx - map->extent.minx) > lp->maxgeowidth)) continue; - if((lp->mingeowidth > 0) && ((map->extent.maxx - map->extent.minx) < lp->mingeowidth)) continue; + if (!scale_independent && lp->maxscaledenom <= 0 && + lp->minscaledenom <= 0) { + if ((lp->maxgeowidth > 0) && + ((map->extent.maxx - map->extent.minx) > lp->maxgeowidth)) + continue; + if ((lp->mingeowidth > 0) && + ((map->extent.maxx - map->extent.minx) < lp->mingeowidth)) + continue; } - - /* set the scale factor so that scale dependant symbols are drawn in the legend with their default size */ - if(lp->sizeunits != MS_PIXELS) { + + /* set the scale factor so that scale dependant symbols are drawn in the + * legend with their default size */ + if (lp->sizeunits != MS_PIXELS) { map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height); - lp->scalefactor = (msInchesPerUnit(lp->sizeunits,0)/msInchesPerUnit(map->units,0)) / map->cellsize; + lp->scalefactor = + (msInchesPerUnit(lp->sizeunits, 0) / msInchesPerUnit(map->units, 0)) / + map->cellsize; } - for(j=lp->numclasses-1; j>=0; j--) { - text = lp->class[j]->title?lp->class[j]->title:lp->class[j]->name; /* point to the right legend text, title takes precedence */ - if(!text) continue; /* skip it */ + for (j = lp->numclasses - 1; j >= 0; j--) { + text = lp->class[j]->title + ? lp->class[j]->title + : lp->class[j]->name; /* point to the right legend text, title + takes precedence */ + if (!text) + continue; /* skip it */ /* skip the class if the classgroup is defined */ - if(lp->classgroup && (lp->class[j]->group == NULL || strcasecmp(lp->class[j]->group, lp->classgroup) != 0)) + if (lp->classgroup && + (lp->class[j] -> group == NULL || strcasecmp(lp->class[j] -> group, + lp -> classgroup) != 0)) continue; - if(!scale_independent && map->scaledenom > 0) { /* verify class scale here */ - if((lp->class[j]->maxscaledenom > 0) && (map->scaledenom > lp->class[j]->maxscaledenom)) continue; - if((lp->class[j]->minscaledenom > 0) && (map->scaledenom <= lp->class[j]->minscaledenom)) continue; + if (!scale_independent && + map->scaledenom > 0) { /* verify class scale here */ + if ((lp->class[j] -> maxscaledenom > 0) && + (map->scaledenom > lp->class[j] -> maxscaledenom)) + continue; + if ((lp->class[j] -> minscaledenom > 0) && + (map->scaledenom <= lp->class[j] -> minscaledenom)) + continue; } - if(hittest && hittest->layerhits[map->layerorder[i]].classhits[j].status == 0) { - continue; + if (hittest && + hittest->layerhits[map->layerorder[i]].classhits[j].status == 0) { + continue; } - cur = (legendlabel*) msSmallMalloc(sizeof(legendlabel)); + cur = (legendlabel *)msSmallMalloc(sizeof(legendlabel)); initTextSymbol(&cur->ts); - if(*text) { - msPopulateTextSymbolForLabelAndString(&cur->ts,&map->legend.label,msStrdup(text),map->resolution/map->defresolution,map->resolution/map->defresolution, 0); - if(MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map,&cur->ts))) { + if (*text) { + msPopulateTextSymbolForLabelAndString( + &cur->ts, &map->legend.label, msStrdup(text), + map->resolution / map->defresolution, + map->resolution / map->defresolution, 0); + if (MS_UNLIKELY(MS_FAILURE == msComputeTextPath(map, &cur->ts))) { ret = MS_FAILURE; goto cleanup; } - if(MS_UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&cur->ts,&rect))) { + if (MS_UNLIKELY(MS_FAILURE == + msGetTextSymbolSize(map, &cur->ts, &rect))) { ret = MS_FAILURE; goto cleanup; } - cur->height = MS_MAX(MS_NINT(rect.maxy - rect.miny), map->legend.keysizey); + cur->height = + MS_MAX(MS_NINT(rect.maxy - rect.miny), map->legend.keysizey); } else { cur->height = map->legend.keysizey; } @@ -725,19 +828,21 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest) } } - /* ensure we have an image format representing the options for the legend. */ msApplyOutputFormat(&format, map->outputformat, map->legend.transparent); /* initialize the legend image */ - image = msImageCreate(size_x, size_y, format, map->web.imagepath, map->web.imageurl, map->resolution, map->defresolution, &map->legend.imagecolor); - if(!image) { + image = msImageCreate(size_x, size_y, format, map->web.imagepath, + map->web.imageurl, map->resolution, map->defresolution, + &map->legend.imagecolor); + if (!image) { msSetError(MS_MISCERR, "Unable to initialize image.", "msDrawLegend()"); return NULL; } image->map = map; - /* image = renderer->createImage(size_x,size_y,format,&(map->legend.imagecolor)); */ + /* image = + * renderer->createImage(size_x,size_y,format,&(map->legend.imagecolor)); */ /* drop this reference to output format */ msApplyOutputFormat(&format, NULL, MS_NOOVERRIDE); @@ -745,37 +850,45 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest) pnt.y = VMARGIN; pnt.x = HMARGIN + map->legend.keysizex + map->legend.keyspacingx; - while(cur) { /* cur initially points on the last legend item, i.e. the one that should be at the top */ + while (cur) { /* cur initially points on the last legend item, i.e. the one + that should be at the top */ class_hittest *ch = NULL; - /* set the scale factor so that scale dependant symbols are drawn in the legend with their default size */ - if(map->layers[cur->layerindex]->sizeunits != MS_PIXELS) { + /* set the scale factor so that scale dependant symbols are drawn in the + * legend with their default size */ + if (map->layers[cur->layerindex]->sizeunits != MS_PIXELS) { map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height); - map->layers[cur->layerindex]->scalefactor = (msInchesPerUnit(map->layers[cur->layerindex]->sizeunits,0)/msInchesPerUnit(map->units,0)) / map->cellsize; + map->layers[cur->layerindex]->scalefactor = + (msInchesPerUnit(map->layers[cur->layerindex]->sizeunits, 0) / + msInchesPerUnit(map->units, 0)) / + map->cellsize; } - if(hittest) { + if (hittest) { ch = &hittest->layerhits[cur->layerindex].classhits[cur->classindex]; } - ret = msDrawLegendIcon(map, map->layers[cur->layerindex], map->layers[cur->layerindex]->class[cur->classindex], map->legend.keysizex, map->legend.keysizey, image, HMARGIN, (int) pnt.y, scale_independent, ch); - if(MS_UNLIKELY(ret != MS_SUCCESS)) + ret = msDrawLegendIcon(map, map->layers[cur->layerindex], + map->layers[cur->layerindex]->class[cur->classindex], + map -> legend.keysizex, map->legend.keysizey, image, + HMARGIN, (int)pnt.y, scale_independent, ch); + if (MS_UNLIKELY(ret != MS_SUCCESS)) goto cleanup; pnt.y += cur->height; - if(cur->ts.annotext) { + if (cur->ts.annotext) { pointObj textPnt = pnt; textPnt.y -= cur->ts.textpath->bounds.bbox.maxy; textPnt.y += map->legend.label.offsety; textPnt.x += map->legend.label.offsetx; - ret = msDrawTextSymbol(map,image,textPnt,&cur->ts); - if(MS_UNLIKELY(ret == MS_FAILURE)) + ret = msDrawTextSymbol(map, image, textPnt, &cur->ts); + if (MS_UNLIKELY(ret == MS_FAILURE)) goto cleanup; /* Coverity Scan is confused by label refcount, and wrongly believe we */ /* might free &map->legend.label, so make it clear we won't */ freeTextSymbolEx(&cur->ts, MS_FALSE); MS_REFCNT_DECR(cur->ts.label); } - + pnt.y += map->legend.keyspacingy; /* bump y for next label */ /* clean up */ @@ -785,7 +898,7 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest) } /* next legend */ cleanup: - while(cur) { + while (cur) { /* Coverity Scan is confused by label refcount, and wrongly believe we */ /* might free &map->legend.label, so make it clear we won't */ freeTextSymbolEx(&cur->ts, MS_FALSE); @@ -794,69 +907,76 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest) cur = cur->pred; free(head); } - if(MS_UNLIKELY(ret != MS_SUCCESS)) { - if(image) msFreeImage(image); + if (MS_UNLIKELY(ret != MS_SUCCESS)) { + if (image) + msFreeImage(image); return NULL; } - return(image); + return (image); } /* TODO */ -int msEmbedLegend(mapObj *map, imageObj *img) -{ - int s,l; +int msEmbedLegend(mapObj *map, imageObj *img) { + int s, l; pointObj point; imageObj *image = NULL; symbolObj *legendSymbol; - char* imageType = NULL; + char *imageType = NULL; rendererVTableObj *renderer; s = msGetSymbolIndex(&(map->symbolset), "legend", MS_FALSE); - if(s != -1) - msRemoveSymbol(&(map->symbolset), s); /* solves some caching issues in AGG with long-running processes */ + if (s != -1) + msRemoveSymbol( + &(map->symbolset), + s); /* solves some caching issues in AGG with long-running processes */ - if(msGrowSymbolSet(&map->symbolset) == NULL) + if (msGrowSymbolSet(&map->symbolset) == NULL) return -1; s = map->symbolset.numsymbols; legendSymbol = map->symbolset.symbol[s]; map->symbolset.numsymbols++; initSymbol(legendSymbol); - if(!MS_RENDERER_PLUGIN(map->outputformat) || !MS_MAP_RENDERER(map)->supports_pixel_buffer) { + if (!MS_RENDERER_PLUGIN(map->outputformat) || + !MS_MAP_RENDERER(map)->supports_pixel_buffer) { imageType = msStrdup(map->imagetype); /* save format */ - if MS_DRIVER_CAIRO(map->outputformat) - map->outputformat = msSelectOutputFormat( map, "cairopng" ); + if MS_DRIVER_CAIRO (map->outputformat) + map->outputformat = msSelectOutputFormat(map, "cairopng"); else - map->outputformat = msSelectOutputFormat( map, "png" ); - + map->outputformat = msSelectOutputFormat(map, "png"); + msInitializeRendererVTable(map->outputformat); } renderer = MS_MAP_RENDERER(map); /* render the legend. */ image = msDrawLegend(map, MS_FALSE, NULL); - if( image == NULL ) { + if (image == NULL) { msFree(imageType); return MS_FAILURE; } if (imageType) { - map->outputformat = msSelectOutputFormat( map, imageType ); /* restore format */ + map->outputformat = + msSelectOutputFormat(map, imageType); /* restore format */ msFree(imageType); } /* copy renderered legend image into symbol */ - legendSymbol->pixmap_buffer = calloc(1,sizeof(rasterBufferObj)); - MS_CHECK_ALLOC(legendSymbol->pixmap_buffer, sizeof(rasterBufferObj), MS_FAILURE); + legendSymbol->pixmap_buffer = calloc(1, sizeof(rasterBufferObj)); + MS_CHECK_ALLOC(legendSymbol->pixmap_buffer, sizeof(rasterBufferObj), + MS_FAILURE); - if(MS_SUCCESS != renderer->getRasterBufferCopy(image,legendSymbol->pixmap_buffer)) + if (MS_SUCCESS != + renderer->getRasterBufferCopy(image, legendSymbol->pixmap_buffer)) return MS_FAILURE; legendSymbol->renderer = renderer; - msFreeImage( image ); + msFreeImage(image); - if(!legendSymbol->pixmap_buffer) return(MS_FAILURE); /* something went wrong creating scalebar */ + if (!legendSymbol->pixmap_buffer) + return (MS_FAILURE); /* something went wrong creating scalebar */ legendSymbol->type = MS_SYMBOL_PIXMAP; /* intialize a few things */ legendSymbol->name = msStrdup("legend"); @@ -867,46 +987,48 @@ int msEmbedLegend(mapObj *map, imageObj *img) /* if(map->legend.transparent == MS_ON) */ /* gdImageColorTransparent(legendSymbol->img_deprecated, 0); */ - switch(map->legend.position) { - case(MS_LL): - point.x = MS_NINT(legendSymbol->sizex/2.0); - point.y = map->height - MS_NINT(legendSymbol->sizey/2.0); - break; - case(MS_LR): - point.x = map->width - MS_NINT(legendSymbol->sizex/2.0); - point.y = map->height - MS_NINT(legendSymbol->sizey/2.0); - break; - case(MS_LC): - point.x = MS_NINT(map->width/2.0); - point.y = map->height - MS_NINT(legendSymbol->sizey/2.0); - break; - case(MS_UR): - point.x = map->width - MS_NINT(legendSymbol->sizex/2.0); - point.y = MS_NINT(legendSymbol->sizey/2.0); - break; - case(MS_UL): - point.x = MS_NINT(legendSymbol->sizex/2.0); - point.y = MS_NINT(legendSymbol->sizey/2.0); - break; - case(MS_UC): - point.x = MS_NINT(map->width/2.0); - point.y = MS_NINT(legendSymbol->sizey/2.0); - break; + switch (map->legend.position) { + case (MS_LL): + point.x = MS_NINT(legendSymbol->sizex / 2.0); + point.y = map->height - MS_NINT(legendSymbol->sizey / 2.0); + break; + case (MS_LR): + point.x = map->width - MS_NINT(legendSymbol->sizex / 2.0); + point.y = map->height - MS_NINT(legendSymbol->sizey / 2.0); + break; + case (MS_LC): + point.x = MS_NINT(map->width / 2.0); + point.y = map->height - MS_NINT(legendSymbol->sizey / 2.0); + break; + case (MS_UR): + point.x = map->width - MS_NINT(legendSymbol->sizex / 2.0); + point.y = MS_NINT(legendSymbol->sizey / 2.0); + break; + case (MS_UL): + point.x = MS_NINT(legendSymbol->sizex / 2.0); + point.y = MS_NINT(legendSymbol->sizey / 2.0); + break; + case (MS_UC): + point.x = MS_NINT(map->width / 2.0); + point.y = MS_NINT(legendSymbol->sizey / 2.0); + break; } l = msGetLayerIndex(map, "__embed__legend"); - if(l == -1) { - if(msGrowMapLayers(map) == NULL) - return(-1); + if (l == -1) { + if (msGrowMapLayers(map) == NULL) + return (-1); l = map->numlayers; map->numlayers++; - if(initLayer((GET_LAYER(map, l)), map) == -1) return(-1); + if (initLayer((GET_LAYER(map, l)), map) == -1) + return (-1); GET_LAYER(map, l)->name = msStrdup("__embed__legend"); GET_LAYER(map, l)->type = MS_LAYER_POINT; - if(msGrowLayerClasses( GET_LAYER(map, l) ) == NULL) - return(-1); - if(initClass(GET_LAYER(map, l)->class[0]) == -1) return(-1); + if (msGrowLayerClasses(GET_LAYER(map, l)) == NULL) + return (-1); + if (initClass(GET_LAYER(map, l)->class[0]) == -1) + return (-1); GET_LAYER(map, l)->numclasses = 1; /* so we make sure to free it */ /* update the layer order list with the layer's index. */ @@ -915,33 +1037,45 @@ int msEmbedLegend(mapObj *map, imageObj *img) GET_LAYER(map, l)->status = MS_ON; - if(map->legend.postlabelcache) { /* add it directly to the image */ - if(MS_UNLIKELY(msMaybeAllocateClassStyle(GET_LAYER(map, l)->class[0], 0)==MS_FAILURE)) return MS_FAILURE; + if (map->legend.postlabelcache) { /* add it directly to the image */ + if (MS_UNLIKELY(msMaybeAllocateClassStyle(GET_LAYER(map, l)->class[0], 0) == + MS_FAILURE)) + return MS_FAILURE; GET_LAYER(map, l)->class[0]->styles[0]->symbol = s; - if(MS_UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, img, &point, GET_LAYER(map, l)->class[0]->styles[0], 1.0))) + if (MS_UNLIKELY(MS_FAILURE == + msDrawMarkerSymbol(map, img, &point, + GET_LAYER(map, l)->class[0] -> styles[0], + 1.0))) return MS_FAILURE; } else { - if(!GET_LAYER(map, l)->class[0]->labels) { - if(msGrowClassLabels(GET_LAYER(map, l)->class[0]) == NULL) return MS_FAILURE; - initLabel(GET_LAYER(map, l)->class[0]->labels[0]); + if (!GET_LAYER(map, l)->class[0] -> labels) { + if (msGrowClassLabels(GET_LAYER(map, l)->class[0]) == NULL) + return MS_FAILURE; + initLabel(GET_LAYER(map, l)->class[0] -> labels[0]); GET_LAYER(map, l)->class[0]->numlabels = 1; GET_LAYER(map, l)->class[0]->labels[0]->force = MS_TRUE; - GET_LAYER(map, l)->class[0]->labels[0]->size = MS_MEDIUM; /* must set a size to have a valid label definition */ + GET_LAYER(map, l)->class[0]->labels[0]->size = + MS_MEDIUM; /* must set a size to have a valid label definition */ GET_LAYER(map, l)->class[0]->labels[0]->priority = MS_MAX_LABEL_PRIORITY; } - if(GET_LAYER(map, l)->class[0]->labels[0]->numstyles == 0) { - if(msGrowLabelStyles(GET_LAYER(map,l)->class[0]->labels[0]) == NULL) - return(MS_FAILURE); - GET_LAYER(map,l)->class[0]->labels[0]->numstyles = 1; - initStyle(GET_LAYER(map,l)->class[0]->labels[0]->styles[0]); - GET_LAYER(map,l)->class[0]->labels[0]->styles[0]->_geomtransform.type = MS_GEOMTRANSFORM_LABELPOINT; + if (GET_LAYER(map, l)->class[0] -> labels[0] -> numstyles == 0) { + if (msGrowLabelStyles(GET_LAYER(map, l)->class[0] -> labels[0]) == NULL) + return (MS_FAILURE); + GET_LAYER(map, l)->class[0]->labels[0]->numstyles = 1; + initStyle(GET_LAYER(map, l)->class[0] -> labels[0] -> styles[0]); + GET_LAYER(map, l)->class[0]->labels[0]->styles[0]->_geomtransform.type = + MS_GEOMTRANSFORM_LABELPOINT; } - GET_LAYER(map,l)->class[0]->labels[0]->styles[0]->symbol = s; - if(MS_UNLIKELY(MS_FAILURE == msAddLabel(map, img, GET_LAYER(map, l)->class[0]->labels[0], l, 0, NULL, &point, -1, NULL))) + GET_LAYER(map, l)->class[0]->labels[0]->styles[0]->symbol = s; + if (MS_UNLIKELY(MS_FAILURE == + msAddLabel(map, img, + GET_LAYER(map, l)->class[0] -> labels[0], l, 0, + NULL, &point, -1, NULL))) return MS_FAILURE; } - /* Mark layer as deleted so that it doesn't interfere with html legends or with saving maps */ + /* Mark layer as deleted so that it doesn't interfere with html legends or + * with saving maps */ GET_LAYER(map, l)->status = MS_DELETE; return MS_SUCCESS; diff --git a/maplexer.c b/maplexer.c index a2d9059381..b27c9dd370 100644 --- a/maplexer.c +++ b/maplexer.c @@ -1,6 +1,6 @@ -#line 2 "/home/bjorn/code/MapServer/maplexer.c" +#line 2 "/home/even/mapserver/mapserver/maplexer.c" -#line 4 "/home/bjorn/code/MapServer/maplexer.c" +#line 4 "/home/even/mapserver/mapserver/maplexer.c" #define YY_INT_ALIGNED short int @@ -2212,12 +2212,46 @@ int msyylineno = 1; #define YY_NO_INPUT +/* Below is a redefinition of the default YY_INPUT() macro but replacing the + * YY_FATAL_ERROR() macro with a call to msSetError(). + */ +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + int n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + msSetError(MS_PARSEERR, "%s", "msyyparse()", "input in flex scanner failed"); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + msSetError(MS_PARSEERR, "%s", "msyyparse()", "input in flex scanner failed"); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + } + int msyysource=MS_STRING_TOKENS; double msyynumber; int msyystate=MS_TOKENIZE_DEFAULT; char *msyystring=NULL; char *msyybasepath=NULL; -char *msyystring_buffer_ptr; int msyystring_buffer_size = 0; int msyystring_size; char msyystring_begin; @@ -2225,25 +2259,21 @@ char *msyystring_buffer = NULL; int msyystring_icase = MS_FALSE; int msyystring_return_state; int msyystring_begin_state; -int msyystring_size_tmp; int msyyreturncomments = 0; -#define MS_LEXER_STRING_REALLOC(string, string_size, max_size, string_ptr) \ +#define MS_LEXER_STRING_REALLOC(string, string_size, max_size) \ do { \ const int string_size_macro = (int)(string_size); \ if (string_size_macro >= (int)(max_size)) { \ - msyystring_size_tmp = (max_size); \ max_size = (((int)(max_size)*2) > string_size_macro) ? ((int)(max_size))*2 : string_size_macro+1; \ string = (char *) msSmallRealloc(string, sizeof(char *) * (max_size)); \ - string_ptr = string; \ - string_ptr += msyystring_size_tmp; \ } \ } while(0) #define MS_LEXER_RETURN_TOKEN(token) \ MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), \ - msyystring_buffer_size, msyystring_buffer_ptr); \ + msyystring_buffer_size); \ strcpy(msyystring_buffer, msyytext); \ return(token); @@ -2253,9 +2283,9 @@ int include_lineno[MAX_INCLUDE_DEPTH]; int include_stack_ptr = 0; char path[MS_MAXPATHLEN]; -#line 2257 "/home/bjorn/code/MapServer/maplexer.c" +#line 2287 "/home/even/mapserver/mapserver/maplexer.c" -#line 2259 "/home/bjorn/code/MapServer/maplexer.c" +#line 2289 "/home/even/mapserver/mapserver/maplexer.c" #define INITIAL 0 #define EXPRESSION_STRING 1 @@ -2469,9 +2499,9 @@ YY_DECL } { -#line 93 "maplexer.l" +#line 123 "maplexer.l" -#line 95 "maplexer.l" +#line 125 "maplexer.l" if (msyystring_buffer == NULL) { msyystring_buffer_size = 256; @@ -2535,7 +2565,7 @@ YY_DECL break; } -#line 2539 "/home/bjorn/code/MapServer/maplexer.c" +#line 2569 "/home/even/mapserver/mapserver/maplexer.c" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -2590,1611 +2620,1611 @@ YY_DECL case 1: YY_RULE_SETUP -#line 158 "maplexer.l" +#line 188 "maplexer.l" ; YY_BREAK case 2: YY_RULE_SETUP -#line 160 "maplexer.l" +#line 190 "maplexer.l" { if (msyyreturncomments) return(MS_COMMENT); } YY_BREAK case 3: YY_RULE_SETUP -#line 162 "maplexer.l" +#line 192 "maplexer.l" { BEGIN(MULTILINE_COMMENT); } YY_BREAK case 4: YY_RULE_SETUP -#line 163 "maplexer.l" +#line 193 "maplexer.l" { BEGIN(INITIAL); } YY_BREAK case 5: YY_RULE_SETUP -#line 164 "maplexer.l" +#line 194 "maplexer.l" ; YY_BREAK case 6: YY_RULE_SETUP -#line 165 "maplexer.l" +#line 195 "maplexer.l" ; YY_BREAK case 7: /* rule 7 can match eol */ YY_RULE_SETUP -#line 166 "maplexer.l" +#line 196 "maplexer.l" { msyylineno++; } YY_BREAK case 8: YY_RULE_SETUP -#line 168 "maplexer.l" +#line 198 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CONFIG_SECTION); } YY_BREAK case 9: YY_RULE_SETUP -#line 169 "maplexer.l" +#line 199 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CONFIG_SECTION_ENV); } YY_BREAK case 10: YY_RULE_SETUP -#line 170 "maplexer.l" +#line 200 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CONFIG_SECTION_MAPS); } YY_BREAK case 11: YY_RULE_SETUP -#line 171 "maplexer.l" +#line 201 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CONFIG_SECTION_PLUGINS) } YY_BREAK case 12: YY_RULE_SETUP -#line 173 "maplexer.l" +#line 203 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_LOGICAL_OR); } YY_BREAK case 13: YY_RULE_SETUP -#line 174 "maplexer.l" +#line 204 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_LOGICAL_AND); } YY_BREAK case 14: YY_RULE_SETUP -#line 175 "maplexer.l" +#line 205 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_LOGICAL_NOT); } YY_BREAK case 15: YY_RULE_SETUP -#line 176 "maplexer.l" +#line 206 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_EQ); } YY_BREAK case 16: YY_RULE_SETUP -#line 177 "maplexer.l" +#line 207 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_NE); } YY_BREAK case 17: YY_RULE_SETUP -#line 178 "maplexer.l" +#line 208 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_GT); } YY_BREAK case 18: YY_RULE_SETUP -#line 179 "maplexer.l" +#line 209 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_LT); } YY_BREAK case 19: YY_RULE_SETUP -#line 180 "maplexer.l" +#line 210 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_GE); } YY_BREAK case 20: YY_RULE_SETUP -#line 181 "maplexer.l" +#line 211 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_LE); } YY_BREAK case 21: YY_RULE_SETUP -#line 182 "maplexer.l" +#line 212 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_RE); } YY_BREAK case 22: YY_RULE_SETUP -#line 184 "maplexer.l" +#line 214 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_IEQ); } YY_BREAK case 23: YY_RULE_SETUP -#line 185 "maplexer.l" +#line 215 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_IRE); } YY_BREAK case 24: YY_RULE_SETUP -#line 187 "maplexer.l" +#line 217 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_IN); /* was IN */ } YY_BREAK case 25: YY_RULE_SETUP -#line 189 "maplexer.l" +#line 219 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_AREA); } YY_BREAK case 26: YY_RULE_SETUP -#line 190 "maplexer.l" +#line 220 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_LENGTH); } YY_BREAK case 27: YY_RULE_SETUP -#line 191 "maplexer.l" +#line 221 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_TOSTRING); } YY_BREAK case 28: YY_RULE_SETUP -#line 192 "maplexer.l" +#line 222 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_COMMIFY); } YY_BREAK case 29: YY_RULE_SETUP -#line 193 "maplexer.l" +#line 223 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_ROUND); } YY_BREAK case 30: YY_RULE_SETUP -#line 194 "maplexer.l" +#line 224 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_UPPER); } YY_BREAK case 31: YY_RULE_SETUP -#line 195 "maplexer.l" +#line 225 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_LOWER); } YY_BREAK case 32: YY_RULE_SETUP -#line 196 "maplexer.l" +#line 226 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_INITCAP); } YY_BREAK case 33: YY_RULE_SETUP -#line 197 "maplexer.l" +#line 227 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_FIRSTCAP); } YY_BREAK case 34: YY_RULE_SETUP -#line 199 "maplexer.l" +#line 229 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_BUFFER); } YY_BREAK case 35: YY_RULE_SETUP -#line 200 "maplexer.l" +#line 230 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_DIFFERENCE); } YY_BREAK case 36: YY_RULE_SETUP -#line 201 "maplexer.l" +#line 231 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_SIMPLIFY); } YY_BREAK case 37: YY_RULE_SETUP -#line 202 "maplexer.l" +#line 232 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_SIMPLIFYPT); } YY_BREAK case 38: YY_RULE_SETUP -#line 203 "maplexer.l" +#line 233 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_GENERALIZE); } YY_BREAK case 39: YY_RULE_SETUP -#line 204 "maplexer.l" +#line 234 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_SMOOTHSIA); } YY_BREAK case 40: YY_RULE_SETUP -#line 205 "maplexer.l" +#line 235 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_CENTERLINE); } YY_BREAK case 41: YY_RULE_SETUP -#line 206 "maplexer.l" +#line 236 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_DENSIFY); } YY_BREAK case 42: YY_RULE_SETUP -#line 207 "maplexer.l" +#line 237 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_OUTER); } YY_BREAK case 43: YY_RULE_SETUP -#line 208 "maplexer.l" +#line 238 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_INNER); } YY_BREAK case 44: YY_RULE_SETUP -#line 209 "maplexer.l" +#line 239 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_JAVASCRIPT); } YY_BREAK case 45: YY_RULE_SETUP -#line 211 "maplexer.l" +#line 241 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_INTERSECTS); } YY_BREAK case 46: YY_RULE_SETUP -#line 212 "maplexer.l" +#line 242 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_DISJOINT); } YY_BREAK case 47: YY_RULE_SETUP -#line 213 "maplexer.l" +#line 243 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_TOUCHES); } YY_BREAK case 48: YY_RULE_SETUP -#line 214 "maplexer.l" +#line 244 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_OVERLAPS); } YY_BREAK case 49: YY_RULE_SETUP -#line 215 "maplexer.l" +#line 245 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_CROSSES); } YY_BREAK case 50: YY_RULE_SETUP -#line 216 "maplexer.l" +#line 246 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_WITHIN); } YY_BREAK case 51: YY_RULE_SETUP -#line 217 "maplexer.l" +#line 247 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_CONTAINS); } YY_BREAK case 52: YY_RULE_SETUP -#line 218 "maplexer.l" +#line 248 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_EQUALS); } YY_BREAK case 53: YY_RULE_SETUP -#line 219 "maplexer.l" +#line 249 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_BEYOND); } YY_BREAK case 54: YY_RULE_SETUP -#line 220 "maplexer.l" +#line 250 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_DWITHIN); } YY_BREAK case 55: YY_RULE_SETUP -#line 222 "maplexer.l" +#line 252 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_FROMTEXT); } YY_BREAK case 56: YY_RULE_SETUP -#line 224 "maplexer.l" +#line 254 "maplexer.l" { msyynumber=MS_TRUE; return(MS_TOKEN_LITERAL_BOOLEAN); } YY_BREAK case 57: YY_RULE_SETUP -#line 225 "maplexer.l" +#line 255 "maplexer.l" { msyynumber=MS_FALSE; return(MS_TOKEN_LITERAL_BOOLEAN); } YY_BREAK case 58: YY_RULE_SETUP -#line 227 "maplexer.l" +#line 257 "maplexer.l" { MS_LEXER_RETURN_TOKEN(COLORRANGE); } YY_BREAK case 59: YY_RULE_SETUP -#line 228 "maplexer.l" +#line 258 "maplexer.l" { MS_LEXER_RETURN_TOKEN(DATARANGE); } YY_BREAK case 60: YY_RULE_SETUP -#line 229 "maplexer.l" +#line 259 "maplexer.l" { MS_LEXER_RETURN_TOKEN(RANGEITEM); } YY_BREAK case 61: YY_RULE_SETUP -#line 231 "maplexer.l" +#line 261 "maplexer.l" { MS_LEXER_RETURN_TOKEN(ALIGN); } YY_BREAK case 62: YY_RULE_SETUP -#line 232 "maplexer.l" +#line 262 "maplexer.l" { MS_LEXER_RETURN_TOKEN(ANCHORPOINT); } YY_BREAK case 63: YY_RULE_SETUP -#line 233 "maplexer.l" +#line 263 "maplexer.l" { MS_LEXER_RETURN_TOKEN(ANGLE); } YY_BREAK case 64: YY_RULE_SETUP -#line 234 "maplexer.l" +#line 264 "maplexer.l" { MS_LEXER_RETURN_TOKEN(ANTIALIAS); } YY_BREAK case 65: YY_RULE_SETUP -#line 235 "maplexer.l" +#line 265 "maplexer.l" { MS_LEXER_RETURN_TOKEN(BACKGROUNDCOLOR); } YY_BREAK case 66: YY_RULE_SETUP -#line 236 "maplexer.l" +#line 266 "maplexer.l" { MS_LEXER_RETURN_TOKEN(BANDSITEM); } YY_BREAK case 67: YY_RULE_SETUP -#line 237 "maplexer.l" +#line 267 "maplexer.l" { MS_LEXER_RETURN_TOKEN(BINDVALS); } YY_BREAK case 68: YY_RULE_SETUP -#line 238 "maplexer.l" +#line 268 "maplexer.l" { MS_LEXER_RETURN_TOKEN(BOM); } YY_BREAK case 69: YY_RULE_SETUP -#line 239 "maplexer.l" +#line 269 "maplexer.l" { MS_LEXER_RETURN_TOKEN(BROWSEFORMAT); } YY_BREAK case 70: YY_RULE_SETUP -#line 240 "maplexer.l" +#line 270 "maplexer.l" { MS_LEXER_RETURN_TOKEN(BUFFER); } YY_BREAK case 71: YY_RULE_SETUP -#line 241 "maplexer.l" +#line 271 "maplexer.l" { MS_LEXER_RETURN_TOKEN(CHARACTER); } YY_BREAK case 72: YY_RULE_SETUP -#line 242 "maplexer.l" +#line 272 "maplexer.l" { MS_LEXER_RETURN_TOKEN(CLASS); } YY_BREAK case 73: YY_RULE_SETUP -#line 243 "maplexer.l" +#line 273 "maplexer.l" { MS_LEXER_RETURN_TOKEN(CLASSITEM); } YY_BREAK case 74: YY_RULE_SETUP -#line 244 "maplexer.l" +#line 274 "maplexer.l" { MS_LEXER_RETURN_TOKEN(CLASSGROUP); } YY_BREAK case 75: YY_RULE_SETUP -#line 245 "maplexer.l" +#line 275 "maplexer.l" { MS_LEXER_RETURN_TOKEN(CLUSTER); } YY_BREAK case 76: YY_RULE_SETUP -#line 246 "maplexer.l" +#line 276 "maplexer.l" { MS_LEXER_RETURN_TOKEN(COLOR); } YY_BREAK case 77: YY_RULE_SETUP -#line 247 "maplexer.l" +#line 277 "maplexer.l" { MS_LEXER_RETURN_TOKEN(COMPFILTER); } YY_BREAK case 78: YY_RULE_SETUP -#line 248 "maplexer.l" +#line 278 "maplexer.l" { MS_LEXER_RETURN_TOKEN(COMPOSITE); } YY_BREAK case 79: YY_RULE_SETUP -#line 249 "maplexer.l" +#line 279 "maplexer.l" { MS_LEXER_RETURN_TOKEN(COMPOP); } YY_BREAK case 80: YY_RULE_SETUP -#line 250 "maplexer.l" +#line 280 "maplexer.l" { MS_LEXER_RETURN_TOKEN(CONFIG); } YY_BREAK case 81: YY_RULE_SETUP -#line 251 "maplexer.l" +#line 281 "maplexer.l" { MS_LEXER_RETURN_TOKEN(CONNECTION); } YY_BREAK case 82: YY_RULE_SETUP -#line 252 "maplexer.l" +#line 282 "maplexer.l" { MS_LEXER_RETURN_TOKEN(CONNECTIONTYPE); } YY_BREAK case 83: YY_RULE_SETUP -#line 253 "maplexer.l" +#line 283 "maplexer.l" { MS_LEXER_RETURN_TOKEN(DATA); } YY_BREAK case 84: YY_RULE_SETUP -#line 254 "maplexer.l" +#line 284 "maplexer.l" { MS_LEXER_RETURN_TOKEN(DEBUG); } YY_BREAK case 85: YY_RULE_SETUP -#line 255 "maplexer.l" +#line 285 "maplexer.l" { MS_LEXER_RETURN_TOKEN(DRIVER); } YY_BREAK case 86: YY_RULE_SETUP -#line 256 "maplexer.l" +#line 286 "maplexer.l" { MS_LEXER_RETURN_TOKEN(EMPTY); } YY_BREAK case 87: YY_RULE_SETUP -#line 257 "maplexer.l" +#line 287 "maplexer.l" { MS_LEXER_RETURN_TOKEN(ENCODING); } YY_BREAK case 88: YY_RULE_SETUP -#line 258 "maplexer.l" +#line 288 "maplexer.l" { MS_LEXER_RETURN_TOKEN(END); } YY_BREAK case 89: YY_RULE_SETUP -#line 259 "maplexer.l" +#line 289 "maplexer.l" { MS_LEXER_RETURN_TOKEN(ERROR); } YY_BREAK case 90: YY_RULE_SETUP -#line 260 "maplexer.l" +#line 290 "maplexer.l" { MS_LEXER_RETURN_TOKEN(EXPRESSION); } YY_BREAK case 91: YY_RULE_SETUP -#line 261 "maplexer.l" +#line 291 "maplexer.l" { MS_LEXER_RETURN_TOKEN(EXTENT); } YY_BREAK case 92: YY_RULE_SETUP -#line 262 "maplexer.l" +#line 292 "maplexer.l" { MS_LEXER_RETURN_TOKEN(EXTENSION); } YY_BREAK case 93: YY_RULE_SETUP -#line 263 "maplexer.l" +#line 293 "maplexer.l" { MS_LEXER_RETURN_TOKEN(FEATURE); } YY_BREAK case 94: YY_RULE_SETUP -#line 264 "maplexer.l" +#line 294 "maplexer.l" { MS_LEXER_RETURN_TOKEN(FILLED); } YY_BREAK case 95: YY_RULE_SETUP -#line 265 "maplexer.l" +#line 295 "maplexer.l" { MS_LEXER_RETURN_TOKEN(FILTER); } YY_BREAK case 96: YY_RULE_SETUP -#line 266 "maplexer.l" +#line 296 "maplexer.l" { MS_LEXER_RETURN_TOKEN(FILTERITEM); } YY_BREAK case 97: YY_RULE_SETUP -#line 267 "maplexer.l" +#line 297 "maplexer.l" { MS_LEXER_RETURN_TOKEN(FOOTER); } YY_BREAK case 98: YY_RULE_SETUP -#line 268 "maplexer.l" +#line 298 "maplexer.l" { MS_LEXER_RETURN_TOKEN(FONT); } YY_BREAK case 99: YY_RULE_SETUP -#line 269 "maplexer.l" +#line 299 "maplexer.l" { MS_LEXER_RETURN_TOKEN(FONTSET); } YY_BREAK case 100: YY_RULE_SETUP -#line 270 "maplexer.l" +#line 300 "maplexer.l" { MS_LEXER_RETURN_TOKEN(FORCE); } YY_BREAK case 101: YY_RULE_SETUP -#line 271 "maplexer.l" +#line 301 "maplexer.l" { MS_LEXER_RETURN_TOKEN(FORMATOPTION); } YY_BREAK case 102: YY_RULE_SETUP -#line 272 "maplexer.l" +#line 302 "maplexer.l" { MS_LEXER_RETURN_TOKEN(FROM); } YY_BREAK case 103: YY_RULE_SETUP -#line 273 "maplexer.l" +#line 303 "maplexer.l" { MS_LEXER_RETURN_TOKEN(GAP); } YY_BREAK case 104: YY_RULE_SETUP -#line 274 "maplexer.l" +#line 304 "maplexer.l" { MS_LEXER_RETURN_TOKEN(GEOMTRANSFORM); } YY_BREAK case 105: YY_RULE_SETUP -#line 275 "maplexer.l" +#line 305 "maplexer.l" { MS_LEXER_RETURN_TOKEN(GRID); } YY_BREAK case 106: YY_RULE_SETUP -#line 276 "maplexer.l" +#line 306 "maplexer.l" { MS_LEXER_RETURN_TOKEN(GRIDSTEP); } YY_BREAK case 107: YY_RULE_SETUP -#line 277 "maplexer.l" +#line 307 "maplexer.l" { MS_LEXER_RETURN_TOKEN(GRATICULE); } YY_BREAK case 108: YY_RULE_SETUP -#line 278 "maplexer.l" +#line 308 "maplexer.l" { MS_LEXER_RETURN_TOKEN(GROUP); } YY_BREAK case 109: YY_RULE_SETUP -#line 279 "maplexer.l" +#line 309 "maplexer.l" { MS_LEXER_RETURN_TOKEN(HEADER); } YY_BREAK case 110: YY_RULE_SETUP -#line 280 "maplexer.l" +#line 310 "maplexer.l" { MS_LEXER_RETURN_TOKEN(IMAGE); } YY_BREAK case 111: YY_RULE_SETUP -#line 281 "maplexer.l" +#line 311 "maplexer.l" { MS_LEXER_RETURN_TOKEN(IMAGECOLOR); } YY_BREAK case 112: YY_RULE_SETUP -#line 282 "maplexer.l" +#line 312 "maplexer.l" { MS_LEXER_RETURN_TOKEN(IMAGETYPE); } YY_BREAK case 113: YY_RULE_SETUP -#line 283 "maplexer.l" +#line 313 "maplexer.l" { MS_LEXER_RETURN_TOKEN(IMAGEMODE); } YY_BREAK case 114: YY_RULE_SETUP -#line 284 "maplexer.l" +#line 314 "maplexer.l" { MS_LEXER_RETURN_TOKEN(IMAGEPATH); } YY_BREAK case 115: YY_RULE_SETUP -#line 285 "maplexer.l" +#line 315 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TEMPPATH); } YY_BREAK case 116: YY_RULE_SETUP -#line 286 "maplexer.l" +#line 316 "maplexer.l" { MS_LEXER_RETURN_TOKEN(IMAGEURL); } YY_BREAK case 117: YY_RULE_SETUP -#line 287 "maplexer.l" +#line 317 "maplexer.l" { BEGIN(INCLUDE); } YY_BREAK case 118: YY_RULE_SETUP -#line 288 "maplexer.l" +#line 318 "maplexer.l" { MS_LEXER_RETURN_TOKEN(INDEX); } YY_BREAK case 119: YY_RULE_SETUP -#line 289 "maplexer.l" +#line 319 "maplexer.l" { MS_LEXER_RETURN_TOKEN(INITIALGAP); } YY_BREAK case 120: YY_RULE_SETUP -#line 290 "maplexer.l" +#line 320 "maplexer.l" { MS_LEXER_RETURN_TOKEN(INTERVALS); } YY_BREAK case 121: YY_RULE_SETUP -#line 291 "maplexer.l" +#line 321 "maplexer.l" { MS_LEXER_RETURN_TOKEN(JOIN); } YY_BREAK case 122: YY_RULE_SETUP -#line 292 "maplexer.l" +#line 322 "maplexer.l" { MS_LEXER_RETURN_TOKEN(KEYIMAGE); } YY_BREAK case 123: YY_RULE_SETUP -#line 293 "maplexer.l" +#line 323 "maplexer.l" { MS_LEXER_RETURN_TOKEN(KEYSIZE); } YY_BREAK case 124: YY_RULE_SETUP -#line 294 "maplexer.l" +#line 324 "maplexer.l" { MS_LEXER_RETURN_TOKEN(KEYSPACING); } YY_BREAK case 125: YY_RULE_SETUP -#line 295 "maplexer.l" +#line 325 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LABEL); } YY_BREAK case 126: YY_RULE_SETUP -#line 296 "maplexer.l" +#line 326 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LABELCACHE); } YY_BREAK case 127: YY_RULE_SETUP -#line 297 "maplexer.l" +#line 327 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LABELFORMAT); } YY_BREAK case 128: YY_RULE_SETUP -#line 298 "maplexer.l" +#line 328 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LABELITEM); } YY_BREAK case 129: YY_RULE_SETUP -#line 299 "maplexer.l" +#line 329 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LABELMAXSCALE); } YY_BREAK case 130: YY_RULE_SETUP -#line 300 "maplexer.l" +#line 330 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LABELMAXSCALEDENOM); } YY_BREAK case 131: YY_RULE_SETUP -#line 301 "maplexer.l" +#line 331 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LABELMINSCALE); } YY_BREAK case 132: YY_RULE_SETUP -#line 302 "maplexer.l" +#line 332 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LABELMINSCALEDENOM); } YY_BREAK case 133: YY_RULE_SETUP -#line 303 "maplexer.l" +#line 333 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LABELREQUIRES); } YY_BREAK case 134: YY_RULE_SETUP -#line 304 "maplexer.l" +#line 334 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LATLON); } YY_BREAK case 135: YY_RULE_SETUP -#line 305 "maplexer.l" +#line 335 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LAYER); } YY_BREAK case 136: YY_RULE_SETUP -#line 306 "maplexer.l" +#line 336 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LEADER); } YY_BREAK case 137: YY_RULE_SETUP -#line 307 "maplexer.l" +#line 337 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LEGEND); } YY_BREAK case 138: YY_RULE_SETUP -#line 308 "maplexer.l" +#line 338 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LEGENDFORMAT); } YY_BREAK case 139: YY_RULE_SETUP -#line 309 "maplexer.l" +#line 339 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LINECAP); } YY_BREAK case 140: YY_RULE_SETUP -#line 310 "maplexer.l" +#line 340 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LINEJOIN); } YY_BREAK case 141: YY_RULE_SETUP -#line 311 "maplexer.l" +#line 341 "maplexer.l" { MS_LEXER_RETURN_TOKEN(LINEJOINMAXSIZE); } YY_BREAK case 142: YY_RULE_SETUP -#line 312 "maplexer.l" +#line 342 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAP); } YY_BREAK case 143: YY_RULE_SETUP -#line 313 "maplexer.l" +#line 343 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MARKER); } YY_BREAK case 144: YY_RULE_SETUP -#line 314 "maplexer.l" +#line 344 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MARKERSIZE); } YY_BREAK case 145: YY_RULE_SETUP -#line 315 "maplexer.l" +#line 345 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MASK); } YY_BREAK case 146: YY_RULE_SETUP -#line 316 "maplexer.l" +#line 346 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXARCS); } YY_BREAK case 147: YY_RULE_SETUP -#line 317 "maplexer.l" +#line 347 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXBOXSIZE); } YY_BREAK case 148: YY_RULE_SETUP -#line 318 "maplexer.l" +#line 348 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXDISTANCE); } YY_BREAK case 149: YY_RULE_SETUP -#line 319 "maplexer.l" +#line 349 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXFEATURES); } YY_BREAK case 150: YY_RULE_SETUP -#line 320 "maplexer.l" +#line 350 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXINTERVAL); } YY_BREAK case 151: YY_RULE_SETUP -#line 321 "maplexer.l" +#line 351 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXSCALE); } YY_BREAK case 152: YY_RULE_SETUP -#line 322 "maplexer.l" +#line 352 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXSCALEDENOM); } YY_BREAK case 153: YY_RULE_SETUP -#line 323 "maplexer.l" +#line 353 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXGEOWIDTH); } YY_BREAK case 154: YY_RULE_SETUP -#line 324 "maplexer.l" +#line 354 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXLENGTH); } YY_BREAK case 155: YY_RULE_SETUP -#line 325 "maplexer.l" +#line 355 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXSIZE); } YY_BREAK case 156: YY_RULE_SETUP -#line 326 "maplexer.l" +#line 356 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXSUBDIVIDE); } YY_BREAK case 157: YY_RULE_SETUP -#line 327 "maplexer.l" +#line 357 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXTEMPLATE); } YY_BREAK case 158: YY_RULE_SETUP -#line 328 "maplexer.l" +#line 358 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXWIDTH); } YY_BREAK case 159: YY_RULE_SETUP -#line 329 "maplexer.l" +#line 359 "maplexer.l" { MS_LEXER_RETURN_TOKEN(METADATA); } YY_BREAK case 160: YY_RULE_SETUP -#line 330 "maplexer.l" +#line 360 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MIMETYPE); } YY_BREAK case 161: YY_RULE_SETUP -#line 331 "maplexer.l" +#line 361 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINARCS); } YY_BREAK case 162: YY_RULE_SETUP -#line 332 "maplexer.l" +#line 362 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINBOXSIZE); } YY_BREAK case 163: YY_RULE_SETUP -#line 333 "maplexer.l" +#line 363 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINDISTANCE); } YY_BREAK case 164: YY_RULE_SETUP -#line 334 "maplexer.l" +#line 364 "maplexer.l" { MS_LEXER_RETURN_TOKEN(REPEATDISTANCE); } YY_BREAK case 165: YY_RULE_SETUP -#line 335 "maplexer.l" +#line 365 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MAXOVERLAPANGLE); } YY_BREAK case 166: YY_RULE_SETUP -#line 336 "maplexer.l" +#line 366 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINFEATURESIZE); } YY_BREAK case 167: YY_RULE_SETUP -#line 337 "maplexer.l" +#line 367 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MININTERVAL); } YY_BREAK case 168: YY_RULE_SETUP -#line 338 "maplexer.l" +#line 368 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINSCALE); } YY_BREAK case 169: YY_RULE_SETUP -#line 339 "maplexer.l" +#line 369 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINSCALEDENOM); } YY_BREAK case 170: YY_RULE_SETUP -#line 340 "maplexer.l" +#line 370 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINGEOWIDTH); } YY_BREAK case 171: YY_RULE_SETUP -#line 341 "maplexer.l" +#line 371 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINSIZE); } YY_BREAK case 172: YY_RULE_SETUP -#line 342 "maplexer.l" +#line 372 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINSUBDIVIDE); } YY_BREAK case 173: YY_RULE_SETUP -#line 343 "maplexer.l" +#line 373 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINTEMPLATE); } YY_BREAK case 174: YY_RULE_SETUP -#line 344 "maplexer.l" +#line 374 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MINWIDTH); } YY_BREAK case 175: YY_RULE_SETUP -#line 345 "maplexer.l" +#line 375 "maplexer.l" { MS_LEXER_RETURN_TOKEN(NAME); } YY_BREAK case 176: YY_RULE_SETUP -#line 346 "maplexer.l" +#line 376 "maplexer.l" { MS_LEXER_RETURN_TOKEN(OFFSET); } YY_BREAK case 177: YY_RULE_SETUP -#line 347 "maplexer.l" +#line 377 "maplexer.l" { MS_LEXER_RETURN_TOKEN(OFFSITE); } YY_BREAK case 178: YY_RULE_SETUP -#line 348 "maplexer.l" +#line 378 "maplexer.l" { MS_LEXER_RETURN_TOKEN(OPACITY); } YY_BREAK case 179: YY_RULE_SETUP -#line 349 "maplexer.l" +#line 379 "maplexer.l" { MS_LEXER_RETURN_TOKEN(CONNECTIONOPTIONS); } YY_BREAK case 180: YY_RULE_SETUP -#line 350 "maplexer.l" +#line 380 "maplexer.l" { MS_LEXER_RETURN_TOKEN(OUTLINECOLOR); } YY_BREAK case 181: YY_RULE_SETUP -#line 351 "maplexer.l" +#line 381 "maplexer.l" { MS_LEXER_RETURN_TOKEN(OUTLINEWIDTH); } YY_BREAK case 182: YY_RULE_SETUP -#line 352 "maplexer.l" +#line 382 "maplexer.l" { MS_LEXER_RETURN_TOKEN(OUTPUTFORMAT); } YY_BREAK case 183: YY_RULE_SETUP -#line 353 "maplexer.l" +#line 383 "maplexer.l" { MS_LEXER_RETURN_TOKEN(PARTIALS); } YY_BREAK case 184: YY_RULE_SETUP -#line 354 "maplexer.l" +#line 384 "maplexer.l" { MS_LEXER_RETURN_TOKEN(PATTERN); } YY_BREAK case 185: YY_RULE_SETUP -#line 355 "maplexer.l" +#line 385 "maplexer.l" { MS_LEXER_RETURN_TOKEN(POINTS); } YY_BREAK case 186: YY_RULE_SETUP -#line 356 "maplexer.l" +#line 386 "maplexer.l" { MS_LEXER_RETURN_TOKEN(ITEMS); } YY_BREAK case 187: YY_RULE_SETUP -#line 357 "maplexer.l" +#line 387 "maplexer.l" { MS_LEXER_RETURN_TOKEN(POSITION); } YY_BREAK case 188: YY_RULE_SETUP -#line 358 "maplexer.l" +#line 388 "maplexer.l" { MS_LEXER_RETURN_TOKEN(POSTLABELCACHE); } YY_BREAK case 189: YY_RULE_SETUP -#line 359 "maplexer.l" +#line 389 "maplexer.l" { MS_LEXER_RETURN_TOKEN(PRIORITY); } YY_BREAK case 190: YY_RULE_SETUP -#line 360 "maplexer.l" +#line 390 "maplexer.l" { MS_LEXER_RETURN_TOKEN(PROCESSING); } YY_BREAK case 191: YY_RULE_SETUP -#line 361 "maplexer.l" +#line 391 "maplexer.l" { MS_LEXER_RETURN_TOKEN(PROJECTION); } YY_BREAK case 192: YY_RULE_SETUP -#line 362 "maplexer.l" +#line 392 "maplexer.l" { MS_LEXER_RETURN_TOKEN(QUERYFORMAT); } YY_BREAK case 193: YY_RULE_SETUP -#line 363 "maplexer.l" +#line 393 "maplexer.l" { MS_LEXER_RETURN_TOKEN(QUERYMAP); } YY_BREAK case 194: YY_RULE_SETUP -#line 364 "maplexer.l" +#line 394 "maplexer.l" { MS_LEXER_RETURN_TOKEN(REFERENCE); } YY_BREAK case 195: YY_RULE_SETUP -#line 365 "maplexer.l" +#line 395 "maplexer.l" { MS_LEXER_RETURN_TOKEN(REGION); } YY_BREAK case 196: YY_RULE_SETUP -#line 366 "maplexer.l" +#line 396 "maplexer.l" { MS_LEXER_RETURN_TOKEN(RELATIVETO); } YY_BREAK case 197: YY_RULE_SETUP -#line 367 "maplexer.l" +#line 397 "maplexer.l" { MS_LEXER_RETURN_TOKEN(REQUIRES); } YY_BREAK case 198: YY_RULE_SETUP -#line 368 "maplexer.l" +#line 398 "maplexer.l" { MS_LEXER_RETURN_TOKEN(RESOLUTION); } YY_BREAK case 199: YY_RULE_SETUP -#line 369 "maplexer.l" +#line 399 "maplexer.l" { MS_LEXER_RETURN_TOKEN(DEFRESOLUTION); } YY_BREAK case 200: YY_RULE_SETUP -#line 370 "maplexer.l" +#line 400 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SCALE); } YY_BREAK case 201: YY_RULE_SETUP -#line 371 "maplexer.l" +#line 401 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SCALEDENOM); } YY_BREAK case 202: YY_RULE_SETUP -#line 372 "maplexer.l" +#line 402 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SCALEBAR); } YY_BREAK case 203: YY_RULE_SETUP -#line 373 "maplexer.l" +#line 403 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SCALETOKEN); } YY_BREAK case 204: YY_RULE_SETUP -#line 374 "maplexer.l" +#line 404 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SHADOWCOLOR); } YY_BREAK case 205: YY_RULE_SETUP -#line 375 "maplexer.l" +#line 405 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SHADOWSIZE); } YY_BREAK case 206: YY_RULE_SETUP -#line 376 "maplexer.l" +#line 406 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SHAPEPATH); } YY_BREAK case 207: YY_RULE_SETUP -#line 377 "maplexer.l" +#line 407 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SIZE); } YY_BREAK case 208: YY_RULE_SETUP -#line 378 "maplexer.l" +#line 408 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SIZEUNITS); } YY_BREAK case 209: YY_RULE_SETUP -#line 379 "maplexer.l" +#line 409 "maplexer.l" { MS_LEXER_RETURN_TOKEN(STATUS); } YY_BREAK case 210: YY_RULE_SETUP -#line 380 "maplexer.l" +#line 410 "maplexer.l" { MS_LEXER_RETURN_TOKEN(STYLE); } YY_BREAK case 211: YY_RULE_SETUP -#line 381 "maplexer.l" +#line 411 "maplexer.l" { MS_LEXER_RETURN_TOKEN(STYLEITEM); } YY_BREAK case 212: YY_RULE_SETUP -#line 382 "maplexer.l" +#line 412 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SYMBOL); } YY_BREAK case 213: YY_RULE_SETUP -#line 383 "maplexer.l" +#line 413 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SYMBOLSCALE); } YY_BREAK case 214: YY_RULE_SETUP -#line 384 "maplexer.l" +#line 414 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SYMBOLSCALEDENOM); } YY_BREAK case 215: YY_RULE_SETUP -#line 385 "maplexer.l" +#line 415 "maplexer.l" { MS_LEXER_RETURN_TOKEN(SYMBOLSET); } YY_BREAK case 216: YY_RULE_SETUP -#line 386 "maplexer.l" +#line 416 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TABLE); } YY_BREAK case 217: YY_RULE_SETUP -#line 387 "maplexer.l" +#line 417 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TEMPLATE); } YY_BREAK case 218: YY_RULE_SETUP -#line 388 "maplexer.l" +#line 418 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TEXT); } YY_BREAK case 219: YY_RULE_SETUP -#line 389 "maplexer.l" +#line 419 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TILEINDEX); } YY_BREAK case 220: YY_RULE_SETUP -#line 390 "maplexer.l" +#line 420 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TILEITEM); } YY_BREAK case 221: YY_RULE_SETUP -#line 391 "maplexer.l" +#line 421 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TILESRS); } YY_BREAK case 222: YY_RULE_SETUP -#line 392 "maplexer.l" +#line 422 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TITLE); } YY_BREAK case 223: YY_RULE_SETUP -#line 393 "maplexer.l" +#line 423 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TO); } YY_BREAK case 224: YY_RULE_SETUP -#line 394 "maplexer.l" +#line 424 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TOLERANCE); } YY_BREAK case 225: YY_RULE_SETUP -#line 395 "maplexer.l" +#line 425 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TOLERANCEUNITS); } YY_BREAK case 226: YY_RULE_SETUP -#line 396 "maplexer.l" +#line 426 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TRANSPARENT); } YY_BREAK case 227: YY_RULE_SETUP -#line 397 "maplexer.l" +#line 427 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TRANSFORM); } YY_BREAK case 228: YY_RULE_SETUP -#line 398 "maplexer.l" +#line 428 "maplexer.l" { MS_LEXER_RETURN_TOKEN(TYPE); } YY_BREAK case 229: YY_RULE_SETUP -#line 399 "maplexer.l" +#line 429 "maplexer.l" { MS_LEXER_RETURN_TOKEN(UNITS); } YY_BREAK case 230: YY_RULE_SETUP -#line 400 "maplexer.l" +#line 430 "maplexer.l" { MS_LEXER_RETURN_TOKEN(UTFDATA); } YY_BREAK case 231: YY_RULE_SETUP -#line 401 "maplexer.l" +#line 431 "maplexer.l" { MS_LEXER_RETURN_TOKEN(UTFITEM); } YY_BREAK case 232: YY_RULE_SETUP -#line 402 "maplexer.l" +#line 432 "maplexer.l" { MS_LEXER_RETURN_TOKEN(VALIDATION); } YY_BREAK case 233: YY_RULE_SETUP -#line 403 "maplexer.l" +#line 433 "maplexer.l" { MS_LEXER_RETURN_TOKEN(VALUES); } YY_BREAK case 234: YY_RULE_SETUP -#line 404 "maplexer.l" +#line 434 "maplexer.l" { MS_LEXER_RETURN_TOKEN(WEB); } YY_BREAK case 235: YY_RULE_SETUP -#line 405 "maplexer.l" +#line 435 "maplexer.l" { MS_LEXER_RETURN_TOKEN(WIDTH); } YY_BREAK case 236: YY_RULE_SETUP -#line 406 "maplexer.l" +#line 436 "maplexer.l" { MS_LEXER_RETURN_TOKEN(WKT); } YY_BREAK case 237: YY_RULE_SETUP -#line 407 "maplexer.l" +#line 437 "maplexer.l" { MS_LEXER_RETURN_TOKEN(WRAP); } YY_BREAK case 238: YY_RULE_SETUP -#line 409 "maplexer.l" +#line 439 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LAYER_ANNOTATION); } YY_BREAK case 239: YY_RULE_SETUP -#line 410 "maplexer.l" +#line 440 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_AUTO); } YY_BREAK case 240: YY_RULE_SETUP -#line 411 "maplexer.l" +#line 441 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_AUTO2); } YY_BREAK case 241: YY_RULE_SETUP -#line 412 "maplexer.l" +#line 442 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CJC_BEVEL); } YY_BREAK case 242: YY_RULE_SETUP -#line 413 "maplexer.l" +#line 443 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_BITMAP); } YY_BREAK case 243: YY_RULE_SETUP -#line 414 "maplexer.l" +#line 444 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CJC_BUTT); } YY_BREAK case 244: YY_RULE_SETUP -#line 415 "maplexer.l" +#line 445 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CC); } YY_BREAK case 245: YY_RULE_SETUP -#line 416 "maplexer.l" +#line 446 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_ALIGN_CENTER); } YY_BREAK case 246: YY_RULE_SETUP -#line 417 "maplexer.l" +#line 447 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LAYER_CHART); } YY_BREAK case 247: YY_RULE_SETUP -#line 418 "maplexer.l" +#line 448 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LAYER_CIRCLE); } YY_BREAK case 248: YY_RULE_SETUP -#line 419 "maplexer.l" +#line 449 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CL); } YY_BREAK case 249: YY_RULE_SETUP -#line 420 "maplexer.l" +#line 450 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CR); } YY_BREAK case 250: YY_RULE_SETUP -#line 421 "maplexer.l" +#line 451 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_DB_CSV); } YY_BREAK case 251: YY_RULE_SETUP -#line 422 "maplexer.l" +#line 452 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_DB_POSTGRES); } YY_BREAK case 252: YY_RULE_SETUP -#line 423 "maplexer.l" +#line 453 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_DB_MYSQL); } YY_BREAK case 253: YY_RULE_SETUP -#line 424 "maplexer.l" +#line 454 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_DEFAULT); } YY_BREAK case 254: YY_RULE_SETUP -#line 425 "maplexer.l" +#line 455 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_DD); } YY_BREAK case 255: YY_RULE_SETUP -#line 426 "maplexer.l" +#line 456 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_SYMBOL_ELLIPSE); } YY_BREAK case 256: YY_RULE_SETUP -#line 427 "maplexer.l" +#line 457 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_EMBED); } YY_BREAK case 257: YY_RULE_SETUP -#line 428 "maplexer.l" +#line 458 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_FALSE); } YY_BREAK case 258: YY_RULE_SETUP -#line 429 "maplexer.l" +#line 459 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_FEET); } YY_BREAK case 259: YY_RULE_SETUP -#line 430 "maplexer.l" +#line 460 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_FOLLOW); } YY_BREAK case 260: YY_RULE_SETUP -#line 431 "maplexer.l" +#line 461 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_GIANT); } YY_BREAK case 261: YY_RULE_SETUP -#line 432 "maplexer.l" +#line 462 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_SYMBOL_HATCH); } YY_BREAK case 262: YY_RULE_SETUP -#line 433 "maplexer.l" +#line 463 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_KERNELDENSITY); } YY_BREAK case 263: YY_RULE_SETUP -#line 434 "maplexer.l" +#line 464 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_IDW); } YY_BREAK case 264: YY_RULE_SETUP -#line 435 "maplexer.l" +#line 465 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_HILITE); } YY_BREAK case 265: YY_RULE_SETUP -#line 436 "maplexer.l" +#line 466 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_INCHES); } YY_BREAK case 266: YY_RULE_SETUP -#line 437 "maplexer.l" +#line 467 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_KILOMETERS); } YY_BREAK case 267: YY_RULE_SETUP -#line 438 "maplexer.l" +#line 468 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LARGE); } YY_BREAK case 268: YY_RULE_SETUP -#line 439 "maplexer.l" +#line 469 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LC); } YY_BREAK case 269: YY_RULE_SETUP -#line 440 "maplexer.l" +#line 470 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_ALIGN_LEFT); } YY_BREAK case 270: YY_RULE_SETUP -#line 441 "maplexer.l" +#line 471 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LAYER_LINE); } YY_BREAK case 271: YY_RULE_SETUP -#line 442 "maplexer.l" +#line 472 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LL); } YY_BREAK case 272: YY_RULE_SETUP -#line 443 "maplexer.l" +#line 473 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LR); } YY_BREAK case 273: YY_RULE_SETUP -#line 444 "maplexer.l" +#line 474 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_MEDIUM); } YY_BREAK case 274: YY_RULE_SETUP -#line 445 "maplexer.l" +#line 475 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_METERS); } YY_BREAK case 275: YY_RULE_SETUP -#line 446 "maplexer.l" +#line 476 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_NAUTICALMILES); } YY_BREAK case 276: YY_RULE_SETUP -#line 447 "maplexer.l" +#line 477 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_MILES); } YY_BREAK case 277: YY_RULE_SETUP -#line 448 "maplexer.l" +#line 478 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CJC_MITER); } YY_BREAK case 278: YY_RULE_SETUP -#line 449 "maplexer.l" +#line 479 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_MULTIPLE); } YY_BREAK case 279: YY_RULE_SETUP -#line 450 "maplexer.l" +#line 480 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CJC_NONE); } YY_BREAK case 280: YY_RULE_SETUP -#line 451 "maplexer.l" +#line 481 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_NORMAL); } YY_BREAK case 281: YY_RULE_SETUP -#line 452 "maplexer.l" +#line 482 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_OFF); } YY_BREAK case 282: YY_RULE_SETUP -#line 453 "maplexer.l" +#line 483 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_OGR); } YY_BREAK case 283: YY_RULE_SETUP -#line 454 "maplexer.l" +#line 484 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_FLATGEOBUF); } YY_BREAK case 284: YY_RULE_SETUP -#line 455 "maplexer.l" +#line 485 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_ON); } YY_BREAK case 285: YY_RULE_SETUP -#line 456 "maplexer.l" +#line 486 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_JOIN_ONE_TO_ONE); } YY_BREAK case 286: YY_RULE_SETUP -#line 457 "maplexer.l" +#line 487 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_JOIN_ONE_TO_MANY); } YY_BREAK case 287: YY_RULE_SETUP -#line 458 "maplexer.l" +#line 488 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_ORACLESPATIAL); } YY_BREAK case 288: YY_RULE_SETUP -#line 459 "maplexer.l" +#line 489 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_PERCENTAGES); } YY_BREAK case 289: YY_RULE_SETUP -#line 460 "maplexer.l" +#line 490 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_SYMBOL_PIXMAP); } YY_BREAK case 290: YY_RULE_SETUP -#line 461 "maplexer.l" +#line 491 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_PIXELS); } YY_BREAK case 291: YY_RULE_SETUP -#line 462 "maplexer.l" +#line 492 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LAYER_POINT); } YY_BREAK case 292: YY_RULE_SETUP -#line 463 "maplexer.l" +#line 493 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LAYER_POLYGON); } YY_BREAK case 293: YY_RULE_SETUP -#line 464 "maplexer.l" +#line 494 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_POSTGIS); } YY_BREAK case 294: YY_RULE_SETUP -#line 465 "maplexer.l" +#line 495 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_PLUGIN); } YY_BREAK case 295: YY_RULE_SETUP -#line 466 "maplexer.l" +#line 496 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LAYER_QUERY); } YY_BREAK case 296: YY_RULE_SETUP -#line 467 "maplexer.l" +#line 497 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_LAYER_RASTER); } YY_BREAK case 297: YY_RULE_SETUP -#line 468 "maplexer.l" +#line 498 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_ALIGN_RIGHT); } YY_BREAK case 298: YY_RULE_SETUP -#line 469 "maplexer.l" +#line 499 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CJC_ROUND); } YY_BREAK case 299: YY_RULE_SETUP -#line 470 "maplexer.l" +#line 500 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_SELECTED); } YY_BREAK case 300: YY_RULE_SETUP -#line 471 "maplexer.l" +#line 501 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_SYMBOL_SIMPLE); } YY_BREAK case 301: YY_RULE_SETUP -#line 472 "maplexer.l" +#line 502 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_SINGLE); } YY_BREAK case 302: YY_RULE_SETUP -#line 473 "maplexer.l" +#line 503 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_SMALL); } YY_BREAK case 303: YY_RULE_SETUP -#line 474 "maplexer.l" +#line 504 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CJC_SQUARE); } YY_BREAK case 304: YY_RULE_SETUP -#line 475 "maplexer.l" +#line 505 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_SYMBOL_SVG); } YY_BREAK case 305: YY_RULE_SETUP -#line 476 "maplexer.l" +#line 506 "maplexer.l" { MS_LEXER_RETURN_TOKEN(POLAROFFSET); } YY_BREAK case 306: YY_RULE_SETUP -#line 477 "maplexer.l" +#line 507 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TINY); } YY_BREAK case 307: YY_RULE_SETUP -#line 478 "maplexer.l" +#line 508 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CJC_TRIANGLE); } YY_BREAK case 308: YY_RULE_SETUP -#line 479 "maplexer.l" +#line 509 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TRUE); } YY_BREAK case 309: YY_RULE_SETUP -#line 480 "maplexer.l" +#line 510 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_TRUETYPE); } YY_BREAK case 310: YY_RULE_SETUP -#line 481 "maplexer.l" +#line 511 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_UC); } YY_BREAK case 311: YY_RULE_SETUP -#line 482 "maplexer.l" +#line 512 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_UL); } YY_BREAK case 312: YY_RULE_SETUP -#line 483 "maplexer.l" +#line 513 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_UR); } YY_BREAK case 313: YY_RULE_SETUP -#line 484 "maplexer.l" +#line 514 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_UNION); } YY_BREAK case 314: YY_RULE_SETUP -#line 485 "maplexer.l" +#line 515 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_UVRASTER); } YY_BREAK case 315: YY_RULE_SETUP -#line 486 "maplexer.l" +#line 516 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_CONTOUR); } YY_BREAK case 316: YY_RULE_SETUP -#line 487 "maplexer.l" +#line 517 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_SYMBOL_VECTOR); } YY_BREAK case 317: YY_RULE_SETUP -#line 488 "maplexer.l" +#line 518 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_WFS); } YY_BREAK case 318: YY_RULE_SETUP -#line 489 "maplexer.l" +#line 519 "maplexer.l" { MS_LEXER_RETURN_TOKEN(MS_WMS); } YY_BREAK case 319: /* rule 319 can match eol */ YY_RULE_SETUP -#line 491 "maplexer.l" +#line 521 "maplexer.l" { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer,msyytext); return(MS_BINDING); } YY_BREAK case 320: YY_RULE_SETUP -#line 500 "maplexer.l" +#line 530 "maplexer.l" { /* attribute binding - shape (fixed value) */ return(MS_TOKEN_BINDING_SHAPE); @@ -4202,7 +4232,7 @@ YY_RULE_SETUP YY_BREAK case 321: YY_RULE_SETUP -#line 504 "maplexer.l" +#line 534 "maplexer.l" { /* attribute binding - map cellsize */ return(MS_TOKEN_BINDING_MAP_CELLSIZE); @@ -4210,7 +4240,7 @@ YY_RULE_SETUP YY_BREAK case 322: YY_RULE_SETUP -#line 508 "maplexer.l" +#line 538 "maplexer.l" { /* attribute binding - data cellsize */ return(MS_TOKEN_BINDING_DATA_CELLSIZE); @@ -4219,13 +4249,13 @@ YY_RULE_SETUP case 323: /* rule 323 can match eol */ YY_RULE_SETUP -#line 512 "maplexer.l" +#line 542 "maplexer.l" { /* attribute binding - numeric (no quotes) */ msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_TOKEN_BINDING_DOUBLE); } @@ -4233,13 +4263,13 @@ YY_RULE_SETUP case 324: /* rule 324 can match eol */ YY_RULE_SETUP -#line 521 "maplexer.l" +#line 551 "maplexer.l" { /* attribute binding - string (single or double quotes) */ msyytext+=2; - msyytext[strlen(msyytext)-2] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-2-2] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_TOKEN_BINDING_STRING); } @@ -4247,23 +4277,23 @@ YY_RULE_SETUP case 325: /* rule 325 can match eol */ YY_RULE_SETUP -#line 530 "maplexer.l" +#line 560 "maplexer.l" { /* attribute binding - time */ msyytext+=2; - msyytext[strlen(msyytext)-2] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-2-2] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_TOKEN_BINDING_TIME); } YY_BREAK case 326: YY_RULE_SETUP -#line 540 "maplexer.l" +#line 570 "maplexer.l" { - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer,msyytext); msyynumber = atof(msyytext); return(MS_NUMBER); @@ -4271,10 +4301,10 @@ YY_RULE_SETUP YY_BREAK case 327: YY_RULE_SETUP -#line 548 "maplexer.l" +#line 578 "maplexer.l" { - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer,msyytext); msyynumber = atof(msyytext); return(MS_TOKEN_LITERAL_NUMBER); @@ -4283,12 +4313,12 @@ YY_RULE_SETUP case 328: /* rule 328 can match eol */ YY_RULE_SETUP -#line 556 "maplexer.l" +#line 586 "maplexer.l" { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_TOKEN_LITERAL_TIME); } @@ -4296,12 +4326,12 @@ YY_RULE_SETUP case 329: /* rule 329 can match eol */ YY_RULE_SETUP -#line 565 "maplexer.l" +#line 595 "maplexer.l" { msyytext++; - msyytext[strlen(msyytext)-2] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-2] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_IREGEX); } @@ -4309,64 +4339,59 @@ YY_RULE_SETUP case 330: /* rule 330 can match eol */ YY_RULE_SETUP -#line 574 "maplexer.l" +#line 604 "maplexer.l" { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_REGEX); } YY_BREAK case 331: YY_RULE_SETUP -#line 583 "maplexer.l" +#line 613 "maplexer.l" { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_EXPRESSION); } YY_BREAK case 332: YY_RULE_SETUP -#line 592 "maplexer.l" +#line 622 "maplexer.l" { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_LIST); } YY_BREAK case 333: YY_RULE_SETUP -#line 601 "maplexer.l" +#line 631 "maplexer.l" { msyystring_return_state = MS_STRING; msyystring_begin = msyytext[0]; msyystring_size = 0; - msyystring_buffer_ptr = msyystring_buffer; + msyystring_buffer[0] = '\0'; BEGIN(MSSTRING); } YY_BREAK case 334: YY_RULE_SETUP -#line 609 "maplexer.l" +#line 639 "maplexer.l" { - MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, - msyystring_buffer_size, msyystring_buffer_ptr); if (msyystring_begin == msyytext[0]) { BEGIN(msyystring_begin_state); - - *msyystring_buffer_ptr = '\0'; - if (msyystring_return_state == MS_STRING) { - if (msyystring_icase && strlen(msyytext)==2) { + if (msyystring_icase && msyyleng==2) { msyystring_icase = MS_FALSE; // reset return MS_ISTRING; } else @@ -4376,62 +4401,58 @@ YY_RULE_SETUP } else { - ++msyystring_size; - *msyystring_buffer_ptr++ = *msyytext; - if (strlen(msyytext)==2) { - MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, - msyystring_buffer_size, msyystring_buffer_ptr); - ++msyystring_size; - *msyystring_buffer_ptr++ = msyytext[1]; + int old_size = msyystring_size; + msyystring_size += (msyyleng==2) ? 2 : 1; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, + msyystring_buffer_size); + msyystring_buffer[old_size] = *msyytext; + if (msyyleng==2) { + msyystring_buffer[old_size+1] = msyytext[1]; } + msyystring_buffer[msyystring_size] = '\0'; } } YY_BREAK case 335: YY_RULE_SETUP -#line 639 "maplexer.l" +#line 665 "maplexer.l" { - MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, - msyystring_buffer_size, msyystring_buffer_ptr); - ++msyystring_size; - if (strlen(msyytext) == 2) - *msyystring_buffer_ptr++ = msyytext[1]; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, + msyystring_buffer_size); + + if (msyyleng == 2) + msyystring_buffer[msyystring_size-1] = msyytext[1]; else - *msyystring_buffer_ptr++ = msyytext[0]; + msyystring_buffer[msyystring_size-1] = msyytext[0]; + msyystring_buffer[msyystring_size] = '\0'; } YY_BREAK case 336: /* rule 336 can match eol */ YY_RULE_SETUP -#line 650 "maplexer.l" +#line 677 "maplexer.l" { - char *yptr = msyytext; - while ( *yptr ) { - MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, - msyystring_buffer_size, msyystring_buffer_ptr); - ++msyystring_size; - *msyystring_buffer_ptr++ = *yptr++; - } + int old_size = msyystring_size; + msyystring_size += msyyleng; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, + msyystring_buffer_size); + memcpy(msyystring_buffer + old_size, msyytext, msyyleng + 1); } YY_BREAK case 337: /* rule 337 can match eol */ YY_RULE_SETUP -#line 660 "maplexer.l" +#line 685 "maplexer.l" { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; + msyytext[msyyleng-1-1] = '\0'; if(include_stack_ptr >= MAX_INCLUDE_DEPTH) { msSetError(MS_IOERR, "Includes nested to deeply.", "msyylex()"); return(-1); } - include_stack[include_stack_ptr] = YY_CURRENT_BUFFER; /* save state */ - include_lineno[include_stack_ptr] = msyylineno; - include_stack_ptr++; - msyyin = fopen(msBuildPath(path, msyybasepath, msyytext), "r"); if(!msyyin) { msSetError(MS_IOERR, "Error opening included file \"%s\".", "msyylex()", msyytext); @@ -4439,6 +4460,10 @@ YY_RULE_SETUP return(-1); } + include_stack[include_stack_ptr] = YY_CURRENT_BUFFER; /* save state */ + include_lineno[include_stack_ptr] = msyylineno; + include_stack_ptr++; + msyy_switch_to_buffer( msyy_create_buffer(msyyin, YY_BUF_SIZE) ); msyylineno = 1; @@ -4447,21 +4472,21 @@ YY_RULE_SETUP YY_BREAK case 338: YY_RULE_SETUP -#line 686 "maplexer.l" +#line 711 "maplexer.l" { msyystring_return_state = MS_TOKEN_LITERAL_STRING; msyystring_begin = msyytext[0]; msyystring_size = 0; - msyystring_buffer_ptr = msyystring_buffer; + msyystring_buffer[0] = '\0'; BEGIN(MSSTRING); } YY_BREAK case 339: YY_RULE_SETUP -#line 694 "maplexer.l" +#line 719 "maplexer.l" { - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_STRING); } @@ -4469,12 +4494,12 @@ YY_RULE_SETUP case 340: /* rule 340 can match eol */ YY_RULE_SETUP -#line 701 "maplexer.l" +#line 726 "maplexer.l" { msyylineno++; } YY_BREAK case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(CONFIG_FILE): -#line 703 "maplexer.l" +#line 728 "maplexer.l" { if( --include_stack_ptr < 0 ) return(EOF); /* end of main file */ @@ -4489,32 +4514,32 @@ case YY_STATE_EOF(CONFIG_FILE): case 341: /* rule 341 can match eol */ YY_RULE_SETUP -#line 714 "maplexer.l" +#line 739 "maplexer.l" { return(0); } YY_BREAK case 342: YY_RULE_SETUP -#line 718 "maplexer.l" +#line 743 "maplexer.l" { - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(0); } YY_BREAK case 343: YY_RULE_SETUP -#line 724 "maplexer.l" +#line 749 "maplexer.l" { return(msyytext[0]); } YY_BREAK case 344: YY_RULE_SETUP -#line 725 "maplexer.l" +#line 750 "maplexer.l" ECHO; YY_BREAK -#line 4518 "/home/bjorn/code/MapServer/maplexer.c" +#line 4543 "/home/even/mapserver/mapserver/maplexer.c" case YY_STATE_EOF(EXPRESSION_STRING): case YY_STATE_EOF(INCLUDE): case YY_STATE_EOF(MSSTRING): @@ -5523,7 +5548,7 @@ void yyfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 725 "maplexer.l" +#line 750 "maplexer.l" /* diff --git a/maplexer.l b/maplexer.l index a3987daeba..e3033d369a 100644 --- a/maplexer.l +++ b/maplexer.l @@ -41,12 +41,46 @@ int msyylineno = 1; #define YY_NO_INPUT +/* Below is a redefinition of the default YY_INPUT() macro but replacing the + * YY_FATAL_ERROR() macro with a call to msSetError(). + */ +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + int n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + msSetError(MS_PARSEERR, "%s", "msyyparse()", "input in flex scanner failed"); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + msSetError(MS_PARSEERR, "%s", "msyyparse()", "input in flex scanner failed"); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + } + int msyysource=MS_STRING_TOKENS; double msyynumber; int msyystate=MS_TOKENIZE_DEFAULT; char *msyystring=NULL; char *msyybasepath=NULL; -char *msyystring_buffer_ptr; int msyystring_buffer_size = 0; int msyystring_size; char msyystring_begin; @@ -54,25 +88,21 @@ char *msyystring_buffer = NULL; int msyystring_icase = MS_FALSE; int msyystring_return_state; int msyystring_begin_state; -int msyystring_size_tmp; int msyyreturncomments = 0; -#define MS_LEXER_STRING_REALLOC(string, string_size, max_size, string_ptr) \ +#define MS_LEXER_STRING_REALLOC(string, string_size, max_size) \ do { \ const int string_size_macro = (int)(string_size); \ if (string_size_macro >= (int)(max_size)) { \ - msyystring_size_tmp = (max_size); \ max_size = (((int)(max_size)*2) > string_size_macro) ? ((int)(max_size))*2 : string_size_macro+1; \ string = (char *) msSmallRealloc(string, sizeof(char *) * (max_size)); \ - string_ptr = string; \ - string_ptr += msyystring_size_tmp; \ } \ } while(0) #define MS_LEXER_RETURN_TOKEN(token) \ MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), \ - msyystring_buffer_size, msyystring_buffer_ptr); \ + msyystring_buffer_size); \ strcpy(msyystring_buffer, msyytext); \ return(token); @@ -489,9 +519,9 @@ char path[MS_MAXPATHLEN]; \[[^\]]*\] { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer,msyytext); return(MS_BINDING); } @@ -511,42 +541,42 @@ char path[MS_MAXPATHLEN]; \[[^\]]*\] { /* attribute binding - numeric (no quotes) */ msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_TOKEN_BINDING_DOUBLE); } \"\[[^\"]*\]\"|\'\[[^\']*\]\' { /* attribute binding - string (single or double quotes) */ msyytext+=2; - msyytext[strlen(msyytext)-2] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-2-2] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_TOKEN_BINDING_STRING); } \`\[[^\`]*\]\` { /* attribute binding - time */ msyytext+=2; - msyytext[strlen(msyytext)-2] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-2-2] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_TOKEN_BINDING_TIME); } -?[0-9]+|-?[0-9]+\.[0-9]*|-?\.[0-9]*|-?[0-9]+[eE][+-]?[0-9]+|-?[0-9]+\.[0-9]*[eE][+-]?[0-9]+|-?\.[0-9]*[eE][+-]?[0-9]+ { - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer,msyytext); msyynumber = atof(msyytext); return(MS_NUMBER); } -?[0-9]+|-?[0-9]+\.[0-9]*|-?\.[0-9]*|-?[0-9]+[eE][+-]?[0-9]+|-?[0-9]+\.[0-9]*[eE][+-]?[0-9]+|-?\.[0-9]*[eE][+-]?[0-9]+ { - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer,msyytext); msyynumber = atof(msyytext); return(MS_TOKEN_LITERAL_NUMBER); @@ -554,45 +584,45 @@ char path[MS_MAXPATHLEN]; \`[^\`]*\` { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_TOKEN_LITERAL_TIME); } \/[^*]{1}[^\/]*\/i { msyytext++; - msyytext[strlen(msyytext)-2] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-2] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_IREGEX); } \/[^*]{1}[^\/]*\/ { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_REGEX); } \(.*\) { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_EXPRESSION); } \{.*\} { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + msyytext[msyyleng-1-1] = '\0'; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_LIST); } @@ -601,20 +631,15 @@ char path[MS_MAXPATHLEN]; msyystring_return_state = MS_STRING; msyystring_begin = msyytext[0]; msyystring_size = 0; - msyystring_buffer_ptr = msyystring_buffer; + msyystring_buffer[0] = '\0'; BEGIN(MSSTRING); } \'|\"|\"i|\'i { - MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, - msyystring_buffer_size, msyystring_buffer_ptr); if (msyystring_begin == msyytext[0]) { BEGIN(msyystring_begin_state); - - *msyystring_buffer_ptr = '\0'; - if (msyystring_return_state == MS_STRING) { - if (msyystring_icase && strlen(msyytext)==2) { + if (msyystring_icase && msyyleng==2) { msyystring_icase = MS_FALSE; // reset return MS_ISTRING; } else @@ -624,51 +649,47 @@ char path[MS_MAXPATHLEN]; } else { - ++msyystring_size; - *msyystring_buffer_ptr++ = *msyytext; - if (strlen(msyytext)==2) { - MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, - msyystring_buffer_size, msyystring_buffer_ptr); - ++msyystring_size; - *msyystring_buffer_ptr++ = msyytext[1]; + int old_size = msyystring_size; + msyystring_size += (msyyleng==2) ? 2 : 1; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, + msyystring_buffer_size); + msyystring_buffer[old_size] = *msyytext; + if (msyyleng==2) { + msyystring_buffer[old_size+1] = msyytext[1]; } + msyystring_buffer[msyystring_size] = '\0'; } } \\\'|\\\"|\\\\|\\ { - MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, - msyystring_buffer_size, msyystring_buffer_ptr); - ++msyystring_size; - if (strlen(msyytext) == 2) - *msyystring_buffer_ptr++ = msyytext[1]; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, + msyystring_buffer_size); + + if (msyyleng == 2) + msyystring_buffer[msyystring_size-1] = msyytext[1]; else - *msyystring_buffer_ptr++ = msyytext[0]; + msyystring_buffer[msyystring_size-1] = msyytext[0]; + msyystring_buffer[msyystring_size] = '\0'; } [^\\\'\\\"]+ { - char *yptr = msyytext; - while ( *yptr ) { - MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, - msyystring_buffer_size, msyystring_buffer_ptr); - ++msyystring_size; - *msyystring_buffer_ptr++ = *yptr++; - } + int old_size = msyystring_size; + msyystring_size += msyyleng; + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyystring_size, + msyystring_buffer_size); + memcpy(msyystring_buffer + old_size, msyytext, msyyleng + 1); } \"[^\"]*\"|\'[^\']*\' { msyytext++; - msyytext[strlen(msyytext)-1] = '\0'; + msyytext[msyyleng-1-1] = '\0'; if(include_stack_ptr >= MAX_INCLUDE_DEPTH) { msSetError(MS_IOERR, "Includes nested to deeply.", "msyylex()"); return(-1); } - include_stack[include_stack_ptr] = YY_CURRENT_BUFFER; /* save state */ - include_lineno[include_stack_ptr] = msyylineno; - include_stack_ptr++; - msyyin = fopen(msBuildPath(path, msyybasepath, msyytext), "r"); if(!msyyin) { msSetError(MS_IOERR, "Error opening included file \"%s\".", "msyylex()", msyytext); @@ -676,6 +697,10 @@ char path[MS_MAXPATHLEN]; return(-1); } + include_stack[include_stack_ptr] = YY_CURRENT_BUFFER; /* save state */ + include_lineno[include_stack_ptr] = msyylineno; + include_stack_ptr++; + msyy_switch_to_buffer( msyy_create_buffer(msyyin, YY_BUF_SIZE) ); msyylineno = 1; @@ -686,13 +711,13 @@ char path[MS_MAXPATHLEN]; msyystring_return_state = MS_TOKEN_LITERAL_STRING; msyystring_begin = msyytext[0]; msyystring_size = 0; - msyystring_buffer_ptr = msyystring_buffer; + msyystring_buffer[0] = '\0'; BEGIN(MSSTRING); } [a-z/\.][a-z0-9/\._\-\=]* { - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(MS_STRING); } @@ -715,8 +740,8 @@ char path[MS_MAXPATHLEN]; } . { - MS_LEXER_STRING_REALLOC(msyystring_buffer, strlen(msyytext), - msyystring_buffer_size, msyystring_buffer_ptr); + MS_LEXER_STRING_REALLOC(msyystring_buffer, msyyleng, + msyystring_buffer_size); strcpy(msyystring_buffer, msyytext); return(0); } diff --git a/maplibxml2.c b/maplibxml2.c index b6a91789f5..8ef7132618 100644 --- a/maplibxml2.c +++ b/maplibxml2.c @@ -31,17 +31,16 @@ #ifdef USE_LIBXML2 -#include -#include -#include -#include - - +#include +#include +#include +#include /** * msLibXml2GenerateList() * - * Convenience function to produce a series of XML elements from a delimited list + * Convenience function to produce a series of XML elements from a delimited + * list * * @param xmlNodePtr psParent the encompassing node * @param xmlNsPtr psNs the namespace object @@ -51,16 +50,17 @@ * */ -void msLibXml2GenerateList(xmlNodePtr psParent, xmlNsPtr psNs, const char *elname, const char *values, char delim) -{ +void msLibXml2GenerateList(xmlNodePtr psParent, xmlNsPtr psNs, + const char *elname, const char *values, char delim) { char **tokens = NULL; int n = 0; int i = 0; tokens = msStringSplit(values, delim, &n); - for (i=0; inodesetval)) { + if (xmlXPathNodeSetIsEmpty(result->nodesetval)) { xmlXPathFreeObject(result); return NULL; } @@ -108,8 +108,7 @@ xmlXPathObjectPtr msLibXml2GetXPath(xmlDocPtr doc, xmlXPathContextPtr context, x * */ -char *msLibXml2GetXPathTree(xmlDocPtr doc, xmlXPathObjectPtr xpath) -{ +char *msLibXml2GetXPathTree(xmlDocPtr doc, xmlXPathObjectPtr xpath) { xmlBufferPtr xbuf; char *result = NULL; diff --git a/maplibxml2.h b/maplibxml2.h index 904eb97070..2307bbf863 100644 --- a/maplibxml2.h +++ b/maplibxml2.h @@ -32,10 +32,10 @@ #ifdef USE_LIBXML2 -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -43,9 +43,11 @@ extern "C" { #endif -xmlXPathObjectPtr msLibXml2GetXPath(xmlDocPtr doc, xmlXPathContextPtr context, xmlChar *xpath); +xmlXPathObjectPtr msLibXml2GetXPath(xmlDocPtr doc, xmlXPathContextPtr context, + xmlChar *xpath); -void msLibXml2GenerateList(xmlNodePtr psParent, xmlNsPtr psNs, const char *elname, const char *values, char delim); +void msLibXml2GenerateList(xmlNodePtr psParent, xmlNsPtr psNs, + const char *elname, const char *values, char delim); char *msLibXml2GetXPathTree(xmlDocPtr doc, xmlXPathObjectPtr xpath); diff --git a/mapmetadata.c b/mapmetadata.c index 179b031cb8..00165ef18d 100644 --- a/mapmetadata.c +++ b/mapmetadata.c @@ -31,13 +31,13 @@ #include "mapowscommon.h" #include "maplibxml2.h" -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) || defined(USE_WMS_LYR) || defined(USE_WFS_LYR) +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) || defined(USE_WMS_LYR) || defined(USE_WFS_LYR) #ifdef USE_LIBXML2 -static -int msMetadataParseRequest(cgiRequestObj *request, - metadataParamsObj *metadataparams); +static int msMetadataParseRequest(cgiRequestObj *request, + metadataParamsObj *metadataparams); /************************************************************************/ /* _msMetadataGetCharacterString */ @@ -45,12 +45,15 @@ int msMetadataParseRequest(cgiRequestObj *request, /* Create a gmd:name/gmd:CharacterString element pattern */ /************************************************************************/ -static -xmlNodePtr _msMetadataGetCharacterString(xmlNsPtr namespace, const char *name, const char *value, xmlNsPtr* ppsNsGco) { +static xmlNodePtr _msMetadataGetCharacterString(xmlNsPtr namespace, + const char *name, + const char *value, + xmlNsPtr *ppsNsGco) { xmlNodePtr psNode = NULL; - if( *ppsNsGco == NULL ) - *ppsNsGco = xmlNewNs(NULL, BAD_CAST "http://www.isotc211.org/2005/gmd", BAD_CAST "gco"); + if (*ppsNsGco == NULL) + *ppsNsGco = xmlNewNs(NULL, BAD_CAST "http://www.isotc211.org/2005/gmd", + BAD_CAST "gco"); psNode = xmlNewNode(namespace, BAD_CAST name); @@ -59,22 +62,21 @@ xmlNodePtr _msMetadataGetCharacterString(xmlNsPtr namespace, const char *name, c else xmlNewChild(psNode, *ppsNsGco, BAD_CAST "CharacterString", BAD_CAST value); return psNode; - } - /************************************************************************/ /* _msMetadataGetURL */ /* */ /* Create a gmd:name/gmd:URL element pattern */ /************************************************************************/ -static -xmlNodePtr _msMetadataGetURL(xmlNsPtr namespace, const char *name, const char *value, xmlNsPtr* ppsNsGco) { +static xmlNodePtr _msMetadataGetURL(xmlNsPtr namespace, const char *name, + const char *value, xmlNsPtr *ppsNsGco) { xmlNodePtr psNode = NULL; - if( *ppsNsGco == NULL ) - *ppsNsGco = xmlNewNs(NULL, BAD_CAST "http://www.isotc211.org/2005/gmd", BAD_CAST "gco"); + if (*ppsNsGco == NULL) + *ppsNsGco = xmlNewNs(NULL, BAD_CAST "http://www.isotc211.org/2005/gmd", + BAD_CAST "gco"); psNode = xmlNewNode(namespace, BAD_CAST name); @@ -83,7 +85,6 @@ xmlNodePtr _msMetadataGetURL(xmlNsPtr namespace, const char *name, const char *v else xmlNewChild(psNode, namespace, BAD_CAST "URL", BAD_CAST value); return psNode; - } /************************************************************************/ @@ -92,16 +93,17 @@ xmlNodePtr _msMetadataGetURL(xmlNsPtr namespace, const char *name, const char *v /* Create a gmd:onLine element pattern */ /************************************************************************/ -static char* _stringConcatenateAndEncodeHTML(char* str, const char* appendStr) -{ - char* pszTmp = msEncodeHTMLEntities(appendStr); +static char *_stringConcatenateAndEncodeHTML(char *str, const char *appendStr) { + char *pszTmp = msEncodeHTMLEntities(appendStr); str = msStringConcatenate(str, pszTmp); msFree(pszTmp); return str; } -static -xmlNodePtr _msMetadataGetOnline(xmlNsPtr namespace, layerObj *layer, const char *service, const char *format, const char *desc, const char *url_in, xmlNsPtr* ppsNsGco) { +static xmlNodePtr _msMetadataGetOnline(xmlNsPtr namespace, layerObj *layer, + const char *service, const char *format, + const char *desc, const char *url_in, + xmlNsPtr *ppsNsGco) { int status; char *url = NULL; @@ -119,16 +121,19 @@ xmlNodePtr _msMetadataGetOnline(xmlNsPtr namespace, layerObj *layer, const char url = msStrdup(url_in); if (strcasecmp(service, "M") == 0) { - url = _stringConcatenateAndEncodeHTML(url, "service=WMS&version=1.3.0&request=GetMap&width=500&height=300&styles=&layers="); + url = _stringConcatenateAndEncodeHTML( + url, "service=WMS&version=1.3.0&request=GetMap&width=500&height=300&" + "styles=&layers="); url = _stringConcatenateAndEncodeHTML(url, layer->name); url = _stringConcatenateAndEncodeHTML(url, "&format="); url = _stringConcatenateAndEncodeHTML(url, format); url = _stringConcatenateAndEncodeHTML(url, "&crs="); { - char* epsg_str = NULL; - msOWSGetEPSGProj(&(layer->projection), &(layer->metadata), "MFCSGO", MS_TRUE, &epsg_str); - url = _stringConcatenateAndEncodeHTML(url, epsg_str); - msFree(epsg_str); + char *epsg_str = NULL; + msOWSGetEPSGProj(&(layer->projection), &(layer->metadata), "MFCSGO", + MS_TRUE, &epsg_str); + url = _stringConcatenateAndEncodeHTML(url, epsg_str); + msFree(epsg_str); } link_protocol = "WWW:DOWNLOAD-1.0-http-get-map"; @@ -148,17 +153,17 @@ xmlNodePtr _msMetadataGetOnline(xmlNsPtr namespace, layerObj *layer, const char sprintf(buffer, "%f", rect.maxx); url = msStringConcatenate(url, buffer); } - } - else if (strcasecmp(service, "F") == 0) { + } else if (strcasecmp(service, "F") == 0) { link_protocol = "WWW:DOWNLOAD-1.0-http--download"; - url = _stringConcatenateAndEncodeHTML(url, "service=WFS&version=1.1.0&request=GetFeature&typename="); + url = _stringConcatenateAndEncodeHTML( + url, "service=WFS&version=1.1.0&request=GetFeature&typename="); url = _stringConcatenateAndEncodeHTML(url, layer->name); url = _stringConcatenateAndEncodeHTML(url, "&outputformat="); url = _stringConcatenateAndEncodeHTML(url, format); - } - else if (strcasecmp(service, "C") == 0) { + } else if (strcasecmp(service, "C") == 0) { link_protocol = "WWW:DOWNLOAD-1.0-http--download"; - url = _stringConcatenateAndEncodeHTML(url, "service=WCS&version=2.0.1&request=GetCoverage&coverageid="); + url = _stringConcatenateAndEncodeHTML( + url, "service=WCS&version=2.0.1&request=GetCoverage&coverageid="); url = _stringConcatenateAndEncodeHTML(url, layer->name); url = _stringConcatenateAndEncodeHTML(url, "&format="); url = _stringConcatenateAndEncodeHTML(url, format); @@ -167,31 +172,34 @@ xmlNodePtr _msMetadataGetOnline(xmlNsPtr namespace, layerObj *layer, const char xmlAddChild(psORNode, _msMetadataGetURL(namespace, "linkage", url, ppsNsGco)); msFree(url); - xmlAddChild(psORNode, _msMetadataGetCharacterString(namespace, "protocol", link_protocol, ppsNsGco)); - xmlAddChild(psORNode, _msMetadataGetCharacterString(namespace, "name", layer->name, ppsNsGco)); + xmlAddChild(psORNode, _msMetadataGetCharacterString(namespace, "protocol", + link_protocol, ppsNsGco)); + xmlAddChild(psORNode, _msMetadataGetCharacterString(namespace, "name", + layer->name, ppsNsGco)); - xmlAddChild(psORNode, _msMetadataGetCharacterString(namespace, "description", desc, ppsNsGco)); + xmlAddChild(psORNode, _msMetadataGetCharacterString(namespace, "description", + desc, ppsNsGco)); return psNode; } - /************************************************************************/ /* _msMetadataGetInteger */ /* */ /* Create a gmd:name/gmd:Integer element pattern */ /************************************************************************/ -static -xmlNodePtr _msMetadataGetInteger(xmlNsPtr namespace, const char *name, int value, xmlNsPtr* ppsNsGco) { +static xmlNodePtr _msMetadataGetInteger(xmlNsPtr namespace, const char *name, + int value, xmlNsPtr *ppsNsGco) { char buffer[8]; xmlNodePtr psNode = NULL; sprintf(buffer, "%d", value); - if( *ppsNsGco == NULL ) - *ppsNsGco = xmlNewNs(NULL, BAD_CAST "http://www.isotc211.org/2005/gmd", BAD_CAST "gco"); + if (*ppsNsGco == NULL) + *ppsNsGco = xmlNewNs(NULL, BAD_CAST "http://www.isotc211.org/2005/gmd", + BAD_CAST "gco"); psNode = xmlNewNode(namespace, BAD_CAST name); @@ -202,23 +210,23 @@ xmlNodePtr _msMetadataGetInteger(xmlNsPtr namespace, const char *name, int value return psNode; } - /************************************************************************/ /* _msMetadataGetDecimal */ /* */ /* Create a gmd:name/gmd:Decimal element pattern */ /************************************************************************/ -static -xmlNodePtr _msMetadataGetDecimal(xmlNsPtr namespace, const char *name, double value, xmlNsPtr* ppsNsGco) { +static xmlNodePtr _msMetadataGetDecimal(xmlNsPtr namespace, const char *name, + double value, xmlNsPtr *ppsNsGco) { char buffer[32]; xmlNodePtr psNode = NULL; snprintf(buffer, sizeof(buffer), "%.6f", value); - if( *ppsNsGco == NULL ) - *ppsNsGco = xmlNewNs(NULL, BAD_CAST "http://www.isotc211.org/2005/gmd", BAD_CAST "gco"); + if (*ppsNsGco == NULL) + *ppsNsGco = xmlNewNs(NULL, BAD_CAST "http://www.isotc211.org/2005/gmd", + BAD_CAST "gco"); psNode = xmlNewNode(namespace, BAD_CAST name); @@ -229,19 +237,21 @@ xmlNodePtr _msMetadataGetDecimal(xmlNsPtr namespace, const char *name, double va return psNode; } - /************************************************************************/ /* _msMetadataGetCodeList */ /* */ /* Create a gmd:name/gmd:* code list element pattern */ /************************************************************************/ -xmlNodePtr _msMetadataGetCodeList(xmlNsPtr namespace, const char *parent_element, const char *name, const char *value) { +xmlNodePtr _msMetadataGetCodeList(xmlNsPtr namespace, + const char *parent_element, const char *name, + const char *value) { char *codelist = NULL; xmlNodePtr psNode = NULL; xmlNodePtr psCodeNode = NULL; - codelist = msStrdup("http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#"); + codelist = msStrdup( + "http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#"); codelist = msStringConcatenate(codelist, name); psNode = xmlNewNode(namespace, BAD_CAST parent_element); @@ -253,20 +263,18 @@ xmlNodePtr _msMetadataGetCodeList(xmlNsPtr namespace, const char *parent_element return psNode; } - /************************************************************************/ /* _msMetadataGetGMLTimePeriod */ /* */ /* Create a gml:TimePeriod element pattern */ /************************************************************************/ -static -xmlNodePtr _msMetadataGetGMLTimePeriod(char **temporal) -{ +static xmlNodePtr _msMetadataGetGMLTimePeriod(char **temporal) { xmlNsPtr psNsGml = NULL; xmlNodePtr psNode = NULL; - psNsGml = xmlNewNs(NULL, BAD_CAST "http://www.opengis.net/gml", BAD_CAST "gml"); + psNsGml = + xmlNewNs(NULL, BAD_CAST "http://www.opengis.net/gml", BAD_CAST "gml"); psNode = xmlNewNode(psNsGml, BAD_CAST "TimePeriod"); xmlNewNsProp(psNode, psNsGml, BAD_CAST "id", BAD_CAST "T001"); xmlNewNs(psNode, BAD_CAST "http://www.opengis.net/gml", BAD_CAST "gml"); @@ -277,16 +285,14 @@ xmlNodePtr _msMetadataGetGMLTimePeriod(char **temporal) return psNode; } - /************************************************************************/ /* _msMetadataGetExtent */ /* */ /* Create a gmd:extent element pattern */ /************************************************************************/ -static -xmlNodePtr _msMetadataGetExtent(xmlNsPtr namespace, layerObj *layer, xmlNsPtr *ppsNsGco) -{ +static xmlNodePtr _msMetadataGetExtent(xmlNsPtr namespace, layerObj *layer, + xmlNsPtr *ppsNsGco) { int n = 0; int status; char *value = NULL; @@ -305,61 +311,68 @@ xmlNodePtr _msMetadataGetExtent(xmlNsPtr namespace, layerObj *layer, xmlNsPtr *p psEXNode = xmlNewChild(psNode, namespace, BAD_CAST "EX_Extent", NULL); /* scan for geospatial extent */ - status = msLayerGetExtent(layer, &rect); + status = msLayerGetExtent(layer, &rect); if (status == 0) { /* always project to lat long */ msOWSProjectToWGS84(&layer->projection, &rect); - psGNode = xmlNewChild(psEXNode, namespace, BAD_CAST "geographicElement", NULL); - psGNode2 = xmlNewChild(psGNode, namespace, BAD_CAST "EX_GeographicBoundingBox", NULL); - xmlAddChild(psGNode2, _msMetadataGetDecimal(namespace, "westBoundLongitude", rect.minx, ppsNsGco)); - xmlAddChild(psGNode2, _msMetadataGetDecimal(namespace, "eastBoundLongitude", rect.maxx, ppsNsGco)); - xmlAddChild(psGNode2, _msMetadataGetDecimal(namespace, "southBoundLatitude", rect.miny, ppsNsGco)); - xmlAddChild(psGNode2, _msMetadataGetDecimal(namespace, "northBoundLatitude", rect.maxy, ppsNsGco)); + psGNode = + xmlNewChild(psEXNode, namespace, BAD_CAST "geographicElement", NULL); + psGNode2 = xmlNewChild(psGNode, namespace, + BAD_CAST "EX_GeographicBoundingBox", NULL); + xmlAddChild(psGNode2, _msMetadataGetDecimal(namespace, "westBoundLongitude", + rect.minx, ppsNsGco)); + xmlAddChild(psGNode2, _msMetadataGetDecimal(namespace, "eastBoundLongitude", + rect.maxx, ppsNsGco)); + xmlAddChild(psGNode2, _msMetadataGetDecimal(namespace, "southBoundLatitude", + rect.miny, ppsNsGco)); + xmlAddChild(psGNode2, _msMetadataGetDecimal(namespace, "northBoundLatitude", + rect.maxy, ppsNsGco)); } /* scan for temporal extent */ value = (char *)msOWSLookupMetadata(&(layer->metadata), "MO", "timeextent"); if (value) { /* WMS */ temporal = msStringSplit(value, '/', &n); - } - else { /* WCS */ - value = (char *)msOWSLookupMetadata(&(layer->metadata), "CO", "timeposition"); + } else { /* WCS */ + value = + (char *)msOWSLookupMetadata(&(layer->metadata), "CO", "timeposition"); if (value) { /* split extent */ temporal = msStringSplit(value, ',', &n); } } if (!value) { /* SOS */ - value = (char *)msOWSLookupMetadata(&(layer->metadata), "SO", "offering_timeextent"); - if (value) - temporal = msStringSplit(value, '/', &n); + value = (char *)msOWSLookupMetadata(&(layer->metadata), "SO", + "offering_timeextent"); + if (value) + temporal = msStringSplit(value, '/', &n); } - if (value) { + if (value) { if (temporal && n > 0) { - psTNode = xmlNewChild(psEXNode, namespace, BAD_CAST "temporalElement", NULL); - psTNode2 = xmlNewChild(psTNode, namespace, BAD_CAST "EX_TemporalExtent", NULL); + psTNode = + xmlNewChild(psEXNode, namespace, BAD_CAST "temporalElement", NULL); + psTNode2 = + xmlNewChild(psTNode, namespace, BAD_CAST "EX_TemporalExtent", NULL); psENode = xmlNewChild(psTNode2, namespace, BAD_CAST "extent", NULL); xmlAddChild(psENode, _msMetadataGetGMLTimePeriod(temporal)); - - msFreeCharArray(temporal, n); } } + msFreeCharArray(temporal, n); return psNode; } - /************************************************************************/ /* _msMetadataGetReferenceSystemInfo */ /* */ /* Create a gmd:referenceSystemInfo element pattern */ /************************************************************************/ -static -xmlNodePtr _msMetadataGetReferenceSystemInfo(xmlNsPtr namespace, layerObj *layer, xmlNsPtr* ppsNsGco) -{ +static xmlNodePtr _msMetadataGetReferenceSystemInfo(xmlNsPtr namespace, + layerObj *layer, + xmlNsPtr *ppsNsGco) { char *epsg_str = NULL; xmlNodePtr psNode = NULL; xmlNodePtr psRSNode = NULL; @@ -367,28 +380,35 @@ xmlNodePtr _msMetadataGetReferenceSystemInfo(xmlNsPtr namespace, layerObj *layer xmlNodePtr psRSINode2 = NULL; psNode = xmlNewNode(namespace, BAD_CAST "referenceSystemInfo"); - psRSNode = xmlNewChild(psNode, namespace, BAD_CAST "MD_ReferenceSystem", NULL); - psRSINode = xmlNewChild(psRSNode, namespace, BAD_CAST "referenceSystemIdentifier", NULL); - psRSINode2 = xmlNewChild(psRSINode, namespace, BAD_CAST "RS_Identifier", NULL); - - msOWSGetEPSGProj(&(layer->projection), &(layer->metadata), "MFCSGO", MS_TRUE, &epsg_str); - xmlAddChild(psRSINode2, _msMetadataGetCharacterString(namespace, "code", epsg_str, ppsNsGco)); - xmlAddChild(psRSINode2, _msMetadataGetCharacterString(namespace, "codeSpace", "http://www.epsg-registry.org", ppsNsGco)); - xmlAddChild(psRSINode2, _msMetadataGetCharacterString(namespace, "version", "6.14", ppsNsGco)); + psRSNode = + xmlNewChild(psNode, namespace, BAD_CAST "MD_ReferenceSystem", NULL); + psRSINode = xmlNewChild(psRSNode, namespace, + BAD_CAST "referenceSystemIdentifier", NULL); + psRSINode2 = + xmlNewChild(psRSINode, namespace, BAD_CAST "RS_Identifier", NULL); + + msOWSGetEPSGProj(&(layer->projection), &(layer->metadata), "MFCSGO", MS_TRUE, + &epsg_str); + xmlAddChild(psRSINode2, _msMetadataGetCharacterString(namespace, "code", + epsg_str, ppsNsGco)); + xmlAddChild(psRSINode2, _msMetadataGetCharacterString( + namespace, "codeSpace", + "http://www.epsg-registry.org", ppsNsGco)); + xmlAddChild(psRSINode2, _msMetadataGetCharacterString(namespace, "version", + "6.14", ppsNsGco)); msFree(epsg_str); return psNode; } - /************************************************************************/ /* _msMetadataGetContact */ /* */ /* Create a gmd:contact element pattern */ /************************************************************************/ -xmlNodePtr _msMetadataGetContact(xmlNsPtr namespace, char *contact_element, mapObj *map, xmlNsPtr* ppsNsGco) -{ +xmlNodePtr _msMetadataGetContact(xmlNsPtr namespace, char *contact_element, + mapObj *map, xmlNsPtr *ppsNsGco) { char *value = NULL; xmlNodePtr psNode = NULL; xmlNodePtr psCNode = NULL; @@ -402,86 +422,112 @@ xmlNodePtr _msMetadataGetContact(xmlNsPtr namespace, char *contact_element, mapO xmlNodePtr psORNode2 = NULL; psNode = xmlNewNode(namespace, BAD_CAST contact_element); - psCNode = xmlNewChild(psNode, namespace, BAD_CAST "CI_ResponsibleParty", NULL); + psCNode = + xmlNewChild(psNode, namespace, BAD_CAST "CI_ResponsibleParty", NULL); xmlNewProp(psCNode, BAD_CAST "id", BAD_CAST contact_element); - value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "contactperson"); + value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", + "contactperson"); if (value) - xmlAddChild(psCNode, _msMetadataGetCharacterString(namespace, "individualName", value, ppsNsGco)); + xmlAddChild(psCNode, _msMetadataGetCharacterString( + namespace, "individualName", value, ppsNsGco)); - value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "contactorganization"); + value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", + "contactorganization"); if (value) - xmlAddChild(psCNode, _msMetadataGetCharacterString(namespace, "organisationName", value, ppsNsGco)); + xmlAddChild(psCNode, _msMetadataGetCharacterString( + namespace, "organisationName", value, ppsNsGco)); - value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "contactposition"); + value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", + "contactposition"); if (value) - xmlAddChild(psCNode, _msMetadataGetCharacterString(namespace, "positionName", value, ppsNsGco)); + xmlAddChild(psCNode, _msMetadataGetCharacterString( + namespace, "positionName", value, ppsNsGco)); psCINode = xmlNewChild(psCNode, namespace, BAD_CAST "contactInfo", NULL); psCINode2 = xmlNewChild(psCINode, namespace, BAD_CAST "CI_Contact", NULL); psPhoneNode = xmlNewChild(psCINode2, namespace, BAD_CAST "phone", NULL); - psCIPhoneNode = xmlNewChild(psPhoneNode, namespace, BAD_CAST "CI_Telephone", NULL); + psCIPhoneNode = + xmlNewChild(psPhoneNode, namespace, BAD_CAST "CI_Telephone", NULL); - value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "contactvoicetelephone"); + value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", + "contactvoicetelephone"); if (value) - xmlAddChild(psCIPhoneNode, _msMetadataGetCharacterString(namespace, "voice", value, ppsNsGco)); + xmlAddChild(psCIPhoneNode, _msMetadataGetCharacterString(namespace, "voice", + value, ppsNsGco)); - value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "contactfacsimiletelephone"); + value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", + "contactfacsimiletelephone"); if (value) - xmlAddChild(psCIPhoneNode, _msMetadataGetCharacterString(namespace, "facsimile", value, ppsNsGco)); + xmlAddChild(psCIPhoneNode, _msMetadataGetCharacterString( + namespace, "facsimile", value, ppsNsGco)); psAddressNode = xmlNewChild(psCINode2, namespace, BAD_CAST "address", NULL); - psCIAddressNode = xmlNewChild(psAddressNode, namespace, BAD_CAST "CI_Address", NULL); + psCIAddressNode = + xmlNewChild(psAddressNode, namespace, BAD_CAST "CI_Address", NULL); value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "address"); if (value) - xmlAddChild(psCIAddressNode, _msMetadataGetCharacterString(namespace, "deliveryPoint", value, ppsNsGco)); + xmlAddChild(psCIAddressNode, + _msMetadataGetCharacterString(namespace, "deliveryPoint", value, + ppsNsGco)); value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "city"); if (value) - xmlAddChild(psCIAddressNode, _msMetadataGetCharacterString(namespace, "city", value, ppsNsGco)); + xmlAddChild(psCIAddressNode, _msMetadataGetCharacterString( + namespace, "city", value, ppsNsGco)); - value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "stateorprovince"); + value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", + "stateorprovince"); if (value) - xmlAddChild(psCIAddressNode, _msMetadataGetCharacterString(namespace, "administrativeArea", value, ppsNsGco)); + xmlAddChild(psCIAddressNode, + _msMetadataGetCharacterString(namespace, "administrativeArea", + value, ppsNsGco)); value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "postcode"); if (value) - xmlAddChild(psCIAddressNode, _msMetadataGetCharacterString(namespace, "postalCode", value, ppsNsGco)); + xmlAddChild(psCIAddressNode, _msMetadataGetCharacterString( + namespace, "postalCode", value, ppsNsGco)); value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "country"); if (value) - xmlAddChild(psCIAddressNode, _msMetadataGetCharacterString(namespace, "country", value, ppsNsGco)); + xmlAddChild(psCIAddressNode, _msMetadataGetCharacterString( + namespace, "country", value, ppsNsGco)); - value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "contactelectronicmailaddress"); + value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", + "contactelectronicmailaddress"); if (value) - xmlAddChild(psCIAddressNode, _msMetadataGetCharacterString(namespace, "electronicMailAddress", value, ppsNsGco)); + xmlAddChild(psCIAddressNode, + _msMetadataGetCharacterString( + namespace, "electronicMailAddress", value, ppsNsGco)); - value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", "onlineresource"); + value = (char *)msOWSLookupMetadata(&(map->web.metadata), "MCFO", + "onlineresource"); if (value) { - psORNode = xmlNewChild(psCINode2, namespace, BAD_CAST "onlineResource", NULL); - psORNode2 = xmlNewChild(psORNode, namespace, BAD_CAST "CI_OnlineResource", NULL); - xmlAddChild(psORNode2, _msMetadataGetURL(namespace, "linkage", value, ppsNsGco)); + psORNode = + xmlNewChild(psCINode2, namespace, BAD_CAST "onlineResource", NULL); + psORNode2 = + xmlNewChild(psORNode, namespace, BAD_CAST "CI_OnlineResource", NULL); + xmlAddChild(psORNode2, + _msMetadataGetURL(namespace, "linkage", value, ppsNsGco)); } - xmlAddChild(psCNode, _msMetadataGetCodeList(namespace, "role", "CI_RoleCode", "pointOfContact")); + xmlAddChild(psCNode, _msMetadataGetCodeList(namespace, "role", "CI_RoleCode", + "pointOfContact")); return psNode; } - /************************************************************************/ /* _msMetadataGetIdentificationInfo */ /* */ /* Create a gmd:identificationInfo element pattern */ /************************************************************************/ -static -xmlNodePtr _msMetadataGetIdentificationInfo(xmlNsPtr namespace, mapObj *map, layerObj *layer, xmlNsPtr *ppsNsGco) -{ - int n; +static xmlNodePtr _msMetadataGetIdentificationInfo(xmlNsPtr namespace, + mapObj *map, layerObj *layer, + xmlNsPtr *ppsNsGco) { char *value; - char **tokens = NULL; xmlNodePtr psNode = NULL; xmlNodePtr psDINode = NULL; xmlNodePtr psCNode = NULL; @@ -492,60 +538,74 @@ xmlNodePtr _msMetadataGetIdentificationInfo(xmlNsPtr namespace, mapObj *map, lay psNode = xmlNewNode(namespace, BAD_CAST "identificationInfo"); - psDINode = xmlNewChild(psNode, namespace, BAD_CAST "MD_DataIdentification", NULL); + psDINode = + xmlNewChild(psNode, namespace, BAD_CAST "MD_DataIdentification", NULL); xmlNewProp(psDINode, BAD_CAST "id", BAD_CAST layer->name); psCNode = xmlNewChild(psDINode, namespace, BAD_CAST "citation", NULL); psCINode = xmlNewChild(psCNode, namespace, BAD_CAST "CI_Citation", NULL); value = (char *)msOWSLookupMetadata(&(layer->metadata), "MCFGO", "title"); if (!value) - value = (char *)msOWSLookupMetadata(&(layer->metadata), "S", "offering_name"); - xmlAddChild(psCINode, _msMetadataGetCharacterString(namespace, "title", value, ppsNsGco)); + value = + (char *)msOWSLookupMetadata(&(layer->metadata), "S", "offering_name"); + xmlAddChild(psCINode, _msMetadataGetCharacterString(namespace, "title", value, + ppsNsGco)); psDNode = xmlNewChild(psCINode, namespace, BAD_CAST "date", NULL); xmlNewNsProp(psDNode, *ppsNsGco, BAD_CAST "nilReason", BAD_CAST "missing"); - value = (char *)msOWSLookupMetadata(&(layer->metadata), "MCFGO", "attribution_title"); + value = (char *)msOWSLookupMetadata(&(layer->metadata), "MCFGO", + "attribution_title"); if (value) { - xmlAddChild(psCINode, _msMetadataGetCharacterString(namespace, "otherCitationDetails", value, ppsNsGco)); + xmlAddChild(psCINode, + _msMetadataGetCharacterString(namespace, "otherCitationDetails", + value, ppsNsGco)); } value = (char *)msOWSLookupMetadata(&(layer->metadata), "MCFGO", "abstract"); if (!value) - value = (char *)msOWSLookupMetadata(&(layer->metadata), "S", "offering_description"); - xmlAddChild(psDINode, _msMetadataGetCharacterString(namespace, "abstract", value, ppsNsGco)); + value = (char *)msOWSLookupMetadata(&(layer->metadata), "S", + "offering_description"); + xmlAddChild(psDINode, _msMetadataGetCharacterString(namespace, "abstract", + value, ppsNsGco)); - value = (char *)msOWSLookupMetadata(&(layer->metadata), "MCFSGO", "keywordlist"); + value = + (char *)msOWSLookupMetadata(&(layer->metadata), "MCFSGO", "keywordlist"); if (value) { - psKWNode = xmlNewChild(psDINode, namespace, BAD_CAST "descriptiveKeywords", NULL); + psKWNode = + xmlNewChild(psDINode, namespace, BAD_CAST "descriptiveKeywords", NULL); psMDKNode = xmlNewChild(psKWNode, namespace, BAD_CAST "MD_Keywords", NULL); - tokens = msStringSplit(value, ',', &n); + int n = 0; + char **tokens = msStringSplit(value, ',', &n); if (tokens && n > 0) { - for (int i=0; itype == MS_LAYER_RASTER) { - psSRNode = xmlNewChild(psNode, namespace, BAD_CAST "MD_GridSpatialRepresentation", NULL); - xmlAddChild(psSRNode, _msMetadataGetInteger(namespace, "numberOfDimensions", 2, ppsNsGco)); - xmlAddChild(psSRNode, _msMetadataGetCodeList(namespace, "cellGeometry", "MD_CellGeometryCode", "area")); - } - else { - psSRNode = xmlNewChild(psNode, namespace, BAD_CAST "MD_VectorSpatialRepresentation", NULL); - xmlAddChild(psSRNode, _msMetadataGetCodeList(namespace, "topologyLevel", "MD_TopologyLevelCode", "geometryOnly")); - psGONode = xmlNewChild(psSRNode, namespace, BAD_CAST "geometricObjects", NULL); - psGONode2 = xmlNewChild(psGONode, namespace, BAD_CAST "MD_GeometricObjects", NULL); + psSRNode = xmlNewChild(psNode, namespace, + BAD_CAST "MD_GridSpatialRepresentation", NULL); + xmlAddChild(psSRNode, _msMetadataGetInteger(namespace, "numberOfDimensions", + 2, ppsNsGco)); + xmlAddChild(psSRNode, + _msMetadataGetCodeList(namespace, "cellGeometry", + "MD_CellGeometryCode", "area")); + } else { + psSRNode = xmlNewChild(psNode, namespace, + BAD_CAST "MD_VectorSpatialRepresentation", NULL); + xmlAddChild(psSRNode, + _msMetadataGetCodeList(namespace, "topologyLevel", + "MD_TopologyLevelCode", "geometryOnly")); + psGONode = + xmlNewChild(psSRNode, namespace, BAD_CAST "geometricObjects", NULL); + psGONode2 = + xmlNewChild(psGONode, namespace, BAD_CAST "MD_GeometricObjects", NULL); if (layer->type == MS_LAYER_POINT) value = "point"; else if (layer->type == MS_LAYER_LINE) @@ -572,24 +640,27 @@ xmlNodePtr _msMetadataGetSpatialRepresentationInfo(xmlNsPtr namespace, layerObj value = "surface"; else value = "complex"; - xmlAddChild(psGONode2, _msMetadataGetCodeList(namespace, "geometricObjectType", "MD_GeometricObjectTypeCode", value)); + xmlAddChild(psGONode2, + _msMetadataGetCodeList(namespace, "geometricObjectType", + "MD_GeometricObjectTypeCode", value)); // TODO: find way to get feature count in a fast way - /* xmlAddChild(psGONode2, _msMetadataGetInteger(namespace, "geometricObjectCount", msLayerGetNumFeatures(layer))); */ + /* xmlAddChild(psGONode2, _msMetadataGetInteger(namespace, + * "geometricObjectCount", msLayerGetNumFeatures(layer))); */ } return psNode; } - /************************************************************************/ /* _msMetadataGetDistributionInfo */ /* */ /* Create a gmd:identificationInfo element pattern */ /************************************************************************/ -static -xmlNodePtr _msMetadataGetDistributionInfo(xmlNsPtr namespace, mapObj *map, layerObj *layer, cgiRequestObj *cgi_request, xmlNsPtr* ppsNsGco) -{ +static xmlNodePtr _msMetadataGetDistributionInfo(xmlNsPtr namespace, + mapObj *map, layerObj *layer, + cgiRequestObj *cgi_request, + xmlNsPtr *ppsNsGco) { char *url = NULL; xmlNodePtr psNode = NULL; xmlNodePtr psMDNode = NULL; @@ -602,35 +673,47 @@ xmlNodePtr _msMetadataGetDistributionInfo(xmlNsPtr namespace, mapObj *map, layer psMDNode = xmlNewChild(psNode, namespace, BAD_CAST "MD_Distribution", NULL); { - char* pszTmp = msOWSGetOnlineResource(map, "MFCSGO", "onlineresource", cgi_request); - url = msEncodeHTMLEntities(pszTmp); - msFree(pszTmp); + char *pszTmp = + msOWSGetOnlineResource(map, "MFCSGO", "onlineresource", cgi_request); + url = msEncodeHTMLEntities(pszTmp); + msFree(pszTmp); } /* gmd:distributor */ psDNode = xmlNewChild(psMDNode, namespace, BAD_CAST "distributor", NULL); psDNode2 = xmlNewChild(psDNode, namespace, BAD_CAST "MD_Distributor", NULL); - xmlAddChild(psDNode2, _msMetadataGetContact(namespace, "distributorContact", map, ppsNsGco)); + xmlAddChild(psDNode2, _msMetadataGetContact(namespace, "distributorContact", + map, ppsNsGco)); /* gmd:transferOptions */ psTONode = xmlNewChild(psMDNode, namespace, BAD_CAST "transferOptions", NULL); - psDTONode = xmlNewChild(psTONode, namespace, BAD_CAST "MD_DigitalTransferOptions", NULL); - xmlAddChild(psDTONode, _msMetadataGetCharacterString(namespace, "unitsOfDistribution", "KB", ppsNsGco)); + psDTONode = xmlNewChild(psTONode, namespace, + BAD_CAST "MD_DigitalTransferOptions", NULL); + xmlAddChild(psDTONode, _msMetadataGetCharacterString( + namespace, "unitsOfDistribution", "KB", ppsNsGco)); /* links */ /* WMS */ - xmlAddChild(psDTONode, _msMetadataGetOnline(namespace, layer, "M", "image/png", "PNG Format", url, ppsNsGco)); - xmlAddChild(psDTONode, _msMetadataGetOnline(namespace, layer, "M", "image/jpeg", "JPEG Format", url, ppsNsGco)); + xmlAddChild(psDTONode, + _msMetadataGetOnline(namespace, layer, "M", "image/png", + "PNG Format", url, ppsNsGco)); + xmlAddChild(psDTONode, + _msMetadataGetOnline(namespace, layer, "M", "image/jpeg", + "JPEG Format", url, ppsNsGco)); /* WCS */ if (layer->type == MS_LAYER_RASTER) { - xmlAddChild(psDTONode, _msMetadataGetOnline(namespace, layer, "C", "image/tiff", "GeoTIFF Format", url, ppsNsGco)); + xmlAddChild(psDTONode, + _msMetadataGetOnline(namespace, layer, "C", "image/tiff", + "GeoTIFF Format", url, ppsNsGco)); } /* WFS */ else { - xmlAddChild(psDTONode, _msMetadataGetOnline(namespace, layer, "F", "GML2", "GML2 Format", url, ppsNsGco)); - xmlAddChild(psDTONode, _msMetadataGetOnline(namespace, layer, "F", "GML3", "GML3 Format", url, ppsNsGco)); + xmlAddChild(psDTONode, _msMetadataGetOnline(namespace, layer, "F", "GML2", + "GML2 Format", url, ppsNsGco)); + xmlAddChild(psDTONode, _msMetadataGetOnline(namespace, layer, "F", "GML3", + "GML3 Format", url, ppsNsGco)); } msFree(url); @@ -644,28 +727,26 @@ xmlNodePtr _msMetadataGetDistributionInfo(xmlNsPtr namespace, mapObj *map, layer /* Generate an OWS Common Exception Report */ /************************************************************************/ -static -xmlNodePtr msMetadataGetExceptionReport(mapObj *map, char *code, char *locator, char *message, xmlNsPtr* ppsNsOws) -{ +static xmlNodePtr msMetadataGetExceptionReport(mapObj *map, char *code, + char *locator, char *message, + xmlNsPtr *ppsNsOws) { char *schemas_location = NULL; xmlNodePtr psRootNode = NULL; schemas_location = msEncodeHTMLEntities(msOWSGetSchemasLocation(map)); - *ppsNsOws = xmlNewNs(NULL, BAD_CAST "http://www.opengis.net/ows/1.1", BAD_CAST "ows"); - - psRootNode = msOWSCommonExceptionReport(*ppsNsOws, - OWS_1_1_0, - schemas_location, - "1.1.0", - msOWSGetLanguage(map, "exception"), - code, locator, message); + *ppsNsOws = + xmlNewNs(NULL, BAD_CAST "http://www.opengis.net/ows/1.1", BAD_CAST "ows"); + + psRootNode = msOWSCommonExceptionReport( + *ppsNsOws, OWS_1_1_0, schemas_location, "1.1.0", + msOWSGetLanguage(map, "exception"), code, locator, message); msFree(schemas_location); - xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/ows/1.1", BAD_CAST "ows"); + xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/ows/1.1", + BAD_CAST "ows"); return psRootNode; - } /************************************************************************/ @@ -674,9 +755,11 @@ xmlNodePtr msMetadataGetExceptionReport(mapObj *map, char *code, char *locator, /* Generate an ISO 19139-1:2019 representation of layer metadata */ /************************************************************************/ -static -xmlNodePtr msMetadataGetLayerMetadata(mapObj *map, metadataParamsObj *paramsObj, cgiRequestObj *cgi_request, xmlNsPtr* ppsNsOws, xmlNsPtr* ppsNsXsi, xmlNsPtr* ppsNsGmd, xmlNsPtr* ppsNsGco) -{ +static xmlNodePtr +msMetadataGetLayerMetadata(mapObj *map, metadataParamsObj *paramsObj, + cgiRequestObj *cgi_request, xmlNsPtr *ppsNsOws, + xmlNsPtr *ppsNsXsi, xmlNsPtr *ppsNsGmd, + xmlNsPtr *ppsNsGco) { int i; int layer_found = MS_FALSE; @@ -684,74 +767,105 @@ xmlNodePtr msMetadataGetLayerMetadata(mapObj *map, metadataParamsObj *paramsObj, layerObj *layer = NULL; - /* Check that layer requested exists in mapfile */ - for (i=0; inumlayers; i++) { - if(strcasecmp(GET_LAYER(map, i)->name, paramsObj->pszLayer) == 0) { - layer_found = MS_TRUE; - layer = GET_LAYER(map, i); - // when checking a layer with clustering msLayerGetExtent does not have access - // to the source layer, so remove clustering first - if (layer->cluster.region) { - layer->cluster.region = NULL; - } - break; + /* Check that layer requested exists in mapfile */ + for (i = 0; i < map->numlayers; i++) { + if (strcasecmp(GET_LAYER(map, i)->name, paramsObj->pszLayer) == 0) { + layer_found = MS_TRUE; + layer = GET_LAYER(map, i); + // when checking a layer with clustering msLayerGetExtent does not have + // access to the source layer, so remove clustering first + if (layer->cluster.region) { + layer->cluster.region = NULL; + } + break; } } if (layer_found == MS_FALSE) { - psRootNode = msMetadataGetExceptionReport(map, "InvalidParameterValue", "layer", "Layer not found", ppsNsOws); + psRootNode = msMetadataGetExceptionReport( + map, "InvalidParameterValue", "layer", "Layer not found", ppsNsOws); } /* Check that outputschema is valid */ - else if (paramsObj->pszOutputSchema && strcasecmp(paramsObj->pszOutputSchema, "http://www.isotc211.org/2005/gmd") != 0) { - psRootNode = msMetadataGetExceptionReport(map, "InvalidParameterValue", "outputschema", "OUTPUTSCHEMA must be \"http://www.isotc211.org/2005/gmd\"", ppsNsOws); + else if (paramsObj->pszOutputSchema && + strcasecmp(paramsObj->pszOutputSchema, + "http://www.isotc211.org/2005/gmd") != 0) { + psRootNode = msMetadataGetExceptionReport( + map, "InvalidParameterValue", "outputschema", + "OUTPUTSCHEMA must be \"http://www.isotc211.org/2005/gmd\"", ppsNsOws); } else { - *ppsNsXsi = xmlNewNs(NULL, BAD_CAST "http://www.w3.org/2001/XMLSchema-instance", BAD_CAST "xsi"); - *ppsNsGmd = xmlNewNs(NULL, BAD_CAST "http://www.isotc211.org/2005/gmd", BAD_CAST "gmd"); + *ppsNsXsi = + xmlNewNs(NULL, BAD_CAST "http://www.w3.org/2001/XMLSchema-instance", + BAD_CAST "xsi"); + *ppsNsGmd = xmlNewNs(NULL, BAD_CAST "http://www.isotc211.org/2005/gmd", + BAD_CAST "gmd"); /* root element */ psRootNode = xmlNewNode(NULL, BAD_CAST "MD_Metadata"); - xmlNewNs(psRootNode, BAD_CAST "http://www.isotc211.org/2005/gmd", BAD_CAST "gmd"); - xmlNewNs(psRootNode, BAD_CAST "http://www.isotc211.org/2005/gco", BAD_CAST "gco"); - xmlNewNs(psRootNode, BAD_CAST "http://www.w3.org/2001/XMLSchema-instance", BAD_CAST "xsi"); + xmlNewNs(psRootNode, BAD_CAST "http://www.isotc211.org/2005/gmd", + BAD_CAST "gmd"); + xmlNewNs(psRootNode, BAD_CAST "http://www.isotc211.org/2005/gco", + BAD_CAST "gco"); + xmlNewNs(psRootNode, BAD_CAST "http://www.w3.org/2001/XMLSchema-instance", + BAD_CAST "xsi"); xmlSetNs(psRootNode, *ppsNsGmd); - xmlNewNsProp(psRootNode, *ppsNsXsi, BAD_CAST "schemaLocation", BAD_CAST "http://www.isotc211.org/2005/gmd http://www.isotc211.org/2005/gmd/gmd.xsd"); + xmlNewNsProp(psRootNode, *ppsNsXsi, BAD_CAST "schemaLocation", + BAD_CAST "http://www.isotc211.org/2005/gmd " + "http://www.isotc211.org/2005/gmd/gmd.xsd"); /* gmd:identifier */ - xmlAddChild(psRootNode, _msMetadataGetCharacterString(*ppsNsGmd, "fileIdentifier", layer->name, ppsNsGco)); + xmlAddChild(psRootNode, + _msMetadataGetCharacterString(*ppsNsGmd, "fileIdentifier", + layer->name, ppsNsGco)); /* gmd:language */ - xmlAddChild(psRootNode, _msMetadataGetCharacterString(*ppsNsGmd, "language", (char *)msOWSGetLanguage(map, "exception"), ppsNsGco)); + xmlAddChild(psRootNode, + _msMetadataGetCharacterString( + *ppsNsGmd, "language", + (char *)msOWSGetLanguage(map, "exception"), ppsNsGco)); /* gmd:hierarchyLevel */ - xmlAddChild(psRootNode, _msMetadataGetCodeList(*ppsNsGmd, "hierarchyLevel", "MD_ScopeCode", "dataset")); + xmlAddChild(psRootNode, _msMetadataGetCodeList(*ppsNsGmd, "hierarchyLevel", + "MD_ScopeCode", "dataset")); /* gmd:contact */ - xmlAddChild(psRootNode, _msMetadataGetContact(*ppsNsGmd, "contact", map, ppsNsGco)); + xmlAddChild(psRootNode, + _msMetadataGetContact(*ppsNsGmd, "contact", map, ppsNsGco)); /* gmd:dateStamp */ /* TODO: nil for now, find way to derive this automagically */ - xmlAddChild(psRootNode, _msMetadataGetCharacterString(*ppsNsGmd, "dateStamp", NULL, ppsNsGco)); + xmlAddChild(psRootNode, _msMetadataGetCharacterString( + *ppsNsGmd, "dateStamp", NULL, ppsNsGco)); /* gmd:metadataStandardName */ - xmlAddChild(psRootNode, _msMetadataGetCharacterString(*ppsNsGmd, "metadataStandardName", "ISO 19115:2003 - Geographic information - Metadata", ppsNsGco)); + xmlAddChild(psRootNode, + _msMetadataGetCharacterString( + *ppsNsGmd, "metadataStandardName", + "ISO 19115:2003 - Geographic information - Metadata", + ppsNsGco)); /* gmd:metadataStandardVersion */ - xmlAddChild(psRootNode, _msMetadataGetCharacterString(*ppsNsGmd, "metadataStandardVersion", "ISO 19115:2003", ppsNsGco)); + xmlAddChild(psRootNode, _msMetadataGetCharacterString( + *ppsNsGmd, "metadataStandardVersion", + "ISO 19115:2003", ppsNsGco)); /* gmd:spatialRepresentationInfo */ - xmlAddChild(psRootNode, _msMetadataGetSpatialRepresentationInfo(*ppsNsGmd, layer, ppsNsGco)); + xmlAddChild(psRootNode, _msMetadataGetSpatialRepresentationInfo( + *ppsNsGmd, layer, ppsNsGco)); /* gmd:referenceSystemInfo */ - xmlAddChild(psRootNode, _msMetadataGetReferenceSystemInfo(*ppsNsGmd, layer, ppsNsGco)); + xmlAddChild(psRootNode, + _msMetadataGetReferenceSystemInfo(*ppsNsGmd, layer, ppsNsGco)); /* gmd:identificationInfo */ - xmlAddChild(psRootNode, _msMetadataGetIdentificationInfo(*ppsNsGmd, map, layer, ppsNsGco)); + xmlAddChild(psRootNode, _msMetadataGetIdentificationInfo(*ppsNsGmd, map, + layer, ppsNsGco)); /* gmd:distributionInfo */ - xmlAddChild(psRootNode, _msMetadataGetDistributionInfo(*ppsNsGmd, map, layer, cgi_request, ppsNsGco)); + xmlAddChild(psRootNode, _msMetadataGetDistributionInfo( + *ppsNsGmd, map, layer, cgi_request, ppsNsGco)); } return psRootNode; @@ -763,15 +877,14 @@ xmlNodePtr msMetadataGetLayerMetadata(mapObj *map, metadataParamsObj *paramsObj, /* Entry point for metadata requests. */ /* */ /* - If this is a valid request then it is processed and MS_SUCCESS */ -/* is returned on success, or MS_FAILURE on failure. */ +/* is returned on success, or MS_FAILURE on failure. */ /* */ /* - If this does not appear to be a valid WFS request then MS_DONE */ /* is returned and MapServer is expected to process this as a regular */ /* MapServer request. */ /************************************************************************/ -int msMetadataDispatch(mapObj *map, cgiRequestObj *cgi_request) -{ +int msMetadataDispatch(mapObj *map, cgiRequestObj *cgi_request) { int i; int status = MS_SUCCESS; xmlNodePtr psRootNode = NULL; @@ -790,31 +903,37 @@ int msMetadataDispatch(mapObj *map, cgiRequestObj *cgi_request) xml_document = xmlNewDoc(BAD_CAST "1.0"); if (msMetadataParseRequest(cgi_request, paramsObj) == MS_FAILURE) { - psRootNode = msMetadataGetExceptionReport(map, "InvalidRequest", "layer", "Request parsing failed", &psNsOws); + psRootNode = msMetadataGetExceptionReport( + map, "InvalidRequest", "layer", "Request parsing failed", &psNsOws); status = MS_FAILURE; } /* if layer= is not specified, */ - if (paramsObj->pszLayer==NULL || strlen(paramsObj->pszLayer)==0) { - psRootNode = msMetadataGetExceptionReport(map, "MissingParameterValue", "layer", "Missing layer parameter", &psNsOws); + if (paramsObj->pszLayer == NULL || strlen(paramsObj->pszLayer) == 0) { + psRootNode = + msMetadataGetExceptionReport(map, "MissingParameterValue", "layer", + "Missing layer parameter", &psNsOws); status = MS_FAILURE; } if (status == MS_SUCCESS) { /* Start dispatching request */ /* Check that layer requested exists in mapfile */ - for (i=0; inumlayers; i++) { - if(strcasecmp(GET_LAYER(map, i)->name, paramsObj->pszLayer) == 0) { + for (i = 0; i < map->numlayers; i++) { + if (strcasecmp(GET_LAYER(map, i)->name, paramsObj->pszLayer) == 0) { layer = GET_LAYER(map, i); break; } } - if (layer != NULL && msOWSLookupMetadata(&(layer->metadata), "MFCO", "metadataurl_href")) { + if (layer != NULL && + msOWSLookupMetadata(&(layer->metadata), "MFCO", "metadataurl_href")) { msIO_setHeader("Status", "301 Moved Permanently"); - msIO_setHeader("Location", "%s", msOWSLookupMetadata(&(layer->metadata), "MFCO", "metadataurl_href")); + msIO_setHeader( + "Location", "%s", + msOWSLookupMetadata(&(layer->metadata), "MFCO", "metadataurl_href")); msIO_sendHeaders(); - } - else { - psRootNode = msMetadataGetLayerMetadata(map, paramsObj, cgi_request, &psNsOws, &psNsXsi, &psNsGmd, &psNsGco); + } else { + psRootNode = msMetadataGetLayerMetadata( + map, paramsObj, cgi_request, &psNsOws, &psNsXsi, &psNsGmd, &psNsGco); } } @@ -823,23 +942,28 @@ int msMetadataDispatch(mapObj *map, cgiRequestObj *cgi_request) int buffersize = 0; xmlDocSetRootElement(xml_document, psRootNode); - msIO_setHeader("Content-type", "text/xml"); + msIO_setHeader("Content-type", "text/xml; charset=UTF-8"); msIO_sendHeaders(); - xmlDocDumpFormatMemory(xml_document, &xml_buffer, &buffersize, 1); - msIO_printf("%s", (char *) xml_buffer); + msIOContext *context = NULL; + + context = msIO_getHandler(stdout); + + xmlDocDumpFormatMemoryEnc(xml_document, &xml_buffer, &buffersize, "UTF-8", + 1); + msIO_contextWrite(context, xml_buffer, buffersize); xmlFree(xml_buffer); } xmlFreeDoc(xml_document); - if( psNsOws ) - xmlFreeNs(psNsOws); - if( psNsXsi ) - xmlFreeNs(psNsXsi); - if( psNsGmd ) - xmlFreeNs(psNsGmd); - if( psNsGco ) - xmlFreeNs(psNsGco); + if (psNsOws) + xmlFreeNs(psNsOws); + if (psNsXsi) + xmlFreeNs(psNsXsi); + if (psNsGmd) + xmlFreeNs(psNsGmd); + if (psNsGco) + xmlFreeNs(psNsGco); msMetadataFreeParamsObj(paramsObj); @@ -855,9 +979,9 @@ int msMetadataDispatch(mapObj *map, cgiRequestObj *cgi_request) /* The caller should free the object using msMetadataFreeParamsObj. */ /************************************************************************/ -metadataParamsObj *msMetadataCreateParamsObj() -{ - metadataParamsObj *paramsObj = (metadataParamsObj *)calloc(1, sizeof(metadataParamsObj)); +metadataParamsObj *msMetadataCreateParamsObj() { + metadataParamsObj *paramsObj = + (metadataParamsObj *)calloc(1, sizeof(metadataParamsObj)); MS_CHECK_ALLOC(paramsObj, sizeof(metadataParamsObj), NULL); paramsObj->pszLayer = NULL; @@ -865,15 +989,13 @@ metadataParamsObj *msMetadataCreateParamsObj() return paramsObj; } - /************************************************************************/ /* msMetadataFreeParmsObj */ /* */ /* Free params object. */ /************************************************************************/ -void msMetadataFreeParamsObj(metadataParamsObj *metadataparams) -{ +void msMetadataFreeParamsObj(metadataParamsObj *metadataparams) { if (metadataparams) { free(metadataparams->pszRequest); free(metadataparams->pszLayer); @@ -882,22 +1004,19 @@ void msMetadataFreeParamsObj(metadataParamsObj *metadataparams) } } - /************************************************************************/ /* msMetadataParseRequest */ /* */ /* Parse request into the params object. */ /************************************************************************/ -static -int msMetadataParseRequest(cgiRequestObj *request, - metadataParamsObj *metadataparams) -{ +static int msMetadataParseRequest(cgiRequestObj *request, + metadataParamsObj *metadataparams) { if (!request || !metadataparams) return MS_FAILURE; if (request->NumParams > 0) { - for(int i=0; iNumParams; i++) { + for (int i = 0; i < request->NumParams; i++) { if (request->ParamNames[i] && request->ParamValues[i]) { if (strcasecmp(request->ParamNames[i], "LAYER") == 0) metadataparams->pszLayer = msStrdup(request->ParamValues[i]); @@ -915,13 +1034,13 @@ int msMetadataParseRequest(cgiRequestObj *request, /* Parse request into the params object. */ /************************************************************************/ -void msMetadataSetGetMetadataURL(layerObj *lp, const char *url) -{ - char *pszMetadataURL=NULL; +void msMetadataSetGetMetadataURL(layerObj *lp, const char *url) { + char *pszMetadataURL = NULL; pszMetadataURL = msStrdup(url); msDecodeHTMLEntities(pszMetadataURL); - pszMetadataURL = msStringConcatenate(pszMetadataURL, "request=GetMetadata&layer="); + pszMetadataURL = + msStringConcatenate(pszMetadataURL, "request=GetMetadata&layer="); pszMetadataURL = msStringConcatenate(pszMetadataURL, lp->name); msInsertHashTable(&(lp->metadata), "ows_metadataurl_href", pszMetadataURL); diff --git a/mapmssql2008.c b/mapmssql2008.c index 2d0a750099..d59be099b1 100644 --- a/mapmssql2008.c +++ b/mapmssql2008.c @@ -87,9 +87,9 @@ SerializationProps (bitmask) 1 byte 0x10 = IsSingleLineSegment 0x20 = IsLargerThanAHemisphere -Point (2-4)x8 bytes, size depends on SerializationProps & HasZValues & HasMValues - [x][y] - SqlGeometry - [latitude][longitude] - SqlGeography +Point (2-4)x8 bytes, size depends on SerializationProps & HasZValues & +HasMValues [x][y] - SqlGeometry [latitude][longitude] - +SqlGeography Figure [FigureAttribute][PointOffset] @@ -145,7 +145,7 @@ SegmentType (1 byte) #define MSSQLGEOMETRY_WKT 2 /* geometry column types */ -#define MSSQLCOLTYPE_GEOMETRY 0 +#define MSSQLCOLTYPE_GEOMETRY 0 #define MSSQLCOLTYPE_GEOGRAPHY 1 #define MSSQLCOLTYPE_BINARY 2 #define MSSQLCOLTYPE_TEXT 3 @@ -176,27 +176,32 @@ SegmentType (1 byte) #define SMT_FIRSTLINE 2 #define SMT_FIRSTARC 3 -#define ReadInt32(nPos) (*((unsigned int*)(gpi->pszData + (nPos)))) +#define ReadInt32(nPos) (*((unsigned int *)(gpi->pszData + (nPos)))) #define ReadByte(nPos) (gpi->pszData[nPos]) -#define ReadDouble(nPos) (*((double*)(gpi->pszData + (nPos)))) +#define ReadDouble(nPos) (*((double *)(gpi->pszData + (nPos)))) -#define ParentOffset(iShape) (ReadInt32(gpi->nShapePos + (iShape) * 9 )) -#define FigureOffset(iShape) (ReadInt32(gpi->nShapePos + (iShape) * 9 + 4)) -#define ShapeType(iShape) (ReadByte(gpi->nShapePos + (iShape) * 9 + 8)) +#define ParentOffset(iShape) (ReadInt32(gpi->nShapePos + (iShape)*9)) +#define FigureOffset(iShape) (ReadInt32(gpi->nShapePos + (iShape)*9 + 4)) +#define ShapeType(iShape) (ReadByte(gpi->nShapePos + (iShape)*9 + 8)) #define SegmentType(iSegment) (ReadByte(gpi->nSegmentPos + (iSegment))) -#define NextFigureOffset(iShape) (iShape + 1 < gpi->nNumShapes? FigureOffset((iShape) +1) : gpi->nNumFigures) +#define NextFigureOffset(iShape) \ + (iShape + 1 < gpi->nNumShapes ? FigureOffset((iShape) + 1) : gpi->nNumFigures) -#define FigureAttribute(iFigure) (ReadByte(gpi->nFigurePos + (iFigure) * 5)) -#define PointOffset(iFigure) (ReadInt32(gpi->nFigurePos + (iFigure) * 5 + 1)) -#define NextPointOffset(iFigure) (iFigure + 1 < gpi->nNumFigures? PointOffset((iFigure) +1) : (unsigned)gpi->nNumPoints) +#define FigureAttribute(iFigure) (ReadByte(gpi->nFigurePos + (iFigure)*5)) +#define PointOffset(iFigure) (ReadInt32(gpi->nFigurePos + (iFigure)*5 + 1)) +#define NextPointOffset(iFigure) \ + (iFigure + 1 < gpi->nNumFigures ? PointOffset((iFigure) + 1) \ + : (unsigned)gpi->nNumPoints) #define ReadX(iPoint) (ReadDouble(gpi->nPointPos + 16 * (iPoint))) #define ReadY(iPoint) (ReadDouble(gpi->nPointPos + 16 * (iPoint) + 8)) -#define ReadZ(iPoint) (ReadDouble(gpi->nPointPos + 16 * gpi->nNumPoints + 8 * (iPoint))) -#define ReadM(iPoint) (ReadDouble(gpi->nPointPos + 24 * gpi->nNumPoints + 8 * (iPoint))) +#define ReadZ(iPoint) \ + (ReadDouble(gpi->nPointPos + 16 * gpi->nNumPoints + 8 * (iPoint))) +#define ReadM(iPoint) \ + (ReadDouble(gpi->nPointPos + 24 * gpi->nNumPoints + 8 * (iPoint))) #define FP_EPSILON 1e-12 #define SEGMENT_ANGLE 5.0 @@ -204,7 +209,7 @@ SegmentType (1 byte) /* Native geometry parser struct */ typedef struct msGeometryParserInfo_t { - unsigned char* pszData; + unsigned char *pszData; int nLen; /* version */ char chVersion; @@ -234,48 +239,58 @@ typedef struct msGeometryParserInfo_t { double maxy; } msGeometryParserInfo; -/* Structure for connection to an ODBC database (Microsoft preferred way to connect to SQL Server 2005 from c/c++) */ +/* Structure for connection to an ODBC database (Microsoft preferred way to + * connect to SQL Server 2005 from c/c++) */ typedef struct msODBCconn_t { - SQLHENV henv; /* ODBC HENV */ - SQLHDBC hdbc; /* ODBC HDBC */ - SQLHSTMT hstmt; /* ODBC HSTMNT */ - char errorMessage[1024]; /* Last error message if any */ + SQLHENV henv; /* ODBC HENV */ + SQLHDBC hdbc; /* ODBC HDBC */ + SQLHSTMT hstmt; /* ODBC HSTMNT */ + char errorMessage[1024]; /* Last error message if any */ } msODBCconn; typedef struct ms_MSSQL2008_layer_info_t { - char *sql; /* sql query to send to DB */ - long row_num; /* what row is the NEXT to be read (for random access) */ - char *geom_column; /* name of the actual geometry column parsed from the LAYER's DATA field */ - char *geom_column_type; /* the type of the geometry column */ - char *geom_table; /* the table name or sub-select decalred in the LAYER's DATA field */ - char *urid_name; /* name of user-specified unique identifier or OID */ - char *user_srid; /* zero length = calculate, non-zero means using this value! */ - char *index_name; /* hopefully this isn't necessary - but if the optimizer ain't cuttin' it... */ - char *sort_spec; /* the sort by specification which should be applied to the generated select statement */ + char *sql; /* sql query to send to DB */ + long row_num; /* what row is the NEXT to be read (for random access) */ + char *geom_column; /* name of the actual geometry column parsed from the + LAYER's DATA field */ + char *geom_column_type; /* the type of the geometry column */ + char *geom_table; /* the table name or sub-select decalred in the LAYER's DATA + field */ + char *urid_name; /* name of user-specified unique identifier or OID */ + char * + user_srid; /* zero length = calculate, non-zero means using this value! */ + char *index_name; /* hopefully this isn't necessary - but if the optimizer + ain't cuttin' it... */ + char *sort_spec; /* the sort by specification which should be applied to the + generated select statement */ int mssqlversion_major; /* the sql server major version number */ - int paging; /* Driver handling of pagination, enabled by default */ - SQLSMALLINT *itemtypes; /* storing the sql field types for further reference */ + int paging; /* Driver handling of pagination, enabled by default */ + SQLSMALLINT + *itemtypes; /* storing the sql field types for further reference */ - msODBCconn * conn; /* Connection to db */ - msGeometryParserInfo gpi; /* struct for the geometry parser */ - int geometry_format; /* Geometry format to be retrieved from the database */ + msODBCconn *conn; /* Connection to db */ + msGeometryParserInfo gpi; /* struct for the geometry parser */ + int geometry_format; /* Geometry format to be retrieved from the database */ tokenListNodeObjPtr current_node; /* filter expression translation */ } msMSSQL2008LayerInfo; #define SQL_COLUMN_NAME_MAX_LENGTH 128 #define SQL_TABLE_NAME_MAX_LENGTH 128 -#define DATA_ERROR_MESSAGE \ - "%s" \ - "Error with MSSQL2008 data variable. You specified '%s'.
\n" \ - "Standard ways of specifiying are :
\n(1) 'geometry_column from geometry_table'
\n(2) 'geometry_column from (<sub query>) as foo using unique <column name> using SRID=<srid#>'

\n\n" \ - "Make sure you utilize the 'using unique <column name>' and 'using with <index name>' clauses in.\n\n

" \ - "For more help, please see http://www.mapdotnet.com \n\n

" \ - "mapmssql2008.c - version of 2007/7/1.\n" +#define DATA_ERROR_MESSAGE \ + "%s" \ + "Error with MSSQL2008 data variable. You specified '%s'.
\n" \ + "Standard ways of specifiying are :
\n(1) 'geometry_column from " \ + "geometry_table'
\n(2) 'geometry_column from (<sub query>) as " \ + "foo using unique <column name> using SRID=<srid#>' " \ + "

\n\n" \ + "Make sure you utilize the 'using unique <column name>' and 'using " \ + "with <index name>' clauses in.\n\n

" \ + "For more help, please see http://www.mapdotnet.com \n\n

" \ + "mapmssql2008.c - version of 2007/7/1.\n" /* Native geometry parser code */ -void ReadPoint(msGeometryParserInfo* gpi, pointObj* p, int iPoint) -{ +void ReadPoint(msGeometryParserInfo *gpi, pointObj *p, int iPoint) { if (gpi->nColType == MSSQLCOLTYPE_GEOGRAPHY) { p->x = ReadY(iPoint); p->y = ReadX(iPoint); @@ -288,131 +303,130 @@ void ReadPoint(msGeometryParserInfo* gpi, pointObj* p, int iPoint) gpi->minx = gpi->maxx = p->x; gpi->miny = gpi->maxy = p->y; } else { - if (gpi->minx > p->x) gpi->minx = p->x; - else if (gpi->maxx < p->x) gpi->maxx = p->x; - if (gpi->miny > p->y) gpi->miny = p->y; - else if (gpi->maxy < p->y) gpi->maxy = p->y; + if (gpi->minx > p->x) + gpi->minx = p->x; + else if (gpi->maxx < p->x) + gpi->maxx = p->x; + if (gpi->miny > p->y) + gpi->miny = p->y; + else if (gpi->maxy < p->y) + gpi->maxy = p->y; } - if ((gpi->chProps & SP_HASZVALUES) && (gpi->chProps & SP_HASMVALUES)) - { + if ((gpi->chProps & SP_HASZVALUES) && (gpi->chProps & SP_HASMVALUES)) { p->z = ReadZ(iPoint); p->m = ReadM(iPoint); - } - else if (gpi->chProps & SP_HASZVALUES) - { - p->z = ReadZ(iPoint); - p->m = 0.0; - } - else if (gpi->chProps & SP_HASMVALUES) - { - p->z = 0.0; - p->m = ReadZ(iPoint); - } - else - { - p->z = 0.0; - p->m = 0.0; + } else if (gpi->chProps & SP_HASZVALUES) { + p->z = ReadZ(iPoint); + p->m = 0.0; + } else if (gpi->chProps & SP_HASMVALUES) { + p->z = 0.0; + p->m = ReadZ(iPoint); + } else { + p->z = 0.0; + p->m = 0.0; } } -int StrokeArcToLine(msGeometryParserInfo* gpi, lineObj* line, int index) -{ - if (index > 1) { - double x, y, x1, y1, x2, y2, x3, y3, dxa, dya, sxa, sya, dxb, dyb; - double d, sxb, syb, ox, oy, a1, a3, sa, da, a, radius; - int numpoints; - double z; - z = line->point[index].z; /* must be equal for arc segments */ - /* first point */ - x1 = line->point[index - 2].x; - y1 = line->point[index - 2].y; - /* second point */ - x2 = line->point[index - 1].x; - y2 = line->point[index - 1].y; - /* third point */ - x3 = line->point[index].x; - y3 = line->point[index].y; - - sxa = (x1 + x2); - sya = (y1 + y2); - dxa = x2 - x1; - dya = y2 - y1; - - sxb = (x2 + x3); - syb = (y2 + y3); - dxb = x3 - x2; - dyb = y3 - y2; - - d = (dxa * dyb - dya * dxb) * 2; - - if (fabs(d) < FP_EPSILON) { - /* points are colinear, nothing to do here */ - return index; - } - - /* calculating the center of circle */ - ox = ((sya - syb) * dya * dyb + sxa * dyb * dxa - sxb * dya * dxb) / d; - oy = ((sxb - sxa) * dxa * dxb + syb * dyb * dxa - sya * dya * dxb) / d; - - radius = sqrt((x1 - ox) * (x1 - ox) + (y1 - oy) * (y1 - oy)); - - /* calculating the angle to be used */ - a1 = atan2(y1 - oy, x1 - ox); - a3 = atan2(y3 - oy, x3 - ox); - - if (d > 0) { - /* draw counterclockwise */ - if (a3 > a1) /* Wrapping past 180? */ - sa = a3 - a1; - else - sa = a3 - a1 + 2.0 * M_PI ; - } - else { - if (a3 > a1) /* Wrapping past 180? */ - sa = a3 - a1 + 2.0 * M_PI; - else - sa = a3 - a1; - } - - numpoints = (int)floor(fabs(sa) * 180 / SEGMENT_ANGLE / M_PI); - if (numpoints < SEGMENT_MINPOINTS) - numpoints = SEGMENT_MINPOINTS; +int StrokeArcToLine(msGeometryParserInfo *gpi, lineObj *line, int index) { + if (index > 1) { + double x, y, x1, y1, x2, y2, x3, y3, dxa, dya, sxa, sya, dxb, dyb; + double d, sxb, syb, ox, oy, a1, a3, sa, da, a, radius; + int numpoints; + double z; + z = line->point[index].z; /* must be equal for arc segments */ + /* first point */ + x1 = line->point[index - 2].x; + y1 = line->point[index - 2].y; + /* second point */ + x2 = line->point[index - 1].x; + y2 = line->point[index - 1].y; + /* third point */ + x3 = line->point[index].x; + y3 = line->point[index].y; + + sxa = (x1 + x2); + sya = (y1 + y2); + dxa = x2 - x1; + dya = y2 - y1; + + sxb = (x2 + x3); + syb = (y2 + y3); + dxb = x3 - x2; + dyb = y3 - y2; + + d = (dxa * dyb - dya * dxb) * 2; + + if (fabs(d) < FP_EPSILON) { + /* points are colinear, nothing to do here */ + return index; + } - da = sa / numpoints; + /* calculating the center of circle */ + ox = ((sya - syb) * dya * dyb + sxa * dyb * dxa - sxb * dya * dxb) / d; + oy = ((sxb - sxa) * dxa * dxb + syb * dyb * dxa - sya * dya * dxb) / d; - /* extend the point array */ - line->numpoints += numpoints - 2; - line->point = msSmallRealloc(line->point, sizeof(pointObj) * line->numpoints); - --index; + radius = sqrt((x1 - ox) * (x1 - ox) + (y1 - oy) * (y1 - oy)); - a = a1 + da; - while (numpoints > 1) { - line->point[index].x = x = ox + radius * cos(a); - line->point[index].y = y = oy + radius * sin(a); - line->point[index].z = z; + /* calculating the angle to be used */ + a1 = atan2(y1 - oy, x1 - ox); + a3 = atan2(y3 - oy, x3 - ox); - /* calculate bounds */ - if (gpi->minx > x) gpi->minx = x; - else if (gpi->maxx < x) gpi->maxx = x; - if (gpi->miny > y) gpi->miny = y; - else if (gpi->maxy < y) gpi->maxy = y; + if (d > 0) { + /* draw counterclockwise */ + if (a3 > a1) /* Wrapping past 180? */ + sa = a3 - a1; + else + sa = a3 - a1 + 2.0 * M_PI; + } else { + if (a3 > a1) /* Wrapping past 180? */ + sa = a3 - a1 + 2.0 * M_PI; + else + sa = a3 - a1; + } - a += da; - ++index; - --numpoints; - } - /* set last point */ - line->point[index].x = x3; - line->point[index].y = y3; - line->point[index].z = z; + numpoints = (int)floor(fabs(sa) * 180 / SEGMENT_ANGLE / M_PI); + if (numpoints < SEGMENT_MINPOINTS) + numpoints = SEGMENT_MINPOINTS; + + da = sa / numpoints; + + /* extend the point array */ + line->numpoints += numpoints - 2; + line->point = + msSmallRealloc(line->point, sizeof(pointObj) * line->numpoints); + --index; + + a = a1 + da; + while (numpoints > 1) { + line->point[index].x = x = ox + radius * cos(a); + line->point[index].y = y = oy + radius * sin(a); + line->point[index].z = z; + + /* calculate bounds */ + if (gpi->minx > x) + gpi->minx = x; + else if (gpi->maxx < x) + gpi->maxx = x; + if (gpi->miny > y) + gpi->miny = y; + else if (gpi->maxy < y) + gpi->maxy = y; + + a += da; + ++index; + --numpoints; } - return index; + /* set last point */ + line->point[index].x = x3; + line->point[index].y = y3; + line->point[index].z = z; + } + return index; } -int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape) -{ - msGeometryParserInfo* gpi = &layerinfo->gpi; +int ParseSqlGeometry(msMSSQL2008LayerInfo *layerinfo, shapeObj *shape) { + msGeometryParserInfo *gpi = &layerinfo->gpi; gpi->nNumPointsRead = 0; @@ -435,13 +449,13 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape) gpi->nPointSize = 16; - if ( gpi->chProps & SP_HASMVALUES ) + if (gpi->chProps & SP_HASMVALUES) gpi->nPointSize += 8; - if ( gpi->chProps & SP_HASZVALUES ) + if (gpi->chProps & SP_HASZVALUES) gpi->nPointSize += 8; - if ( gpi->chProps & SP_ISSINGLEPOINT ) { + if (gpi->chProps & SP_ISSINGLEPOINT) { // single point geometry gpi->nNumPoints = 1; if (gpi->nLen < 6 + gpi->nPointSize) { @@ -450,14 +464,14 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape) } shape->type = MS_SHAPE_POINT; - shape->line = (lineObj *) msSmallMalloc(sizeof(lineObj)); + shape->line = (lineObj *)msSmallMalloc(sizeof(lineObj)); shape->numlines = 1; - shape->line[0].point = (pointObj *) msSmallMalloc(sizeof(pointObj)); + shape->line[0].point = (pointObj *)msSmallMalloc(sizeof(pointObj)); shape->line[0].numpoints = 1; gpi->nPointPos = 6; ReadPoint(gpi, &shape->line[0].point[0], 0); - } else if ( gpi->chProps & SP_ISSINGLELINESEGMENT ) { + } else if (gpi->chProps & SP_ISSINGLELINESEGMENT) { // single line segment with 2 points gpi->nNumPoints = 2; if (gpi->nLen < 6 + 2 * gpi->nPointSize) { @@ -466,9 +480,9 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape) } shape->type = MS_SHAPE_LINE; - shape->line = (lineObj *) msSmallMalloc(sizeof(lineObj)); + shape->line = (lineObj *)msSmallMalloc(sizeof(lineObj)); shape->numlines = 1; - shape->line[0].point = (pointObj *) msSmallMalloc(sizeof(pointObj) * 2); + shape->line[0].point = (pointObj *)msSmallMalloc(sizeof(pointObj) * 2); shape->line[0].numpoints = 2; gpi->nPointPos = 6; @@ -479,7 +493,7 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape) // complex geometries gpi->nNumPoints = ReadInt32(6); - if ( gpi->nNumPoints <= 0 ) { + if (gpi->nNumPoints <= 0) { return NOERROR; } @@ -496,7 +510,7 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape) gpi->nNumFigures = ReadInt32(gpi->nFigurePos - 4); - if ( gpi->nNumFigures <= 0 ) { + if (gpi->nNumFigures <= 0) { return NOERROR; } @@ -515,12 +529,12 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape) return NOT_ENOUGH_DATA; } - if ( gpi->nNumShapes <= 0 ) { + if (gpi->nNumShapes <= 0) { return NOERROR; } // pick up the root shape - if ( ParentOffset(0) != 0xFFFFFFFF) { + if (ParentOffset(0) != 0xFFFFFFFF) { msDebug("ParseSqlGeometry CORRUPT_DATA\n"); return CORRUPT_DATA; } @@ -531,19 +545,20 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape) if (shapeType == ST_POINT || shapeType == ST_MULTIPOINT) { shape->type = MS_SHAPE_POINT; break; - } else if (shapeType == ST_LINESTRING || shapeType == ST_MULTILINESTRING || - shapeType == ST_CIRCULARSTRING || shapeType == ST_COMPOUNDCURVE) { + } else if (shapeType == ST_LINESTRING || + shapeType == ST_MULTILINESTRING || + shapeType == ST_CIRCULARSTRING || + shapeType == ST_COMPOUNDCURVE) { shape->type = MS_SHAPE_LINE; break; - } else if (shapeType == ST_POLYGON || shapeType == ST_MULTIPOLYGON || - shapeType == ST_CURVEPOLYGON) - { + } else if (shapeType == ST_POLYGON || shapeType == ST_MULTIPOLYGON || + shapeType == ST_CURVEPOLYGON) { shape->type = MS_SHAPE_POLYGON; break; } } - shape->line = (lineObj *) msSmallMalloc(sizeof(lineObj) * gpi->nNumFigures); + shape->line = (lineObj *)msSmallMalloc(sizeof(lineObj) * gpi->nNumFigures); shape->numlines = gpi->nNumFigures; gpi->nNumSegments = 0; @@ -553,61 +568,63 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape) iPoint = PointOffset(iFigure); iNextPoint = NextPointOffset(iFigure); - shape->line[iFigure].point = (pointObj *) msSmallMalloc(sizeof(pointObj)*(iNextPoint - iPoint)); + shape->line[iFigure].point = + (pointObj *)msSmallMalloc(sizeof(pointObj) * (iNextPoint - iPoint)); shape->line[iFigure].numpoints = iNextPoint - iPoint; i = 0; if (gpi->chVersion == 0x02 && FigureAttribute(iFigure) >= 0x02) { - int nPointPrepared = 0; - lineObj* line = &shape->line[iFigure]; - if (FigureAttribute(iFigure) == 0x03) { - if (gpi->nNumSegments == 0) { - /* position of the segment types */ - gpi->nSegmentPos = gpi->nShapePos + 9 * gpi->nNumShapes + 4; - gpi->nNumSegments = ReadInt32(gpi->nSegmentPos - 4); - if (gpi->nLen < gpi->nSegmentPos + gpi->nNumSegments) { - msDebug("ParseSqlGeometry NOT_ENOUGH_DATA\n"); - return NOT_ENOUGH_DATA; - } - iSegment = 0; - } - - while (iPoint < iNextPoint && iSegment < gpi->nNumSegments) { - ReadPoint(gpi, &line->point[i], iPoint); - ++iPoint; - ++nPointPrepared; - - if (nPointPrepared == 2 && (SegmentType(iSegment) == SMT_FIRSTLINE || SegmentType(iSegment) == SMT_LINE)) { - ++iSegment; - nPointPrepared = 1; - } - else if (nPointPrepared == 3 && (SegmentType(iSegment) == SMT_FIRSTARC || SegmentType(iSegment) == SMT_ARC)) { - i = StrokeArcToLine(gpi, line, i); - ++iSegment; - nPointPrepared = 1; - } - ++i; - } + int nPointPrepared = 0; + lineObj *line = &shape->line[iFigure]; + if (FigureAttribute(iFigure) == 0x03) { + if (gpi->nNumSegments == 0) { + /* position of the segment types */ + gpi->nSegmentPos = gpi->nShapePos + 9 * gpi->nNumShapes + 4; + gpi->nNumSegments = ReadInt32(gpi->nSegmentPos - 4); + if (gpi->nLen < gpi->nSegmentPos + gpi->nNumSegments) { + msDebug("ParseSqlGeometry NOT_ENOUGH_DATA\n"); + return NOT_ENOUGH_DATA; + } + iSegment = 0; } - else { - while (iPoint < iNextPoint) { - ReadPoint(gpi, &line->point[i], iPoint); - ++iPoint; - ++nPointPrepared; - if (nPointPrepared == 3) { - i = StrokeArcToLine(gpi, line, i); - nPointPrepared = 1; - } - ++i; - } + + while (iPoint < iNextPoint && iSegment < gpi->nNumSegments) { + ReadPoint(gpi, &line->point[i], iPoint); + ++iPoint; + ++nPointPrepared; + + if (nPointPrepared == 2 && + (SegmentType(iSegment) == SMT_FIRSTLINE || + SegmentType(iSegment) == SMT_LINE)) { + ++iSegment; + nPointPrepared = 1; + } else if (nPointPrepared == 3 && + (SegmentType(iSegment) == SMT_FIRSTARC || + SegmentType(iSegment) == SMT_ARC)) { + i = StrokeArcToLine(gpi, line, i); + ++iSegment; + nPointPrepared = 1; + } + ++i; } - } - else { + } else { while (iPoint < iNextPoint) { - ReadPoint(gpi, &shape->line[iFigure].point[i], iPoint); - ++iPoint; - ++i; + ReadPoint(gpi, &line->point[i], iPoint); + ++iPoint; + ++nPointPrepared; + if (nPointPrepared == 3) { + i = StrokeArcToLine(gpi, line, i); + nPointPrepared = 1; + } + ++i; } + } + } else { + while (iPoint < iNextPoint) { + ReadPoint(gpi, &shape->line[iFigure].point[i], iPoint); + ++iPoint; + ++i; + } } } } @@ -623,22 +640,20 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape) /* MS SQL driver code*/ -msMSSQL2008LayerInfo *getMSSQL2008LayerInfo(const layerObj *layer) -{ +msMSSQL2008LayerInfo *getMSSQL2008LayerInfo(const layerObj *layer) { return layer->layerinfo; } -void setMSSQL2008LayerInfo(layerObj *layer, msMSSQL2008LayerInfo *MSSQL2008layerinfo) -{ - layer->layerinfo = (void*) MSSQL2008layerinfo; +void setMSSQL2008LayerInfo(layerObj *layer, + msMSSQL2008LayerInfo *MSSQL2008layerinfo) { + layer->layerinfo = (void *)MSSQL2008layerinfo; } -void handleSQLError(layerObj *layer) -{ - SQLCHAR SqlState[6], Msg[SQL_MAX_MESSAGE_LENGTH]; - SQLINTEGER NativeError; - SQLSMALLINT i, MsgLen; - SQLRETURN rc; +void handleSQLError(layerObj *layer) { + SQLCHAR SqlState[6], Msg[SQL_MAX_MESSAGE_LENGTH]; + SQLINTEGER NativeError; + SQLSMALLINT i, MsgLen; + SQLRETURN rc; msMSSQL2008LayerInfo *layerinfo = getMSSQL2008LayerInfo(layer); if (layerinfo == NULL) @@ -646,9 +661,10 @@ void handleSQLError(layerObj *layer) // Get the status records. i = 1; - while ((rc = SQLGetDiagRec(SQL_HANDLE_STMT, layerinfo->conn->hstmt, i, SqlState, &NativeError, - Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA) { - if(layer->debug) { + while ((rc = SQLGetDiagRec(SQL_HANDLE_STMT, layerinfo->conn->hstmt, i, + SqlState, &NativeError, Msg, sizeof(Msg), + &MsgLen)) != SQL_NO_DATA) { + if (layer->debug) { msDebug("SQLError: %s\n", Msg); } i++; @@ -656,33 +672,32 @@ void handleSQLError(layerObj *layer) } /* TODO Take a look at glibc's strcasestr */ -static char *strstrIgnoreCase(const char *haystack, const char *needle) -{ - char *hay_lower; - char *needle_lower; - size_t len_hay,len_need, match; - int found = MS_FALSE; - char *loc; +static char *strstrIgnoreCase(const char *haystack, const char *needle) { + char *hay_lower; + char *needle_lower; + size_t len_hay, len_need, match; + int found = MS_FALSE; + char *loc; len_hay = strlen(haystack); len_need = strlen(needle); - hay_lower = (char*) msSmallMalloc(len_hay + 1); - needle_lower =(char*) msSmallMalloc(len_need + 1); + hay_lower = (char *)msSmallMalloc(len_hay + 1); + needle_lower = (char *)msSmallMalloc(len_need + 1); size_t t; - for(t = 0; t < len_hay; t++) { + for (t = 0; t < len_hay; t++) { hay_lower[t] = (char)tolower(haystack[t]); } hay_lower[t] = 0; - for(t = 0; t < len_need; t++) { + for (t = 0; t < len_need; t++) { needle_lower[t] = (char)tolower(needle[t]); } needle_lower[t] = 0; loc = strstr(hay_lower, needle_lower); - if(loc) { + if (loc) { match = loc - hay_lower; found = MS_TRUE; } @@ -690,15 +705,18 @@ static char *strstrIgnoreCase(const char *haystack, const char *needle) msFree(hay_lower); msFree(needle_lower); - return (char *) (found == MS_FALSE ? NULL : haystack + match); + return (char *)(found == MS_FALSE ? NULL : haystack + match); } -static int msMSSQL2008LayerParseData(layerObj *layer, char **geom_column_name, char **geom_column_type, char **table_name, char **urid_name, char **user_srid, char **index_name, char **sort_spec, int debug); +static int msMSSQL2008LayerParseData(layerObj *layer, char **geom_column_name, + char **geom_column_type, char **table_name, + char **urid_name, char **user_srid, + char **index_name, char **sort_spec, + int debug); /* Close connection and handles */ -static void msMSSQL2008CloseConnection(void *conn_handle) -{ - msODBCconn * conn = (msODBCconn *) conn_handle; +static void msMSSQL2008CloseConnection(void *conn_handle) { + msODBCconn *conn = (msODBCconn *)conn_handle; if (!conn) { return; @@ -719,69 +737,72 @@ static void msMSSQL2008CloseConnection(void *conn_handle) } /* Set the error string for the connection */ -static void setConnError(msODBCconn *conn) -{ +static void setConnError(msODBCconn *conn) { SQLSMALLINT len; - SQLGetDiagField(SQL_HANDLE_DBC, conn->hdbc, 1, SQL_DIAG_MESSAGE_TEXT, (SQLPOINTER) conn->errorMessage, sizeof(conn->errorMessage), &len); + SQLGetDiagField(SQL_HANDLE_DBC, conn->hdbc, 1, SQL_DIAG_MESSAGE_TEXT, + (SQLPOINTER)conn->errorMessage, sizeof(conn->errorMessage), + &len); conn->errorMessage[len] = 0; } #ifdef USE_ICONV -static SQLWCHAR* convertCwchartToSQLWCHAR(const wchar_t* inStr) -{ - SQLWCHAR* outStr; - int i, len; - for( len = 0; inStr[len] != 0; ++len ) - { - /* do nothing */ - } - outStr = (SQLWCHAR*)msSmallMalloc(sizeof(SQLWCHAR) * (len + 1)); - for( i = 0; i <= len; i++ ) - { - outStr[i] = (SQLWCHAR)inStr[i]; - } - return outStr; +static SQLWCHAR *convertCwchartToSQLWCHAR(const wchar_t *inStr) { + SQLWCHAR *outStr; + int i, len; + for (len = 0; inStr[len] != 0; ++len) { + /* do nothing */ + } + outStr = (SQLWCHAR *)msSmallMalloc(sizeof(SQLWCHAR) * (len + 1)); + for (i = 0; i <= len; i++) { + outStr[i] = (SQLWCHAR)inStr[i]; + } + return outStr; } #endif /* Connect to db */ -static msODBCconn * mssql2008Connect(const char * connString) -{ +static msODBCconn *mssql2008Connect(const char *connString) { SQLSMALLINT outConnStringLen; SQLRETURN rc; - msODBCconn * conn = msSmallMalloc(sizeof(msODBCconn)); + msODBCconn *conn = msSmallMalloc(sizeof(msODBCconn)); char fullConnString[1024]; memset(conn, 0, sizeof(*conn)); SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &conn->henv); - SQLSetEnvAttr(conn->henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0); + SQLSetEnvAttr(conn->henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0); SQLAllocHandle(SQL_HANDLE_DBC, conn->henv, &conn->hdbc); - if (strcasestr(connString, "DRIVER=") == 0) - { - snprintf(fullConnString, sizeof(fullConnString), "DRIVER={SQL Server};%s", connString); + if (strcasestr(connString, "DRIVER=") == 0) { + snprintf(fullConnString, sizeof(fullConnString), "DRIVER={SQL Server};%s", + connString); - connString = fullConnString; + connString = fullConnString; } { #ifdef USE_ICONV - wchar_t *decodedConnString = msConvertWideStringFromUTF8(connString, "UCS-2LE"); - SQLWCHAR outConnString[1024]; - SQLWCHAR* decodedConnStringSQLWCHAR = convertCwchartToSQLWCHAR(decodedConnString); - rc = SQLDriverConnectW(conn->hdbc, NULL, decodedConnStringSQLWCHAR, SQL_NTS, outConnString, 1024, &outConnStringLen, SQL_DRIVER_NOPROMPT); - msFree(decodedConnString); - msFree(decodedConnStringSQLWCHAR); + wchar_t *decodedConnString = + msConvertWideStringFromUTF8(connString, "UCS-2LE"); + SQLWCHAR outConnString[1024]; + SQLWCHAR *decodedConnStringSQLWCHAR = + convertCwchartToSQLWCHAR(decodedConnString); + rc = SQLDriverConnectW(conn->hdbc, NULL, decodedConnStringSQLWCHAR, SQL_NTS, + outConnString, 1024, &outConnStringLen, + SQL_DRIVER_NOPROMPT); + msFree(decodedConnString); + msFree(decodedConnStringSQLWCHAR); #else - SQLCHAR outConnString[1024]; - rc = SQLDriverConnect(conn->hdbc, NULL, (SQLCHAR*)connString, SQL_NTS, outConnString, 1024, &outConnStringLen, SQL_DRIVER_NOPROMPT); + SQLCHAR outConnString[1024]; + rc = SQLDriverConnect(conn->hdbc, NULL, (SQLCHAR *)connString, SQL_NTS, + outConnString, 1024, &outConnStringLen, + SQL_DRIVER_NOPROMPT); #endif - } + } if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { setConnError(conn); @@ -795,18 +816,18 @@ static msODBCconn * mssql2008Connect(const char * connString) } /* Set the error string for the statement execution */ -static void setStmntError(msODBCconn *conn) -{ +static void setStmntError(msODBCconn *conn) { SQLSMALLINT len; - SQLGetDiagField(SQL_HANDLE_STMT, conn->hstmt, 1, SQL_DIAG_MESSAGE_TEXT, (SQLPOINTER) conn->errorMessage, sizeof(conn->errorMessage), &len); + SQLGetDiagField(SQL_HANDLE_STMT, conn->hstmt, 1, SQL_DIAG_MESSAGE_TEXT, + (SQLPOINTER)conn->errorMessage, sizeof(conn->errorMessage), + &len); conn->errorMessage[len] = 0; } /* Execute SQL against connection. Set error string if failed */ -static int executeSQL(msODBCconn *conn, const char * sql) -{ +static int executeSQL(msODBCconn *conn, const char *sql) { SQLRETURN rc; SQLCloseCursor(conn->hstmt); @@ -814,13 +835,13 @@ static int executeSQL(msODBCconn *conn, const char * sql) #ifdef USE_ICONV { wchar_t *decodedSql = msConvertWideStringFromUTF8(sql, "UCS-2LE"); - SQLWCHAR* decodedSqlSQLWCHAR = convertCwchartToSQLWCHAR(decodedSql); + SQLWCHAR *decodedSqlSQLWCHAR = convertCwchartToSQLWCHAR(decodedSql); rc = SQLExecDirectW(conn->hstmt, decodedSqlSQLWCHAR, SQL_NTS); msFree(decodedSql); msFree(decodedSqlSQLWCHAR); } #else - rc = SQLExecDirect(conn->hstmt, (SQLCHAR *) sql, SQL_NTS); + rc = SQLExecDirect(conn->hstmt, (SQLCHAR *)sql, SQL_NTS); #endif if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { @@ -832,8 +853,9 @@ static int executeSQL(msODBCconn *conn, const char * sql) } /* Get columns name from query results */ -static int columnName(msODBCconn *conn, int index, char *buffer, int bufferLength, layerObj *layer, char pass_field_def, SQLSMALLINT *itemType) -{ +static int columnName(msODBCconn *conn, int index, char *buffer, + int bufferLength, layerObj *layer, char pass_field_def, + SQLSMALLINT *itemType) { SQLRETURN rc; SQLCHAR columnName[SQL_COLUMN_NAME_MAX_LENGTH + 1]; @@ -843,16 +865,9 @@ static int columnName(msODBCconn *conn, int index, char *buffer, int bufferLengt SQLSMALLINT decimalDigits; SQLSMALLINT nullable; - rc = SQLDescribeCol( - conn->hstmt, - (SQLUSMALLINT)index, - columnName, - SQL_COLUMN_NAME_MAX_LENGTH, - &columnNameLen, - &dataType, - &columnSize, - &decimalDigits, - &nullable); + rc = SQLDescribeCol(conn->hstmt, (SQLUSMALLINT)index, columnName, + SQL_COLUMN_NAME_MAX_LENGTH, &columnNameLen, &dataType, + &columnSize, &decimalDigits, &nullable); if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { if (bufferLength < SQL_COLUMN_NAME_MAX_LENGTH + 1) @@ -869,50 +884,51 @@ static int columnName(msODBCconn *conn, int index, char *buffer, int bufferLengt gml_width[0] = '\0'; gml_precision[0] = '\0'; - switch( dataType ) { - case SQL_INTEGER: - case SQL_SMALLINT: - case SQL_TINYINT: - gml_type = "Integer"; - break; - - case SQL_BIGINT: - gml_type = "Long"; - break; - - case SQL_REAL: - case SQL_FLOAT: - case SQL_DOUBLE: - case SQL_DECIMAL: - case SQL_NUMERIC: - gml_type = "Real"; - if( decimalDigits > 0 ) - sprintf( gml_precision, "%d", decimalDigits ); - break; - - case SQL_TYPE_DATE: - gml_type = "Date"; - break; - case SQL_TYPE_TIME: - gml_type = "Time"; - break; - case SQL_TYPE_TIMESTAMP: - gml_type = "DateTime"; - break; - - case SQL_BIT: - gml_type = "Boolean"; - break; - - default: - gml_type = "Character"; - break; + switch (dataType) { + case SQL_INTEGER: + case SQL_SMALLINT: + case SQL_TINYINT: + gml_type = "Integer"; + break; + + case SQL_BIGINT: + gml_type = "Long"; + break; + + case SQL_REAL: + case SQL_FLOAT: + case SQL_DOUBLE: + case SQL_DECIMAL: + case SQL_NUMERIC: + gml_type = "Real"; + if (decimalDigits > 0) + sprintf(gml_precision, "%d", decimalDigits); + break; + + case SQL_TYPE_DATE: + gml_type = "Date"; + break; + case SQL_TYPE_TIME: + gml_type = "Time"; + break; + case SQL_TYPE_TIMESTAMP: + gml_type = "DateTime"; + break; + + case SQL_BIT: + gml_type = "Boolean"; + break; + + default: + gml_type = "Character"; + break; } - if( columnSize > 0 ) - sprintf( gml_width, "%u", (unsigned int)columnSize ); + if (columnSize > 0) + sprintf(gml_width, "%u", (unsigned int)columnSize); - msUpdateGMLFieldMetadata(layer, buffer, gml_type, gml_width, gml_precision, (const short) nullable); + msUpdateGMLFieldMetadata(layer, buffer, gml_type, gml_width, + gml_precision, (const short)nullable); } return 1; } else { @@ -921,40 +937,43 @@ static int columnName(msODBCconn *conn, int index, char *buffer, int bufferLengt } } -/* open up a connection to the MS SQL 2008 database using the connection string in layer->connection */ -/* ie. "driver=;server=;database=;integrated security=?;user id=;password=" */ -int msMSSQL2008LayerOpen(layerObj *layer) -{ - msMSSQL2008LayerInfo *layerinfo; - char *index, *maskeddata; - int i, count; +/* open up a connection to the MS SQL 2008 database using the connection string + * in layer->connection */ +/* ie. "driver=;server=;database=;integrated + * security=?;user id=;password=" */ +int msMSSQL2008LayerOpen(layerObj *layer) { + msMSSQL2008LayerInfo *layerinfo; char *conn_decrypted = NULL; - if(layer->debug) { + if (layer->debug) { msDebug("msMSSQL2008LayerOpen called datastatement: %s\n", layer->data); } - if(getMSSQL2008LayerInfo(layer)) { - if(layer->debug) { + if (getMSSQL2008LayerInfo(layer)) { + if (layer->debug) { msDebug("msMSSQL2008LayerOpen :: layer is already open!!\n"); } - return MS_SUCCESS; /* already open */ + return MS_SUCCESS; /* already open */ } - if(!layer->data) { - msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerOpen()", "", "Error parsing MSSQL2008 data variable: nothing specified in DATA statement.

\n\nMore Help:

\n\n"); + if (!layer->data) { + msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerOpen()", "", + "Error parsing MSSQL2008 data variable: nothing specified in " + "DATA statement.

\n\nMore Help:

\n\n"); return MS_FAILURE; } - if(!layer->connection) { - msSetError( MS_QUERYERR, "MSSQL connection parameter not specified.", "msMSSQL2008LayerOpen()"); + if (!layer->connection) { + msSetError(MS_QUERYERR, "MSSQL connection parameter not specified.", + "msMSSQL2008LayerOpen()"); return MS_FAILURE; } /* have to setup a connection to the database */ - layerinfo = (msMSSQL2008LayerInfo*) msSmallMalloc(sizeof(msMSSQL2008LayerInfo)); + layerinfo = + (msMSSQL2008LayerInfo *)msSmallMalloc(sizeof(msMSSQL2008LayerInfo)); layerinfo->sql = NULL; /* calc later */ layerinfo->row_num = 0; @@ -970,17 +989,17 @@ int msMSSQL2008LayerOpen(layerObj *layer) layerinfo->mssqlversion_major = 0; layerinfo->paging = MS_TRUE; - layerinfo->conn = (msODBCconn *) msConnPoolRequest(layer); + layerinfo->conn = (msODBCconn *)msConnPoolRequest(layer); - if(!layerinfo->conn) { - if(layer->debug) { + if (!layerinfo->conn) { + if (layer->debug) { msDebug("MSMSSQL2008LayerOpen -- shared connection not available.\n"); } /* Decrypt any encrypted token in connection and attempt to connect */ conn_decrypted = msDecryptStringTokens(layer->map, layer->connection); if (conn_decrypted == NULL) { - return(MS_FAILURE); /* An error should already have been produced */ + return (MS_FAILURE); /* An error should already have been produced */ } layerinfo->conn = mssql2008Connect(conn_decrypted); @@ -988,38 +1007,35 @@ int msMSSQL2008LayerOpen(layerObj *layer) msFree(conn_decrypted); conn_decrypted = NULL; - if(!layerinfo->conn || layerinfo->conn->errorMessage[0]) { + if (!layerinfo->conn || layerinfo->conn->errorMessage[0]) { char *errMess = "Out of memory"; - msDebug("FAILURE!!!"); - maskeddata = (char *)msSmallMalloc(strlen(layer->connection) + 1); - strcpy(maskeddata, layer->connection); - index = strstr(maskeddata, "password="); - if(index != NULL) { - index = (char *)(index + 9); - count = (int)(strstr(index, " ") - index); - for(i = 0; i < count; i++) { - strlcpy(index, "*", (int)1); - index++; - } - } + if (layer->debug) + msDebug("MSMSSQL2008LayerOpen: Connection failure.\n"); if (layerinfo->conn) { errMess = layerinfo->conn->errorMessage; } + msDebug( + "Couldn't make connection to MS SQL Server with connect string " + "'%s'.\n" + "Error reported was '%s'.\n\n" + "This error occured when trying to make a connection to the " + "specified SQL server.\n" + "Most commonly this is caused by: \n" + "(1) incorrect connection string \n" + "(2) you didn't specify a 'user id=...' in your connection string \n" + "(3) SQL server isnt running \n" + "(4) TCPIP not enabled for SQL Client or server \n\n", + layer->connection, errMess); msSetError(MS_QUERYERR, - "Couldnt make connection to MS SQL Server 2008 with connect string '%s'.\n
\n" - "Error reported was '%s'.\n
\n\n" - "This error occured when trying to make a connection to the specified SQL server. \n" - "
\nMost commonly this is caused by
\n" - "(1) incorrect connection string
\n" - "(2) you didn't specify a 'user id=...' in your connection string
\n" - "(3) SQL server isnt running
\n" - "(4) TCPIP not enabled for SQL Client or server
\n\n", - "msMSSQL2008LayerOpen()", maskeddata, errMess); - - msFree(maskeddata); + "Database connection failed. Check server logs for more " + "details. Is SQL Server running? Is it allowing connections? " + "Does the specified user exist? Is the password valid? Is the " + "database on the standard port?", + "MSMSSQL2008LayerOpen()"); + msMSSQL2008CloseConnection(layerinfo->conn); msFree(layerinfo); return MS_FAILURE; @@ -1030,13 +1046,18 @@ int msMSSQL2008LayerOpen(layerObj *layer) setMSSQL2008LayerInfo(layer, layerinfo); - if (msMSSQL2008LayerParseData(layer, &layerinfo->geom_column, &layerinfo->geom_column_type, &layerinfo->geom_table, &layerinfo->urid_name, &layerinfo->user_srid, &layerinfo->index_name, &layerinfo->sort_spec, layer->debug) != MS_SUCCESS) { - msSetError( MS_QUERYERR, "Could not parse the layer data", "msMSSQL2008LayerOpen()"); + if (msMSSQL2008LayerParseData( + layer, &layerinfo->geom_column, &layerinfo->geom_column_type, + &layerinfo->geom_table, &layerinfo->urid_name, &layerinfo->user_srid, + &layerinfo->index_name, &layerinfo->sort_spec, + layer->debug) != MS_SUCCESS) { + msSetError(MS_QUERYERR, "Could not parse the layer data", + "msMSSQL2008LayerOpen()"); return MS_FAILURE; } /* identify the geometry transfer type */ - if (msLayerGetProcessingKey( layer, "MSSQL_READ_WKB" ) != NULL) + if (msLayerGetProcessingKey(layer, "MSSQL_READ_WKB") != NULL) layerinfo->geometry_format = MSSQLGEOMETRY_WKB; else { layerinfo->geometry_format = MSSQLGEOMETRY_NATIVE; @@ -1050,75 +1071,72 @@ int msMSSQL2008LayerOpen(layerObj *layer) } /* Return MS_TRUE if layer is open, MS_FALSE otherwise. */ -int msMSSQL2008LayerIsOpen(layerObj *layer) -{ +int msMSSQL2008LayerIsOpen(layerObj *layer) { return getMSSQL2008LayerInfo(layer) ? MS_TRUE : MS_FALSE; } - /* Free the itemindexes array in a layer. */ -void msMSSQL2008LayerFreeItemInfo(layerObj *layer) -{ - if(layer->debug) { +void msMSSQL2008LayerFreeItemInfo(layerObj *layer) { + if (layer->debug) { msDebug("msMSSQL2008LayerFreeItemInfo called\n"); } - if(layer->iteminfo) { + if (layer->iteminfo) { msFree(layer->iteminfo); } layer->iteminfo = NULL; } - /* allocate the iteminfo index array - same order as the item list */ -int msMSSQL2008LayerInitItemInfo(layerObj *layer) -{ - int i; - int *itemindexes ; +int msMSSQL2008LayerInitItemInfo(layerObj *layer) { + int i; + int *itemindexes; if (layer->debug) { msDebug("msMSSQL2008LayerInitItemInfo called\n"); } - if(layer->numitems == 0) { + if (layer->numitems == 0) { return MS_SUCCESS; } msFree(layer->iteminfo); - layer->iteminfo = (int *) msSmallMalloc(sizeof(int) * layer->numitems); + layer->iteminfo = (int *)msSmallMalloc(sizeof(int) * layer->numitems); - itemindexes = (int*)layer->iteminfo; + itemindexes = (int *)layer->iteminfo; - for(i = 0; i < layer->numitems; i++) { - itemindexes[i] = i; /* last one is always the geometry one - the rest are non-geom */ + for (i = 0; i < layer->numitems; i++) { + itemindexes[i] = + i; /* last one is always the geometry one - the rest are non-geom */ } return MS_SUCCESS; } -static int getMSSQLMajorVersion(layerObj* layer) -{ - msMSSQL2008LayerInfo *layerinfo = getMSSQL2008LayerInfo(layer); +static int getMSSQLMajorVersion(layerObj *layer) { + msMSSQL2008LayerInfo *layerinfo = getMSSQL2008LayerInfo(layer); if (layerinfo == NULL) return 0; if (layerinfo->mssqlversion_major == 0) { - const char* mssqlversion_major = msLayerGetProcessingKey(layer, "MSSQL_VERSION_MAJOR"); + const char *mssqlversion_major = + msLayerGetProcessingKey(layer, "MSSQL_VERSION_MAJOR"); if (mssqlversion_major != NULL) { layerinfo->mssqlversion_major = atoi(mssqlversion_major); - } - else { + } else { /* need to query from database */ - if (executeSQL(layerinfo->conn, "SELECT SERVERPROPERTY('ProductVersion')")) { + if (executeSQL(layerinfo->conn, + "SELECT SERVERPROPERTY('ProductVersion')")) { SQLRETURN rc = SQLFetch(layerinfo->conn->hstmt); if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { /* process results */ char result_data[256]; SQLLEN retLen = 0; - rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_CHAR, result_data, sizeof(result_data), &retLen); + rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_CHAR, result_data, + sizeof(result_data), &retLen); if (rc != SQL_ERROR) { result_data[retLen] = 0; @@ -1132,17 +1150,16 @@ static int getMSSQLMajorVersion(layerObj* layer) return layerinfo->mssqlversion_major; } -static int addFilter(layerObj *layer, char **query) -{ +static int addFilter(layerObj *layer, char **query) { if (layer->filter.native_string) { (*query) = msStringConcatenate(*query, " WHERE ("); (*query) = msStringConcatenate(*query, layer->filter.native_string); (*query) = msStringConcatenate(*query, ")"); return MS_TRUE; - } - else if (msLayerGetProcessingKey(layer, "NATIVE_FILTER") != NULL) { + } else if (msLayerGetProcessingKey(layer, "NATIVE_FILTER") != NULL) { (*query) = msStringConcatenate(*query, " WHERE ("); - (*query) = msStringConcatenate(*query, msLayerGetProcessingKey(layer, "NATIVE_FILTER")); + (*query) = msStringConcatenate( + *query, msLayerGetProcessingKey(layer, "NATIVE_FILTER")); (*query) = msStringConcatenate(*query, ")"); return MS_TRUE; } @@ -1152,195 +1169,214 @@ static int addFilter(layerObj *layer, char **query) /* Get the layer extent as specified in the mapfile or a largest area */ /* covering all features */ -int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent) -{ - msMSSQL2008LayerInfo *layerinfo; - char *query = 0; - char result_data[256]; - SQLLEN retLen; - SQLRETURN rc; - - if(layer->debug) { - msDebug("msMSSQL2008LayerGetExtent called\n"); - } - - if (!(layer->extent.minx == -1.0 && layer->extent.miny == -1.0 && - layer->extent.maxx == -1.0 && layer->extent.maxy == -1.0)) { - /* extent was already set */ - extent->minx = layer->extent.minx; - extent->miny = layer->extent.miny; - extent->maxx = layer->extent.maxx; - extent->maxy = layer->extent.maxy; - } +int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent) { + msMSSQL2008LayerInfo *layerinfo; + char *query = 0; + char result_data[256]; + SQLLEN retLen; + SQLRETURN rc; - layerinfo = getMSSQL2008LayerInfo(layer); + if (layer->debug) { + msDebug("msMSSQL2008LayerGetExtent called\n"); + } - if (!layerinfo) { - msSetError(MS_QUERYERR, "GetExtent called with layerinfo = NULL", "msMSSQL2008LayerGetExtent()"); - return MS_FAILURE; - } + if (!(layer->extent.minx == -1.0 && layer->extent.miny == -1.0 && + layer->extent.maxx == -1.0 && layer->extent.maxy == -1.0)) { + /* extent was already set */ + extent->minx = layer->extent.minx; + extent->miny = layer->extent.miny; + extent->maxx = layer->extent.maxx; + extent->maxy = layer->extent.maxy; + } - /* set up statement */ - if (getMSSQLMajorVersion(layer) >= 11) { - if (strcasecmp(layerinfo->geom_column_type, "geography") == 0) { - query = msStringConcatenate(query, "WITH extent(extentcol) AS (SELECT geometry::EnvelopeAggregate(geometry::STGeomFromWKB("); - query = msStringConcatenate(query, layerinfo->geom_column); - query = msStringConcatenate(query, ".STAsBinary(), "); - query = msStringConcatenate(query, layerinfo->geom_column); - query = msStringConcatenate(query, ".STSrid)"); - } - else { - query = msStringConcatenate(query, "WITH extent(extentcol) AS (SELECT geometry::EnvelopeAggregate("); - query = msStringConcatenate(query, layerinfo->geom_column); - } - query = msStringConcatenate(query, ") AS extentcol FROM "); - query = msStringConcatenate(query, layerinfo->geom_table); + layerinfo = getMSSQL2008LayerInfo(layer); - /* adding attribute filter */ - addFilter(layer, &query); + if (!layerinfo) { + msSetError(MS_QUERYERR, "GetExtent called with layerinfo = NULL", + "msMSSQL2008LayerGetExtent()"); + return MS_FAILURE; + } - query = msStringConcatenate(query, ") SELECT extentcol.STPointN(1).STX, extentcol.STPointN(1).STY, extentcol.STPointN(3).STX, extentcol.STPointN(3).STY FROM extent"); + /* set up statement */ + if (getMSSQLMajorVersion(layer) >= 11) { + if (strcasecmp(layerinfo->geom_column_type, "geography") == 0) { + query = msStringConcatenate( + query, "WITH extent(extentcol) AS (SELECT " + "geometry::EnvelopeAggregate(geometry::STGeomFromWKB("); + query = msStringConcatenate(query, layerinfo->geom_column); + query = msStringConcatenate(query, ".STAsBinary(), "); + query = msStringConcatenate(query, layerinfo->geom_column); + query = msStringConcatenate(query, ".STSrid)"); + } else { + query = msStringConcatenate( + query, + "WITH extent(extentcol) AS (SELECT geometry::EnvelopeAggregate("); + query = msStringConcatenate(query, layerinfo->geom_column); } - else { - if (strcasecmp(layerinfo->geom_column_type, "geography") == 0) { - query = msStringConcatenate(query, "WITH ENVELOPE as (SELECT geometry::STGeomFromWKB("); - query = msStringConcatenate(query, layerinfo->geom_column); - query = msStringConcatenate(query, ".STAsBinary(), "); - query = msStringConcatenate(query, layerinfo->geom_column); - query = msStringConcatenate(query, ".STSrid)"); - } - else { - query = msStringConcatenate(query, "WITH ENVELOPE as (SELECT "); - query = msStringConcatenate(query, layerinfo->geom_column); - } - query = msStringConcatenate(query, ".STEnvelope() as envelope from "); - query = msStringConcatenate(query, layerinfo->geom_table); + query = msStringConcatenate(query, ") AS extentcol FROM "); + query = msStringConcatenate(query, layerinfo->geom_table); - /* adding attribute filter */ - addFilter(layer, &query); + /* adding attribute filter */ + addFilter(layer, &query); - query = msStringConcatenate(query, "), CORNERS as (SELECT envelope.STPointN(1) as point from ENVELOPE UNION ALL select envelope.STPointN(3) from ENVELOPE) SELECT MIN(point.STX), MIN(point.STY), MAX(point.STX), MAX(point.STY) FROM CORNERS"); + query = msStringConcatenate( + query, + ") SELECT extentcol.STPointN(1).STX, extentcol.STPointN(1).STY, " + "extentcol.STPointN(3).STX, extentcol.STPointN(3).STY FROM extent"); + } else { + if (strcasecmp(layerinfo->geom_column_type, "geography") == 0) { + query = msStringConcatenate( + query, "WITH ENVELOPE as (SELECT geometry::STGeomFromWKB("); + query = msStringConcatenate(query, layerinfo->geom_column); + query = msStringConcatenate(query, ".STAsBinary(), "); + query = msStringConcatenate(query, layerinfo->geom_column); + query = msStringConcatenate(query, ".STSrid)"); + } else { + query = msStringConcatenate(query, "WITH ENVELOPE as (SELECT "); + query = msStringConcatenate(query, layerinfo->geom_column); } + query = msStringConcatenate(query, ".STEnvelope() as envelope from "); + query = msStringConcatenate(query, layerinfo->geom_table); - if (!executeSQL(layerinfo->conn, query)) { - msFree(query); - return MS_FAILURE; - } + /* adding attribute filter */ + addFilter(layer, &query); + query = msStringConcatenate( + query, "), CORNERS as (SELECT envelope.STPointN(1) as point from " + "ENVELOPE UNION ALL select envelope.STPointN(3) from ENVELOPE) " + "SELECT MIN(point.STX), MIN(point.STY), MAX(point.STX), " + "MAX(point.STY) FROM CORNERS"); + } + + if (!executeSQL(layerinfo->conn, query)) { msFree(query); + return MS_FAILURE; + } - /* process results */ - rc = SQLFetch(layerinfo->conn->hstmt); + msFree(query); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - if (layer->debug) { - msDebug("msMSSQL2008LayerGetExtent: No results found.\n"); - } - return MS_FAILURE; - } + /* process results */ + rc = SQLFetch(layerinfo->conn->hstmt); - rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_CHAR, result_data, sizeof(result_data), &retLen); - if (rc == SQL_ERROR || retLen < 0) { - msSetError(MS_QUERYERR, "Failed to get MinX value", "msMSSQL2008LayerGetExtent()"); - return MS_FAILURE; + if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { + if (layer->debug) { + msDebug("msMSSQL2008LayerGetExtent: No results found.\n"); } + return MS_FAILURE; + } + + rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_CHAR, result_data, + sizeof(result_data), &retLen); + if (rc == SQL_ERROR || retLen < 0) { + msSetError(MS_QUERYERR, "Failed to get MinX value", + "msMSSQL2008LayerGetExtent()"); + return MS_FAILURE; + } - result_data[retLen] = 0; + result_data[retLen] = 0; - extent->minx = atof(result_data); + extent->minx = atof(result_data); - rc = SQLGetData(layerinfo->conn->hstmt, 2, SQL_C_CHAR, result_data, sizeof(result_data), &retLen); - if (rc == SQL_ERROR || retLen < 0) { - msSetError(MS_QUERYERR, "Failed to get MinY value", "msMSSQL2008LayerGetExtent()"); - return MS_FAILURE; - } + rc = SQLGetData(layerinfo->conn->hstmt, 2, SQL_C_CHAR, result_data, + sizeof(result_data), &retLen); + if (rc == SQL_ERROR || retLen < 0) { + msSetError(MS_QUERYERR, "Failed to get MinY value", + "msMSSQL2008LayerGetExtent()"); + return MS_FAILURE; + } - result_data[retLen] = 0; + result_data[retLen] = 0; - extent->miny = atof(result_data); + extent->miny = atof(result_data); - rc = SQLGetData(layerinfo->conn->hstmt, 3, SQL_C_CHAR, result_data, sizeof(result_data), &retLen); - if (rc == SQL_ERROR || retLen < 0) { - msSetError(MS_QUERYERR, "Failed to get MaxX value", "msMSSQL2008LayerGetExtent()"); - return MS_FAILURE; - } + rc = SQLGetData(layerinfo->conn->hstmt, 3, SQL_C_CHAR, result_data, + sizeof(result_data), &retLen); + if (rc == SQL_ERROR || retLen < 0) { + msSetError(MS_QUERYERR, "Failed to get MaxX value", + "msMSSQL2008LayerGetExtent()"); + return MS_FAILURE; + } - result_data[retLen] = 0; + result_data[retLen] = 0; - extent->maxx = atof(result_data); + extent->maxx = atof(result_data); - rc = SQLGetData(layerinfo->conn->hstmt, 4, SQL_C_CHAR, result_data, sizeof(result_data), &retLen); - if (rc == SQL_ERROR || retLen < 0) { - msSetError(MS_QUERYERR, "Failed to get MaxY value", "msMSSQL2008LayerGetExtent()"); - return MS_FAILURE; - } + rc = SQLGetData(layerinfo->conn->hstmt, 4, SQL_C_CHAR, result_data, + sizeof(result_data), &retLen); + if (rc == SQL_ERROR || retLen < 0) { + msSetError(MS_QUERYERR, "Failed to get MaxY value", + "msMSSQL2008LayerGetExtent()"); + return MS_FAILURE; + } - result_data[retLen] = 0; + result_data[retLen] = 0; - extent->maxy = atof(result_data); + extent->maxy = atof(result_data); - return MS_SUCCESS; + return MS_SUCCESS; } /* Get the layer feature count */ -int msMSSQL2008LayerGetNumFeatures(layerObj *layer) -{ - msMSSQL2008LayerInfo *layerinfo; - char *query = 0; - char result_data[256]; - SQLLEN retLen; - SQLRETURN rc; - - if (layer->debug) { - msDebug("msMSSQL2008LayerGetNumFeatures called\n"); - } +int msMSSQL2008LayerGetNumFeatures(layerObj *layer) { + msMSSQL2008LayerInfo *layerinfo; + char *query = 0; + char result_data[256]; + SQLLEN retLen; + SQLRETURN rc; - layerinfo = getMSSQL2008LayerInfo(layer); + if (layer->debug) { + msDebug("msMSSQL2008LayerGetNumFeatures called\n"); + } - if (!layerinfo) { - msSetError(MS_QUERYERR, "GetNumFeatures called with layerinfo = NULL", "msMSSQL2008LayerGetNumFeatures()"); - return -1; - } + layerinfo = getMSSQL2008LayerInfo(layer); - /* set up statement */ - query = msStringConcatenate(query, "SELECT count(*) FROM "); - query = msStringConcatenate(query, layerinfo->geom_table); + if (!layerinfo) { + msSetError(MS_QUERYERR, "GetNumFeatures called with layerinfo = NULL", + "msMSSQL2008LayerGetNumFeatures()"); + return -1; + } - /* adding attribute filter */ - addFilter(layer, &query); + /* set up statement */ + query = msStringConcatenate(query, "SELECT count(*) FROM "); + query = msStringConcatenate(query, layerinfo->geom_table); - if (!executeSQL(layerinfo->conn, query)) { - msFree(query); - return -1; - } + /* adding attribute filter */ + addFilter(layer, &query); + if (!executeSQL(layerinfo->conn, query)) { msFree(query); + return -1; + } - rc = SQLFetch(layerinfo->conn->hstmt); + msFree(query); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - if (layer->debug) { - msDebug("msMSSQL2008LayerGetNumFeatures: No results found.\n"); - } + rc = SQLFetch(layerinfo->conn->hstmt); - return -1; + if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { + if (layer->debug) { + msDebug("msMSSQL2008LayerGetNumFeatures: No results found.\n"); } - rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_CHAR, result_data, sizeof(result_data), &retLen); + return -1; + } + + rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_CHAR, result_data, + sizeof(result_data), &retLen); - if (rc == SQL_ERROR) { - msSetError(MS_QUERYERR, "Failed to get feature count", "msMSSQL2008LayerGetNumFeatures()"); - return -1; - } + if (rc == SQL_ERROR) { + msSetError(MS_QUERYERR, "Failed to get feature count", + "msMSSQL2008LayerGetNumFeatures()"); + return -1; + } - result_data[retLen] = 0; + result_data[retLen] = 0; - return atoi(result_data); + return atoi(result_data); } /* Prepare and execute the SQL statement for this layer */ -static int prepare_database(layerObj *layer, rectObj rect, char **query_string) -{ +static int prepare_database(layerObj *layer, rectObj rect, char **query_string, + int isQuery) { msMSSQL2008LayerInfo *layerinfo; char *query = 0; char *data_source = 0; @@ -1350,24 +1386,26 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string) char *paging_query = 0; /* "Geometry::STGeomFromText('POLYGON(())',)" + terminator = 40 chars - Plus 10 formatted doubles (15 digits of precision, a decimal point, a space/comma delimiter each = 17 chars each) - Plus SRID + comma - if SRID is a long...we'll be safe with 10 chars + Plus 10 formatted doubles (15 digits of precision, a decimal point, a + space/comma delimiter each = 17 chars each) Plus SRID + comma - if SRID is a + long...we'll be safe with 10 chars + + or for geography columns - or for geography columns - "Geography::STGeomFromText('CURVEPOLYGON(())',)" + terminator = 46 chars - Plus 18 formatted doubles (15 digits of precision, a decimal point, a space/comma delimiter each = 17 chars each) - Plus SRID + comma - if SRID is a long...we'll be safe with 10 chars + Plus 18 formatted doubles (15 digits of precision, a decimal point, a + space/comma delimiter each = 17 chars each) Plus SRID + comma - if SRID is a + long...we'll be safe with 10 chars */ - char box3d[46 + 18 * 22 + 11]; - int t; + char box3d[46 + 18 * 22 + 11]; + int t; - char *pos_from, *pos_ftab, *pos_space, *pos_paren; + char *pos_from, *pos_ftab, *pos_space, *pos_paren; int hasFilter = MS_FALSE; const rectObj rectInvalid = MS_INIT_INVALID_RECT; const int bIsValidRect = memcmp(&rect, &rectInvalid, sizeof(rect)) != 0; - layerinfo = getMSSQL2008LayerInfo(layer); + layerinfo = getMSSQL2008LayerInfo(layer); /* Extract the proper f_table_name from the geom_table string. * We are expecting the geom_table to be either a single word @@ -1382,10 +1420,10 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string) geom_table = msStrdup(layerinfo->geom_table); pos_from = strstrIgnoreCase(geom_table, " from "); - if(!pos_from) { - f_table_name = (char *) msSmallMalloc(strlen(geom_table) + 1); + if (!pos_from) { + f_table_name = (char *)msSmallMalloc(strlen(geom_table) + 1); strcpy(f_table_name, geom_table); - } else { /* geom_table is a sub-select clause */ + } else { /* geom_table is a sub-select clause */ pos_ftab = pos_from + 6; /* This should be the start of the ftab name */ pos_space = strstr(pos_ftab, " "); /* First space */ @@ -1396,82 +1434,83 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string) pos_paren = rindex(pos_ftab, ')'); #endif - if(!pos_space || !pos_paren) { - msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "prepare_database()", geom_table, "Error parsing MSSQL2008 data variable: Something is wrong with your subselect statement.

\n\nMore Help:

\n\n"); + if (!pos_space || !pos_paren) { + msSetError( + MS_QUERYERR, DATA_ERROR_MESSAGE, "prepare_database()", geom_table, + "Error parsing MSSQL2008 data variable: Something is wrong with your " + "subselect statement.

\n\nMore Help:

\n\n"); return MS_FAILURE; } if (pos_paren < pos_space) { /* closing parenthesis preceeds any space */ - f_table_name = (char *) msSmallMalloc(pos_paren - pos_ftab + 1); + f_table_name = (char *)msSmallMalloc(pos_paren - pos_ftab + 1); strlcpy(f_table_name, pos_ftab, pos_paren - pos_ftab + 1); } else { - f_table_name = (char *) msSmallMalloc(pos_space - pos_ftab + 1); + f_table_name = (char *)msSmallMalloc(pos_space - pos_ftab + 1); strlcpy(f_table_name, pos_ftab, pos_space - pos_ftab + 1); } } if (rect.minx == rect.maxx || rect.miny == rect.maxy) { - /* create point shape for rectangles with zero area */ - sprintf(box3d, "%s::STGeomFromText('POINT(%.15g %.15g)',%s)", /* %s.STSrid)", */ - layerinfo->geom_column_type, rect.minx, rect.miny, layerinfo->user_srid); + /* create point shape for rectangles with zero area */ + sprintf(box3d, + "%s::STGeomFromText('POINT(%.15g %.15g)',%s)", /* %s.STSrid)", */ + layerinfo->geom_column_type, rect.minx, rect.miny, + layerinfo->user_srid); } else if (strcasecmp(layerinfo->geom_column_type, "geography") == 0) { - /* SQL Server has a problem when x is -180 or 180 */ - double minx = rect.minx <= -180? -179.999: rect.minx; - double maxx = rect.maxx >= 180? 179.999: rect.maxx; - double miny = rect.miny < -90? -90: rect.miny; - double maxy = rect.maxy > 90? 90: rect.maxy; - sprintf(box3d, "Geography::STGeomFromText('CURVEPOLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */ - minx, miny, - minx + (maxx - minx) / 2, miny, - maxx, miny, - maxx, miny + (maxy - miny) / 2, - maxx, maxy, - minx + (maxx - minx) / 2, maxy, - minx, maxy, - minx, miny + (maxy - miny) / 2, - minx, miny, - layerinfo->user_srid); + /* SQL Server has a problem when x is -180 or 180 */ + double minx = rect.minx <= -180 ? -179.999 : rect.minx; + double maxx = rect.maxx >= 180 ? 179.999 : rect.maxx; + double miny = rect.miny < -90 ? -90 : rect.miny; + double maxy = rect.maxy > 90 ? 90 : rect.maxy; + sprintf(box3d, + "Geography::STGeomFromText('CURVEPOLYGON((%.15g %.15g,%.15g " + "%.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g " + "%.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */ + minx, miny, minx + (maxx - minx) / 2, miny, maxx, miny, maxx, + miny + (maxy - miny) / 2, maxx, maxy, minx + (maxx - minx) / 2, + maxy, minx, maxy, minx, miny + (maxy - miny) / 2, minx, miny, + layerinfo->user_srid); } else { - sprintf(box3d, "Geometry::STGeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */ - rect.minx, rect.miny, - rect.maxx, rect.miny, - rect.maxx, rect.maxy, - rect.minx, rect.maxy, - rect.minx, rect.miny, - layerinfo->user_srid - ); + sprintf(box3d, + "Geometry::STGeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g " + "%.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */ + rect.minx, rect.miny, rect.maxx, rect.miny, rect.maxx, rect.maxy, + rect.minx, rect.maxy, rect.minx, rect.miny, layerinfo->user_srid); } - /* substitute token '!BOX!' in geom_table with the box3d - do an unlimited # of subs */ - /* to not undo the work here, we need to make sure that data_source is malloc'd here */ + /* substitute token '!BOX!' in geom_table with the box3d - do an unlimited # + * of subs */ + /* to not undo the work here, we need to make sure that data_source is + * malloc'd here */ if (!strstr(geom_table, "!BOX!")) { - data_source = (char *)msSmallMalloc(strlen(geom_table) + 1); - strcpy(data_source, geom_table); - } - else { - char* result = NULL; + data_source = (char *)msSmallMalloc(strlen(geom_table) + 1); + strcpy(data_source, geom_table); + } else { + char *result = NULL; - while (strstr(geom_table, "!BOX!")) { - /* need to do a substition */ - char *start, *end; - char *oldresult = result; - start = strstr(geom_table, "!BOX!"); - end = start + 5; + while (strstr(geom_table, "!BOX!")) { + /* need to do a substition */ + char *start, *end; + char *oldresult = result; + start = strstr(geom_table, "!BOX!"); + end = start + 5; - result = (char *)msSmallMalloc((start - geom_table) + strlen(box3d) + strlen(end) + 1); + result = (char *)msSmallMalloc((start - geom_table) + strlen(box3d) + + strlen(end) + 1); - strlcpy(result, geom_table, start - geom_table + 1); - strcpy(result + (start - geom_table), box3d); - strcat(result, end); + strlcpy(result, geom_table, start - geom_table + 1); + strcpy(result + (start - geom_table), box3d); + strcat(result, end); - geom_table = result; - msFree(oldresult); - } + geom_table = result; + msFree(oldresult); + } - /* if we're here, this will be a malloc'd string, so no need to copy it */ - data_source = (char *)geom_table; + /* if we're here, this will be a malloc'd string, so no need to copy it */ + data_source = (char *)geom_table; } /* start creating the query */ @@ -1483,64 +1522,61 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string) /* adding items to the select list */ for (t = 0; t < layer->numitems; t++) { #ifdef USE_ICONV - query = msStringConcatenate(query, "convert(nvarchar(max), ["); + query = msStringConcatenate(query, "convert(nvarchar(max), ["); #else - query = msStringConcatenate(query, "convert(varchar(max), ["); + query = msStringConcatenate(query, "convert(varchar(max), ["); #endif - query = msStringConcatenate(query, layer->items[t]); - query = msStringConcatenate(query, "]) '"); - tmp = msIntToString(t); - query = msStringConcatenate(query, tmp); - if (paging_query) { - paging_query = msStringConcatenate(paging_query, "["); - paging_query = msStringConcatenate(paging_query, tmp); - paging_query = msStringConcatenate(paging_query, "], "); - } - msFree(tmp); - query = msStringConcatenate(query, "',"); + query = msStringConcatenate(query, layer->items[t]); + query = msStringConcatenate(query, "]) '"); + tmp = msIntToString(t); + query = msStringConcatenate(query, tmp); + if (paging_query) { + paging_query = msStringConcatenate(paging_query, "["); + paging_query = msStringConcatenate(paging_query, tmp); + paging_query = msStringConcatenate(paging_query, "], "); + } + msFree(tmp); + query = msStringConcatenate(query, "',"); } /* adding geometry column */ query = msStringConcatenate(query, "["); query = msStringConcatenate(query, layerinfo->geom_column); if (layerinfo->geometry_format == MSSQLGEOMETRY_NATIVE) - query = msStringConcatenate(query, "] 'geom',"); + query = msStringConcatenate(query, "] 'geom',"); else { - query = msStringConcatenate(query, "].STAsBinary() 'geom',"); + query = msStringConcatenate(query, "].STAsBinary() 'geom',"); } /* adding id column */ query = msStringConcatenate(query, "convert(varchar(36), ["); query = msStringConcatenate(query, layerinfo->urid_name); if (paging_query) { - paging_query = msStringConcatenate(paging_query, "[geom], [id] FROM ("); - query = msStringConcatenate(query, "]) 'id', row_number() over ("); - if (layerinfo->sort_spec) { - query = msStringConcatenate(query, layerinfo->sort_spec); - } + paging_query = msStringConcatenate(paging_query, "[geom], [id] FROM ("); + query = msStringConcatenate(query, "]) 'id', row_number() over ("); + if (layerinfo->sort_spec) { + query = msStringConcatenate(query, layerinfo->sort_spec); + } - if (layer->sortBy.nProperties > 0) { - tmp = msLayerBuildSQLOrderBy(layer); - if (layerinfo->sort_spec) { - query = msStringConcatenate(query, ", "); - } - else { - query = msStringConcatenate(query, " ORDER BY "); - } - query = msStringConcatenate(query, tmp); - msFree(tmp); + if (layer->sortBy.nProperties > 0) { + tmp = msLayerBuildSQLOrderBy(layer); + if (layerinfo->sort_spec) { + query = msStringConcatenate(query, ", "); + } else { + query = msStringConcatenate(query, " ORDER BY "); } - else { - if (!layerinfo->sort_spec) { - // use the unique Id as the default sort for paging - query = msStringConcatenate(query, "ORDER BY "); - query = msStringConcatenate(query, layerinfo->urid_name); - } + query = msStringConcatenate(query, tmp); + msFree(tmp); + } else { + if (!layerinfo->sort_spec) { + // use the unique Id as the default sort for paging + query = msStringConcatenate(query, "ORDER BY "); + query = msStringConcatenate(query, layerinfo->urid_name); } - query = msStringConcatenate(query, ") 'rownum' FROM "); - } - else { - query = msStringConcatenate(query, "]) 'id' FROM "); + } + query = msStringConcatenate(query, ") 'rownum' FROM "); + } else { + query = msStringConcatenate(query, "]) 'id' FROM "); } /* adding the source */ @@ -1550,20 +1586,20 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string) /* use the index hint if provided */ if (layerinfo->index_name) { - query = msStringConcatenate(query, " WITH (INDEX("); - query = msStringConcatenate(query, layerinfo->index_name); - query = msStringConcatenate(query, "))"); + query = msStringConcatenate(query, " WITH (INDEX("); + query = msStringConcatenate(query, layerinfo->index_name); + query = msStringConcatenate(query, "))"); } /* adding attribute filter */ hasFilter = addFilter(layer, &query); - if( bIsValidRect ) { + if (bIsValidRect) { /* adding spatial filter */ if (hasFilter == MS_FALSE) - query = msStringConcatenate(query, " WHERE "); + query = msStringConcatenate(query, " WHERE "); else - query = msStringConcatenate(query, " AND "); + query = msStringConcatenate(query, " AND "); query = msStringConcatenate(query, layerinfo->geom_column); query = msStringConcatenate(query, ".STIntersects("); @@ -1572,111 +1608,123 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string) } if (paging_query) { - paging_query = msStringConcatenate(paging_query, query); - paging_query = msStringConcatenate(paging_query, ") tbl where [rownum] "); - if (layer->startindex > 0) { - tmp = msIntToString(layer->startindex); - paging_query = msStringConcatenate(paging_query, ">= "); - paging_query = msStringConcatenate(paging_query, tmp); - if (layer->maxfeatures >= 0) { - msFree(tmp); - tmp = msIntToString(layer->startindex + layer->maxfeatures); - paging_query = msStringConcatenate(paging_query, " and [rownum] < "); - paging_query = msStringConcatenate(paging_query, tmp); - } - } - else { - tmp = msIntToString(layer->maxfeatures); - paging_query = msStringConcatenate(paging_query, "< "); - paging_query = msStringConcatenate(paging_query, tmp); - } - msFree(tmp); - msFree(query); - query = paging_query; - } - else { - if (layerinfo->sort_spec) { - query = msStringConcatenate(query, layerinfo->sort_spec); + paging_query = msStringConcatenate(paging_query, query); + paging_query = msStringConcatenate(paging_query, ") tbl where [rownum] "); + if (layer->startindex > 0) { + tmp = msIntToString(layer->startindex); + paging_query = msStringConcatenate(paging_query, ">= "); + paging_query = msStringConcatenate(paging_query, tmp); + if (layer->maxfeatures >= 0) { + msFree(tmp); + tmp = msIntToString(layer->startindex + layer->maxfeatures); + paging_query = msStringConcatenate(paging_query, " and [rownum] < "); + paging_query = msStringConcatenate(paging_query, tmp); } + } else { + tmp = msIntToString(layer->maxfeatures); + paging_query = msStringConcatenate(paging_query, "< "); + paging_query = msStringConcatenate(paging_query, tmp); + } + msFree(tmp); + msFree(query); + query = paging_query; + } else { + if (layerinfo->sort_spec) { + query = msStringConcatenate(query, layerinfo->sort_spec); + } - /* Add extra sort by */ - if (layer->sortBy.nProperties > 0) { - char* pszTmp = msLayerBuildSQLOrderBy(layer); - if (layerinfo->sort_spec) - query = msStringConcatenate(query, ", "); - else - query = msStringConcatenate(query, " ORDER BY "); - query = msStringConcatenate(query, pszTmp); - msFree(pszTmp); - } + /* Add extra sort by */ + if (layer->sortBy.nProperties > 0) { + char *pszTmp = msLayerBuildSQLOrderBy(layer); + if (layerinfo->sort_spec) + query = msStringConcatenate(query, ", "); + else + query = msStringConcatenate(query, " ORDER BY "); + query = msStringConcatenate(query, pszTmp); + msFree(pszTmp); + } else if (isQuery && !layerinfo->sort_spec) { + /* Add orderby to make the result set order deterministic */ + query = msStringConcatenate(query, " ORDER BY ["); + query = msStringConcatenate(query, layerinfo->urid_name); + query = msStringConcatenate(query, "]"); + } } - if (layer->debug) { - msDebug("query:%s\n", query); + msDebug("query:%s\n", query); } if (executeSQL(layerinfo->conn, query)) { - char pass_field_def = 0; - int t; - const char *value; - *query_string = query; - /* collect result information */ - if ((value = msOWSLookupMetadata(&(layer->metadata), "G", "types")) != NULL - && strcasecmp(value, "auto") == 0) - pass_field_def = 1; - - msFree(layerinfo->itemtypes); - layerinfo->itemtypes = msSmallMalloc(sizeof(SQLSMALLINT) * (layer->numitems + 1)); - for (t = 0; t < layer->numitems; t++) { - char colBuff[256]; - SQLSMALLINT itemType = 0; - - columnName(layerinfo->conn, t + 1, colBuff, sizeof(colBuff), layer, pass_field_def, &itemType); - layerinfo->itemtypes[t] = itemType; - } + char pass_field_def = 0; + int t; + const char *value; + *query_string = query; + /* collect result information */ + if ((value = msOWSLookupMetadata(&(layer->metadata), "G", "types")) != + NULL && + strcasecmp(value, "auto") == 0) + pass_field_def = 1; + + msFree(layerinfo->itemtypes); + layerinfo->itemtypes = + msSmallMalloc(sizeof(SQLSMALLINT) * (layer->numitems + 1)); + for (t = 0; t < layer->numitems; t++) { + char colBuff[256]; + SQLSMALLINT itemType = 0; + + columnName(layerinfo->conn, t + 1, colBuff, sizeof(colBuff), layer, + pass_field_def, &itemType); + layerinfo->itemtypes[t] = itemType; + } - return MS_SUCCESS; - } - else { - msSetError(MS_QUERYERR, "Error executing MSSQL2008 SQL statement: %s\n-%s\n", "msMSSQL2008LayerGetShape()", query, layerinfo->conn->errorMessage); + return MS_SUCCESS; + } else { + msSetError( + MS_QUERYERR, "Error executing MSSQL2008 SQL statement: %s\n-%s\n", + "msMSSQL2008LayerGetShape()", query, layerinfo->conn->errorMessage); - msFree(query); + msFree(query); - return MS_FAILURE; + return MS_FAILURE; } } /* Execute SQL query for this layer */ -int msMSSQL2008LayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) -{ +int msMSSQL2008LayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) { (void)isQuery; - msMSSQL2008LayerInfo *layerinfo = 0; - char *query_str = 0; - int set_up_result; + msMSSQL2008LayerInfo *layerinfo = 0; + char *query_str = 0; + int set_up_result; - if(layer->debug) { + if (layer->debug) { msDebug("msMSSQL2008LayerWhichShapes called\n"); } layerinfo = getMSSQL2008LayerInfo(layer); - if(!layerinfo) { + if (!layerinfo) { /* layer not opened yet */ - msSetError(MS_QUERYERR, "msMSSQL2008LayerWhichShapes called on unopened layer (layerinfo = NULL)", "msMSSQL2008LayerWhichShapes()"); + msSetError(MS_QUERYERR, + "msMSSQL2008LayerWhichShapes called on unopened layer " + "(layerinfo = NULL)", + "msMSSQL2008LayerWhichShapes()"); return MS_FAILURE; } - if(!layer->data) { - msSetError(MS_QUERYERR, "Missing DATA clause in MSSQL2008 Layer definition. DATA statement must contain 'geometry_column from table_name' or 'geometry_column from (sub-query) as foo'.", "msMSSQL2008LayerWhichShapes()"); + if (!layer->data) { + msSetError(MS_QUERYERR, + "Missing DATA clause in MSSQL2008 Layer definition. DATA " + "statement must contain 'geometry_column from table_name' or " + "'geometry_column from (sub-query) as foo'.", + "msMSSQL2008LayerWhichShapes()"); return MS_FAILURE; } - set_up_result = prepare_database(layer, rect, &query_str); + set_up_result = prepare_database(layer, rect, &query_str, isQuery); - if(set_up_result != MS_SUCCESS) { + if (set_up_result != MS_SUCCESS) { msFree(query_str); return set_up_result; /* relay error */ @@ -1690,13 +1738,12 @@ int msMSSQL2008LayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) } /* Close the MSSQL2008 record set and connection */ -int msMSSQL2008LayerClose(layerObj *layer) -{ - msMSSQL2008LayerInfo *layerinfo; +int msMSSQL2008LayerClose(layerObj *layer) { + msMSSQL2008LayerInfo *layerinfo; layerinfo = getMSSQL2008LayerInfo(layer); - if(layer->debug) { + if (layer->debug) { char *data = ""; if (layer->data) { @@ -1706,56 +1753,56 @@ int msMSSQL2008LayerClose(layerObj *layer) msDebug("msMSSQL2008LayerClose datastatement: %s\n", data); } - if(layer->debug && !layerinfo) { + if (layer->debug && !layerinfo) { msDebug("msMSSQL2008LayerClose -- layerinfo is NULL\n"); } - if(layerinfo) { + if (layerinfo) { msConnPoolRelease(layer, layerinfo->conn); layerinfo->conn = NULL; - if(layerinfo->user_srid) { + if (layerinfo->user_srid) { msFree(layerinfo->user_srid); layerinfo->user_srid = NULL; } - if(layerinfo->urid_name) { + if (layerinfo->urid_name) { msFree(layerinfo->urid_name); layerinfo->urid_name = NULL; } - if(layerinfo->index_name) { + if (layerinfo->index_name) { msFree(layerinfo->index_name); layerinfo->index_name = NULL; } - if(layerinfo->sort_spec) { + if (layerinfo->sort_spec) { msFree(layerinfo->sort_spec); layerinfo->sort_spec = NULL; } - if(layerinfo->sql) { + if (layerinfo->sql) { msFree(layerinfo->sql); layerinfo->sql = NULL; } - if(layerinfo->geom_column) { + if (layerinfo->geom_column) { msFree(layerinfo->geom_column); layerinfo->geom_column = NULL; } - if(layerinfo->geom_column_type) { + if (layerinfo->geom_column_type) { msFree(layerinfo->geom_column_type); layerinfo->geom_column_type = NULL; } - if(layerinfo->geom_table) { + if (layerinfo->geom_table) { msFree(layerinfo->geom_table); layerinfo->geom_table = NULL; } - if(layerinfo->itemtypes) { + if (layerinfo->itemtypes) { msFree(layerinfo->itemtypes); layerinfo->itemtypes = NULL; } @@ -1771,83 +1818,82 @@ int msMSSQL2008LayerClose(layerObj *layer) /* wkb is assumed to be 2d (force_2d) */ /* and wkb is a GEOMETRYCOLLECTION (force_collection) */ /* and wkb is in the endian of this computer (asbinary(...,'[XN]DR')) */ -/* each of the sub-geom inside the collection are point,linestring, or polygon */ +/* each of the sub-geom inside the collection are point,linestring, or polygon + */ /* */ /* also, int is 32bits long */ /* double is 64bits long */ /* ******************************************************* */ - /* convert the wkb into points */ /* points -> pass through */ /* lines-> constituent points */ /* polys-> treat ring like line and pull out the consituent points */ -static int force_to_points(char *wkb, shapeObj *shape) -{ - /* we're going to make a 'line' for each entity (point, line or ring) in the geom collection */ +static int force_to_points(char *wkb, shapeObj *shape) { + /* we're going to make a 'line' for each entity (point, line or ring) in the + * geom collection */ - int offset = 0; - int ngeoms; - int t, u, v; - int type, nrings, npoints; + int offset = 0; + int ngeoms; + int t, u, v; + int type, nrings, npoints; lineObj line = {0, NULL}; - shape->type = MS_SHAPE_NULL; /* nothing in it */ + shape->type = MS_SHAPE_NULL; /* nothing in it */ memcpy(&ngeoms, &wkb[5], 4); - offset = 9; /* were the first geometry is */ - for(t=0; t < ngeoms; t++) { - memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ + offset = 9; /* were the first geometry is */ + for (t = 0; t < ngeoms; t++) { + memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ - if(type == 1) { + if (type == 1) { /* Point */ shape->type = MS_SHAPE_POINT; line.numpoints = 1; - line.point = (pointObj *) msSmallMalloc(sizeof(pointObj)); + line.point = (pointObj *)msSmallMalloc(sizeof(pointObj)); memcpy(&line.point[0].x, &wkb[offset + 5], 8); memcpy(&line.point[0].y, &wkb[offset + 5 + 8], 8); offset += 5 + 16; msAddLine(shape, &line); msFree(line.point); - } else if(type == 2) { + } else if (type == 2) { /* Linestring */ shape->type = MS_SHAPE_POINT; - memcpy(&line.numpoints, &wkb[offset+5], 4); /* num points */ - line.point = (pointObj *) msSmallMalloc(sizeof(pointObj) * line.numpoints); - for(u = 0; u < line.numpoints; u++) { - memcpy( &line.point[u].x, &wkb[offset+9 + (16 * u)], 8); - memcpy( &line.point[u].y, &wkb[offset+9 + (16 * u)+8], 8); + memcpy(&line.numpoints, &wkb[offset + 5], 4); /* num points */ + line.point = (pointObj *)msSmallMalloc(sizeof(pointObj) * line.numpoints); + for (u = 0; u < line.numpoints; u++) { + memcpy(&line.point[u].x, &wkb[offset + 9 + (16 * u)], 8); + memcpy(&line.point[u].y, &wkb[offset + 9 + (16 * u) + 8], 8); } - offset += 9 + 16 * line.numpoints; /* length of object */ + offset += 9 + 16 * line.numpoints; /* length of object */ msAddLine(shape, &line); msFree(line.point); - } else if(type == 3) { + } else if (type == 3) { /* Polygon */ shape->type = MS_SHAPE_POINT; - memcpy(&nrings, &wkb[offset+5],4); /* num rings */ + memcpy(&nrings, &wkb[offset + 5], 4); /* num rings */ /* add a line for each polygon ring */ offset += 9; /* now points at 1st linear ring */ - for(u = 0; u < nrings; u++) { + for (u = 0; u < nrings; u++) { /* for each ring, make a line */ memcpy(&npoints, &wkb[offset], 4); /* num points */ line.numpoints = npoints; - line.point = (pointObj *) msSmallMalloc(sizeof(pointObj)* npoints); + line.point = (pointObj *)msSmallMalloc(sizeof(pointObj) * npoints); /* point struct */ - for(v = 0; v < npoints; v++) { + for (v = 0; v < npoints; v++) { memcpy(&line.point[v].x, &wkb[offset + 4 + (16 * v)], 8); memcpy(&line.point[v].y, &wkb[offset + 4 + (16 * v) + 8], 8); } /* make offset point to next linear ring */ msAddLine(shape, &line); msFree(line.point); - offset += 4 + 16 *npoints; + offset += 4 + 16 * npoints; } } - } return MS_SUCCESS; @@ -1858,50 +1904,49 @@ static int force_to_points(char *wkb, shapeObj *shape) /* lines -> pass through */ /* polys -> treat rings as lines */ -static int force_to_lines(char *wkb, shapeObj *shape) -{ - int offset = 0; - int ngeoms; - int t, u, v; - int type, nrings, npoints; +static int force_to_lines(char *wkb, shapeObj *shape) { + int offset = 0; + int ngeoms; + int t, u, v; + int type, nrings, npoints; lineObj line = {0, NULL}; - shape->type = MS_SHAPE_NULL; /* nothing in it */ + shape->type = MS_SHAPE_NULL; /* nothing in it */ memcpy(&ngeoms, &wkb[5], 4); - offset = 9; /* were the first geometry is */ - for(t=0; t < ngeoms; t++) { - memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ + offset = 9; /* were the first geometry is */ + for (t = 0; t < ngeoms; t++) { + memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ /* cannot do anything with a point */ - if(type == 2) { + if (type == 2) { /* Linestring */ shape->type = MS_SHAPE_LINE; memcpy(&line.numpoints, &wkb[offset + 5], 4); - line.point = (pointObj*) msSmallMalloc(sizeof(pointObj) * line.numpoints ); - for(u=0; u < line.numpoints; u++) { + line.point = (pointObj *)msSmallMalloc(sizeof(pointObj) * line.numpoints); + for (u = 0; u < line.numpoints; u++) { memcpy(&line.point[u].x, &wkb[offset + 9 + (16 * u)], 8); - memcpy(&line.point[u].y, &wkb[offset + 9 + (16 * u)+8], 8); + memcpy(&line.point[u].y, &wkb[offset + 9 + (16 * u) + 8], 8); } - offset += 9 + 16 * line.numpoints; /* length of object */ + offset += 9 + 16 * line.numpoints; /* length of object */ msAddLine(shape, &line); msFree(line.point); - } else if(type == 3) { + } else if (type == 3) { /* polygon */ shape->type = MS_SHAPE_LINE; memcpy(&nrings, &wkb[offset + 5], 4); /* num rings */ /* add a line for each polygon ring */ offset += 9; /* now points at 1st linear ring */ - for(u = 0; u < nrings; u++) { + for (u = 0; u < nrings; u++) { /* for each ring, make a line */ memcpy(&npoints, &wkb[offset], 4); line.numpoints = npoints; - line.point = (pointObj*) msSmallMalloc(sizeof(pointObj) * npoints); + line.point = (pointObj *)msSmallMalloc(sizeof(pointObj) * npoints); /* point struct */ - for(v = 0; v < npoints; v++) { + for (v = 0; v < npoints; v++) { memcpy(&line.point[v].x, &wkb[offset + 4 + (16 * v)], 8); memcpy(&line.point[v].y, &wkb[offset + 4 + (16 * v) + 8], 8); } @@ -1919,34 +1964,33 @@ static int force_to_lines(char *wkb, shapeObj *shape) /* point -> reject */ /* line -> reject */ /* polygon -> lines of linear rings */ -static int force_to_polygons(char *wkb, shapeObj *shape) -{ - int offset = 0; - int ngeoms; - int t, u, v; - int type, nrings, npoints; +static int force_to_polygons(char *wkb, shapeObj *shape) { + int offset = 0; + int ngeoms; + int t, u, v; + int type, nrings, npoints; lineObj line = {0, NULL}; - shape->type = MS_SHAPE_NULL; /* nothing in it */ + shape->type = MS_SHAPE_NULL; /* nothing in it */ memcpy(&ngeoms, &wkb[5], 4); - offset = 9; /* were the first geometry is */ - for(t = 0; t < ngeoms; t++) { - memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ + offset = 9; /* were the first geometry is */ + for (t = 0; t < ngeoms; t++) { + memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ - if(type == 3) { + if (type == 3) { /* polygon */ shape->type = MS_SHAPE_POLYGON; memcpy(&nrings, &wkb[offset + 5], 4); /* num rings */ /* add a line for each polygon ring */ offset += 9; /* now points at 1st linear ring */ - for(u=0; u < nrings; u++) { + for (u = 0; u < nrings; u++) { /* for each ring, make a line */ memcpy(&npoints, &wkb[offset], 4); /* num points */ line.numpoints = npoints; - line.point = (pointObj*) msSmallMalloc(sizeof(pointObj) * npoints); - for(v=0; v < npoints; v++) { + line.point = (pointObj *)msSmallMalloc(sizeof(pointObj) * npoints); + for (v = 0; v < npoints; v++) { memcpy(&line.point[v].x, &wkb[offset + 4 + (16 * v)], 8); memcpy(&line.point[v].y, &wkb[offset + 4 + (16 * v) + 8], 8); } @@ -1965,36 +2009,35 @@ static int force_to_polygons(char *wkb, shapeObj *shape) /* if there is any line in wkb, return force_line */ /* otherwise return force_point */ -static int dont_force(char *wkb, shapeObj *shape) -{ - int offset =0; - int ngeoms; - int type, t; - int best_type; +static int dont_force(char *wkb, shapeObj *shape) { + int offset = 0; + int ngeoms; + int type, t; + int best_type; - best_type = MS_SHAPE_NULL; /* nothing in it */ + best_type = MS_SHAPE_NULL; /* nothing in it */ memcpy(&ngeoms, &wkb[5], 4); - offset = 9; /* were the first geometry is */ - for(t = 0; t < ngeoms; t++) { - memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ + offset = 9; /* were the first geometry is */ + for (t = 0; t < ngeoms; t++) { + memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ - if(type == 3) { + if (type == 3) { best_type = MS_SHAPE_POLYGON; - } else if(type ==2 && best_type != MS_SHAPE_POLYGON) { + } else if (type == 2 && best_type != MS_SHAPE_POLYGON) { best_type = MS_SHAPE_LINE; - } else if(type == 1 && best_type == MS_SHAPE_NULL) { + } else if (type == 1 && best_type == MS_SHAPE_NULL) { best_type = MS_SHAPE_POINT; } } - if(best_type == MS_SHAPE_POINT) { + if (best_type == MS_SHAPE_POINT) { return force_to_points(wkb, shape); } - if(best_type == MS_SHAPE_LINE) { + if (best_type == MS_SHAPE_LINE) { return force_to_lines(wkb, shape); } - if(best_type == MS_SHAPE_POLYGON) { + if (best_type == MS_SHAPE_POLYGON) { return force_to_polygons(wkb, shape); } @@ -2098,81 +2141,80 @@ static int force_to_shapeType(char *wkb, shapeObj *shape, int msShapeType) ///* if there is any polygon in wkb, return force_polygon */ ///* if there is any line in wkb, return force_line */ ///* otherwise return force_point */ -//static int dont_force(char *wkb, shapeObj *shape) +// static int dont_force(char *wkb, shapeObj *shape) //{ -// int offset =0; -// int ngeoms = 1; -// int type; -// int best_type; -// int u; -// int nrings, npoints; +// int offset =0; +// int ngeoms = 1; +// int type; +// int best_type; +// int u; +// int nrings, npoints; // -// best_type = MS_SHAPE_NULL; /* nothing in it */ +// best_type = MS_SHAPE_NULL; /* nothing in it */ // -// do -// { -// ngeoms--; +// do +// { +// ngeoms--; // -// memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ +// memcpy(&type, &wkb[offset + 1], 4); /* type of this geometry */ // -// if(type == 3) { -// best_type = MS_SHAPE_POLYGON; -// } else if(type ==2 && best_type != MS_SHAPE_POLYGON) { -// best_type = MS_SHAPE_LINE; -// } else if(type == 1 && best_type == MS_SHAPE_NULL) { -// best_type = MS_SHAPE_POINT; -// } +// if(type == 3) { +// best_type = MS_SHAPE_POLYGON; +// } else if(type ==2 && best_type != MS_SHAPE_POLYGON) { +// best_type = MS_SHAPE_LINE; +// } else if(type == 1 && best_type == MS_SHAPE_NULL) { +// best_type = MS_SHAPE_POINT; +// } // -// if (type == 1) -// { -// /* Point */ -// offset += 5 + 16; -// } -// else if(type == 2) -// { -// int numPoints; +// if (type == 1) +// { +// /* Point */ +// offset += 5 + 16; +// } +// else if(type == 2) +// { +// int numPoints; // -// memcpy(&numPoints, &wkb[offset+5], 4); /* num points */ -// /* Linestring */ -// offset += 9 + 16 * numPoints; /* length of object */ -// } -// else if(type == 3) -// { -// /* Polygon */ -// memcpy(&nrings, &wkb[offset+5],4); /* num rings */ -// offset += 9; /* now points at 1st linear ring */ -// for(u = 0; u < nrings; u++) { -// /* for each ring, make a line */ -// memcpy(&npoints, &wkb[offset], 4); /* num points */ -// offset += 4 + 16 *npoints; -// } -// } -// else if(type >= 4 && type <= 7) -// { -// int cnt = 0; +// memcpy(&numPoints, &wkb[offset+5], 4); /* num points */ +// /* Linestring */ +// offset += 9 + 16 * numPoints; /* length of object */ +// } +// else if(type == 3) +// { +// /* Polygon */ +// memcpy(&nrings, &wkb[offset+5],4); /* num rings */ +// offset += 9; /* now points at 1st linear ring */ +// for(u = 0; u < nrings; u++) { +// /* for each ring, make a line */ +// memcpy(&npoints, &wkb[offset], 4); /* num points */ +// offset += 4 + 16 *npoints; +// } +// } +// else if(type >= 4 && type <= 7) +// { +// int cnt = 0; // -// offset += 5; +// offset += 5; // -// memcpy(&cnt, &wkb[offset], 4); -// offset += 4; /* were the first geometry is */ +// memcpy(&cnt, &wkb[offset], 4); +// offset += 4; /* were the first geometry is */ // -// ngeoms += cnt; -// } -// } -// while (ngeoms > 0); +// ngeoms += cnt; +// } +// } +// while (ngeoms > 0); // -// return force_to_shapeType(wkb, shape, best_type); -//} +// return force_to_shapeType(wkb, shape, best_type); +// } // /* find the bounds of the shape */ -static void find_bounds(shapeObj *shape) -{ - int t, u; - int first_one = 1; +static void find_bounds(shapeObj *shape) { + int t, u; + int first_one = 1; - for(t = 0; t < shape->numlines; t++) { - for(u = 0; u < shape->line[t].numpoints; u++) { - if(first_one) { + for (t = 0; t < shape->numlines; t++) { + for (u = 0; u < shape->line[t].numpoints; u++) { + if (first_one) { shape->bounds.minx = shape->line[t].point[u].x; shape->bounds.maxx = shape->line[t].point[u].x; @@ -2180,17 +2222,17 @@ static void find_bounds(shapeObj *shape) shape->bounds.maxy = shape->line[t].point[u].y; first_one = 0; } else { - if(shape->line[t].point[u].x < shape->bounds.minx) { + if (shape->line[t].point[u].x < shape->bounds.minx) { shape->bounds.minx = shape->line[t].point[u].x; } - if(shape->line[t].point[u].x > shape->bounds.maxx) { + if (shape->line[t].point[u].x > shape->bounds.maxx) { shape->bounds.maxx = shape->line[t].point[u].x; } - if(shape->line[t].point[u].y < shape->bounds.miny) { + if (shape->line[t].point[u].y < shape->bounds.miny) { shape->bounds.miny = shape->line[t].point[u].y; } - if(shape->line[t].point[u].y > shape->bounds.maxy) { + if (shape->line[t].point[u].y > shape->bounds.maxy) { shape->bounds.maxy = shape->line[t].point[u].y; } } @@ -2199,15 +2241,16 @@ static void find_bounds(shapeObj *shape) } /* Used by NextShape() to access a shape in the query set */ -int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *record) -{ - msMSSQL2008LayerInfo *layerinfo; +int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, + long *record) { + msMSSQL2008LayerInfo *layerinfo; SQLLEN needLen = 0; SQLLEN retLen = 0; char dummyBuffer[1]; char *wkbBuffer; char *valueBuffer; - char oidBuffer[ 16 ]; /* assuming the OID will always be a long this should be enough */ + char oidBuffer[16]; /* assuming the OID will always be a long this should be + enough */ long record_oid; int t; @@ -2217,22 +2260,27 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor layerinfo = getMSSQL2008LayerInfo(layer); - if(!layerinfo) { - msSetError(MS_QUERYERR, "GetShape called with layerinfo = NULL", "msMSSQL2008LayerGetShape()"); + if (!layerinfo) { + msSetError(MS_QUERYERR, "GetShape called with layerinfo = NULL", + "msMSSQL2008LayerGetShape()"); return MS_FAILURE; } - if(!layerinfo->conn) { - msSetError(MS_QUERYERR, "NextShape called on MSSQL2008 layer with no connection to DB.", "msMSSQL2008LayerGetShape()"); + if (!layerinfo->conn) { + msSetError(MS_QUERYERR, + "NextShape called on MSSQL2008 layer with no connection to DB.", + "msMSSQL2008LayerGetShape()"); return MS_FAILURE; } shape->type = MS_SHAPE_NULL; - while(shape->type == MS_SHAPE_NULL) { - /* SQLRETURN rc = SQLFetchScroll(layerinfo->conn->hstmt, SQL_FETCH_ABSOLUTE, (SQLLEN) (*record) + 1); */ + while (shape->type == MS_SHAPE_NULL) { + /* SQLRETURN rc = SQLFetchScroll(layerinfo->conn->hstmt, SQL_FETCH_ABSOLUTE, + * (SQLLEN) (*record) + 1); */ - /* We only do forward fetches. the parameter 'record' is ignored, but is incremented */ + /* We only do forward fetches. the parameter 'record' is ignored, but is + * incremented */ SQLRETURN rc = SQLFetch(layerinfo->conn->hstmt); /* Any error assume out of recordset bounds */ @@ -2245,15 +2293,17 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor { /* have to retrieve shape attributes */ - shape->values = (char **) msSmallMalloc(sizeof(char *) * layer->numitems); + shape->values = (char **)msSmallMalloc(sizeof(char *) * layer->numitems); shape->numvalues = layer->numitems; - for(t=0; t < layer->numitems; t++) { - /* Startwith a 64 character long buffer. This may need to be increased after calling SQLGetData. */ + for (t = 0; t < layer->numitems; t++) { + /* Startwith a 64 character long buffer. This may need to be increased + * after calling SQLGetData. */ SQLLEN emptyLen = 64; - valueBuffer = (char*) msSmallMalloc(emptyLen); - if ( valueBuffer == NULL ) { - msSetError( MS_QUERYERR, "Could not allocate value buffer.", "msMSSQL2008LayerGetShapeRandom()" ); + valueBuffer = (char *)msSmallMalloc(emptyLen); + if (valueBuffer == NULL) { + msSetError(MS_QUERYERR, "Could not allocate value buffer.", + "msMSSQL2008LayerGetShapeRandom()"); return MS_FAILURE; } @@ -2266,27 +2316,36 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor char *bufferLocation = valueBuffer; int r = 0; while (r < 20) { - rc = SQLGetData(layerinfo->conn->hstmt, (SQLUSMALLINT)(t + 1), targetType, bufferLocation, emptyLen, &retLen); + rc = SQLGetData(layerinfo->conn->hstmt, (SQLUSMALLINT)(t + 1), + targetType, bufferLocation, emptyLen, &retLen); if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) - totalLen += retLen > emptyLen || retLen == SQL_NO_TOTAL ? emptyLen : retLen; + totalLen += + retLen > emptyLen || retLen == SQL_NO_TOTAL ? emptyLen : retLen; if (rc == SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - /* We must compensate for the last null termination that SQLGetData include */ - /* If we get SQL_NO_TOTAL we do not know how big buffer we need so we increase it with 512. */ + /* We must compensate for the last null termination that SQLGetData + * include */ + /* If we get SQL_NO_TOTAL we do not know how big buffer we need so + * we increase it with 512. */ #ifdef USE_ICONV totalLen -= sizeof(wchar_t); - emptyLen = retLen != SQL_NO_TOTAL? retLen - emptyLen + 2 * sizeof(wchar_t): 512; + emptyLen = retLen != SQL_NO_TOTAL + ? retLen - emptyLen + 2 * sizeof(wchar_t) + : 512; #else totalLen -= sizeof(char); - emptyLen = retLen != SQL_NO_TOTAL? retLen - emptyLen + 2 * sizeof(char): 512; + emptyLen = retLen != SQL_NO_TOTAL + ? retLen - emptyLen + 2 * sizeof(char) + : 512; #endif - valueBuffer = (char *)msSmallRealloc(valueBuffer, totalLen + emptyLen); + valueBuffer = + (char *)msSmallRealloc(valueBuffer, totalLen + emptyLen); bufferLocation = valueBuffer + totalLen; } else break; - + r++; } @@ -2296,7 +2355,8 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor if (totalLen > 0) { /* Pop the value into the shape's value array */ #ifdef USE_ICONV - shape->values[t] = msConvertWideStringToUTF8((wchar_t*)valueBuffer, "UCS-2LE"); + shape->values[t] = + msConvertWideStringToUTF8((wchar_t *)valueBuffer, "UCS-2LE"); msFree(valueBuffer); #else shape->values[t] = valueBuffer; @@ -2311,46 +2371,51 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor /* Get shape geometry */ { /* Set up to request the size of the buffer needed */ - rc = SQLGetData(layerinfo->conn->hstmt, (SQLUSMALLINT)(layer->numitems + 1), SQL_C_BINARY, dummyBuffer, 0, &needLen); + rc = SQLGetData(layerinfo->conn->hstmt, + (SQLUSMALLINT)(layer->numitems + 1), SQL_C_BINARY, + dummyBuffer, 0, &needLen); if (rc == SQL_ERROR) handleSQLError(layer); /* allow space for coercion to geometry collection if needed*/ - wkbTemp = (char*)msSmallMalloc(needLen+9); + wkbTemp = (char *)msSmallMalloc(needLen + 9); /* write data above space allocated for geometry collection coercion */ wkbBuffer = wkbTemp + 9; - if ( wkbBuffer == NULL ) { - msSetError( MS_QUERYERR, "Could not allocate value buffer.", "msMSSQL2008LayerGetShapeRandom()" ); + if (wkbBuffer == NULL) { + msSetError(MS_QUERYERR, "Could not allocate value buffer.", + "msMSSQL2008LayerGetShapeRandom()"); return MS_FAILURE; } /* Grab the WKB */ - rc = SQLGetData(layerinfo->conn->hstmt, (SQLUSMALLINT)(layer->numitems + 1), SQL_C_BINARY, wkbBuffer, needLen, &retLen); + rc = SQLGetData(layerinfo->conn->hstmt, + (SQLUSMALLINT)(layer->numitems + 1), SQL_C_BINARY, + wkbBuffer, needLen, &retLen); if (rc == SQL_ERROR || rc == SQL_SUCCESS_WITH_INFO) handleSQLError(layer); if (layerinfo->geometry_format == MSSQLGEOMETRY_NATIVE) { - layerinfo->gpi.pszData = (unsigned char*)wkbBuffer; + layerinfo->gpi.pszData = (unsigned char *)wkbBuffer; layerinfo->gpi.nLen = (int)retLen; if (!ParseSqlGeometry(layerinfo, shape)) { - switch(layer->type) { - case MS_LAYER_POINT: - shape->type = MS_SHAPE_POINT; - break; + switch (layer->type) { + case MS_LAYER_POINT: + shape->type = MS_SHAPE_POINT; + break; - case MS_LAYER_LINE: - shape->type = MS_SHAPE_LINE; - break; + case MS_LAYER_LINE: + shape->type = MS_SHAPE_LINE; + break; - case MS_LAYER_POLYGON: - shape->type = MS_SHAPE_POLYGON; - break; + case MS_LAYER_POLYGON: + shape->type = MS_SHAPE_POLYGON; + break; - default: - break; + default: + break; } } } else { @@ -2362,7 +2427,8 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor wkbTemp[0] = wkbBuffer[0]; wkbBuffer = wkbTemp; - /* indicate type is geometry collection (although geomType + 3 would also work) */ + /* indicate type is geometry collection (although geomType + 3 would + * also work) */ wkbBuffer[1] = (char)7; wkbBuffer[2] = (char)0; wkbBuffer[3] = (char)0; @@ -2375,65 +2441,65 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor wkbBuffer[8] = (char)0; } - switch(layer->type) { - case MS_LAYER_POINT: - /*result =*/ force_to_points(wkbBuffer, shape); - break; + switch (layer->type) { + case MS_LAYER_POINT: + /*result =*/force_to_points(wkbBuffer, shape); + break; - case MS_LAYER_LINE: - /*result =*/ force_to_lines(wkbBuffer, shape); - break; + case MS_LAYER_LINE: + /*result =*/force_to_lines(wkbBuffer, shape); + break; - case MS_LAYER_POLYGON: - /*result =*/ force_to_polygons(wkbBuffer, shape); - break; + case MS_LAYER_POLYGON: + /*result =*/force_to_polygons(wkbBuffer, shape); + break; - case MS_LAYER_QUERY: - case MS_LAYER_CHART: - /*result =*/ dont_force(wkbBuffer, shape); - break; + case MS_LAYER_QUERY: + case MS_LAYER_CHART: + /*result =*/dont_force(wkbBuffer, shape); + break; - case MS_LAYER_RASTER: - msDebug( "Ignoring MS_LAYER_RASTER in mapMSSQL2008.c\n" ); - break; + case MS_LAYER_RASTER: + msDebug("Ignoring MS_LAYER_RASTER in mapMSSQL2008.c\n"); + break; - case MS_LAYER_CIRCLE: - msDebug( "Ignoring MS_LAYER_CIRCLE in mapMSSQL2008.c\n" ); - break; + case MS_LAYER_CIRCLE: + msDebug("Ignoring MS_LAYER_CIRCLE in mapMSSQL2008.c\n"); + break; - default: - msDebug( "Unsupported layer type in msMSSQL2008LayerNextShape()!" ); - break; + default: + msDebug("Unsupported layer type in msMSSQL2008LayerNextShape()!"); + break; } find_bounds(shape); } - //free(wkbBuffer); + // free(wkbBuffer); msFree(wkbTemp); } - /* Next get unique id for row - since the OID shouldn't be larger than a long we'll assume billions as a limit */ - rc = SQLGetData(layerinfo->conn->hstmt, (SQLUSMALLINT)(layer->numitems + 2), SQL_C_BINARY, oidBuffer, sizeof(oidBuffer) - 1, &retLen); + /* Next get unique id for row - since the OID shouldn't be larger than a + * long we'll assume billions as a limit */ + rc = SQLGetData(layerinfo->conn->hstmt, + (SQLUSMALLINT)(layer->numitems + 2), SQL_C_BINARY, + oidBuffer, sizeof(oidBuffer) - 1, &retLen); if (rc == SQL_ERROR || rc == SQL_SUCCESS_WITH_INFO) handleSQLError(layer); - if (retLen < (int)sizeof(oidBuffer)) - { - oidBuffer[retLen] = 0; - record_oid = strtol(oidBuffer, NULL, 10); - shape->index = record_oid; - } - else - { - /* non integer fid column, use single pass */ - shape->index = -1; - } + if (retLen < (int)sizeof(oidBuffer)) { + oidBuffer[retLen] = 0; + record_oid = strtol(oidBuffer, NULL, 10); + shape->index = record_oid; + } else { + /* non integer fid column, use single pass */ + shape->index = -1; + } shape->resultindex = (*record); - (*record)++; /* move to next shape */ + (*record)++; /* move to next shape */ - if(shape->type != MS_SHAPE_NULL) { + if (shape->type != MS_SHAPE_NULL) { return MS_SUCCESS; } else { msDebug("msMSSQL2008LayerGetShapeRandom bad shape: %ld\n", *record); @@ -2447,19 +2513,20 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor return MS_FAILURE; } -/* find the next shape with the appropriate shape type (convert it if necessary) */ +/* find the next shape with the appropriate shape type (convert it if necessary) + */ /* also, load in the attribute data */ /* MS_DONE => no more data */ -int msMSSQL2008LayerNextShape(layerObj *layer, shapeObj *shape) -{ - int result; +int msMSSQL2008LayerNextShape(layerObj *layer, shapeObj *shape) { + int result; - msMSSQL2008LayerInfo *layerinfo; + msMSSQL2008LayerInfo *layerinfo; layerinfo = getMSSQL2008LayerInfo(layer); - if(!layerinfo) { - msSetError(MS_QUERYERR, "NextShape called with layerinfo = NULL", "msMSSQL2008LayerNextShape()"); + if (!layerinfo) { + msSetError(MS_QUERYERR, "NextShape called with layerinfo = NULL", + "msMSSQL2008LayerNextShape()"); return MS_FAILURE; } @@ -2471,44 +2538,53 @@ int msMSSQL2008LayerNextShape(layerObj *layer, shapeObj *shape) } /* Execute a query on the DB based on the query result. */ -int msMSSQL2008LayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) -{ - char *query_str; - char *columns_wanted = 0; +int msMSSQL2008LayerGetShape(layerObj *layer, shapeObj *shape, + resultObj *record) { + char *query_str; + char *columns_wanted = 0; - msMSSQL2008LayerInfo *layerinfo; - int t; + msMSSQL2008LayerInfo *layerinfo; + int t; char buffer[32000] = ""; long shapeindex = record->shapeindex; long resultindex = record->resultindex; - if(layer->debug) { - msDebug("msMSSQL2008LayerGetShape called for shapeindex = %ld\n", shapeindex); + if (layer->debug) { + msDebug("msMSSQL2008LayerGetShape called for shapeindex = %ld\n", + shapeindex); } layerinfo = getMSSQL2008LayerInfo(layer); - if(!layerinfo) { + if (!layerinfo) { /* Layer not open */ - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetShape called on unopened layer (layerinfo = NULL)", "msMSSQL2008LayerGetShape()"); + msSetError( + MS_QUERYERR, + "msMSSQL2008LayerGetShape called on unopened layer (layerinfo = NULL)", + "msMSSQL2008LayerGetShape()"); return MS_FAILURE; } if (resultindex >= 0 && layerinfo->sql) { - /* trying to provide the result from the current resultset (single-pass query) */ - if( resultindex < layerinfo->row_num) { + /* trying to provide the result from the current resultset (single-pass + * query) */ + if (resultindex < layerinfo->row_num) { /* re-issue the query */ if (!executeSQL(layerinfo->conn, layerinfo->sql)) { - msSetError(MS_QUERYERR, "Error executing MSSQL2008 SQL statement: %s\n-%s\n", "msMSSQL2008LayerGetShape()", layerinfo->sql, layerinfo->conn->errorMessage); + msSetError(MS_QUERYERR, + "Error executing MSSQL2008 SQL statement: %s\n-%s\n", + "msMSSQL2008LayerGetShape()", layerinfo->sql, + layerinfo->conn->errorMessage); return MS_FAILURE; } layerinfo->row_num = 0; } - while( layerinfo->row_num < resultindex ) { + while (layerinfo->row_num < resultindex) { /* move forward until we reach the desired index */ - if (msMSSQL2008LayerGetShapeRandom(layer, shape, &(layerinfo->row_num)) != MS_SUCCESS) + if (msMSSQL2008LayerGetShapeRandom(layer, shape, &(layerinfo->row_num)) != + MS_SUCCESS) return MS_FAILURE; } @@ -2517,39 +2593,51 @@ int msMSSQL2008LayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record /* non single-pass case, fetch the record from the database */ - if(layer->numitems == 0) { + if (layer->numitems == 0) { if (layerinfo->geometry_format == MSSQLGEOMETRY_NATIVE) - snprintf(buffer, sizeof(buffer), "%s, convert(varchar(36), %s)", layerinfo->geom_column, layerinfo->urid_name); + snprintf(buffer, sizeof(buffer), "%s, convert(varchar(36), %s)", + layerinfo->geom_column, layerinfo->urid_name); else - snprintf(buffer, sizeof(buffer), "%s.STAsBinary(), convert(varchar(36), %s)", layerinfo->geom_column, layerinfo->urid_name); + snprintf(buffer, sizeof(buffer), + "%s.STAsBinary(), convert(varchar(36), %s)", + layerinfo->geom_column, layerinfo->urid_name); columns_wanted = msStrdup(buffer); } else { - for(t = 0; t < layer->numitems; t++) { - snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "convert(varchar(max), %s),", layer->items[t]); + for (t = 0; t < layer->numitems; t++) { + snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), + "convert(varchar(max), %s),", layer->items[t]); } if (layerinfo->geometry_format == MSSQLGEOMETRY_NATIVE) - snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "%s, convert(varchar(36), %s)", layerinfo->geom_column, layerinfo->urid_name); + snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), + "%s, convert(varchar(36), %s)", layerinfo->geom_column, + layerinfo->urid_name); else - snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "%s.STAsBinary(), convert(varchar(36), %s)", layerinfo->geom_column, layerinfo->urid_name); + snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), + "%s.STAsBinary(), convert(varchar(36), %s)", + layerinfo->geom_column, layerinfo->urid_name); columns_wanted = msStrdup(buffer); } - /* index_name is ignored here since the hint should be for the spatial index, not the PK index */ - snprintf(buffer, sizeof(buffer), "select %s from %s where %s = %ld", columns_wanted, layerinfo->geom_table, layerinfo->urid_name, shapeindex); + /* index_name is ignored here since the hint should be for the spatial index, + * not the PK index */ + snprintf(buffer, sizeof(buffer), "select %s from %s where %s = %ld", + columns_wanted, layerinfo->geom_table, layerinfo->urid_name, + shapeindex); query_str = msStrdup(buffer); - if(layer->debug) { + if (layer->debug) { msDebug("msMSSQL2008LayerGetShape: %s \n", query_str); } msFree(columns_wanted); if (!executeSQL(layerinfo->conn, query_str)) { - msSetError(MS_QUERYERR, "Error executing MSSQL2008 SQL statement: %s\n-%s\n", "msMSSQL2008LayerGetShape()", - query_str, layerinfo->conn->errorMessage); + msSetError( + MS_QUERYERR, "Error executing MSSQL2008 SQL statement: %s\n-%s\n", + "msMSSQL2008LayerGetShape()", query_str, layerinfo->conn->errorMessage); msFree(query_str); @@ -2565,167 +2653,180 @@ int msMSSQL2008LayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record /* ** Returns the number of shapes that match the potential filter and extent. - * rectProjection is the projection in which rect is expressed, or can be NULL if - * rect should be considered in the layer projection. - * This should be equivalent to calling msLayerWhichShapes() and counting the - * number of shapes returned by msLayerNextShape(), honouring layer->maxfeatures - * limitation if layer->maxfeatures>=0, and honouring layer->startindex if - * layer->startindex >= 1 and paging is enabled. - * Returns -1 in case of failure. - */ -int msMSSQL2008LayerGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rectProjection) -{ - msMSSQL2008LayerInfo *layerinfo; - char *query = 0; - char result_data[256]; - char box3d[40 + 10 * 22 + 11]; - SQLLEN retLen; - SQLRETURN rc; - int hasFilter = MS_FALSE; - const rectObj rectInvalid = MS_INIT_INVALID_RECT; - const int bIsValidRect = memcmp(&rect, &rectInvalid, sizeof(rect)) != 0; - - rectObj searchrectInLayerProj = rect; +* rectProjection is the projection in which rect is expressed, or can be NULL if +* rect should be considered in the layer projection. +* This should be equivalent to calling msLayerWhichShapes() and counting the +* number of shapes returned by msLayerNextShape(), honouring layer->maxfeatures +* limitation if layer->maxfeatures>=0, and honouring layer->startindex if +* layer->startindex >= 1 and paging is enabled. +* Returns -1 in case of failure. +*/ +int msMSSQL2008LayerGetShapeCount(layerObj *layer, rectObj rect, + projectionObj *rectProjection) { + msMSSQL2008LayerInfo *layerinfo; + char *query = 0; + char result_data[256]; + char box3d[40 + 10 * 22 + 11]; + SQLLEN retLen; + SQLRETURN rc; + int hasFilter = MS_FALSE; + const rectObj rectInvalid = MS_INIT_INVALID_RECT; + const int bIsValidRect = memcmp(&rect, &rectInvalid, sizeof(rect)) != 0; - if (layer->debug) { - msDebug("msMSSQL2008LayerGetShapeCount called.\n"); - } + rectObj searchrectInLayerProj = rect; - layerinfo = getMSSQL2008LayerInfo(layer); + if (layer->debug) { + msDebug("msMSSQL2008LayerGetShapeCount called.\n"); + } - if (!layerinfo) { - /* Layer not open */ - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetShapeCount called on unopened layer (layerinfo = NULL)", "msMSSQL2008LayerGetShapeCount()"); + layerinfo = getMSSQL2008LayerInfo(layer); - return MS_FAILURE; - } + if (!layerinfo) { + /* Layer not open */ + msSetError(MS_QUERYERR, + "msMSSQL2008LayerGetShapeCount called on unopened layer " + "(layerinfo = NULL)", + "msMSSQL2008LayerGetShapeCount()"); - // Special processing if the specified projection for the rect is different from the layer projection - // We want to issue a WHERE that includes - // ((the_geom && rect_reprojected_in_layer_SRID) AND NOT ST_Disjoint(ST_Transform(the_geom, rect_SRID), rect)) - if (rectProjection != NULL && layer->project && - msProjectionsDiffer(&(layer->projection), rectProjection)) - { - // If we cannot guess the EPSG code of the rectProjection, fallback on slow implementation - if (rectProjection->numargs < 1 || - strncasecmp(rectProjection->args[0], "init=epsg:", (int)strlen("init=epsg:")) != 0) - { - if (layer->debug) { - msDebug("msMSSQL2008LayerGetShapeCount(): cannot find EPSG code of rectProjection. Falling back on client-side feature count.\n"); - } - return LayerDefaultGetShapeCount(layer, rect, rectProjection); - } + return MS_FAILURE; + } - // Reproject the passed rect into the layer projection and get - // the SRID from the rectProjection - msProjectRect(rectProjection, &(layer->projection), &searchrectInLayerProj); /* project the searchrect to source coords */ + // Special processing if the specified projection for the rect is different + // from the layer projection We want to issue a WHERE that includes + // ((the_geom && rect_reprojected_in_layer_SRID) AND NOT + // ST_Disjoint(ST_Transform(the_geom, rect_SRID), rect)) + if (rectProjection != NULL && layer->project && + msProjectionsDiffer(&(layer->projection), rectProjection)) { + // If we cannot guess the EPSG code of the rectProjection, fallback on slow + // implementation + if (rectProjection->numargs < 1 || + strncasecmp(rectProjection->args[0], + "init=epsg:", (int)strlen("init=epsg:")) != 0) { + if (layer->debug) { + msDebug("msMSSQL2008LayerGetShapeCount(): cannot find EPSG code of " + "rectProjection. Falling back on client-side feature count.\n"); + } + return LayerDefaultGetShapeCount(layer, rect, rectProjection); } - if (searchrectInLayerProj.minx == searchrectInLayerProj.maxx || - searchrectInLayerProj.miny == searchrectInLayerProj.maxy) { - /* create point shape for rectangles with zero area */ - snprintf(box3d, sizeof(box3d), "%s::STGeomFromText('POINT(%.15g %.15g)',%s)", /* %s.STSrid)", */ - layerinfo->geom_column_type, searchrectInLayerProj.minx, searchrectInLayerProj.miny, layerinfo->user_srid); - } - else { - snprintf(box3d, sizeof(box3d), "%s::STGeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */ - layerinfo->geom_column_type, - searchrectInLayerProj.minx, searchrectInLayerProj.miny, - searchrectInLayerProj.maxx, searchrectInLayerProj.miny, - searchrectInLayerProj.maxx, searchrectInLayerProj.maxy, - searchrectInLayerProj.minx, searchrectInLayerProj.maxy, - searchrectInLayerProj.minx, searchrectInLayerProj.miny, - layerinfo->user_srid - ); - } + // Reproject the passed rect into the layer projection and get + // the SRID from the rectProjection + msProjectRect( + rectProjection, &(layer->projection), + &searchrectInLayerProj); /* project the searchrect to source coords */ + } - msLayerTranslateFilter(layer, &layer->filter, layer->filteritem); + if (searchrectInLayerProj.minx == searchrectInLayerProj.maxx || + searchrectInLayerProj.miny == searchrectInLayerProj.maxy) { + /* create point shape for rectangles with zero area */ + snprintf(box3d, sizeof(box3d), + "%s::STGeomFromText('POINT(%.15g %.15g)',%s)", /* %s.STSrid)", */ + layerinfo->geom_column_type, searchrectInLayerProj.minx, + searchrectInLayerProj.miny, layerinfo->user_srid); + } else { + snprintf(box3d, sizeof(box3d), + "%s::STGeomFromText('POLYGON((%.15g %.15g,%.15g %.15g,%.15g " + "%.15g,%.15g %.15g,%.15g %.15g))',%s)", /* %s.STSrid)", */ + layerinfo->geom_column_type, searchrectInLayerProj.minx, + searchrectInLayerProj.miny, searchrectInLayerProj.maxx, + searchrectInLayerProj.miny, searchrectInLayerProj.maxx, + searchrectInLayerProj.maxy, searchrectInLayerProj.minx, + searchrectInLayerProj.maxy, searchrectInLayerProj.minx, + searchrectInLayerProj.miny, layerinfo->user_srid); + } - /* set up statement */ - query = msStringConcatenate(query, "SELECT count(*) FROM "); - query = msStringConcatenate(query, layerinfo->geom_table); + msLayerTranslateFilter(layer, &layer->filter, layer->filteritem); - /* adding attribute filter */ - hasFilter = addFilter(layer, &query); + /* set up statement */ + query = msStringConcatenate(query, "SELECT count(*) FROM "); + query = msStringConcatenate(query, layerinfo->geom_table); - if( bIsValidRect ) { - /* adding spatial filter */ - if (hasFilter == MS_FALSE) - query = msStringConcatenate(query, " WHERE "); - else - query = msStringConcatenate(query, " AND "); + /* adding attribute filter */ + hasFilter = addFilter(layer, &query); - query = msStringConcatenate(query, layerinfo->geom_column); - query = msStringConcatenate(query, ".STIntersects("); - query = msStringConcatenate(query, box3d); - query = msStringConcatenate(query, ") = 1 "); - } + if (bIsValidRect) { + /* adding spatial filter */ + if (hasFilter == MS_FALSE) + query = msStringConcatenate(query, " WHERE "); + else + query = msStringConcatenate(query, " AND "); - if (layer->debug) { - msDebug("query:%s\n", query); - } + query = msStringConcatenate(query, layerinfo->geom_column); + query = msStringConcatenate(query, ".STIntersects("); + query = msStringConcatenate(query, box3d); + query = msStringConcatenate(query, ") = 1 "); + } - if (!executeSQL(layerinfo->conn, query)) { - msFree(query); - return -1; - } + if (layer->debug) { + msDebug("query:%s\n", query); + } + if (!executeSQL(layerinfo->conn, query)) { msFree(query); + return -1; + } - rc = SQLFetch(layerinfo->conn->hstmt); + msFree(query); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - if (layer->debug) { - msDebug("msMSSQL2008LayerGetShapeCount: No results found.\n"); - } + rc = SQLFetch(layerinfo->conn->hstmt); - return -1; + if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { + if (layer->debug) { + msDebug("msMSSQL2008LayerGetShapeCount: No results found.\n"); } - rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_CHAR, result_data, sizeof(result_data), &retLen); + return -1; + } - if (rc == SQL_ERROR) { - msSetError(MS_QUERYERR, "Failed to get feature count", "msMSSQL2008LayerGetShapeCount()"); - return -1; - } + rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_CHAR, result_data, + sizeof(result_data), &retLen); + + if (rc == SQL_ERROR) { + msSetError(MS_QUERYERR, "Failed to get feature count", + "msMSSQL2008LayerGetShapeCount()"); + return -1; + } - result_data[retLen] = 0; + result_data[retLen] = 0; - return atoi(result_data); + return atoi(result_data); } /* Query the DB for info about the requested table */ -int msMSSQL2008LayerGetItems(layerObj *layer) -{ - msMSSQL2008LayerInfo *layerinfo; - char *sql = NULL; - size_t sqlSize; - char found_geom = 0; - int t, item_num; +int msMSSQL2008LayerGetItems(layerObj *layer) { + msMSSQL2008LayerInfo *layerinfo; + char *sql = NULL; + size_t sqlSize; + char found_geom = 0; + int t, item_num; SQLSMALLINT cols = 0; const char *value; /* - * Pass the field definitions through to the layer metadata in the - * "gml_[item]_{type,width,precision}" set of metadata items for - * defining fields. - */ - char pass_field_def = 0; + * Pass the field definitions through to the layer metadata in the + * "gml_[item]_{type,width,precision}" set of metadata items for + * defining fields. + */ + char pass_field_def = 0; - if(layer->debug) { + if (layer->debug) { msDebug("in msMSSQL2008LayerGetItems (find column names)\n"); } layerinfo = getMSSQL2008LayerInfo(layer); - if(!layerinfo) { + if (!layerinfo) { /* layer not opened yet */ - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetItems called on unopened layer", "msMSSQL2008LayerGetItems()"); + msSetError(MS_QUERYERR, "msMSSQL2008LayerGetItems called on unopened layer", + "msMSSQL2008LayerGetItems()"); return MS_FAILURE; } - if(!layerinfo->conn) { - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetItems called on MSSQL2008 layer with no connection to DB.", "msMSSQL2008LayerGetItems()"); + if (!layerinfo->conn) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerGetItems called on MSSQL2008 layer with no " + "connection to DB.", + "msMSSQL2008LayerGetItems()"); return MS_FAILURE; } @@ -2742,12 +2843,16 @@ int msMSSQL2008LayerGetItems(layerObj *layer) msFree(sql); - SQLNumResultCols (layerinfo->conn->hstmt, &cols); + SQLNumResultCols(layerinfo->conn->hstmt, &cols); layer->numitems = cols - 1; /* dont include the geometry column */ - layer->items = msSmallMalloc(sizeof(char *) * (layer->numitems + 1)); /* +1 in case there is a problem finding goeometry column */ - layerinfo->itemtypes = msSmallMalloc(sizeof(SQLSMALLINT) * (layer->numitems + 1)); + layer->items = msSmallMalloc( + sizeof(char *) * + (layer->numitems + + 1)); /* +1 in case there is a problem finding goeometry column */ + layerinfo->itemtypes = + msSmallMalloc(sizeof(SQLSMALLINT) * (layer->numitems + 1)); /* it will return an error if there is no geometry column found, */ /* so this isnt a problem */ @@ -2755,19 +2860,20 @@ int msMSSQL2008LayerGetItems(layerObj *layer) item_num = 0; /* consider populating the field definitions in metadata */ - if((value = msOWSLookupMetadata(&(layer->metadata), "G", "types")) != NULL - && strcasecmp(value,"auto") == 0 ) + if ((value = msOWSLookupMetadata(&(layer->metadata), "G", "types")) != NULL && + strcasecmp(value, "auto") == 0) pass_field_def = 1; - for(t = 0; t < cols; t++) { + for (t = 0; t < cols; t++) { char colBuff[256]; SQLSMALLINT itemType = 0; - columnName(layerinfo->conn, t + 1, colBuff, sizeof(colBuff), layer, pass_field_def, &itemType); + columnName(layerinfo->conn, t + 1, colBuff, sizeof(colBuff), layer, + pass_field_def, &itemType); - if(strcmp(colBuff, layerinfo->geom_column) != 0) { + if (strcmp(colBuff, layerinfo->geom_column) != 0) { /* this isnt the geometry column */ - layer->items[item_num] = (char *) msSmallMalloc(strlen(colBuff) + 1); + layer->items[item_num] = (char *)msSmallMalloc(strlen(colBuff) + 1); strcpy(layer->items[item_num], colBuff); layerinfo->itemtypes[item_num] = itemType; item_num++; @@ -2776,8 +2882,12 @@ int msMSSQL2008LayerGetItems(layerObj *layer) } } - if(!found_geom) { - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetItems: tried to find the geometry column in the results from the database, but couldnt find it. Is it miss-capitialized? '%s'", "msMSSQL2008LayerGetItems()", layerinfo->geom_column); + if (!found_geom) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerGetItems: tried to find the geometry column in " + "the results from the database, but couldnt find it. Is it " + "miss-capitialized? '%s'", + "msMSSQL2008LayerGetItems()", layerinfo->geom_column); return MS_FAILURE; } @@ -2785,55 +2895,64 @@ int msMSSQL2008LayerGetItems(layerObj *layer) } /* Get primary key column of table */ -int msMSSQL2008LayerRetrievePK(layerObj *layer, char **urid_name, char* table_name, int debug) -{ +int msMSSQL2008LayerRetrievePK(layerObj *layer, char **urid_name, + char *table_name, int debug) { - char sql[1024]; + char sql[1024]; msMSSQL2008LayerInfo *layerinfo = 0; SQLRETURN rc; snprintf(sql, sizeof(sql), - "SELECT convert(varchar(50), sys.columns.name) AS ColumnName, sys.indexes.name " + "SELECT convert(varchar(50), sys.columns.name) AS ColumnName, " + "sys.indexes.name " "FROM sys.columns INNER JOIN " " sys.indexes INNER JOIN " - " sys.tables ON sys.indexes.object_id = sys.tables.object_id INNER JOIN " - " sys.index_columns ON sys.indexes.object_id = sys.index_columns.object_id AND sys.indexes.index_id = sys.index_columns.index_id ON " - " sys.columns.object_id = sys.index_columns.object_id AND sys.columns.column_id = sys.index_columns.column_id " - "WHERE (sys.indexes.is_primary_key = 1) AND (sys.tables.name = N'%s') ", + " sys.tables ON sys.indexes.object_id = " + "sys.tables.object_id INNER JOIN " + " sys.index_columns ON sys.indexes.object_id = " + "sys.index_columns.object_id AND sys.indexes.index_id = " + "sys.index_columns.index_id ON " + " sys.columns.object_id = " + "sys.index_columns.object_id AND sys.columns.column_id = " + "sys.index_columns.column_id " + "WHERE (sys.indexes.is_primary_key = 1) AND (sys.tables.name = " + "N'%s') ", table_name); if (debug) { msDebug("msMSSQL2008LayerRetrievePK: query = %s\n", sql); } - layerinfo = (msMSSQL2008LayerInfo *) layer->layerinfo; + layerinfo = (msMSSQL2008LayerInfo *)layer->layerinfo; - if(layerinfo->conn == NULL) { + if (layerinfo->conn == NULL) { - msSetError(MS_QUERYERR, "Layer does not have a MSSQL2008 connection.", "msMSSQL2008LayerRetrievePK()"); + msSetError(MS_QUERYERR, "Layer does not have a MSSQL2008 connection.", + "msMSSQL2008LayerRetrievePK()"); - return(MS_FAILURE); + return (MS_FAILURE); } /* error somewhere above here in this method */ - if(!executeSQL(layerinfo->conn, sql)) { + if (!executeSQL(layerinfo->conn, sql)) { char *tmp1; char *tmp2 = NULL; tmp1 = "Error executing MSSQL2008 statement (msMSSQL2008LayerRetrievePK():"; - tmp2 = (char *)msSmallMalloc(sizeof(char)*(strlen(tmp1) + strlen(sql) + 1)); + tmp2 = + (char *)msSmallMalloc(sizeof(char) * (strlen(tmp1) + strlen(sql) + 1)); strcpy(tmp2, tmp1); strcat(tmp2, sql); msSetError(MS_QUERYERR, "%s", "msMSSQL2008LayerRetrievePK()", tmp2); msFree(tmp2); - return(MS_FAILURE); + return (MS_FAILURE); } rc = SQLFetch(layerinfo->conn->hstmt); - if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - if(debug) { + if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { + if (debug) { msDebug("msMSSQL2008LayerRetrievePK: No results found.\n"); } @@ -2843,13 +2962,15 @@ int msMSSQL2008LayerRetrievePK(layerObj *layer, char **urid_name, char* table_na { char buff[100]; SQLLEN retLen; - rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_BINARY, buff, sizeof(buff), &retLen); + rc = SQLGetData(layerinfo->conn->hstmt, 1, SQL_C_BINARY, buff, sizeof(buff), + &retLen); rc = SQLFetch(layerinfo->conn->hstmt); - if(rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if(debug) { - msDebug("msMSSQL2008LayerRetrievePK: Multiple primary key columns are not supported in MapServer\n"); + if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { + if (debug) { + msDebug("msMSSQL2008LayerRetrievePK: Multiple primary key columns are " + "not supported in MapServer\n"); } return MS_FAILURE; @@ -2867,10 +2988,14 @@ int msMSSQL2008LayerRetrievePK(layerObj *layer, char **urid_name, char* table_na * column name, table name and name of a column to serve as a * unique record id */ -static int msMSSQL2008LayerParseData(layerObj *layer, char **geom_column_name, char **geom_column_type, char **table_name, char **urid_name, char **user_srid, char **index_name, char **sort_spec, int debug) -{ - char *pos_opt, *pos_scn, *tmp, *pos_srid, *pos_urid, *pos_geomtype, *pos_geomtype2, *pos_indexHint, *data, *pos_order; - size_t slength; +static int msMSSQL2008LayerParseData(layerObj *layer, char **geom_column_name, + char **geom_column_type, char **table_name, + char **urid_name, char **user_srid, + char **index_name, char **sort_spec, + int debug) { + char *pos_opt, *pos_scn, *tmp, *pos_srid, *pos_urid, *pos_geomtype, + *pos_geomtype2, *pos_indexHint, *data, *pos_order; + size_t slength; data = msStrdup(layer->data); /* replace tabs with spaces */ @@ -2884,57 +3009,72 @@ static int msMSSQL2008LayerParseData(layerObj *layer, char **geom_column_name, c /* First look for the optional ' using unique ID' string */ pos_urid = strstrIgnoreCase(data, " using unique "); - if(pos_urid) { - /* CHANGE - protect the trailing edge for thing like 'using unique ftab_id using srid=33' */ + if (pos_urid) { + /* CHANGE - protect the trailing edge for thing like 'using unique ftab_id + * using srid=33' */ tmp = strstr(pos_urid + 14, " "); - if(!tmp) { + if (!tmp) { tmp = pos_urid + strlen(pos_urid); } - *urid_name = (char *) msSmallMalloc((tmp - (pos_urid + 14)) + 1); + *urid_name = (char *)msSmallMalloc((tmp - (pos_urid + 14)) + 1); strlcpy(*urid_name, pos_urid + 14, (tmp - (pos_urid + 14)) + 1); } /* Find the srid */ pos_srid = strstrIgnoreCase(data, " using SRID="); - if(!pos_srid) { - *user_srid = (char *) msSmallMalloc(2); + if (!pos_srid) { + *user_srid = (char *)msSmallMalloc(2); (*user_srid)[0] = '0'; (*user_srid)[1] = 0; } else { slength = strspn(pos_srid + 12, "-0123456789"); - if(!slength) { - msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", "Error parsing MSSQL2008 data variable: You specified 'using SRID=#' but didn't have any numbers!

\n\nMore Help:

\n\n", data); + if (!slength) { + msSetError( + MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", + "Error parsing MSSQL2008 data variable: You specified 'using SRID=#' " + "but didn't have any numbers!

\n\nMore Help:

\n\n", + data); msFree(data); return MS_FAILURE; } else { - *user_srid = (char *) msSmallMalloc(slength + 1); - strlcpy(*user_srid, pos_srid + 12, slength+1); + *user_srid = (char *)msSmallMalloc(slength + 1); + strlcpy(*user_srid, pos_srid + 12, slength + 1); } } pos_indexHint = strstrIgnoreCase(data, " using index "); - if(pos_indexHint) { - /* CHANGE - protect the trailing edge for thing like 'using unique ftab_id using srid=33' */ + if (pos_indexHint) { + /* CHANGE - protect the trailing edge for thing like 'using unique ftab_id + * using srid=33' */ tmp = strstr(pos_indexHint + 13, " "); - if(!tmp) { + if (!tmp) { tmp = pos_indexHint + strlen(pos_indexHint); } - *index_name = (char *) msSmallMalloc((tmp - (pos_indexHint + 13)) + 1); - strlcpy(*index_name, pos_indexHint + 13, tmp - (pos_indexHint + 13)+1); + *index_name = (char *)msSmallMalloc((tmp - (pos_indexHint + 13)) + 1); + strlcpy(*index_name, pos_indexHint + 13, tmp - (pos_indexHint + 13) + 1); } - /* this is a little hack so the rest of the code works. If the ' using SRID=' comes before */ - /* the ' using unique ', then make sure pos_opt points to where the ' using SRID' starts! */ + /* this is a little hack so the rest of the code works. If the ' using SRID=' + * comes before */ + /* the ' using unique ', then make sure pos_opt points to where the ' using + * SRID' starts! */ pos_opt = pos_urid; - if ( !pos_opt || ( pos_srid && pos_srid < pos_opt ) ) pos_opt = pos_srid; - if ( !pos_opt || ( pos_indexHint && pos_indexHint < pos_opt ) ) pos_opt = pos_indexHint; - if ( !pos_opt ) pos_opt = data + strlen(data); + if (!pos_opt || (pos_srid && pos_srid < pos_opt)) + pos_opt = pos_srid; + if (!pos_opt || (pos_indexHint && pos_indexHint < pos_opt)) + pos_opt = pos_indexHint; + if (!pos_opt) + pos_opt = data + strlen(data); /* Scan for the table or sub-select clause */ pos_scn = strstrIgnoreCase(data, " from "); - if(!pos_scn) { - msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", "Error parsing MSSQL2008 data variable. Must contain 'geometry_column from table_name' or 'geom from (subselect) as foo' (couldn't find ' from '). More help:

\n\n", data); + if (!pos_scn) { + msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", + "Error parsing MSSQL2008 data variable. Must contain " + "'geometry_column from table_name' or 'geom from (subselect) as " + "foo' (couldn't find ' from '). More help:

\n\n", + data); msFree(data); return MS_FAILURE; @@ -2945,42 +3085,54 @@ static int msMSSQL2008LayerParseData(layerObj *layer, char **geom_column_name, c while (pos_geomtype < pos_scn && *pos_geomtype != '(' && *pos_geomtype != 0) ++pos_geomtype; - if(*pos_geomtype == '(') { + if (*pos_geomtype == '(') { pos_geomtype2 = pos_geomtype; - while (pos_geomtype2 < pos_scn && *pos_geomtype2 != ')' && *pos_geomtype2 != 0) + while (pos_geomtype2 < pos_scn && *pos_geomtype2 != ')' && + *pos_geomtype2 != 0) ++pos_geomtype2; if (*pos_geomtype2 != ')' || pos_geomtype2 == pos_geomtype) { - msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", "Error parsing MSSQL2008 data variable. Invalid syntax near geometry column type.", data); + msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", + "Error parsing MSSQL2008 data variable. Invalid syntax near " + "geometry column type.", + data); msFree(data); return MS_FAILURE; } - *geom_column_name = (char *) msSmallMalloc((pos_geomtype - data) + 1); + *geom_column_name = (char *)msSmallMalloc((pos_geomtype - data) + 1); strlcpy(*geom_column_name, data, pos_geomtype - data + 1); - *geom_column_type = (char *) msSmallMalloc(pos_geomtype2 - pos_geomtype); + *geom_column_type = (char *)msSmallMalloc(pos_geomtype2 - pos_geomtype); strlcpy(*geom_column_type, pos_geomtype + 1, pos_geomtype2 - pos_geomtype); } else { /* Copy the geometry column name */ - *geom_column_name = (char *) msSmallMalloc((pos_scn - data) + 1); + *geom_column_name = (char *)msSmallMalloc((pos_scn - data) + 1); strlcpy(*geom_column_name, data, pos_scn - data + 1); *geom_column_type = msStrdup("geometry"); } /* Copy out the table name or sub-select clause */ - *table_name = (char *) msSmallMalloc((pos_opt - (pos_scn + 6)) + 1); + *table_name = (char *)msSmallMalloc((pos_opt - (pos_scn + 6)) + 1); strlcpy(*table_name, pos_scn + 6, pos_opt - (pos_scn + 6) + 1); - if(strlen(*table_name) < 1 || strlen(*geom_column_name) < 1) { - msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", "Error parsing MSSQL2008 data variable. Must contain 'geometry_column from table_name' or 'geom from (subselect) as foo' (couldnt find a geometry_column or table/subselect). More help:

\n\n", data); + if (strlen(*table_name) < 1 || strlen(*geom_column_name) < 1) { + msSetError( + MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", + "Error parsing MSSQL2008 data variable. Must contain 'geometry_column " + "from table_name' or 'geom from (subselect) as foo' (couldnt find a " + "geometry_column or table/subselect). More help:

\n\n", + data); msFree(data); return MS_FAILURE; } - if( !pos_urid ) { - if( msMSSQL2008LayerRetrievePK(layer, urid_name, *table_name, debug) != MS_SUCCESS ) { - msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", "No primary key defined for table, or primary key contains more that one column\n\n", + if (!pos_urid) { + if (msMSSQL2008LayerRetrievePK(layer, urid_name, *table_name, debug) != + MS_SUCCESS) { + msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", + "No primary key defined for table, or primary key contains " + "more that one column\n\n", *table_name); msFree(data); @@ -2990,32 +3142,34 @@ static int msMSSQL2008LayerParseData(layerObj *layer, char **geom_column_name, c /* Find the order by */ pos_order = strstrIgnoreCase(pos_opt, " order by "); - + if (pos_order) { *sort_spec = msStrdup(pos_order); } - if(debug) { - msDebug("msMSSQL2008LayerParseData: unique column = %s, srid='%s', geom_column_name = %s, table_name=%s\n", *urid_name, *user_srid, *geom_column_name, *table_name); + if (debug) { + msDebug("msMSSQL2008LayerParseData: unique column = %s, srid='%s', " + "geom_column_name = %s, table_name=%s\n", + *urid_name, *user_srid, *geom_column_name, *table_name); } msFree(data); return MS_SUCCESS; } -char *msMSSQL2008LayerEscapePropertyName(layerObj *layer, const char* pszString) -{ +char *msMSSQL2008LayerEscapePropertyName(layerObj *layer, + const char *pszString) { (void)layer; - char* pszEscapedStr=NULL; + char *pszEscapedStr = NULL; int j = 0; if (pszString && strlen(pszString) > 0) { size_t nLength = strlen(pszString); - pszEscapedStr = (char*) msSmallMalloc( 1 + nLength + 1 + 1); + pszEscapedStr = (char *)msSmallMalloc(1 + nLength + 1 + 1); pszEscapedStr[j++] = '['; - for (size_t i=0; ilayerinfo != NULL); - layerinfo = (msMSSQL2008LayerInfo *)layer->layerinfo; + assert(layer->layerinfo != NULL); + layerinfo = (msMSSQL2008LayerInfo *)layer->layerinfo; - return layerinfo->paging; + return layerinfo->paging; } -void msMSSQL2008EnablePaging(layerObj *layer, int value) -{ - msMSSQL2008LayerInfo *layerinfo = NULL; +void msMSSQL2008EnablePaging(layerObj *layer, int value) { + msMSSQL2008LayerInfo *layerinfo = NULL; - if (!msMSSQL2008LayerIsOpen(layer)) - { - if(msMSSQL2008LayerOpen(layer) != MS_SUCCESS) - { - return; - } + if (!msMSSQL2008LayerIsOpen(layer)) { + if (msMSSQL2008LayerOpen(layer) != MS_SUCCESS) { + return; } + } - assert(layer->layerinfo != NULL); - layerinfo = (msMSSQL2008LayerInfo *)layer->layerinfo; + assert(layer->layerinfo != NULL); + layerinfo = (msMSSQL2008LayerInfo *)layer->layerinfo; - layerinfo->paging = value; + layerinfo->paging = value; } -int process_node(layerObj* layer, expressionObj *filter) -{ +int process_node(layerObj *layer, expressionObj *filter) { char *snippet = NULL; char *strtmpl = NULL; char *stresc = NULL; - msMSSQL2008LayerInfo *layerinfo = (msMSSQL2008LayerInfo *) layer->layerinfo; + msMSSQL2008LayerInfo *layerinfo = (msMSSQL2008LayerInfo *)layer->layerinfo; - if (!layerinfo->current_node) - { - msSetError(MS_MISCERR, "Unecpected end of expression", "msMSSQL2008LayerTranslateFilter()"); + if (!layerinfo->current_node) { + msSetError(MS_MISCERR, "Unecpected end of expression", + "msMSSQL2008LayerTranslateFilter()"); return 0; } - switch(layerinfo->current_node->token) { - case '(': - filter->native_string = msStringConcatenate(filter->native_string, "("); - /* process subexpression */ - layerinfo->current_node = layerinfo->current_node->next; - while (layerinfo->current_node != NULL) { - if (!process_node(layer, filter)) - return 0; - if (!layerinfo->current_node) - break; - if (layerinfo->current_node->token == ')') - break; - layerinfo->current_node = layerinfo->current_node->next; - } - break; - case ')': - filter->native_string = msStringConcatenate(filter->native_string, ")"); - break; - /* argument separator */ - case ',': - break; - /* literal tokens */ - case MS_TOKEN_LITERAL_BOOLEAN: - if(layerinfo->current_node->tokenval.dblval == MS_TRUE) - filter->native_string = msStringConcatenate(filter->native_string, "1"); - else - filter->native_string = msStringConcatenate(filter->native_string, "0"); - break; - case MS_TOKEN_LITERAL_NUMBER: - { - char buffer[32]; - snprintf(buffer, sizeof(buffer), "%.18g", layerinfo->current_node->tokenval.dblval); - filter->native_string = msStringConcatenate(filter->native_string, buffer); - break; + switch (layerinfo->current_node->token) { + case '(': + filter->native_string = msStringConcatenate(filter->native_string, "("); + /* process subexpression */ + layerinfo->current_node = layerinfo->current_node->next; + while (layerinfo->current_node != NULL) { + if (!process_node(layer, filter)) + return 0; + if (!layerinfo->current_node) + break; + if (layerinfo->current_node->token == ')') + break; + layerinfo->current_node = layerinfo->current_node->next; } - case MS_TOKEN_LITERAL_STRING: - strtmpl = "'%s'"; - stresc = msMSSQL2008LayerEscapeSQLParam(layer, layerinfo->current_node->tokenval.strval); - snippet = (char *) msSmallMalloc(strlen(strtmpl) + strlen(stresc)); - sprintf(snippet, strtmpl, stresc); - filter->native_string = msStringConcatenate(filter->native_string, snippet); - msFree(snippet); - msFree(stresc); + break; + case ')': + filter->native_string = msStringConcatenate(filter->native_string, ")"); + break; + /* argument separator */ + case ',': + break; + /* literal tokens */ + case MS_TOKEN_LITERAL_BOOLEAN: + if (layerinfo->current_node->tokenval.dblval == MS_TRUE) + filter->native_string = msStringConcatenate(filter->native_string, "1"); + else + filter->native_string = msStringConcatenate(filter->native_string, "0"); + break; + case MS_TOKEN_LITERAL_NUMBER: { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%.18g", + layerinfo->current_node->tokenval.dblval); + filter->native_string = msStringConcatenate(filter->native_string, buffer); + break; + } + case MS_TOKEN_LITERAL_STRING: + strtmpl = "'%s'"; + stresc = msMSSQL2008LayerEscapeSQLParam( + layer, layerinfo->current_node->tokenval.strval); + snippet = (char *)msSmallMalloc(strlen(strtmpl) + strlen(stresc)); + sprintf(snippet, strtmpl, stresc); + filter->native_string = msStringConcatenate(filter->native_string, snippet); + msFree(snippet); + msFree(stresc); + break; + case MS_TOKEN_LITERAL_TIME: { + int resolution = msTimeGetResolution(layerinfo->current_node->tokensrc); + snippet = (char *)msSmallMalloc(128); + switch (resolution) { + case TIME_RESOLUTION_YEAR: + sprintf(snippet, "'%d'", + (layerinfo->current_node->tokenval.tmval.tm_year + 1900)); break; - case MS_TOKEN_LITERAL_TIME: - { - int resolution = msTimeGetResolution(layerinfo->current_node->tokensrc); - snippet = (char *) msSmallMalloc(128); - switch(resolution) { - case TIME_RESOLUTION_YEAR: - sprintf(snippet, "'%d'", (layerinfo->current_node->tokenval.tmval.tm_year+1900)); - break; - case TIME_RESOLUTION_MONTH: - sprintf(snippet, "'%d-%02d-01'", (layerinfo->current_node->tokenval.tmval.tm_year+1900), - (layerinfo->current_node->tokenval.tmval.tm_mon+1)); - break; - case TIME_RESOLUTION_DAY: - sprintf(snippet, "'%d-%02d-%02d'", (layerinfo->current_node->tokenval.tmval.tm_year+1900), - (layerinfo->current_node->tokenval.tmval.tm_mon+1), - layerinfo->current_node->tokenval.tmval.tm_mday); - break; - case TIME_RESOLUTION_HOUR: - sprintf(snippet, "'%d-%02d-%02d %02d:00'", (layerinfo->current_node->tokenval.tmval.tm_year+1900), - (layerinfo->current_node->tokenval.tmval.tm_mon+1), - layerinfo->current_node->tokenval.tmval.tm_mday, - layerinfo->current_node->tokenval.tmval.tm_hour); - break; - case TIME_RESOLUTION_MINUTE: - sprintf(snippet, "%d-%02d-%02d %02d:%02d'", (layerinfo->current_node->tokenval.tmval.tm_year+1900), - (layerinfo->current_node->tokenval.tmval.tm_mon+1), - layerinfo->current_node->tokenval.tmval.tm_mday, - layerinfo->current_node->tokenval.tmval.tm_hour, - layerinfo->current_node->tokenval.tmval.tm_min); - break; - case TIME_RESOLUTION_SECOND: - sprintf(snippet, "'%d-%02d-%02d %02d:%02d:%02d'", (layerinfo->current_node->tokenval.tmval.tm_year+1900), - (layerinfo->current_node->tokenval.tmval.tm_mon+1), - layerinfo->current_node->tokenval.tmval.tm_mday, - layerinfo->current_node->tokenval.tmval.tm_hour, - layerinfo->current_node->tokenval.tmval.tm_min, - layerinfo->current_node->tokenval.tmval.tm_sec); - break; - } - filter->native_string = msStringConcatenate(filter->native_string, snippet); - msFree(snippet); - } + case TIME_RESOLUTION_MONTH: + sprintf(snippet, "'%d-%02d-01'", + (layerinfo->current_node->tokenval.tmval.tm_year + 1900), + (layerinfo->current_node->tokenval.tmval.tm_mon + 1)); break; - case MS_TOKEN_LITERAL_SHAPE: - if (strcasecmp(layerinfo->geom_column_type, "geography") == 0) - filter->native_string = msStringConcatenate(filter->native_string, "geography::STGeomFromText('"); - else - filter->native_string = msStringConcatenate(filter->native_string, "geometry::STGeomFromText('"); - filter->native_string = msStringConcatenate(filter->native_string, msShapeToWKT(layerinfo->current_node->tokenval.shpval)); - filter->native_string = msStringConcatenate(filter->native_string, "'"); - if(layerinfo->user_srid && strcmp(layerinfo->user_srid, "") != 0) { - filter->native_string = msStringConcatenate(filter->native_string, ", "); - filter->native_string = msStringConcatenate(filter->native_string, layerinfo->user_srid); - } - filter->native_string = msStringConcatenate(filter->native_string, ")"); + case TIME_RESOLUTION_DAY: + sprintf(snippet, "'%d-%02d-%02d'", + (layerinfo->current_node->tokenval.tmval.tm_year + 1900), + (layerinfo->current_node->tokenval.tmval.tm_mon + 1), + layerinfo->current_node->tokenval.tmval.tm_mday); break; - case MS_TOKEN_BINDING_TIME: - case MS_TOKEN_BINDING_DOUBLE: - case MS_TOKEN_BINDING_INTEGER: - case MS_TOKEN_BINDING_STRING: - if(layerinfo->current_node->next->token == MS_TOKEN_COMPARISON_IRE) - strtmpl = "LOWER(%s)"; - else - strtmpl = "%s"; - - stresc = msMSSQL2008LayerEscapePropertyName(layer, layerinfo->current_node->tokenval.bindval.item); - snippet = (char *) msSmallMalloc(strlen(strtmpl) + strlen(stresc)); - sprintf(snippet, strtmpl, stresc); - filter->native_string = msStringConcatenate(filter->native_string, snippet); - msFree(snippet); - msFree(stresc); + case TIME_RESOLUTION_HOUR: + sprintf(snippet, "'%d-%02d-%02d %02d:00'", + (layerinfo->current_node->tokenval.tmval.tm_year + 1900), + (layerinfo->current_node->tokenval.tmval.tm_mon + 1), + layerinfo->current_node->tokenval.tmval.tm_mday, + layerinfo->current_node->tokenval.tmval.tm_hour); break; - case MS_TOKEN_BINDING_SHAPE: - filter->native_string = msStringConcatenate(filter->native_string, layerinfo->geom_column); + case TIME_RESOLUTION_MINUTE: + sprintf(snippet, "%d-%02d-%02d %02d:%02d'", + (layerinfo->current_node->tokenval.tmval.tm_year + 1900), + (layerinfo->current_node->tokenval.tmval.tm_mon + 1), + layerinfo->current_node->tokenval.tmval.tm_mday, + layerinfo->current_node->tokenval.tmval.tm_hour, + layerinfo->current_node->tokenval.tmval.tm_min); break; - case MS_TOKEN_BINDING_MAP_CELLSIZE: - { - char buffer[32]; - snprintf(buffer, sizeof(buffer), "%.18g", layer->map->cellsize); - filter->native_string = msStringConcatenate(filter->native_string, buffer); + case TIME_RESOLUTION_SECOND: + sprintf(snippet, "'%d-%02d-%02d %02d:%02d:%02d'", + (layerinfo->current_node->tokenval.tmval.tm_year + 1900), + (layerinfo->current_node->tokenval.tmval.tm_mon + 1), + layerinfo->current_node->tokenval.tmval.tm_mday, + layerinfo->current_node->tokenval.tmval.tm_hour, + layerinfo->current_node->tokenval.tmval.tm_min, + layerinfo->current_node->tokenval.tmval.tm_sec); break; } + filter->native_string = msStringConcatenate(filter->native_string, snippet); + msFree(snippet); + } break; + case MS_TOKEN_LITERAL_SHAPE: + if (strcasecmp(layerinfo->geom_column_type, "geography") == 0) + filter->native_string = msStringConcatenate( + filter->native_string, "geography::STGeomFromText('"); + else + filter->native_string = msStringConcatenate(filter->native_string, + "geometry::STGeomFromText('"); + filter->native_string = msStringConcatenate( + filter->native_string, + msShapeToWKT(layerinfo->current_node->tokenval.shpval)); + filter->native_string = msStringConcatenate(filter->native_string, "'"); + if (layerinfo->user_srid && strcmp(layerinfo->user_srid, "") != 0) { + filter->native_string = msStringConcatenate(filter->native_string, ", "); + filter->native_string = + msStringConcatenate(filter->native_string, layerinfo->user_srid); + } + filter->native_string = msStringConcatenate(filter->native_string, ")"); + break; + case MS_TOKEN_BINDING_TIME: + case MS_TOKEN_BINDING_DOUBLE: + case MS_TOKEN_BINDING_INTEGER: + case MS_TOKEN_BINDING_STRING: + if (layerinfo->current_node->next->token == MS_TOKEN_COMPARISON_IRE) + strtmpl = "LOWER(%s)"; + else + strtmpl = "%s"; - /* comparisons */ - case MS_TOKEN_COMPARISON_IN: - filter->native_string = msStringConcatenate(filter->native_string, " IN "); - break; - case MS_TOKEN_COMPARISON_RE: - case MS_TOKEN_COMPARISON_IRE: - case MS_TOKEN_COMPARISON_LIKE: { - /* process regexp */ - size_t i = 0, j = 0; - char c; - char c_next; - int bCaseInsensitive = (layerinfo->current_node->token == MS_TOKEN_COMPARISON_IRE); - int nEscapeLen = 0; - if (bCaseInsensitive) - filter->native_string = msStringConcatenate(filter->native_string, " LIKE LOWER("); - else - filter->native_string = msStringConcatenate(filter->native_string, " LIKE "); + stresc = msMSSQL2008LayerEscapePropertyName( + layer, layerinfo->current_node->tokenval.bindval.item); + snippet = (char *)msSmallMalloc(strlen(strtmpl) + strlen(stresc)); + sprintf(snippet, strtmpl, stresc); + filter->native_string = msStringConcatenate(filter->native_string, snippet); + msFree(snippet); + msFree(stresc); + break; + case MS_TOKEN_BINDING_SHAPE: + filter->native_string = + msStringConcatenate(filter->native_string, layerinfo->geom_column); + break; + case MS_TOKEN_BINDING_MAP_CELLSIZE: { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%.18g", layer->map->cellsize); + filter->native_string = msStringConcatenate(filter->native_string, buffer); + break; + } - layerinfo->current_node = layerinfo->current_node->next; - if (layerinfo->current_node->token != MS_TOKEN_LITERAL_STRING) return 0; + /* comparisons */ + case MS_TOKEN_COMPARISON_IN: + filter->native_string = msStringConcatenate(filter->native_string, " IN "); + break; + case MS_TOKEN_COMPARISON_RE: + case MS_TOKEN_COMPARISON_IRE: + case MS_TOKEN_COMPARISON_LIKE: { + /* process regexp */ + size_t i = 0, j = 0; + char c; + char c_next; + int bCaseInsensitive = + (layerinfo->current_node->token == MS_TOKEN_COMPARISON_IRE); + int nEscapeLen = 0; + if (bCaseInsensitive) + filter->native_string = + msStringConcatenate(filter->native_string, " LIKE LOWER("); + else + filter->native_string = + msStringConcatenate(filter->native_string, " LIKE "); - strtmpl = msStrdup(layerinfo->current_node->tokenval.strval); - if (strtmpl[0] == '/') { - stresc = strtmpl + 1; - strtmpl[strlen(strtmpl) - 1] = '\0'; - } - else if (strtmpl[0] == '^') - stresc = strtmpl + 1; - else - stresc = strtmpl; + layerinfo->current_node = layerinfo->current_node->next; + if (layerinfo->current_node->token != MS_TOKEN_LITERAL_STRING) + return 0; - while (*stresc) { - c = stresc[i]; - if (c == '%' || c == '_' || c == '[' || c == ']' || c == '^') { - nEscapeLen++; - } - stresc++; - } - snippet = (char *)msSmallMalloc(strlen(strtmpl) + nEscapeLen + 3); - snippet[j++] = '\''; - while (i < strlen(strtmpl)) { - c = strtmpl[i]; - c_next = strtmpl[i+1]; - - if (i == 0 && c == '^') { - i++; - continue; - } - if( c == '$' && c_next == 0 && strtmpl[0] == '^' ) - break; + strtmpl = msStrdup(layerinfo->current_node->tokenval.strval); + if (strtmpl[0] == '/') { + stresc = strtmpl + 1; + strtmpl[strlen(strtmpl) - 1] = '\0'; + } else if (strtmpl[0] == '^') + stresc = strtmpl + 1; + else + stresc = strtmpl; - if (c == '\\') { - i++; - c = c_next; - } - - if (c == '%' || c == '_' || c == '[' || c == ']' || c == '^') { - snippet[j++] = '\\'; - } - - if (c == '.' && c_next == '*') { - i++; - c = '%'; - } - else if (c == '.') - c = '_'; + while (*stresc) { + c = stresc[i]; + if (c == '%' || c == '_' || c == '[' || c == ']' || c == '^') { + nEscapeLen++; + } + stresc++; + } + snippet = (char *)msSmallMalloc(strlen(strtmpl) + nEscapeLen + 3); + snippet[j++] = '\''; + while (i < strlen(strtmpl)) { + c = strtmpl[i]; + c_next = strtmpl[i + 1]; + + if (i == 0 && c == '^') { + i++; + continue; + } + if (c == '$' && c_next == 0 && strtmpl[0] == '^') + break; - - snippet[j++] = c; - i++; + if (c == '\\') { + i++; + c = c_next; } - snippet[j++] = '\''; - snippet[j] = '\0'; - filter->native_string = msStringConcatenate(filter->native_string, snippet); - msFree(strtmpl); - msFree(snippet); + if (c == '%' || c == '_' || c == '[' || c == ']' || c == '^') { + snippet[j++] = '\\'; + } - if (bCaseInsensitive) - filter->native_string = msStringConcatenate(filter->native_string, ")"); + if (c == '.' && c_next == '*') { + i++; + c = '%'; + } else if (c == '.') + c = '_'; - if (nEscapeLen > 0) - filter->native_string = msStringConcatenate(filter->native_string, " ESCAPE '\\'"); + snippet[j++] = c; + i++; } - break; - case MS_TOKEN_COMPARISON_EQ: - filter->native_string = msStringConcatenate(filter->native_string, " = "); - break; - case MS_TOKEN_COMPARISON_NE: - filter->native_string = msStringConcatenate(filter->native_string, " != "); - break; - case MS_TOKEN_COMPARISON_GT: - filter->native_string = msStringConcatenate(filter->native_string, " > "); - break; - case MS_TOKEN_COMPARISON_GE: - filter->native_string = msStringConcatenate(filter->native_string, " >= "); - break; - case MS_TOKEN_COMPARISON_LT: - filter->native_string = msStringConcatenate(filter->native_string, " < "); - break; - case MS_TOKEN_COMPARISON_LE: - filter->native_string = msStringConcatenate(filter->native_string, " <= "); - break; + snippet[j++] = '\''; + snippet[j] = '\0'; - /* logical ops */ - case MS_TOKEN_LOGICAL_AND: - filter->native_string = msStringConcatenate(filter->native_string, " AND "); - break; - case MS_TOKEN_LOGICAL_OR: - filter->native_string = msStringConcatenate(filter->native_string, " OR "); - break; - case MS_TOKEN_LOGICAL_NOT: - filter->native_string = msStringConcatenate(filter->native_string, " NOT "); - break; - - /* spatial comparison tokens */ - case MS_TOKEN_COMPARISON_INTERSECTS: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STIntersects("); - if (!process_node(layer, filter)) - return 0; - break; + filter->native_string = msStringConcatenate(filter->native_string, snippet); + msFree(strtmpl); + msFree(snippet); - case MS_TOKEN_COMPARISON_DISJOINT: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STDisjoint("); - if (!process_node(layer, filter)) - return 0; - break; + if (bCaseInsensitive) + filter->native_string = msStringConcatenate(filter->native_string, ")"); - case MS_TOKEN_COMPARISON_TOUCHES: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STTouches("); - if (!process_node(layer, filter)) - return 0; - break; + if (nEscapeLen > 0) + filter->native_string = + msStringConcatenate(filter->native_string, " ESCAPE '\\'"); + } break; + case MS_TOKEN_COMPARISON_EQ: + filter->native_string = msStringConcatenate(filter->native_string, " = "); + break; + case MS_TOKEN_COMPARISON_NE: + filter->native_string = msStringConcatenate(filter->native_string, " != "); + break; + case MS_TOKEN_COMPARISON_GT: + filter->native_string = msStringConcatenate(filter->native_string, " > "); + break; + case MS_TOKEN_COMPARISON_GE: + filter->native_string = msStringConcatenate(filter->native_string, " >= "); + break; + case MS_TOKEN_COMPARISON_LT: + filter->native_string = msStringConcatenate(filter->native_string, " < "); + break; + case MS_TOKEN_COMPARISON_LE: + filter->native_string = msStringConcatenate(filter->native_string, " <= "); + break; - case MS_TOKEN_COMPARISON_OVERLAPS: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STOverlaps("); - if (!process_node(layer, filter)) - return 0; - break; + /* logical ops */ + case MS_TOKEN_LOGICAL_AND: + filter->native_string = msStringConcatenate(filter->native_string, " AND "); + break; + case MS_TOKEN_LOGICAL_OR: + filter->native_string = msStringConcatenate(filter->native_string, " OR "); + break; + case MS_TOKEN_LOGICAL_NOT: + filter->native_string = msStringConcatenate(filter->native_string, " NOT "); + break; - case MS_TOKEN_COMPARISON_CROSSES: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STCrosses("); - if (!process_node(layer, filter)) - return 0; - break; + /* spatial comparison tokens */ + case MS_TOKEN_COMPARISON_INTERSECTS: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STIntersects("); + if (!process_node(layer, filter)) + return 0; + break; - case MS_TOKEN_COMPARISON_WITHIN: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STWithin("); - if (!process_node(layer, filter)) - return 0; - break; + case MS_TOKEN_COMPARISON_DISJOINT: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STDisjoint("); + if (!process_node(layer, filter)) + return 0; + break; - case MS_TOKEN_COMPARISON_CONTAINS: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STContains("); - if (!process_node(layer, filter)) - return 0; - break; + case MS_TOKEN_COMPARISON_TOUCHES: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STTouches("); + if (!process_node(layer, filter)) + return 0; + break; - case MS_TOKEN_COMPARISON_EQUALS: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STEquals("); - if (!process_node(layer, filter)) - return 0; - break; + case MS_TOKEN_COMPARISON_OVERLAPS: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STOverlaps("); + if (!process_node(layer, filter)) + return 0; + break; - case MS_TOKEN_COMPARISON_BEYOND: - msSetError(MS_MISCERR, "Beyond operator is unsupported.", "msMSSQL2008LayerTranslateFilter()"); + case MS_TOKEN_COMPARISON_CROSSES: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STCrosses("); + if (!process_node(layer, filter)) + return 0; + break; - case MS_TOKEN_COMPARISON_DWITHIN: - msSetError(MS_MISCERR, "DWithin operator is unsupported.", "msMSSQL2008LayerTranslateFilter()"); + case MS_TOKEN_COMPARISON_WITHIN: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STWithin("); + if (!process_node(layer, filter)) + return 0; + break; - /* spatial functions */ - case MS_TOKEN_FUNCTION_AREA: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STArea()"); - break; + case MS_TOKEN_COMPARISON_CONTAINS: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STContains("); + if (!process_node(layer, filter)) + return 0; + break; - case MS_TOKEN_FUNCTION_BUFFER: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STBuffer("); - if (!process_node(layer, filter)) - return 0; - filter->native_string = msStringConcatenate(filter->native_string, ")"); - break; + case MS_TOKEN_COMPARISON_EQUALS: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STEquals("); + if (!process_node(layer, filter)) + return 0; + break; - case MS_TOKEN_FUNCTION_DIFFERENCE: - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (!process_node(layer, filter)) - return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - if (layerinfo->current_node->next) layerinfo->current_node = layerinfo->current_node->next; - else return 0; - filter->native_string = msStringConcatenate(filter->native_string, ".STDifference("); - if (!process_node(layer, filter)) - return 0; - filter->native_string = msStringConcatenate(filter->native_string, ")"); - break; + case MS_TOKEN_COMPARISON_BEYOND: + msSetError(MS_MISCERR, "Beyond operator is unsupported.", + "msMSSQL2008LayerTranslateFilter()"); + return 0; - case MS_TOKEN_FUNCTION_FROMTEXT: - if (strcasecmp(layerinfo->geom_column_type, "geography") == 0) - filter->native_string = msStringConcatenate(filter->native_string, "geography::STGeomFromText"); - else - filter->native_string = msStringConcatenate(filter->native_string, "geometry::STGeomFromText"); - break; + case MS_TOKEN_COMPARISON_DWITHIN: + msSetError(MS_MISCERR, "DWithin operator is unsupported.", + "msMSSQL2008LayerTranslateFilter()"); + return 0; - case MS_TOKEN_FUNCTION_LENGTH: - filter->native_string = msStringConcatenate(filter->native_string, "len"); - break; + /* spatial functions */ + case MS_TOKEN_FUNCTION_AREA: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STArea()"); + break; - case MS_TOKEN_FUNCTION_ROUND: - filter->native_string = msStringConcatenate(filter->native_string, "round"); - break; - - case MS_TOKEN_FUNCTION_TOSTRING: - break; + case MS_TOKEN_FUNCTION_BUFFER: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STBuffer("); + if (!process_node(layer, filter)) + return 0; + filter->native_string = msStringConcatenate(filter->native_string, ")"); + break; - case MS_TOKEN_FUNCTION_COMMIFY: - break; + case MS_TOKEN_FUNCTION_DIFFERENCE: + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (!process_node(layer, filter)) + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + if (layerinfo->current_node->next) + layerinfo->current_node = layerinfo->current_node->next; + else + return 0; + filter->native_string = + msStringConcatenate(filter->native_string, ".STDifference("); + if (!process_node(layer, filter)) + return 0; + filter->native_string = msStringConcatenate(filter->native_string, ")"); + break; - case MS_TOKEN_FUNCTION_SIMPLIFY: - filter->native_string = msStringConcatenate(filter->native_string, ".Reduce"); - break; - case MS_TOKEN_FUNCTION_SIMPLIFYPT: - break; - case MS_TOKEN_FUNCTION_GENERALIZE: - filter->native_string = msStringConcatenate(filter->native_string, ".Reduce"); - break; + case MS_TOKEN_FUNCTION_FROMTEXT: + if (strcasecmp(layerinfo->geom_column_type, "geography") == 0) + filter->native_string = msStringConcatenate(filter->native_string, + "geography::STGeomFromText"); + else + filter->native_string = msStringConcatenate(filter->native_string, + "geometry::STGeomFromText"); + break; - default: - msSetError(MS_MISCERR, "Translation to native SQL failed.","msMSSQL2008LayerTranslateFilter()"); - if (layer->debug) { - msDebug("Token not caught, exiting: Token is %i\n", layerinfo->current_node->token); - } - return 0; + case MS_TOKEN_FUNCTION_LENGTH: + filter->native_string = msStringConcatenate(filter->native_string, "len"); + break; + + case MS_TOKEN_FUNCTION_ROUND: + filter->native_string = msStringConcatenate(filter->native_string, "round"); + break; + + case MS_TOKEN_FUNCTION_TOSTRING: + break; + + case MS_TOKEN_FUNCTION_COMMIFY: + break; + + case MS_TOKEN_FUNCTION_SIMPLIFY: + filter->native_string = + msStringConcatenate(filter->native_string, ".Reduce"); + break; + case MS_TOKEN_FUNCTION_SIMPLIFYPT: + break; + case MS_TOKEN_FUNCTION_GENERALIZE: + filter->native_string = + msStringConcatenate(filter->native_string, ".Reduce"); + break; + + default: + msSetError(MS_MISCERR, "Translation to native SQL failed.", + "msMSSQL2008LayerTranslateFilter()"); + if (layer->debug) { + msDebug("Token not caught, exiting: Token is %i\n", + layerinfo->current_node->token); + } + return 0; } return 1; } /* Translate filter expression to native msssql filter */ -int msMSSQL2008LayerTranslateFilter(layerObj *layer, expressionObj *filter, char *filteritem) -{ +int msMSSQL2008LayerTranslateFilter(layerObj *layer, expressionObj *filter, + char *filteritem) { char *snippet = NULL; char *strtmpl = NULL; char *stresc = NULL; - msMSSQL2008LayerInfo *layerinfo = (msMSSQL2008LayerInfo *) layer->layerinfo; + msMSSQL2008LayerInfo *layerinfo = (msMSSQL2008LayerInfo *)layer->layerinfo; - if(!filter->string) return MS_SUCCESS; + if (!filter->string) + return MS_SUCCESS; msFree(filter->native_string); filter->native_string = NULL; - if(filter->type == MS_STRING && filter->string && filteritem) { /* item/value pair */ + if (filter->type == MS_STRING && filter->string && + filteritem) { /* item/value pair */ stresc = msMSSQL2008LayerEscapePropertyName(layer, filteritem); - if(filter->flags & MS_EXP_INSENSITIVE) { - filter->native_string = msStringConcatenate(filter->native_string, "upper("); - filter->native_string = msStringConcatenate(filter->native_string, stresc); - filter->native_string = msStringConcatenate(filter->native_string, ") = upper("); + if (filter->flags & MS_EXP_INSENSITIVE) { + filter->native_string = + msStringConcatenate(filter->native_string, "upper("); + filter->native_string = + msStringConcatenate(filter->native_string, stresc); + filter->native_string = + msStringConcatenate(filter->native_string, ") = upper("); } else { - filter->native_string = msStringConcatenate(filter->native_string, stresc); + filter->native_string = + msStringConcatenate(filter->native_string, stresc); filter->native_string = msStringConcatenate(filter->native_string, " = "); } msFree(stresc); - strtmpl = "'%s'"; /* don't have a type for the righthand literal so assume it's a string and we quote */ - snippet = (char *) msSmallMalloc(strlen(strtmpl) + strlen(filter->string)); - sprintf(snippet, strtmpl, filter->string); // TODO: escape filter->string + strtmpl = "'%s'"; /* don't have a type for the righthand literal so assume + it's a string and we quote */ + snippet = (char *)msSmallMalloc(strlen(strtmpl) + strlen(filter->string)); + sprintf(snippet, strtmpl, filter->string); // TODO: escape filter->string filter->native_string = msStringConcatenate(filter->native_string, snippet); free(snippet); - if(filter->flags & MS_EXP_INSENSITIVE) - filter->native_string = msStringConcatenate(filter->native_string, ")"); - - } else if(filter->type == MS_REGEX && filter->string && filteritem) { /* item/regex pair */ - /* NOTE: regex is not supported by MSSQL natively. We should install it in CLR UDF - according to https://msdn.microsoft.com/en-us/magazine/cc163473.aspx*/ - filter->native_string = msStringConcatenate(filter->native_string, "dbo.RegexMatch("); - if(filter->flags & MS_EXP_INSENSITIVE) { - filter->native_string = msStringConcatenate(filter->native_string, "'(?i)"); + if (filter->flags & MS_EXP_INSENSITIVE) + filter->native_string = msStringConcatenate(filter->native_string, ")"); + + } else if (filter->type == MS_REGEX && filter->string && + filteritem) { /* item/regex pair */ + /* NOTE: regex is not supported by MSSQL natively. We should install it in + CLR UDF according to + https://msdn.microsoft.com/en-us/magazine/cc163473.aspx*/ + filter->native_string = + msStringConcatenate(filter->native_string, "dbo.RegexMatch("); + if (filter->flags & MS_EXP_INSENSITIVE) { + filter->native_string = + msStringConcatenate(filter->native_string, "'(?i)"); } filter->native_string = msStrdup(filteritem); filter->native_string = msStringConcatenate(filter->native_string, ", "); strtmpl = "'%s'"; - snippet = (char *) msSmallMalloc(strlen(strtmpl) + strlen(filter->string)); + snippet = (char *)msSmallMalloc(strlen(strtmpl) + strlen(filter->string)); sprintf(snippet, strtmpl, filter->string); // TODO: escape filter->string filter->native_string = msStringConcatenate(filter->native_string, snippet); filter->native_string = msStringConcatenate(filter->native_string, "')"); free(snippet); - } else if(filter->type == MS_EXPRESSION) { - - if(layer->debug >= 2) + } else if (filter->type == MS_EXPRESSION) { + + if (layer->debug >= 2) msDebug("msMSSQL2008LayerTranslateFilter. String: %s.\n", filter->string); - if(!filter->tokens) { - if(layer->debug >= 2) - msDebug("msMSSQL2008LayerTranslateFilter. There are tokens to process... \n"); + if (!filter->tokens) { + if (layer->debug >= 2) + msDebug("msMSSQL2008LayerTranslateFilter. There are tokens to " + "process... \n"); return MS_SUCCESS; } /* start processing nodes */ layerinfo->current_node = filter->tokens; while (layerinfo->current_node != NULL) { - if (!process_node(layer, filter)) - { + if (!process_node(layer, filter)) { msFree(filter->native_string); filter->native_string = 0; return MS_FAILURE; @@ -3630,7 +3904,7 @@ int msMSSQL2008LayerTranslateFilter(layerObj *layer, expressionObj *filter, char break; layerinfo->current_node = layerinfo->current_node->next; - } + } } return MS_SUCCESS; @@ -3640,110 +3914,150 @@ int msMSSQL2008LayerTranslateFilter(layerObj *layer, expressionObj *filter, char /* prototypes if MSSQL2008 isnt supposed to be compiled */ -int msMSSQL2008LayerOpen(layerObj *layer) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerOpen called but unimplemented! (mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerOpen()"); +int msMSSQL2008LayerOpen(layerObj *layer) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerOpen called but unimplemented! (mapserver not " + "compiled with MSSQL2008 support)", + "msMSSQL2008LayerOpen()"); return MS_FAILURE; } -int msMSSQL2008LayerIsOpen(layerObj *layer) -{ - msSetError(MS_QUERYERR, "msMSSQL2008IsLayerOpen called but unimplemented! (mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerIsOpen()"); +int msMSSQL2008LayerIsOpen(layerObj *layer) { + msSetError(MS_QUERYERR, + "msMSSQL2008IsLayerOpen called but unimplemented! (mapserver not " + "compiled with MSSQL2008 support)", + "msMSSQL2008LayerIsOpen()"); return MS_FALSE; } -void msMSSQL2008LayerFreeItemInfo(layerObj *layer) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerFreeItemInfo called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerFreeItemInfo()"); +void msMSSQL2008LayerFreeItemInfo(layerObj *layer) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerFreeItemInfo called but unimplemented!(mapserver " + "not compiled with MSSQL2008 support)", + "msMSSQL2008LayerFreeItemInfo()"); } -int msMSSQL2008LayerInitItemInfo(layerObj *layer) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerInitItemInfo called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerInitItemInfo()"); +int msMSSQL2008LayerInitItemInfo(layerObj *layer) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerInitItemInfo called but unimplemented!(mapserver " + "not compiled with MSSQL2008 support)", + "msMSSQL2008LayerInitItemInfo()"); return MS_FAILURE; } -int msMSSQL2008LayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerWhichShapes called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerWhichShapes()"); +int msMSSQL2008LayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerWhichShapes called but unimplemented!(mapserver " + "not compiled with MSSQL2008 support)", + "msMSSQL2008LayerWhichShapes()"); return MS_FAILURE; } -int msMSSQL2008LayerClose(layerObj *layer) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerClose called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerClose()"); +int msMSSQL2008LayerClose(layerObj *layer) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerClose called but unimplemented!(mapserver not " + "compiled with MSSQL2008 support)", + "msMSSQL2008LayerClose()"); return MS_FAILURE; } -int msMSSQL2008LayerNextShape(layerObj *layer, shapeObj *shape) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerNextShape called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerNextShape()"); +int msMSSQL2008LayerNextShape(layerObj *layer, shapeObj *shape) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerNextShape called but unimplemented!(mapserver " + "not compiled with MSSQL2008 support)", + "msMSSQL2008LayerNextShape()"); return MS_FAILURE; } -int msMSSQL2008LayerGetShape(layerObj *layer, shapeObj *shape, long record) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetShape called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerGetShape()"); +int msMSSQL2008LayerGetShape(layerObj *layer, shapeObj *shape, long record) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerGetShape called but unimplemented!(mapserver not " + "compiled with MSSQL2008 support)", + "msMSSQL2008LayerGetShape()"); return MS_FAILURE; } -int msMSSQL2008LayerGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rectProjection) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetShapeCount called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerGetShapeCount()"); - return MS_FAILURE; +int msMSSQL2008LayerGetShapeCount(layerObj *layer, rectObj rect, + projectionObj *rectProjection) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerGetShapeCount called but " + "unimplemented!(mapserver not compiled with MSSQL2008 support)", + "msMSSQL2008LayerGetShapeCount()"); + return MS_FAILURE; } -int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetExtent called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerGetExtent()"); +int msMSSQL2008LayerGetExtent(layerObj *layer, rectObj *extent) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerGetExtent called but unimplemented!(mapserver " + "not compiled with MSSQL2008 support)", + "msMSSQL2008LayerGetExtent()"); return MS_FAILURE; } -int msMSSQL2008LayerGetNumFeatures(layerObj *layer) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetNumFeatures called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerGetNumFeatures()"); - return -1; +int msMSSQL2008LayerGetNumFeatures(layerObj *layer) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerGetNumFeatures called but " + "unimplemented!(mapserver not compiled with MSSQL2008 support)", + "msMSSQL2008LayerGetNumFeatures()"); + return -1; } -int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *record) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetShapeRandom called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerGetShapeRandom()"); +int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, + long *record) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerGetShapeRandom called but " + "unimplemented!(mapserver not compiled with MSSQL2008 support)", + "msMSSQL2008LayerGetShapeRandom()"); return MS_FAILURE; } -int msMSSQL2008LayerGetItems(layerObj *layer) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerGetItems called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerGetItems()"); +int msMSSQL2008LayerGetItems(layerObj *layer) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerGetItems called but unimplemented!(mapserver not " + "compiled with MSSQL2008 support)", + "msMSSQL2008LayerGetItems()"); return MS_FAILURE; } -void msMSSQL2008EnablePaging(layerObj *layer, int value) -{ - msSetError(MS_QUERYERR, "msMSSQL2008EnablePaging called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008EnablePaging()"); - return; +void msMSSQL2008EnablePaging(layerObj *layer, int value) { + msSetError(MS_QUERYERR, + "msMSSQL2008EnablePaging called but unimplemented!(mapserver not " + "compiled with MSSQL2008 support)", + "msMSSQL2008EnablePaging()"); + return; } -int msMSSQL2008GetPaging(layerObj *layer) -{ - msSetError(MS_QUERYERR, "msMSSQL2008GetPaging called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008GetPaging()"); - return MS_FAILURE; +int msMSSQL2008GetPaging(layerObj *layer) { + msSetError(MS_QUERYERR, + "msMSSQL2008GetPaging called but unimplemented!(mapserver not " + "compiled with MSSQL2008 support)", + "msMSSQL2008GetPaging()"); + return MS_FAILURE; } -int msMSSQL2008LayerTranslateFilter(layerObj *layer, expressionObj *filter, char *filteritem) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerTranslateFilter called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerTranslateFilter()"); +int msMSSQL2008LayerTranslateFilter(layerObj *layer, expressionObj *filter, + char *filteritem) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerTranslateFilter called but " + "unimplemented!(mapserver not compiled with MSSQL2008 support)", + "msMSSQL2008LayerTranslateFilter()"); return MS_FAILURE; } -char *msMSSQL2008LayerEscapeSQLParam(layerObj *layer, const char *pszString) -{ - msSetError(MS_QUERYERR, "msMSSQL2008EscapeSQLParam called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerEscapeSQLParam()"); +char *msMSSQL2008LayerEscapeSQLParam(layerObj *layer, const char *pszString) { + msSetError(MS_QUERYERR, + "msMSSQL2008EscapeSQLParam called but unimplemented!(mapserver " + "not compiled with MSSQL2008 support)", + "msMSSQL2008LayerEscapeSQLParam()"); return NULL; } -char *msMSSQL2008LayerEscapePropertyName(layerObj *layer, const char *pszString) -{ - msSetError(MS_QUERYERR, "msMSSQL2008LayerEscapePropertyName called but unimplemented!(mapserver not compiled with MSSQL2008 support)", "msMSSQL2008LayerEscapePropertyName()"); +char *msMSSQL2008LayerEscapePropertyName(layerObj *layer, + const char *pszString) { + msSetError(MS_QUERYERR, + "msMSSQL2008LayerEscapePropertyName called but " + "unimplemented!(mapserver not compiled with MSSQL2008 support)", + "msMSSQL2008LayerEscapePropertyName()"); return NULL; } @@ -3752,8 +4066,8 @@ char *msMSSQL2008LayerEscapePropertyName(layerObj *layer, const char *pszString) #ifdef USE_MSSQL2008_PLUGIN -MS_DLL_EXPORT int PluginInitializeVirtualTable(layerVTableObj* vtable, layerObj *layer) -{ +MS_DLL_EXPORT int PluginInitializeVirtualTable(layerVTableObj *vtable, + layerObj *layer) { assert(layer != NULL); assert(vtable != NULL); @@ -3792,9 +4106,7 @@ MS_DLL_EXPORT int PluginInitializeVirtualTable(layerVTableObj* vtable, layerObj #endif -int -msMSSQL2008LayerInitializeVirtualTable(layerObj *layer) -{ +int msMSSQL2008LayerInitializeVirtualTable(layerObj *layer) { assert(layer != NULL); assert(layer->vtable != NULL); @@ -3827,6 +4139,5 @@ msMSSQL2008LayerInitializeVirtualTable(layerObj *layer) /* layer->vtable->LayerCreateItems, use default */ layer->vtable->LayerGetNumFeatures = msMSSQL2008LayerGetNumFeatures; - return MS_SUCCESS; } diff --git a/mapmvt.c b/mapmvt.c index 280d899594..c733fb3a25 100644 --- a/mapmvt.c +++ b/mapmvt.c @@ -42,7 +42,11 @@ #define FEATURES_INCREMENT_SIZE 5 -enum MS_RING_DIRECTION { MS_DIRECTION_INVALID_RING, MS_DIRECTION_CLOCKWISE, MS_DIRECTION_COUNTERCLOCKWISE }; +enum MS_RING_DIRECTION { + MS_DIRECTION_INVALID_RING, + MS_DIRECTION_CLOCKWISE, + MS_DIRECTION_COUNTERCLOCKWISE +}; typedef struct { char *value; @@ -54,46 +58,54 @@ typedef struct { value_lookup *cache; } value_lookup_table; -#define COMMAND(id, count) (((id) & 0x7) | ((count) << 3)) +#define COMMAND(id, count) (((id)&0x7) | ((count) << 3)) #define PARAMETER(n) (((n) << 1) ^ ((n) >> 31)) -static double getTriangleHeight(lineObj *ring) -{ +static double getTriangleHeight(lineObj *ring) { int i; - double s=0, b=0; + double s = 0, b = 0; - if(ring->numpoints != 4) return -1; /* not a triangle */ + if (ring->numpoints != 4) + return -1; /* not a triangle */ - for(i=0; inumpoints-1; i++) { - s += (ring->point[i].x*ring->point[i+1].y - ring->point[i+1].x*ring->point[i].y); - b = MS_MAX(b, msDistancePointToPoint(&ring->point[i], &ring->point[i+1])); + for (i = 0; i < ring->numpoints - 1; i++) { + s += (ring->point[i].x * ring->point[i + 1].y - + ring->point[i + 1].x * ring->point[i].y); + b = MS_MAX(b, msDistancePointToPoint(&ring->point[i], &ring->point[i + 1])); } - return (MS_ABS(s/b)); + return (MS_ABS(s / b)); } static enum MS_RING_DIRECTION mvtGetRingDirection(lineObj *ring) { - int i, sum=0; + int i, sum = 0; - if(ring->numpoints < 4) return MS_DIRECTION_INVALID_RING; + if (ring->numpoints < 4) + return MS_DIRECTION_INVALID_RING; /* step throught the edges */ - for(i=0; inumpoints-1; i++) { - sum += ring->point[i].x * ring->point[i+1].y - ring->point[i+1].x * ring->point[i].y; + for (i = 0; i < ring->numpoints - 1; i++) { + sum += ring->point[i].x * ring->point[i + 1].y - + ring->point[i + 1].x * ring->point[i].y; } - return sum > 0 ? MS_DIRECTION_CLOCKWISE : - sum < 0 ? MS_DIRECTION_COUNTERCLOCKWISE : MS_DIRECTION_INVALID_RING; + return sum > 0 ? MS_DIRECTION_CLOCKWISE + : sum < 0 ? MS_DIRECTION_COUNTERCLOCKWISE + : MS_DIRECTION_INVALID_RING; } static void mvtReverseRingDirection(lineObj *ring) { pointObj temp; - int start=1, end=ring->numpoints-2; /* first and last points are the same so skip 'em */ + int start = 1, end = ring->numpoints - + 2; /* first and last points are the same so skip 'em */ while (start < end) { - temp.x = ring->point[start].x; temp.y = ring->point[start].y; - ring->point[start].x = ring->point[end].x; ring->point[start].y = ring->point[end].y; - ring->point[end].x = temp.x; ring->point[end].y = temp.y; + temp.x = ring->point[start].x; + temp.y = ring->point[start].y; + ring->point[start].x = ring->point[end].x; + ring->point[start].y = ring->point[end].y; + ring->point[end].x = temp.x; + ring->point[end].y = temp.y; start++; end--; } @@ -102,201 +114,228 @@ static void mvtReverseRingDirection(lineObj *ring) { static void mvtReorderRings(shapeObj *shape, int *outers) { int i, j; int t1; - lineObj t2; + lineObj t2; - for(i=0; i<(shape->numlines-1); i++) { - for(j=0; j<(shape->numlines-i-1); j++) { - if(outers[j] < outers[j+1]) { + for (i = 0; i < (shape->numlines - 1); i++) { + for (j = 0; j < (shape->numlines - i - 1); j++) { + if (outers[j] < outers[j + 1]) { /* swap */ - t1 = outers[j]; - outers[j] = outers[j+1]; - outers[j+1] = t1; + t1 = outers[j]; + outers[j] = outers[j + 1]; + outers[j + 1] = t1; - t2 = shape->line[j]; - shape->line[j] = shape->line[j+1]; - shape->line[j+1] = t2; + t2 = shape->line[j]; + shape->line[j] = shape->line[j + 1]; + shape->line[j + 1] = t2; } } } } -static int mvtTransformShape(shapeObj *shape, rectObj *extent, int layer_type, int mvt_layer_extent) { - double scale_x,scale_y; - int i,j,outj; +static int mvtTransformShape(shapeObj *shape, rectObj *extent, int layer_type, + int mvt_layer_extent) { + double scale_x, scale_y; + int i, j, outj; - int *outers=NULL, ring_direction; + int *outers = NULL, ring_direction; - scale_x = (double)mvt_layer_extent/(extent->maxx - extent->minx); - scale_y = (double)mvt_layer_extent/(extent->maxy - extent->miny); + scale_x = (double)mvt_layer_extent / (extent->maxx - extent->minx); + scale_y = (double)mvt_layer_extent / (extent->maxy - extent->miny); - if(layer_type == MS_LAYER_POLYGON) { + if (layer_type == MS_LAYER_POLYGON) { outers = msGetOuterList(shape); /* compute before we muck with the shape */ - if(outers[0] == 0) /* first ring must be an outer */ + if (outers[0] == 0) /* first ring must be an outer */ mvtReorderRings(shape, outers); } - for(i=0;inumlines;i++) { - for(j=0,outj=0;jline[i].numpoints;j++) { + for (i = 0; i < shape->numlines; i++) { + for (j = 0, outj = 0; j < shape->line[i].numpoints; j++) { - shape->line[i].point[outj].x = (int)((shape->line[i].point[j].x - extent->minx)*scale_x); - shape->line[i].point[outj].y = mvt_layer_extent - (int)((shape->line[i].point[j].y - extent->miny)*scale_y); + shape->line[i].point[outj].x = + (int)((shape->line[i].point[j].x - extent->minx) * scale_x); + shape->line[i].point[outj].y = + mvt_layer_extent - + (int)((shape->line[i].point[j].y - extent->miny) * scale_y); - if(!outj || shape->line[i].point[outj].x != shape->line[i].point[outj-1].x || shape->line[i].point[outj].y != shape->line[i].point[outj-1].y) - outj++; /* add the point to the shape only if it's the first one or if it's different than the previous one */ + if (!outj || + shape->line[i].point[outj].x != shape->line[i].point[outj - 1].x || + shape->line[i].point[outj].y != shape->line[i].point[outj - 1].y) + outj++; /* add the point to the shape only if it's the first one or if + it's different than the previous one */ } shape->line[i].numpoints = outj; - if(layer_type == MS_LAYER_POLYGON) { - if(shape->line[i].numpoints == 4 && getTriangleHeight(&shape->line[i]) < 1) { + if (layer_type == MS_LAYER_POLYGON) { + if (shape->line[i].numpoints == 4 && + getTriangleHeight(&shape->line[i]) < 1) { shape->line[i].numpoints = 0; /* so it's not considered anymore */ - continue; /* next ring */ + continue; /* next ring */ } ring_direction = mvtGetRingDirection(&shape->line[i]); - if(ring_direction == MS_DIRECTION_INVALID_RING) + if (ring_direction == MS_DIRECTION_INVALID_RING) shape->line[i].numpoints = 0; /* so it's not considered anymore */ - else if((outers[i] && ring_direction != MS_DIRECTION_CLOCKWISE) || (!outers[i] && ring_direction != MS_DIRECTION_COUNTERCLOCKWISE)) + else if ((outers[i] && ring_direction != MS_DIRECTION_CLOCKWISE) || + (!outers[i] && ring_direction != MS_DIRECTION_COUNTERCLOCKWISE)) mvtReverseRingDirection(&shape->line[i]); } } - msComputeBounds(shape); /* TODO: might need to limit this to just valid parts... */ + msComputeBounds( + shape); /* TODO: might need to limit this to just valid parts... */ msFree(outers); - return (shape->numlines == 0)?MS_FAILURE:MS_SUCCESS; /* sucess if at least one line */ + return (shape->numlines == 0) ? MS_FAILURE + : MS_SUCCESS; /* sucess if at least one line */ } -static int mvtClipShape(shapeObj *shape, int layer_type, int buffer, int mvt_layer_extent) { +static int mvtClipShape(shapeObj *shape, int layer_type, int buffer, + int mvt_layer_extent) { rectObj tile_rect; - tile_rect.minx = tile_rect.miny=-buffer*16; - tile_rect.maxx = tile_rect.maxy=mvt_layer_extent + buffer*16; + tile_rect.minx = tile_rect.miny = -buffer * 16; + tile_rect.maxx = tile_rect.maxy = mvt_layer_extent + buffer * 16; - if(layer_type == MS_LAYER_POLYGON) { + if (layer_type == MS_LAYER_POLYGON) { msClipPolygonRect(shape, tile_rect); - } else if(layer_type == MS_LAYER_LINE) { + } else if (layer_type == MS_LAYER_LINE) { msClipPolylineRect(shape, tile_rect); } /* success if at least one line and not a degenerate bounding box */ - if(shape->numlines > 0 && (layer_type == MS_LAYER_POINT || (shape->bounds.minx != shape->bounds.maxx || shape->bounds.miny != shape->bounds.maxy))) + if (shape->numlines > 0 && (layer_type == MS_LAYER_POINT || + (shape->bounds.minx != shape->bounds.maxx || + shape->bounds.miny != shape->bounds.maxy))) return MS_SUCCESS; else return MS_FAILURE; } -static void freeMvtFeature( VectorTile__Tile__Feature *mvt_feature ) { - if(mvt_feature->tags) +static void freeMvtFeature(VectorTile__Tile__Feature *mvt_feature) { + if (mvt_feature->tags) msFree(mvt_feature->tags); - if(mvt_feature->geometry) + if (mvt_feature->geometry) msFree(mvt_feature->geometry); } -static void freeMvtValue( VectorTile__Tile__Value *mvt_value ) { - if(mvt_value->string_value) +static void freeMvtValue(VectorTile__Tile__Value *mvt_value) { + if (mvt_value->string_value) msFree(mvt_value->string_value); } -static void freeMvtLayer( VectorTile__Tile__Layer *mvt_layer ) { - if(mvt_layer->keys) { - for(unsigned i=0;in_keys; i++) { +static void freeMvtLayer(VectorTile__Tile__Layer *mvt_layer) { + if (mvt_layer->keys) { + for (unsigned i = 0; i < mvt_layer->n_keys; i++) { msFree(mvt_layer->keys[i]); } msFree(mvt_layer->keys); } - if(mvt_layer->values) { - for(unsigned i=0;in_values; i++) { - freeMvtValue(mvt_layer->values[i]); - msFree(mvt_layer->values[i]); + if (mvt_layer->values) { + for (unsigned i = 0; i < mvt_layer->n_values; i++) { + freeMvtValue(mvt_layer->values[i]); + msFree(mvt_layer->values[i]); } msFree(mvt_layer->values); } - if(mvt_layer->features) { - for(unsigned i=0;in_features; i++) { - freeMvtFeature(mvt_layer->features[i]); - msFree(mvt_layer->features[i]); + if (mvt_layer->features) { + for (unsigned i = 0; i < mvt_layer->n_features; i++) { + freeMvtFeature(mvt_layer->features[i]); + msFree(mvt_layer->features[i]); } msFree(mvt_layer->features); } } -int mvtWriteShape( layerObj *layer, shapeObj *shape, VectorTile__Tile__Layer *mvt_layer, - gmlItemListObj *item_list, value_lookup_table *value_lookup_cache, - rectObj *unbuffered_bbox, int buffer) { +int mvtWriteShape(layerObj *layer, shapeObj *shape, + VectorTile__Tile__Layer *mvt_layer, gmlItemListObj *item_list, + value_lookup_table *value_lookup_cache, + rectObj *unbuffered_bbox, int buffer) { VectorTile__Tile__Feature *mvt_feature; - int i,j,iout; + int i, j, iout; value_lookup *value; long int n_geometry; /* could consider an intersection test here */ - if(mvtTransformShape(shape, unbuffered_bbox, layer->type, mvt_layer->extent) != MS_SUCCESS) { + if (mvtTransformShape(shape, unbuffered_bbox, layer->type, + mvt_layer->extent) != MS_SUCCESS) { return MS_SUCCESS; /* degenerate shape */ } - if(mvtClipShape(shape, layer->type, buffer, mvt_layer->extent) != MS_SUCCESS) { + if (mvtClipShape(shape, layer->type, buffer, mvt_layer->extent) != + MS_SUCCESS) { return MS_SUCCESS; /* no features left after clipping */ } n_geometry = 0; - if(layer->type == MS_LAYER_POINT) { - for(i=0;inumlines;i++) + if (layer->type == MS_LAYER_POINT) { + for (i = 0; i < shape->numlines; i++) n_geometry += shape->line[i].numpoints * 2; - if(n_geometry) + if (n_geometry) n_geometry++; /* one MOVETO */ - } else if(layer->type == MS_LAYER_LINE) { - for(i=0;inumlines;i++) - if(shape->line[i].numpoints >= 2) n_geometry += 2 + shape->line[i].numpoints * 2; /* one MOVETO, one LINETO */ - } else { /* MS_LAYER_POLYGON */ - for(i=0;inumlines;i++) - if(shape->line[i].numpoints >= 4) n_geometry += 3 + (shape->line[i].numpoints-1) * 2; /* one MOVETO, one LINETO, one CLOSEPATH (don't consider last duplicate point) */ + } else if (layer->type == MS_LAYER_LINE) { + for (i = 0; i < shape->numlines; i++) + if (shape->line[i].numpoints >= 2) + n_geometry += + 2 + shape->line[i].numpoints * 2; /* one MOVETO, one LINETO */ + } else { /* MS_LAYER_POLYGON */ + for (i = 0; i < shape->numlines; i++) + if (shape->line[i].numpoints >= 4) + n_geometry += 3 + (shape->line[i].numpoints - 1) * + 2; /* one MOVETO, one LINETO, one CLOSEPATH (don't + consider last duplicate point) */ } - if(n_geometry == 0) return MS_SUCCESS; + if (n_geometry == 0) + return MS_SUCCESS; - mvt_layer->features[mvt_layer->n_features++] = msSmallMalloc(sizeof(VectorTile__Tile__Feature)); - mvt_feature = mvt_layer->features[mvt_layer->n_features-1]; + mvt_layer->features[mvt_layer->n_features++] = + msSmallMalloc(sizeof(VectorTile__Tile__Feature)); + mvt_feature = mvt_layer->features[mvt_layer->n_features - 1]; vector_tile__tile__feature__init(mvt_feature); mvt_feature->n_tags = mvt_layer->n_keys * 2; mvt_feature->tags = msSmallMalloc(mvt_feature->n_tags * sizeof(uint32_t)); mvt_feature->id = shape->index; mvt_feature->has_id = 1; - if(layer->type == MS_LAYER_POLYGON) + if (layer->type == MS_LAYER_POLYGON) mvt_feature->type = VECTOR_TILE__TILE__GEOM_TYPE__POLYGON; - else if(layer->type == MS_LAYER_LINE) + else if (layer->type == MS_LAYER_LINE) mvt_feature->type = VECTOR_TILE__TILE__GEOM_TYPE__LINESTRING; else mvt_feature->type = VECTOR_TILE__TILE__GEOM_TYPE__POINT; mvt_feature->has_type = 1; /* output values */ - for( i = 0, iout = 0; i < item_list->numitems; i++ ) { + for (i = 0, iout = 0; i < item_list->numitems; i++) { gmlItemObj *item = item_list->items + i; - if( !item->visible ) + if (!item->visible) continue; UT_HASH_FIND_STR(value_lookup_cache->cache, shape->values[i], value); - if(!value) { + if (!value) { VectorTile__Tile__Value *mvt_value; value = msSmallMalloc(sizeof(value_lookup)); value->value = msStrdup(shape->values[i]); value->index = mvt_layer->n_values; - mvt_layer->values = msSmallRealloc(mvt_layer->values,(++mvt_layer->n_values)*sizeof(VectorTile__Tile__Value*)); - mvt_layer->values[mvt_layer->n_values-1] = msSmallMalloc(sizeof(VectorTile__Tile__Value)); - mvt_value = mvt_layer->values[mvt_layer->n_values-1]; + mvt_layer->values = msSmallRealloc(mvt_layer->values, + (++mvt_layer->n_values) * + sizeof(VectorTile__Tile__Value *)); + mvt_layer->values[mvt_layer->n_values - 1] = + msSmallMalloc(sizeof(VectorTile__Tile__Value)); + mvt_value = mvt_layer->values[mvt_layer->n_values - 1]; vector_tile__tile__value__init(mvt_value); - if( item->type && EQUAL(item->type,"Integer")) { + if (item->type && EQUAL(item->type, "Integer")) { mvt_value->int_value = atoi(value->value); mvt_value->has_int_value = 1; - } else if( item->type && EQUAL(item->type,"Long")) { /* signed */ - mvt_value->sint_value = atol(value->value); - mvt_value->has_sint_value = 1; - } else if( item->type && EQUAL(item->type,"Real")) { + } else if (item->type && EQUAL(item->type, "Long")) { /* signed */ + mvt_value->sint_value = atol(value->value); + mvt_value->has_sint_value = 1; + } else if (item->type && EQUAL(item->type, "Real")) { mvt_value->float_value = atof(value->value); mvt_value->has_float_value = 1; - } else if( item->type && EQUAL(item->type,"Boolean") ) { - if(EQUAL(value->value,"0") || EQUAL(value->value,"false")) + } else if (item->type && EQUAL(item->type, "Boolean")) { + if (EQUAL(value->value, "0") || EQUAL(value->value, "false")) mvt_value->bool_value = 0; else mvt_value->bool_value = 1; @@ -304,52 +343,63 @@ int mvtWriteShape( layerObj *layer, shapeObj *shape, VectorTile__Tile__Layer *mv } else { mvt_value->string_value = msStrdup(value->value); } - UT_HASH_ADD_KEYPTR(hh,value_lookup_cache->cache,value->value, strlen(value->value), value); + UT_HASH_ADD_KEYPTR(hh, value_lookup_cache->cache, value->value, + strlen(value->value), value); } - mvt_feature->tags[iout*2] = iout; - mvt_feature->tags[iout*2+1] = value->index; + mvt_feature->tags[iout * 2] = iout; + mvt_feature->tags[iout * 2 + 1] = value->index; iout++; } /* output geom */ mvt_feature->n_geometry = n_geometry; - mvt_feature->geometry = msSmallMalloc(mvt_feature->n_geometry * sizeof(uint32_t)); - - if(layer->type == MS_LAYER_POINT) { - int idx=0, lastx=0, lasty=0; - mvt_feature->geometry[idx++] = COMMAND(MOVETO, (mvt_feature->n_geometry-1) / 2); - for(i=0;inumlines;i++) { - for(j=0;jline[i].numpoints;j++) { - mvt_feature->geometry[idx++] = PARAMETER(MS_NINT(shape->line[i].point[j].x)-lastx); - mvt_feature->geometry[idx++] = PARAMETER(MS_NINT(shape->line[i].point[j].y)-lasty); + mvt_feature->geometry = + msSmallMalloc(mvt_feature->n_geometry * sizeof(uint32_t)); + + if (layer->type == MS_LAYER_POINT) { + int idx = 0, lastx = 0, lasty = 0; + mvt_feature->geometry[idx++] = + COMMAND(MOVETO, (mvt_feature->n_geometry - 1) / 2); + for (i = 0; i < shape->numlines; i++) { + for (j = 0; j < shape->line[i].numpoints; j++) { + mvt_feature->geometry[idx++] = + PARAMETER(MS_NINT(shape->line[i].point[j].x) - lastx); + mvt_feature->geometry[idx++] = + PARAMETER(MS_NINT(shape->line[i].point[j].y) - lasty); lastx = MS_NINT(shape->line[i].point[j].x); lasty = MS_NINT(shape->line[i].point[j].y); } } } else { /* MS_LAYER_LINE or MS_LAYER_POLYGON */ int numpoints; - int idx=0, lastx=0, lasty=0; - for(i=0;inumlines;i++) { + int idx = 0, lastx = 0, lasty = 0; + for (i = 0; i < shape->numlines; i++) { - if((layer->type == MS_LAYER_LINE && !(shape->line[i].numpoints >= 2)) || - (layer->type == MS_LAYER_POLYGON && !(shape->line[i].numpoints >= 4))) { + if ((layer->type == MS_LAYER_LINE && !(shape->line[i].numpoints >= 2)) || + (layer->type == MS_LAYER_POLYGON && + !(shape->line[i].numpoints >= 4))) { continue; /* skip malformed parts */ } - numpoints = (layer->type == MS_LAYER_LINE)?shape->line[i].numpoints:(shape->line[i].numpoints-1); /* don't consider last point for polygons */ - for(j=0;jtype == MS_LAYER_LINE) + ? shape->line[i].numpoints + : (shape->line[i].numpoints - + 1); /* don't consider last point for polygons */ + for (j = 0; j < numpoints; j++) { + if (j == 0) { mvt_feature->geometry[idx++] = COMMAND(MOVETO, 1); - } else if(j==1) { - mvt_feature->geometry[idx++] = COMMAND(LINETO, numpoints-1); + } else if (j == 1) { + mvt_feature->geometry[idx++] = COMMAND(LINETO, numpoints - 1); } - mvt_feature->geometry[idx++] = PARAMETER(MS_NINT(shape->line[i].point[j].x)-lastx); - mvt_feature->geometry[idx++] = PARAMETER(MS_NINT(shape->line[i].point[j].y)-lasty); - lastx = MS_NINT(shape->line[i].point[j].x); - lasty = MS_NINT(shape->line[i].point[j].y); + mvt_feature->geometry[idx++] = + PARAMETER(MS_NINT(shape->line[i].point[j].x) - lastx); + mvt_feature->geometry[idx++] = + PARAMETER(MS_NINT(shape->line[i].point[j].y) - lasty); + lastx = MS_NINT(shape->line[i].point[j].x); + lasty = MS_NINT(shape->line[i].point[j].y); } - if(layer->type == MS_LAYER_POLYGON) { + if (layer->type == MS_LAYER_POLYGON) { mvt_feature->geometry[idx++] = COMMAND(CLOSEPATH, 1); } } @@ -358,36 +408,41 @@ int mvtWriteShape( layerObj *layer, shapeObj *shape, VectorTile__Tile__Layer *mv return MS_SUCCESS; } -static void freeMvtTile( VectorTile__Tile *mvt_tile ) { - for(unsigned iLayer=0;iLayern_layers;iLayer++) { +static void freeMvtTile(VectorTile__Tile *mvt_tile) { + for (unsigned iLayer = 0; iLayer < mvt_tile->n_layers; iLayer++) { freeMvtLayer(mvt_tile->layers[iLayer]); msFree(mvt_tile->layers[iLayer]); } msFree(mvt_tile->layers); } -int msMVTWriteTile( mapObj *map, int sendheaders ) { - int iLayer,retcode=MS_SUCCESS; +int msMVTWriteTile(mapObj *map, int sendheaders) { + int iLayer, retcode = MS_SUCCESS; unsigned len; void *buf; - const char *mvt_extent = msGetOutputFormatOption(map->outputformat, "EXTENT", "4096"); - const char *mvt_buffer = msGetOutputFormatOption(map->outputformat, "EDGE_BUFFER", "10"); + const char *mvt_extent = + msGetOutputFormatOption(map->outputformat, "EXTENT", "4096"); + const char *mvt_buffer = + msGetOutputFormatOption(map->outputformat, "EDGE_BUFFER", "10"); int buffer = MS_ABS(atoi(mvt_buffer)); VectorTile__Tile mvt_tile = VECTOR_TILE__TILE__INIT; - mvt_tile.layers = msSmallCalloc(map->numlayers, sizeof(VectorTile__Tile__Layer*)); + mvt_tile.layers = + msSmallCalloc(map->numlayers, sizeof(VectorTile__Tile__Layer *)); /* make sure we have a scale and cellsize computed */ map->cellsize = MS_CELLSIZE(map->extent.minx, map->extent.maxx, map->width); - msCalculateScale(map->extent, map->units, map->width, map->height, map->resolution, &map->scaledenom); + msCalculateScale(map->extent, map->units, map->width, map->height, + map->resolution, &map->scaledenom); - /* expand the map->extent so it goes from pixel center (MapServer) to pixel edge (OWS) */ + /* expand the map->extent so it goes from pixel center (MapServer) to pixel + * edge (OWS) */ map->extent.minx -= map->cellsize * 0.5; map->extent.maxx += map->cellsize * 0.5; map->extent.miny -= map->cellsize * 0.5; map->extent.maxy += map->cellsize * 0.5; - for( iLayer = 0; iLayer < map->numlayers; iLayer++ ) { - int status=MS_SUCCESS; + for (iLayer = 0; iLayer < map->numlayers; iLayer++) { + int status = MS_SUCCESS; layerObj *layer = GET_LAYER(map, iLayer); int i; shapeObj shape; @@ -399,19 +454,23 @@ int msMVTWriteTile( mapObj *map, int sendheaders ) { unsigned features_size = 0; - if(!msLayerIsVisible(map, layer)) continue; + if (!msLayerIsVisible(map, layer)) + continue; - if(layer->type != MS_LAYER_POINT && layer->type != MS_LAYER_POLYGON && layer->type != MS_LAYER_LINE) + if (layer->type != MS_LAYER_POINT && layer->type != MS_LAYER_POLYGON && + layer->type != MS_LAYER_LINE) continue; status = msLayerOpen(layer); - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { retcode = status; goto layer_cleanup; } - status = msLayerWhichItems(layer, MS_TRUE, NULL); /* we want all items - behaves like a query in that sense */ - if(status != MS_SUCCESS) { + status = msLayerWhichItems( + layer, MS_TRUE, + NULL); /* we want all items - behaves like a query in that sense */ + if (status != MS_SUCCESS) { retcode = status; goto layer_cleanup; } @@ -419,22 +478,25 @@ int msMVTWriteTile( mapObj *map, int sendheaders ) { /* -------------------------------------------------------------------- */ /* Will we need to reproject? */ /* -------------------------------------------------------------------- */ - layer->project = msProjectionsDiffer(&(layer->projection), &(map->projection)); + layer->project = + msProjectionsDiffer(&(layer->projection), &(map->projection)); rect = map->extent; - if(layer->project) msProjectRect(&(map->projection), &(layer->projection), &rect); + if (layer->project) + msProjectRect(&(map->projection), &(layer->projection), &rect); status = msLayerWhichShapes(layer, rect, MS_TRUE); - if(status == MS_DONE) { /* no overlap - that's ok */ + if (status == MS_DONE) { /* no overlap - that's ok */ retcode = MS_SUCCESS; goto layer_cleanup; - } else if(status != MS_SUCCESS) { + } else if (status != MS_SUCCESS) { retcode = status; goto layer_cleanup; } - mvt_tile.layers[mvt_tile.n_layers++] = msSmallMalloc(sizeof(VectorTile__Tile__Layer)); - mvt_layer = mvt_tile.layers[mvt_tile.n_layers-1]; + mvt_tile.layers[mvt_tile.n_layers++] = + msSmallMalloc(sizeof(VectorTile__Tile__Layer)); + mvt_layer = mvt_tile.layers[mvt_tile.n_layers - 1]; vector_tile__tile__layer__init(mvt_layer); mvt_layer->version = 2; mvt_layer->name = layer->name; @@ -445,18 +507,18 @@ int msMVTWriteTile( mapObj *map, int sendheaders ) { /* -------------------------------------------------------------------- */ /* Create appropriate attributes on this layer. */ /* -------------------------------------------------------------------- */ - item_list = msGMLGetItems( layer, "G" ); - assert( item_list->numitems == layer->numitems ); + item_list = msGMLGetItems(layer, "G"); + assert(item_list->numitems == layer->numitems); - mvt_layer->keys = msSmallMalloc(layer->numitems * sizeof(char*)); + mvt_layer->keys = msSmallMalloc(layer->numitems * sizeof(char *)); - for( i = 0; i < layer->numitems; i++ ) { + for (i = 0; i < layer->numitems; i++) { gmlItemObj *item = item_list->items + i; - if( !item->visible ) + if (!item->visible) continue; - if( item->alias ) + if (item->alias) mvt_layer->keys[mvt_layer->n_keys++] = msStrdup(item->alias); else mvt_layer->keys[mvt_layer->n_keys++] = msStrdup(item->name); @@ -465,109 +527,122 @@ int msMVTWriteTile( mapObj *map, int sendheaders ) { /* -------------------------------------------------------------------- */ /* Setup joins if needed. This is likely untested. */ /* -------------------------------------------------------------------- */ - if(layer->numjoins > 0) { + if (layer->numjoins > 0) { int j; - for(j=0; jnumjoins; j++) { + for (j = 0; j < layer->numjoins; j++) { status = msJoinConnect(layer, &(layer->joins[j])); - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { retcode = status; goto layer_cleanup; } } } - mvt_layer->features = msSmallCalloc(FEATURES_INCREMENT_SIZE, sizeof(VectorTile__Tile__Feature*)); + mvt_layer->features = msSmallCalloc(FEATURES_INCREMENT_SIZE, + sizeof(VectorTile__Tile__Feature *)); features_size = FEATURES_INCREMENT_SIZE; msInitShape(&shape); - while((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) { - - if(layer->numclasses > 0) { - shape.classindex = msShapeGetClass(layer, map, &shape, NULL, -1); /* Perform classification, and some annotation related magic. */ - if(shape.classindex < 0) + while ((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) { + + if (layer->numclasses > 0) { + shape.classindex = msShapeGetClass( + layer, map, &shape, NULL, -1); /* Perform classification, and some + annotation related magic. */ + if (shape.classindex < 0) goto feature_cleanup; /* no matching CLASS found, skip this feature */ } /* ** prepare any necessary JOINs here (one-to-one only) */ - if( layer->numjoins > 0) { + if (layer->numjoins > 0) { int j; - for(j=0; j < layer->numjoins; j++) { - if(layer->joins[j].type == MS_JOIN_ONE_TO_ONE) { + for (j = 0; j < layer->numjoins; j++) { + if (layer->joins[j].type == MS_JOIN_ONE_TO_ONE) { msJoinPrepare(&(layer->joins[j]), &shape); msJoinNext(&(layer->joins[j])); /* fetch the first row */ } } } - if(mvt_layer->n_features == features_size) { /* need to allocate more space */ + if (mvt_layer->n_features == + features_size) { /* need to allocate more space */ features_size += FEATURES_INCREMENT_SIZE; - mvt_layer->features = msSmallRealloc(mvt_layer->features, sizeof(VectorTile__Tile__Feature*)*(features_size)); + mvt_layer->features = msSmallRealloc( + mvt_layer->features, + sizeof(VectorTile__Tile__Feature *) * (features_size)); } - if( layer->project ) { - if( layer->reprojectorLayerToMap == NULL ) - { - layer->reprojectorLayerToMap = msProjectCreateReprojector( - &layer->projection, &map->projection); + if (layer->project) { + if (layer->reprojectorLayerToMap == NULL) { + layer->reprojectorLayerToMap = + msProjectCreateReprojector(&layer->projection, &map->projection); } - if( layer->reprojectorLayerToMap ) - status = msProjectShapeEx(layer->reprojectorLayerToMap, &shape); + if (layer->reprojectorLayerToMap) + status = msProjectShapeEx(layer->reprojectorLayerToMap, &shape); else - status = MS_FAILURE; + status = MS_FAILURE; } - if( status == MS_SUCCESS ) { - status = mvtWriteShape( layer, &shape, mvt_layer, item_list, &value_lookup_cache, &map->extent, buffer ); + if (status == MS_SUCCESS) { + status = mvtWriteShape(layer, &shape, mvt_layer, item_list, + &value_lookup_cache, &map->extent, buffer); } - feature_cleanup: + feature_cleanup: msFreeShape(&shape); - if(status != MS_SUCCESS) goto layer_cleanup; + if (status != MS_SUCCESS) + goto layer_cleanup; } /* next shape */ -layer_cleanup: + layer_cleanup: msLayerClose(layer); msGMLFreeItems(item_list); - UT_HASH_ITER(hh, value_lookup_cache.cache, cur_value_lookup, tmp_value_lookup) { + UT_HASH_ITER(hh, value_lookup_cache.cache, cur_value_lookup, + tmp_value_lookup) { msFree(cur_value_lookup->value); - UT_HASH_DEL(value_lookup_cache.cache,cur_value_lookup); + UT_HASH_DEL(value_lookup_cache.cache, cur_value_lookup); msFree(cur_value_lookup); } - if(retcode != MS_SUCCESS) goto cleanup; + if (retcode != MS_SUCCESS) + goto cleanup; } /* next layer */ - len = vector_tile__tile__get_packed_size(&mvt_tile); // This is the calculated packing length + len = vector_tile__tile__get_packed_size( + &mvt_tile); // This is the calculated packing length buf = msSmallMalloc(len); // Allocate memory vector_tile__tile__pack(&mvt_tile, buf); - if( sendheaders ) { - msIO_fprintf( stdout, - "Content-Length: %d\r\n" - "Content-Type: %s\r\n\r\n", - len, MS_IMAGE_MIME_TYPE(map->outputformat)); + if (sendheaders) { + msIO_fprintf(stdout, + "Content-Length: %d\r\n" + "Content-Type: %s\r\n\r\n", + len, MS_IMAGE_MIME_TYPE(map->outputformat)); } - msIO_fwrite(buf,len,1,stdout); + msIO_fwrite(buf, len, 1, stdout); msFree(buf); - cleanup: +cleanup: freeMvtTile(&mvt_tile); return retcode; } -int msPopulateRendererVTableMVT(rendererVTableObj * renderer) { +int msPopulateRendererVTableMVT(rendererVTableObj *renderer) { (void)renderer; return MS_SUCCESS; } #else -int msPopulateRendererVTableMVT(rendererVTableObj * renderer) { - msSetError(MS_MISCERR, "Vector Tile Driver requested but support is not compiled in", "msPopulateRendererVTableMVT()"); +int msPopulateRendererVTableMVT(rendererVTableObj *renderer) { + msSetError(MS_MISCERR, + "Vector Tile Driver requested but support is not compiled in", + "msPopulateRendererVTableMVT()"); return MS_FAILURE; } -int msMVTWriteTile( mapObj *map, int sendheaders ) { - msSetError(MS_MISCERR, "Vector Tile support is not available.", "msMVTWriteTile()"); +int msMVTWriteTile(mapObj *map, int sendheaders) { + msSetError(MS_MISCERR, "Vector Tile support is not available.", + "msMVTWriteTile()"); return MS_FAILURE; } #endif diff --git a/mapobject.c b/mapobject.c index ffe8c53ac6..91baafe71b 100644 --- a/mapobject.c +++ b/mapobject.c @@ -45,24 +45,23 @@ void freeLegend(legendObj *legend); /* Create a new initialized map object. */ /************************************************************************/ -mapObj *msNewMapObj() -{ +mapObj *msNewMapObj() { mapObj *map = NULL; /* create an empty map, no layers etc... */ - map = (mapObj *)calloc(sizeof(mapObj),1); + map = (mapObj *)calloc(sizeof(mapObj), 1); - if(!map) { + if (!map) { msSetError(MS_MEMERR, NULL, "msCreateMap()"); return NULL; } - if( initMap( map ) == -1 ) { + if (initMap(map) == -1) { msFreeMap(map); return NULL; } - if( msPostMapParseOutputFormatSetup( map ) == MS_FAILURE ) { + if (msPostMapParseOutputFormatSetup(map) == MS_FAILURE) { msFreeMap(map); return NULL; } @@ -74,18 +73,19 @@ mapObj *msNewMapObj() /* msFreeMap() */ /************************************************************************/ -void msFreeMap(mapObj *map) -{ +void msFreeMap(mapObj *map) { int i; - if(!map) return; + if (!map) + return; - /* printf("msFreeMap(): maybe freeing map at %p count=%d.\n",map, map->refcount); */ - if(MS_REFCNT_DECR_IS_NOT_ZERO(map)) { + /* printf("msFreeMap(): maybe freeing map at %p count=%d.\n",map, + * map->refcount); */ + if (MS_REFCNT_DECR_IS_NOT_ZERO(map)) { return; } - if(map->debug >= MS_DEBUGLEVEL_VV) - msDebug("msFreeMap(): freeing map at %p.\n",map); + if (map->debug >= MS_DEBUGLEVEL_VV) + msDebug("msFreeMap(): freeing map at %p.\n", map); msCloseConnections(map); @@ -112,29 +112,31 @@ void msFreeMap(mapObj *map) freeReferenceMap(&(map->reference)); freeLegend(&(map->legend)); - for(i=0; imaxlayers; i++) { - if(GET_LAYER(map, i) != NULL) { + for (i = 0; i < map->maxlayers; i++) { + if (GET_LAYER(map, i) != NULL) { GET_LAYER(map, i)->map = NULL; - if(freeLayer((GET_LAYER(map, i))) == MS_SUCCESS) + if (freeLayer((GET_LAYER(map, i))) == MS_SUCCESS) free(GET_LAYER(map, i)); } } msFree(map->layers); - if(map->layerorder) + if (map->layerorder) free(map->layerorder); msFree(map->templatepattern); msFree(map->datapattern); msFreeHashItems(&(map->configoptions)); - if(map->outputformat && map->outputformat->refcount > 0 && --map->outputformat->refcount < 1) + if (map->outputformat && map->outputformat->refcount > 0 && + --map->outputformat->refcount < 1) msFreeOutputFormat(map->outputformat); - for(i=0; inumoutputformats; i++ ) { - if(map->outputformatlist[i]->refcount > 0 && --map->outputformatlist[i]->refcount < 1) + for (i = 0; i < map->numoutputformats; i++) { + if (map->outputformatlist[i]->refcount > 0 && + --map->outputformatlist[i]->refcount < 1) msFreeOutputFormat(map->outputformatlist[i]); } - if(map->outputformatlist != NULL) + if (map->outputformatlist != NULL) msFree(map->outputformatlist); msFreeQuery(&(map->query)); @@ -151,38 +153,38 @@ void msFreeMap(mapObj *map) /* msGetConfigOption() */ /************************************************************************/ -const char *msGetConfigOption( mapObj *map, const char *key) +const char *msGetConfigOption(mapObj *map, const char *key) { - return msLookupHashTable( &(map->configoptions), key ); + return msLookupHashTable(&(map->configoptions), key); } /************************************************************************/ /* msSetConfigOption() */ /************************************************************************/ -int msSetConfigOption( mapObj *map, const char *key, const char *value) +int msSetConfigOption(mapObj *map, const char *key, const char *value) { /* We have special "early" handling of this so that it will be */ /* in effect when the projection blocks are parsed and pj_init is called. */ - if( strcasecmp(key,"PROJ_LIB") == 0 ) { + if (strcasecmp(key, "PROJ_DATA") == 0 || strcasecmp(key, "PROJ_LIB") == 0) { /* value may be relative to map path */ - msSetPROJ_LIB( value, map->mappath ); + msSetPROJ_DATA(value, map->mappath); } /* Same for MS_ERRORFILE, we want it to kick in as early as possible * to catch parsing errors. * Value can be relative to mapfile, unless it's already absolute */ - if( strcasecmp(key,"MS_ERRORFILE") == 0 ) { - if (msSetErrorFile( value, map->mappath ) != MS_SUCCESS) + if (strcasecmp(key, "MS_ERRORFILE") == 0) { + if (msSetErrorFile(value, map->mappath) != MS_SUCCESS) return MS_FAILURE; } - if( msLookupHashTable( &(map->configoptions), key ) != NULL ) - msRemoveHashTable( &(map->configoptions), key ); - msInsertHashTable( &(map->configoptions), key, value ); + if (msLookupHashTable(&(map->configoptions), key) != NULL) + msRemoveHashTable(&(map->configoptions), key); + msInsertHashTable(&(map->configoptions), key, value); return MS_SUCCESS; } @@ -191,17 +193,16 @@ int msSetConfigOption( mapObj *map, const char *key, const char *value) /* msTestConfigOption() */ /************************************************************************/ -int msTestConfigOption( mapObj *map, const char *key, int default_result ) +int msTestConfigOption(mapObj *map, const char *key, int default_result) { - const char *result = msGetConfigOption( map, key ); + const char *result = msGetConfigOption(map, key); - if( result == NULL ) + if (result == NULL) return default_result; - if( strcasecmp(result,"YES") == 0 - || strcasecmp(result,"ON") == 0 - || strcasecmp(result,"TRUE") == 0 ) + if (strcasecmp(result, "YES") == 0 || strcasecmp(result, "ON") == 0 || + strcasecmp(result, "TRUE") == 0) return MS_TRUE; else return MS_FALSE; @@ -211,47 +212,45 @@ int msTestConfigOption( mapObj *map, const char *key, int default_result ) /* msApplyMapConfigOptions() */ /************************************************************************/ -void msApplyMapConfigOptions( mapObj *map ) +void msApplyMapConfigOptions(mapObj *map) { const char *key; - for( key = msFirstKeyFromHashTable( &(map->configoptions) ); - key != NULL; - key = msNextKeyFromHashTable( &(map->configoptions), key ) ) { - const char *value = msLookupHashTable( &(map->configoptions), key ); - if( strcasecmp(key,"PROJ_LIB") == 0 ) { - msSetPROJ_LIB( value, map->mappath ); - } else if( strcasecmp(key,"MS_ERRORFILE") == 0 ) { - msSetErrorFile( value, map->mappath ); + for (key = msFirstKeyFromHashTable(&(map->configoptions)); key != NULL; + key = msNextKeyFromHashTable(&(map->configoptions), key)) { + const char *value = msLookupHashTable(&(map->configoptions), key); + if (strcasecmp(key, "PROJ_DATA") == 0 || strcasecmp(key, "PROJ_LIB") == 0) { + msSetPROJ_DATA(value, map->mappath); + } else if (strcasecmp(key, "MS_ERRORFILE") == 0) { + msSetErrorFile(value, map->mappath); } else { - CPLSetConfigOption( key, value ); + CPLSetConfigOption(key, value); } } } /************************************************************************/ -/* msMapIgnoreMissingData() */ +/* msMapIgnoreMissingData() */ /************************************************************************/ -int msMapIgnoreMissingData( mapObj *map ) -{ - const char *result = msGetConfigOption( map, "ON_MISSING_DATA" ); +int msMapIgnoreMissingData(mapObj *map) { + const char *result = msGetConfigOption(map, "ON_MISSING_DATA"); const int default_result = #ifndef IGNORE_MISSING_DATA - MS_MISSING_DATA_FAIL; + MS_MISSING_DATA_FAIL; #else - MS_MISSING_DATA_LOG; + MS_MISSING_DATA_LOG; #endif - if( result == NULL ) + if (result == NULL) return default_result; - if( strcasecmp(result,"FAIL") == 0 ) + if (strcasecmp(result, "FAIL") == 0) return MS_MISSING_DATA_FAIL; - else if( strcasecmp(result,"LOG") == 0 ) + else if (strcasecmp(result, "LOG") == 0) return MS_MISSING_DATA_LOG; - else if( strcasecmp(result,"IGNORE") == 0 ) + else if (strcasecmp(result, "IGNORE") == 0) return MS_MISSING_DATA_IGNORE; return default_result; @@ -261,9 +260,8 @@ int msMapIgnoreMissingData( mapObj *map ) /* msMapSetExtent() */ /************************************************************************/ -int msMapSetExtent( mapObj *map, - double minx, double miny, double maxx, double maxy) -{ +int msMapSetExtent(mapObj *map, double minx, double miny, double maxx, + double maxy) { map->extent.minx = minx; map->extent.miny = miny; @@ -271,44 +269,43 @@ int msMapSetExtent( mapObj *map, map->extent.maxy = maxy; if (!MS_VALID_EXTENT(map->extent)) { - msSetError(MS_MISCERR, "Given map extent is invalid. Check that it " \ - "is in the form: minx, miny, maxx, maxy", "setExtent()"); + msSetError(MS_MISCERR, + "Given map extent is invalid. Check that it " + "is in the form: minx, miny, maxx, maxy", + "setExtent()"); return MS_FAILURE; } - map->cellsize = msAdjustExtent(&(map->extent), map->width, - map->height); + map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height); /* if the map size is also set, recompute scale, ignore errors? */ - if( map->width != -1 || map->height != -1 ) + if (map->width != -1 || map->height != -1) msCalculateScale(map->extent, map->units, map->width, map->height, map->resolution, &(map->scaledenom)); - return msMapComputeGeotransform( map ); + return msMapComputeGeotransform(map); } /************************************************************************/ /* msMapOffsetExtent() */ /************************************************************************/ -int msMapOffsetExtent( mapObj *map, double x, double y) -{ - return msMapSetExtent( map, - map->extent.minx + x, map->extent.miny + y, - map->extent.maxx + x, map->extent.maxy + y); +int msMapOffsetExtent(mapObj *map, double x, double y) { + return msMapSetExtent(map, map->extent.minx + x, map->extent.miny + y, + map->extent.maxx + x, map->extent.maxy + y); } /************************************************************************/ /* msMapScaleExtent() */ /************************************************************************/ -int msMapScaleExtent( mapObj *map, double zoomfactor, - double minscaledenom, double maxscaledenom) -{ +int msMapScaleExtent(mapObj *map, double zoomfactor, double minscaledenom, + double maxscaledenom) { double geo_width, geo_height, center_x, center_y, md; if (zoomfactor <= 0.0) { - msSetError(MS_MISCERR, "The given zoomfactor is invalid", "msMapScaleExtent()"); + msSetError(MS_MISCERR, "The given zoomfactor is invalid", + "msMapScaleExtent()"); } geo_width = map->extent.maxx - map->extent.minx; @@ -321,7 +318,8 @@ int msMapScaleExtent( mapObj *map, double zoomfactor, if (minscaledenom > 0 || maxscaledenom > 0) { /* ensure we are within the valid scale domain */ - md = (map->width-1)/(map->resolution * msInchesPerUnit(map->units, center_y)); + md = (map->width - 1) / + (map->resolution * msInchesPerUnit(map->units, center_y)); if (minscaledenom > 0 && geo_width < minscaledenom * md) geo_width = minscaledenom * md; if (maxscaledenom > 0 && geo_width > maxscaledenom * md) @@ -331,57 +329,57 @@ int msMapScaleExtent( mapObj *map, double zoomfactor, geo_width *= 0.5; geo_height = geo_width * map->height / map->width; - return msMapSetExtent( map, - center_x - geo_width, center_y - geo_height, - center_x + geo_width, center_y + geo_height); + return msMapSetExtent(map, center_x - geo_width, center_y - geo_height, + center_x + geo_width, center_y + geo_height); } /************************************************************************/ /* msMapSetCenter() */ /************************************************************************/ -int msMapSetCenter( mapObj *map, pointObj *center) -{ - return msMapOffsetExtent(map, center->x - (map->extent.minx + map->extent.maxx) * 0.5, - center->y - (map->extent.miny + map->extent.maxy) * 0.5); +int msMapSetCenter(mapObj *map, pointObj *center) { + return msMapOffsetExtent( + map, center->x - (map->extent.minx + map->extent.maxx) * 0.5, + center->y - (map->extent.miny + map->extent.maxy) * 0.5); } /************************************************************************/ /* msMapSetRotation() */ /************************************************************************/ -int msMapSetRotation( mapObj *map, double rotation_angle ) +int msMapSetRotation(mapObj *map, double rotation_angle) { map->gt.rotation_angle = rotation_angle; - if( map->gt.rotation_angle != 0.0 ) + if (map->gt.rotation_angle != 0.0) map->gt.need_geotransform = MS_TRUE; else map->gt.need_geotransform = MS_FALSE; - return msMapComputeGeotransform( map ); + return msMapComputeGeotransform(map); } /************************************************************************/ /* msMapSetSize() */ /************************************************************************/ -int msMapSetSize( mapObj *map, int width, int height ) +int msMapSetSize(mapObj *map, int width, int height) { map->width = width; map->height = height; - return msMapComputeGeotransform( map ); /* like SetRotation -- sean */ + return msMapComputeGeotransform(map); /* like SetRotation -- sean */ } /************************************************************************/ /* msMapComputeGeotransform() */ /************************************************************************/ -extern int InvGeoTransform( double *gt_in, double *gt_out ); +extern int InvGeoTransform(double *gt_in, double *gt_out); -int msMapComputeGeotransform( mapObj * map ) +int msMapComputeGeotransformEx(mapObj *map, double resolutionX, + double resolutionY) { double rot_angle; @@ -389,52 +387,56 @@ int msMapComputeGeotransform( mapObj * map ) map->saved_extent = map->extent; - /* Do we have all required parameters? */ - if( map->extent.minx == map->extent.maxx - || map->width == 0 || map->height == 0 ) - return MS_FAILURE; - rot_angle = map->gt.rotation_angle * MS_PI / 180.0; geo_width = map->extent.maxx - map->extent.minx; geo_height = map->extent.maxy - map->extent.miny; - center_x = map->extent.minx + geo_width*0.5; - center_y = map->extent.miny + geo_height*0.5; + center_x = map->extent.minx + geo_width * 0.5; + center_y = map->extent.miny + geo_height * 0.5; /* ** Per bug 1916 we have to adjust for the fact that map extents ** are based on the center of the edge pixels, not the outer ** edges as is expected in a geotransform. */ - map->gt.geotransform[1] = - cos(rot_angle) * geo_width / (map->width-1); - map->gt.geotransform[2] = - sin(rot_angle) * geo_height / (map->height-1); - map->gt.geotransform[0] = center_x - - (map->width * 0.5) * map->gt.geotransform[1] - - (map->height * 0.5) * map->gt.geotransform[2]; - - map->gt.geotransform[4] = - sin(rot_angle) * geo_width / (map->width-1); - map->gt.geotransform[5] = - - cos(rot_angle) * geo_height / (map->height-1); - map->gt.geotransform[3] = center_y - - (map->width * 0.5) * map->gt.geotransform[4] - - (map->height * 0.5) * map->gt.geotransform[5]; - - if( InvGeoTransform( map->gt.geotransform, - map->gt.invgeotransform ) ) + map->gt.geotransform[1] = cos(rot_angle) * resolutionX; + map->gt.geotransform[2] = sin(rot_angle) * resolutionY; + map->gt.geotransform[0] = center_x - + (map->width * 0.5) * map->gt.geotransform[1] - + (map->height * 0.5) * map->gt.geotransform[2]; + + map->gt.geotransform[4] = sin(rot_angle) * resolutionX; + map->gt.geotransform[5] = -cos(rot_angle) * resolutionY; + map->gt.geotransform[3] = center_y - + (map->width * 0.5) * map->gt.geotransform[4] - + (map->height * 0.5) * map->gt.geotransform[5]; + + if (InvGeoTransform(map->gt.geotransform, map->gt.invgeotransform)) return MS_SUCCESS; else return MS_FAILURE; } +int msMapComputeGeotransform(mapObj *map) + +{ + /* Do we have all required parameters? */ + if (map->extent.minx == map->extent.maxx || map->width <= 1 || + map->height <= 1) + return MS_FAILURE; + + const double geo_width = map->extent.maxx - map->extent.minx; + const double geo_height = map->extent.maxy - map->extent.miny; + return msMapComputeGeotransformEx(map, geo_width / (map->width - 1), + geo_height / (map->height - 1)); +} + /************************************************************************/ /* msMapPixelToGeoref() */ /************************************************************************/ -void msMapPixelToGeoref( mapObj *map, double *x, double *y ) +void msMapPixelToGeoref(mapObj *map, double *x, double *y) { (void)map; @@ -447,7 +449,7 @@ void msMapPixelToGeoref( mapObj *map, double *x, double *y ) /* msMapGeorefToPixel() */ /************************************************************************/ -void msMapGeorefToPixel( mapObj *map, double *x, double *y ) +void msMapGeorefToPixel(mapObj *map, double *x, double *y) { (void)map; @@ -460,7 +462,7 @@ void msMapGeorefToPixel( mapObj *map, double *x, double *y ) /* msMapSetFakedExtent() */ /************************************************************************/ -int msMapSetFakedExtent( mapObj *map ) +int msMapSetFakedExtent(mapObj *map) { int i; @@ -491,26 +493,24 @@ int msMapSetFakedExtent( mapObj *map ) /* -------------------------------------------------------------------- */ map->projection.gt = map->gt; - map->projection.gt.geotransform[0] - += map->height * map->gt.geotransform[2]; - map->projection.gt.geotransform[3] - += map->height * map->gt.geotransform[5]; + map->projection.gt.geotransform[0] += map->height * map->gt.geotransform[2]; + map->projection.gt.geotransform[3] += map->height * map->gt.geotransform[5]; map->projection.gt.geotransform[2] *= -1; map->projection.gt.geotransform[5] *= -1; - for(i=0; inumlayers; i++) + for (i = 0; i < map->numlayers; i++) GET_LAYER(map, i)->project = MS_TRUE; - return InvGeoTransform( map->projection.gt.geotransform, - map->projection.gt.invgeotransform ); + return InvGeoTransform(map->projection.gt.geotransform, + map->projection.gt.invgeotransform); } /************************************************************************/ /* msMapRestoreRealExtent() */ /************************************************************************/ -int msMapRestoreRealExtent( mapObj *map ) +int msMapRestoreRealExtent(mapObj *map) { map->projection.gt.need_geotransform = MS_FALSE; @@ -526,8 +526,7 @@ int msMapRestoreRealExtent( mapObj *map ) /* Returns the index at which the layer was inserted */ -int msInsertLayer(mapObj *map, layerObj *layer, int nIndex) -{ +int msInsertLayer(mapObj *map, layerObj *layer, int nIndex) { if (!layer) { msSetError(MS_CHILDERR, "Can't insert a NULL Layer", "msInsertLayer()"); return -1; @@ -539,16 +538,17 @@ int msInsertLayer(mapObj *map, layerObj *layer, int nIndex) return -1; } - /* msGrowMapLayers allocates the new layer which we don't need to do since we have 1 that we are inserting - not sure if it is possible for this to be non null otherwise, but better to check since this function - replaces the value */ - if (map->layers[map->numlayers]!=NULL) + /* msGrowMapLayers allocates the new layer which we don't need to do since we + have 1 that we are inserting not sure if it is possible for this to be non + null otherwise, but better to check since this function replaces the value + */ + if (map->layers[map->numlayers] != NULL) free(map->layers[map->numlayers]); /* Catch attempt to insert past end of layers array */ if (nIndex >= map->numlayers) { msSetError(MS_CHILDERR, "Cannot insert layer beyond index %d", - "msInsertLayer()", map->numlayers-1); + "msInsertLayer()", map->numlayers - 1); return -1; } else if (nIndex < 0) { /* Insert at the end by default */ map->layerorder[map->numlayers] = map->numlayers; @@ -557,28 +557,30 @@ int msInsertLayer(mapObj *map, layerObj *layer, int nIndex) GET_LAYER(map, map->numlayers)->map = map; MS_REFCNT_INCR(layer); map->numlayers++; - return map->numlayers-1; - } else { + return map->numlayers - 1; + } else { /* Move existing layers at the specified nIndex or greater */ /* to an index one higher */ int i; - for (i=map->numlayers; i>nIndex; i--) { - GET_LAYER(map, i)=GET_LAYER(map, i-1); + for (i = map->numlayers; i > nIndex; i--) { + GET_LAYER(map, i) = GET_LAYER(map, i - 1); GET_LAYER(map, i)->index = i; } /* assign new layer to specified index */ - GET_LAYER(map, nIndex)=layer; + GET_LAYER(map, nIndex) = layer; GET_LAYER(map, nIndex)->index = nIndex; GET_LAYER(map, nIndex)->map = map; /* adjust layers drawing order */ - for (i=map->numlayers; i>nIndex; i--) { - map->layerorder[i] = map->layerorder[i-1]; - if (map->layerorder[i] >= nIndex) map->layerorder[i]++; + for (i = map->numlayers; i > nIndex; i--) { + map->layerorder[i] = map->layerorder[i - 1]; + if (map->layerorder[i] >= nIndex) + map->layerorder[i]++; } - for (i=0; ilayerorder[i] >= nIndex) map->layerorder[i]++; + for (i = 0; i < nIndex; i++) { + if (map->layerorder[i] >= nIndex) + map->layerorder[i]++; } map->layerorder[nIndex] = nIndex; @@ -592,8 +594,7 @@ int msInsertLayer(mapObj *map, layerObj *layer, int nIndex) /************************************************************************/ /* msRemoveLayer() */ /************************************************************************/ -layerObj *msRemoveLayer(mapObj *map, int nIndex) -{ +layerObj *msRemoveLayer(mapObj *map, int nIndex) { int i; int order_index; layerObj *layer; @@ -603,38 +604,40 @@ layerObj *msRemoveLayer(mapObj *map, int nIndex) "msRemoveLayer()", nIndex); return NULL; } else { - layer=GET_LAYER(map, nIndex); + layer = GET_LAYER(map, nIndex); /* msCopyLayer(layer, (GET_LAYER(map, nIndex))); */ /* Iteratively copy the higher index layers down one index */ - for (i=nIndex; inumlayers-1; i++) { + for (i = nIndex; i < map->numlayers - 1; i++) { /* freeLayer((GET_LAYER(map, i))); */ /* initLayer((GET_LAYER(map, i)), map); */ /* msCopyLayer(GET_LAYER(map, i), GET_LAYER(map, i+1)); */ - GET_LAYER(map, i)=GET_LAYER(map, i+1); + GET_LAYER(map, i) = GET_LAYER(map, i + 1); GET_LAYER(map, i)->index = i; } /* Free the extra layer at the end */ /* freeLayer((GET_LAYER(map, map->numlayers-1))); */ - GET_LAYER(map, map->numlayers-1)=NULL; + GET_LAYER(map, map->numlayers - 1) = NULL; /* Adjust drawing order */ order_index = 0; - for (i=0; inumlayers; i++) { - if (map->layerorder[i] > nIndex) map->layerorder[i]--; + for (i = 0; i < map->numlayers; i++) { + if (map->layerorder[i] > nIndex) + map->layerorder[i]--; if (map->layerorder[i] == nIndex) { order_index = i; break; } } - for (i=order_index; inumlayers-1; i++) { - map->layerorder[i] = map->layerorder[i+1]; - if (map->layerorder[i] > nIndex) map->layerorder[i]--; + for (i = order_index; i < map->numlayers - 1; i++) { + map->layerorder[i] = map->layerorder[i + 1]; + if (map->layerorder[i] > nIndex) + map->layerorder[i]--; } /* decrement number of layers and return copy of removed layer */ map->numlayers--; - layer->map=NULL; + layer->map = NULL; MS_REFCNT_DECR(layer); return layer; } @@ -644,30 +647,27 @@ layerObj *msRemoveLayer(mapObj *map, int nIndex) ** Move the layer's order for drawing purpose. Moving it up here ** will have the effect of drawing the layer earlier. */ -int msMoveLayerUp(mapObj *map, int nLayerIndex) -{ +int msMoveLayerUp(mapObj *map, int nLayerIndex) { int iCurrentIndex = -1; - if (map && nLayerIndex < map->numlayers && nLayerIndex >=0) { - for (int i=0; inumlayers; i++) { - if ( map->layerorder[i] == nLayerIndex) { + if (map && nLayerIndex < map->numlayers && nLayerIndex >= 0) { + for (int i = 0; i < map->numlayers; i++) { + if (map->layerorder[i] == nLayerIndex) { iCurrentIndex = i; break; } } - if (iCurrentIndex >=0) { + if (iCurrentIndex >= 0) { /* we do not need to promote if it is the first one. */ if (iCurrentIndex == 0) return MS_FAILURE; - map->layerorder[iCurrentIndex] = - map->layerorder[iCurrentIndex-1]; - map->layerorder[iCurrentIndex-1] = nLayerIndex; + map->layerorder[iCurrentIndex] = map->layerorder[iCurrentIndex - 1]; + map->layerorder[iCurrentIndex - 1] = nLayerIndex; return MS_SUCCESS; } } - msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveLayerUp()", - nLayerIndex); + msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveLayerUp()", nLayerIndex); return MS_FAILURE; } @@ -675,24 +675,22 @@ int msMoveLayerUp(mapObj *map, int nLayerIndex) ** Move the layer's order for drawing purpose. Moving it down here ** will have the effect of drawing the layer later. */ -int msMoveLayerDown(mapObj *map, int nLayerIndex) -{ +int msMoveLayerDown(mapObj *map, int nLayerIndex) { int iCurrentIndex = -1; - if (map && nLayerIndex < map->numlayers && nLayerIndex >=0) { - for (int i=0; inumlayers; i++) { - if ( map->layerorder[i] == nLayerIndex) { + if (map && nLayerIndex < map->numlayers && nLayerIndex >= 0) { + for (int i = 0; i < map->numlayers; i++) { + if (map->layerorder[i] == nLayerIndex) { iCurrentIndex = i; break; } } - if (iCurrentIndex >=0) { + if (iCurrentIndex >= 0) { /* we do not need to demote if it is the last one. */ - if (iCurrentIndex == map->numlayers-1) + if (iCurrentIndex == map->numlayers - 1) return MS_FAILURE; - map->layerorder[iCurrentIndex] = - map->layerorder[iCurrentIndex+1]; - map->layerorder[iCurrentIndex+1] = nLayerIndex; + map->layerorder[iCurrentIndex] = map->layerorder[iCurrentIndex + 1]; + map->layerorder[iCurrentIndex + 1] = nLayerIndex; return MS_SUCCESS; } @@ -702,7 +700,6 @@ int msMoveLayerDown(mapObj *map, int nLayerIndex) return MS_FAILURE; } - /* ** Set the array used for the drawing order. The array passed must contain ** all the layer's index ordered by the drawing priority. @@ -717,13 +714,12 @@ int msMoveLayerDown(mapObj *map, int nLayerIndex) ** of elements as the number of layers in the map. ** Return TRUE on success else FALSE. */ -int msSetLayersdrawingOrder(mapObj *self, int *panIndexes) -{ +int msSetLayersdrawingOrder(mapObj *self, int *panIndexes) { if (self && panIndexes) { const int nElements = self->numlayers; - for (int i=0; ilayerorder[i] = panIndexes[i]; } return 1; @@ -743,7 +739,6 @@ int msSetLayersdrawingOrder(mapObj *self, int *panIndexes) return 0; } - /* ========================================================================= msMapLoadOWSParameters @@ -751,32 +746,29 @@ int msSetLayersdrawingOrder(mapObj *self, int *panIndexes) ========================================================================= */ int msMapLoadOWSParameters(mapObj *map, cgiRequestObj *request, - const char *wmtver) -{ + const char *wmtver) { #ifdef USE_WMS_SVR int version; char *wms_exception_format = NULL; - const char *wms_request= NULL; + const char *wms_request = NULL; int result, i = 0; owsRequestObj ows_request; msOWSInitRequestObj(&ows_request); - version = msOWSParseVersionString(wmtver); - for(i=0; iNumParams; i++) { + for (i = 0; i < request->NumParams; i++) { if (strcasecmp(request->ParamNames[i], "EXCEPTIONS") == 0) wms_exception_format = request->ParamValues[i]; else if (strcasecmp(request->ParamNames[i], "REQUEST") == 0) wms_request = request->ParamValues[i]; - } msOWSRequestLayersEnabled(map, "M", wms_request, &ows_request); - result = msWMSLoadGetMapParams(map, version, request->ParamNames, - request->ParamValues, request->NumParams, wms_exception_format, - wms_request, &ows_request); + result = msWMSLoadGetMapParams( + map, version, request->ParamNames, request->ParamValues, + request->NumParams, wms_exception_format, wms_request, &ows_request); msOWSClearRequestObj(&ows_request); @@ -788,4 +780,3 @@ int msMapLoadOWSParameters(mapObj *map, cgiRequestObj *request, return MS_FAILURE; #endif } - diff --git a/mapogcapi.cpp b/mapogcapi.cpp index 4c5c08cd3a..e5ec09d167 100644 --- a/mapogcapi.cpp +++ b/mapogcapi.cpp @@ -6,7 +6,7 @@ * Author: Steve Lime and the MapServer team. * ********************************************************************** - * Copyright (c) 1996-2005 Regents of the University of Minnesota. + * Copyright (c) 1996-2005 Regents of the University of Minnesota. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -55,17 +55,12 @@ using json = nlohmann::json; #define OGCAPI_TEMPLATE_HTML_COLLECTION_ITEM "collection-item.html" #define OGCAPI_TEMPLATE_HTML_OPENAPI "openapi.html" -enum class OGCAPIFormat -{ - JSON, - GeoJSON, - OpenAPI_V3, - HTML -}; +enum class OGCAPIFormat { JSON, GeoJSON, OpenAPI_V3, HTML }; #define OGCAPI_MIMETYPE_JSON "application/json" #define OGCAPI_MIMETYPE_GEOJSON "application/geo+json" -#define OGCAPI_MIMETYPE_OPENAPI_V3 "application/vnd.oai.openapi+json;version=3.0" +#define OGCAPI_MIMETYPE_OPENAPI_V3 \ + "application/vnd.oai.openapi+json;version=3.0" #define OGCAPI_MIMETYPE_HTML "text/html" #define OGCAPI_DEFAULT_LIMIT 10 // by specification @@ -84,21 +79,16 @@ enum class OGCAPIFormat /* ** Returns a JSON object using and a description. */ -static void outputError(int code, const std::string& description) -{ - if(code < 0 || code >= OGCAPI_NUM_ERROR_CODES) code = 0; - - json error_codes = { - { {"text", "ServerError"}, {"status", "500"} }, - { {"text", "ConfigError"}, {"status", "500"} }, - { {"text", "InvalidParamterValue"}, {"status", "400"} }, - { {"text", "NotFound"}, {"status", "404"} } - }; +static void outputError(int code, const std::string &description) { + if (code < 0 || code >= OGCAPI_NUM_ERROR_CODES) + code = 0; - json j = { - { "code", error_codes[code]["text"] }, - { "description", description } - }; + json error_codes = {{{"text", "ServerError"}, {"status", "500"}}, + {{"text", "ConfigError"}, {"status", "500"}}, + {{"text", "InvalidParamterValue"}, {"status", "400"}}, + {{"text", "NotFound"}, {"status", "404"}}}; + + json j = {{"code", error_codes[code]["text"]}, {"description", description}}; std::string status = error_codes[code]["status"]; @@ -109,9 +99,8 @@ static void outputError(int code, const std::string& description) } static int includeLayer(mapObj *map, layerObj *layer) { - if(!msOWSRequestIsEnabled(map, layer, "AO", "OGCAPI", MS_FALSE) || - !msWFSIsLayerSupported(layer) || - !msIsLayerQueryable(layer)) { + if (!msOWSRequestIsEnabled(map, layer, "AO", "OGCAPI", MS_FALSE) || + !msWFSIsLayerSupported(layer) || !msIsLayerQueryable(layer)) { return MS_FALSE; } else { return MS_TRUE; @@ -123,58 +112,63 @@ static int includeLayer(mapObj *map, layerObj *layer) { */ /* -** Returns the value associated with an item from the request's query string and NULL if the item was not found. +** Returns the value associated with an item from the request's query string and +*NULL if the item was not found. */ -static const char *getRequestParameter(cgiRequestObj *request, const char *item) -{ +static const char *getRequestParameter(cgiRequestObj *request, + const char *item) { int i; - for(i=0; iNumParams; i++) { - if(strcmp(item, request->ParamNames[i]) == 0) + for (i = 0; i < request->NumParams; i++) { + if (strcmp(item, request->ParamNames[i]) == 0) return request->ParamValues[i]; } return NULL; } -static int getMaxLimit(mapObj *map, layerObj *layer) -{ +static int getMaxLimit(mapObj *map, layerObj *layer) { int max_limit = OGCAPI_MAX_LIMIT; - const char *value; + const char *value; // check metadata, layer then map value = msOWSLookupMetadata(&(layer->metadata), "A", "max_limit"); - if(value == NULL) value = msOWSLookupMetadata(&(map->web.metadata), "A", "max_limit"); + if (value == NULL) + value = msOWSLookupMetadata(&(map->web.metadata), "A", "max_limit"); - if(value != NULL) { + if (value != NULL) { int status = msStringToInt(value, &max_limit, 10); - if(status != MS_SUCCESS) max_limit = OGCAPI_MAX_LIMIT; // conversion failed + if (status != MS_SUCCESS) + max_limit = OGCAPI_MAX_LIMIT; // conversion failed } return max_limit; } -static int getDefaultLimit(mapObj *map, layerObj *layer) -{ +static int getDefaultLimit(mapObj *map, layerObj *layer) { int default_limit = OGCAPI_DEFAULT_LIMIT; // check metadata, layer then map - const char* value = msOWSLookupMetadata(&(layer->metadata), "A", "default_limit"); - if(value == NULL) value = msOWSLookupMetadata(&(map->web.metadata), "A", "default_limit"); + const char *value = + msOWSLookupMetadata(&(layer->metadata), "A", "default_limit"); + if (value == NULL) + value = msOWSLookupMetadata(&(map->web.metadata), "A", "default_limit"); - if(value != NULL) { + if (value != NULL) { int status = msStringToInt(value, &default_limit, 10); - if(status != MS_SUCCESS) default_limit = OGCAPI_DEFAULT_LIMIT; // conversion failed + if (status != MS_SUCCESS) + default_limit = OGCAPI_DEFAULT_LIMIT; // conversion failed } return default_limit; } /* -** Returns the limit as an int - between 1 and getMaxLimit(). We always return a valid value... +** Returns the limit as an int - between 1 and getMaxLimit(). We always return a +*valid value... */ -static int getLimit(mapObj *map, cgiRequestObj *request, layerObj *layer, int *limit) -{ +static int getLimit(mapObj *map, cgiRequestObj *request, layerObj *layer, + int *limit) { int status; const char *p; @@ -182,15 +176,17 @@ static int getLimit(mapObj *map, cgiRequestObj *request, layerObj *layer, int *l max_limit = getMaxLimit(map, layer); p = getRequestParameter(request, "limit"); - if(!p || (p && strlen(p) == 0)) { // missing or empty - *limit = MS_MIN(getDefaultLimit(map, layer), max_limit); // max could be smaller than the default + if (!p || (p && strlen(p) == 0)) { // missing or empty + *limit = MS_MIN(getDefaultLimit(map, layer), + max_limit); // max could be smaller than the default } else { status = msStringToInt(p, limit, 10); - if(status != MS_SUCCESS) + if (status != MS_SUCCESS) return MS_FAILURE; - if(*limit <= 0) { - *limit = MS_MIN(getDefaultLimit(map, layer), max_limit); // max could be smaller than the default + if (*limit <= 0) { + *limit = MS_MIN(getDefaultLimit(map, layer), + max_limit); // max could be smaller than the default } else { *limit = MS_MIN(*limit, max_limit); } @@ -202,27 +198,27 @@ static int getLimit(mapObj *map, cgiRequestObj *request, layerObj *layer, int *l /* ** Returns the bbox in SRS of the map. */ -static bool getBbox(mapObj *map, cgiRequestObj *request, rectObj *bbox) -{ +static bool getBbox(mapObj *map, cgiRequestObj *request, rectObj *bbox) { int status; const char *p; p = getRequestParameter(request, "bbox"); - if(!p || (p && strlen(p) == 0)) { // missing or empty - assign map->extent (no projection necessary) + if (!p || (p && strlen(p) == 0)) { // missing or empty - assign map->extent + // (no projection necessary) bbox->minx = map->extent.minx; bbox->miny = map->extent.miny; bbox->maxx = map->extent.maxx; bbox->maxy = map->extent.maxy; } else { const auto tokens = msStringSplit(p, ','); - if(tokens.size() != 4) { + if (tokens.size() != 4) { return false; } double values[4]; - for(int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { status = msStringToDouble(tokens[i].c_str(), &values[i]); - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { return false; } } @@ -233,11 +229,13 @@ static bool getBbox(mapObj *map, cgiRequestObj *request, rectObj *bbox) bbox->maxy = values[3]; // validate bbox is well-formed (degenerate is ok) - if(MS_VALID_SEARCH_EXTENT(*bbox) != MS_TRUE) return false; + if (MS_VALID_SEARCH_EXTENT(*bbox) != MS_TRUE) + return false; // at the moment we are assuming the bbox is given in lat/lon status = msProjectRect(&map->latlon, &map->projection, bbox); - if(status != MS_SUCCESS) return false; + if (status != MS_SUCCESS) + return false; } return true; @@ -246,28 +244,30 @@ static bool getBbox(mapObj *map, cgiRequestObj *request, rectObj *bbox) /* ** Returns the template directory location or NULL if it isn't set. */ -static const char *getTemplateDirectory(mapObj *map, const char *key, const char *envvar) -{ +static const char *getTemplateDirectory(mapObj *map, const char *key, + const char *envvar) { const char *directory; - // TODO: if directory is provided then perhaps we need to check for a trailing slash + // TODO: if directory is provided then perhaps we need to check for a trailing + // slash - if((directory = msOWSLookupMetadata(&(map->web.metadata), "A", key)) != NULL) + if ((directory = msOWSLookupMetadata(&(map->web.metadata), "A", key)) != NULL) return directory; - else if((directory = CPLGetConfigOption(envvar, NULL)) != NULL) + else if ((directory = CPLGetConfigOption(envvar, NULL)) != NULL) return directory; else return NULL; } /* -** Returns the service title from oga_{key} and/or ows_{key} or a default value if not set. +** Returns the service title from oga_{key} and/or ows_{key} or a default value +*if not set. */ -static const char *getWebMetadata(mapObj *map, const char* domain, const char* key, const char* defaultVal) -{ +static const char *getWebMetadata(mapObj *map, const char *domain, + const char *key, const char *defaultVal) { const char *value; - if((value = msOWSLookupMetadata(&(map->web.metadata), domain, key)) != NULL) + if ((value = msOWSLookupMetadata(&(map->web.metadata), domain, key)) != NULL) return value; else return defaultVal; @@ -276,107 +276,94 @@ static const char *getWebMetadata(mapObj *map, const char* domain, const char* k /* ** Returns the service title from oga|ows_title or a default value if not set. */ -static const char *getTitle(mapObj *map) -{ +static const char *getTitle(mapObj *map) { return getWebMetadata(map, "OA", "title", OGCAPI_DEFAULT_TITLE); } /* -** Returns the API root URL from oga_onlineresource or builds a value if not set. +** Returns the API root URL from oga_onlineresource or builds a value if not +*set. */ -static std::string getApiRootUrl(mapObj *map) -{ +static std::string getApiRootUrl(mapObj *map) { const char *root; - if((root = msOWSLookupMetadata(&(map->web.metadata), "A", "onlineresource")) != NULL) + if ((root = msOWSLookupMetadata(&(map->web.metadata), "A", + "onlineresource")) != NULL) return std::string(root); else - return "http://" + std::string(getenv("SERVER_NAME")) + ":" + std::string(getenv("SERVER_PORT")) + std::string(getenv("SCRIPT_NAME")) + std::string(getenv("PATH_INFO")); + return "http://" + std::string(getenv("SERVER_NAME")) + ":" + + std::string(getenv("SERVER_PORT")) + + std::string(getenv("SCRIPT_NAME")) + + std::string(getenv("PATH_INFO")); } -static json getFeatureConstant(const gmlConstantObj *constant) -{ +static json getFeatureConstant(const gmlConstantObj *constant) { json j; // empty (null) - if(!constant) throw std::runtime_error("Null constant metadata."); - if(!constant->value) return j; - + if (!constant) + throw std::runtime_error("Null constant metadata."); + if (!constant->value) + return j; + // initialize - j = { { constant->name, constant->value } }; + j = {{constant->name, constant->value}}; return j; } -static json getFeatureItem(const gmlItemObj *item, const char *value) -{ +static json getFeatureItem(const gmlItemObj *item, const char *value) { json j; // empty (null) const char *key; - if(!item) throw std::runtime_error("Null item metadata."); - if(!item->visible) return j; + if (!item) + throw std::runtime_error("Null item metadata."); + if (!item->visible) + return j; - if(item->alias) + if (item->alias) key = item->alias; else key = item->name; // initialize - j = { { key, value } }; - - if( item->type && (EQUAL(item->type, "Date") || - EQUAL(item->type, "DateTime") || - EQUAL(item->type, "Time")) ) { - struct tm tm; - if( msParseTime(value, &tm) == MS_TRUE ) { - char tmpValue[64]; - if( EQUAL(item->type, "Date") ) - snprintf(tmpValue, sizeof(tmpValue), - "%04d-%02d-%02d", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); - else if( EQUAL(item->type, "Time") ) - snprintf(tmpValue, sizeof(tmpValue), - "%02d:%02d:%02dZ", - tm.tm_hour, tm.tm_min, tm.tm_sec); - else - snprintf(tmpValue, sizeof(tmpValue), - "%04d-%02d-%02dT%02d:%02d:%02dZ", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); - - j = { { key, tmpValue } }; - } - } - else if( item->type && (EQUAL(item->type, "Integer") || - EQUAL(item->type, "Long")) ) - { - try - { - j = { { key, std::stoll(value) } }; - } - catch( const std::exception& ) - { - } - } - else if( item->type && EQUAL(item->type, "Real")) - { - try - { - j = { { key, std::stod(value) } }; - } - catch( const std::exception& ) - { - } - } - else if( item->type && EQUAL(item->type, "Boolean")) - { - if( EQUAL(value,"0") || EQUAL(value,"false") ) - { - j = { { key, false } }; - } + j = {{key, value}}; + + if (item->type && + (EQUAL(item->type, "Date") || EQUAL(item->type, "DateTime") || + EQUAL(item->type, "Time"))) { + struct tm tm; + if (msParseTime(value, &tm) == MS_TRUE) { + char tmpValue[64]; + if (EQUAL(item->type, "Date")) + snprintf(tmpValue, sizeof(tmpValue), "%04d-%02d-%02d", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); + else if (EQUAL(item->type, "Time")) + snprintf(tmpValue, sizeof(tmpValue), "%02d:%02d:%02dZ", tm.tm_hour, + tm.tm_min, tm.tm_sec); else - { - j = { { key, true } }; - } + snprintf(tmpValue, sizeof(tmpValue), "%04d-%02d-%02dT%02d:%02d:%02dZ", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, + tm.tm_min, tm.tm_sec); + + j = {{key, tmpValue}}; + } + } else if (item->type && + (EQUAL(item->type, "Integer") || EQUAL(item->type, "Long"))) { + try { + j = {{key, std::stoll(value)}}; + } catch (const std::exception &) { + } + } else if (item->type && EQUAL(item->type, "Real")) { + try { + j = {{key, std::stod(value)}}; + } catch (const std::exception &) { + } + } else if (item->type && EQUAL(item->type, "Boolean")) { + if (EQUAL(value, "0") || EQUAL(value, "false")) { + j = {{key, false}}; + } else { + j = {{key, true}}; + } } return j; @@ -392,69 +379,82 @@ static double round_up(double value, int decimal_places) { return std::ceil(value * multiplier) / multiplier; } -static json getFeatureGeometry(shapeObj *shape, int precision) -{ +static json getFeatureGeometry(shapeObj *shape, int precision) { json geometry; // empty (null) - int *outerList=NULL, numOuterRings=0; + int *outerList = NULL, numOuterRings = 0; - if(!shape) throw std::runtime_error("Null shape."); + if (!shape) + throw std::runtime_error("Null shape."); - switch(shape->type) { - case(MS_SHAPE_POINT): - if(shape->numlines == 0 || shape->line[0].numpoints == 0) // not enough info for a point + switch (shape->type) { + case (MS_SHAPE_POINT): + if (shape->numlines == 0 || + shape->line[0].numpoints == 0) // not enough info for a point return geometry; - if(shape->line[0].numpoints == 1) { + if (shape->line[0].numpoints == 1) { geometry["type"] = "Point"; - geometry["coordinates"] = { round_up(shape->line[0].point[0].x, precision), round_up(shape->line[0].point[0].y, precision) }; + geometry["coordinates"] = { + round_up(shape->line[0].point[0].x, precision), + round_up(shape->line[0].point[0].y, precision)}; } else { geometry["type"] = "MultiPoint"; geometry["coordinates"] = json::array(); - for(int j=0; jline[0].numpoints; j++) { - geometry["coordinates"].push_back( { round_up(shape->line[0].point[j].x, precision), round_up(shape->line[0].point[j].y, precision) } ); + for (int j = 0; j < shape->line[0].numpoints; j++) { + geometry["coordinates"].push_back( + {round_up(shape->line[0].point[j].x, precision), + round_up(shape->line[0].point[j].y, precision)}); } } break; - case(MS_SHAPE_LINE): - if(shape->numlines == 0 || shape->line[0].numpoints < 2) // not enough info for a line + case (MS_SHAPE_LINE): + if (shape->numlines == 0 || + shape->line[0].numpoints < 2) // not enough info for a line return geometry; - if(shape->numlines == 1) { + if (shape->numlines == 1) { geometry["type"] = "LineString"; geometry["coordinates"] = json::array(); - for(int j=0; jline[0].numpoints; j++) { - geometry["coordinates"].push_back( { round_up(shape->line[0].point[j].x, precision), round_up(shape->line[0].point[j].y, precision) } ); + for (int j = 0; j < shape->line[0].numpoints; j++) { + geometry["coordinates"].push_back( + {round_up(shape->line[0].point[j].x, precision), + round_up(shape->line[0].point[j].y, precision)}); } } else { geometry["type"] = "MultiLineString"; geometry["coordinates"] = json::array(); - for(int i=0; inumlines; i++) { + for (int i = 0; i < shape->numlines; i++) { json part = json::array(); - for(int j=0; jline[i].numpoints; j++) { - part.push_back( { round_up(shape->line[i].point[j].x, precision), round_up(shape->line[i].point[j].y, precision) } ); + for (int j = 0; j < shape->line[i].numpoints; j++) { + part.push_back({round_up(shape->line[i].point[j].x, precision), + round_up(shape->line[i].point[j].y, precision)}); } geometry["coordinates"].push_back(part); } } break; - case(MS_SHAPE_POLYGON): - if(shape->numlines == 0 || shape->line[0].numpoints < 4) // not enough info for a polygon (first=last) + case (MS_SHAPE_POLYGON): + if (shape->numlines == 0 || + shape->line[0].numpoints < + 4) // not enough info for a polygon (first=last) return geometry; outerList = msGetOuterList(shape); - if(outerList == NULL) throw std::runtime_error("Unable to allocate list of outer rings."); - for(int k=0; knumlines; k++) { - if(outerList[k] == MS_TRUE) - numOuterRings++; + if (outerList == NULL) + throw std::runtime_error("Unable to allocate list of outer rings."); + for (int k = 0; k < shape->numlines; k++) { + if (outerList[k] == MS_TRUE) + numOuterRings++; } - if(numOuterRings == 1) { + if (numOuterRings == 1) { geometry["type"] = "Polygon"; geometry["coordinates"] = json::array(); - for(int i=0; inumlines; i++) { + for (int i = 0; i < shape->numlines; i++) { json part = json::array(); - for(int j=0; jline[i].numpoints; j++) { - part.push_back( { round_up(shape->line[i].point[j].x, precision), round_up(shape->line[i].point[j].y, precision) } ); + for (int j = 0; j < shape->line[i].numpoints; j++) { + part.push_back({round_up(shape->line[i].point[j].x, precision), + round_up(shape->line[i].point[j].y, precision)}); } geometry["coordinates"].push_back(part); } @@ -462,20 +462,25 @@ static json getFeatureGeometry(shapeObj *shape, int precision) geometry["type"] = "MultiPolygon"; geometry["coordinates"] = json::array(); - for(int k=0; knumlines; k++) { - if(outerList[k] == MS_TRUE) { // outer ring: generate polygon and add to coordinates + for (int k = 0; k < shape->numlines; k++) { + if (outerList[k] == + MS_TRUE) { // outer ring: generate polygon and add to coordinates int *innerList = msGetInnerList(shape, k, outerList); - if(innerList == NULL) { + if (innerList == NULL) { msFree(outerList); throw std::runtime_error("Unable to allocate list of inner rings."); } json polygon = json::array(); - for(int i=0; inumlines; i++) { - if(i == k || outerList[i] == MS_TRUE) { // add outer ring (k) and any inner rings + for (int i = 0; i < shape->numlines; i++) { + if (i == k || + outerList[i] == + MS_TRUE) { // add outer ring (k) and any inner rings json part = json::array(); - for(int j=0; jline[i].numpoints; j++) { - part.push_back( { round_up(shape->line[i].point[j].x, precision), round_up(shape->line[i].point[j].y, precision) } ); + for (int j = 0; j < shape->line[i].numpoints; j++) { + part.push_back( + {round_up(shape->line[i].point[j].x, precision), + round_up(shape->line[i].point[j].y, precision)}); } polygon.push_back(part); } @@ -499,55 +504,61 @@ static json getFeatureGeometry(shapeObj *shape, int precision) /* ** Return a GeoJSON representation of a shape. */ -static json getFeature(layerObj *layer, shapeObj *shape, gmlItemListObj *items, gmlConstantListObj *constants, int geometry_precision) -{ +static json getFeature(layerObj *layer, shapeObj *shape, gmlItemListObj *items, + gmlConstantListObj *constants, int geometry_precision) { int i; json feature; // empty (null) - if(!layer || !shape) throw std::runtime_error("Null arguments."); + if (!layer || !shape) + throw std::runtime_error("Null arguments."); // initialize - feature = { - { "type", "Feature" }, - { "properties", json::object() } - }; + feature = {{"type", "Feature"}, {"properties", json::object()}}; // id - const char *featureIdItem = msOWSLookupMetadata(&(layer->metadata), "AGFO", "featureid"); - if(featureIdItem == NULL) throw std::runtime_error("Missing required featureid metadata."); // should have been trapped earlier - for(i=0; inumitems; i++) { - if(strcasecmp(featureIdItem, items->items[i].name) == 0) { + const char *featureIdItem = + msOWSLookupMetadata(&(layer->metadata), "AGFO", "featureid"); + if (featureIdItem == NULL) + throw std::runtime_error( + "Missing required featureid metadata."); // should have been trapped + // earlier + for (i = 0; i < items->numitems; i++) { + if (strcasecmp(featureIdItem, items->items[i].name) == 0) { feature["id"] = shape->values[i]; break; } } - if(i == items->numitems) throw std::runtime_error("Feature id not found."); + if (i == items->numitems) + throw std::runtime_error("Feature id not found."); // properties - build from items and constants, no group support for now - for(int i=0; inumitems; i++) { + for (int i = 0; i < items->numitems; i++) { try { json item = getFeatureItem(&(items->items[i]), shape->values[i]); - if(!item.is_null()) feature["properties"].insert(item.begin(), item.end()); + if (!item.is_null()) + feature["properties"].insert(item.begin(), item.end()); } catch (const std::runtime_error &) { throw std::runtime_error("Error fetching item."); } } - for(int i=0; inumconstants; i++) { + for (int i = 0; i < constants->numconstants; i++) { try { json constant = getFeatureConstant(&(constants->constants[i])); - if(!constant.is_null()) feature["properties"].insert(constant.begin(), constant.end()); + if (!constant.is_null()) + feature["properties"].insert(constant.begin(), constant.end()); } catch (const std::runtime_error &) { - throw std::runtime_error("Error fetching constant."); + throw std::runtime_error("Error fetching constant."); } } // geometry try { json geometry = getFeatureGeometry(shape, geometry_precision); - if(!geometry.is_null()) feature["geometry"] = geometry; + if (!geometry.is_null()) + feature["geometry"] = geometry; } catch (const std::runtime_error &) { throw std::runtime_error("Error fetching geometry."); } @@ -555,72 +566,85 @@ static json getFeature(layerObj *layer, shapeObj *shape, gmlItemListObj *items, return feature; } -static json getLink(hashTableObj *metadata, const std::string& name) -{ +static json getLink(hashTableObj *metadata, const std::string &name) { json link; - const char *href = msOWSLookupMetadata(metadata, "A", (name + "_href").c_str()); - if(!href) throw std::runtime_error("Missing required link href property."); + const char *href = + msOWSLookupMetadata(metadata, "A", (name + "_href").c_str()); + if (!href) + throw std::runtime_error("Missing required link href property."); - const char *title = msOWSLookupMetadata(metadata, "A", (name + "_title").c_str()); - const char *type = msOWSLookupMetadata(metadata, "A", (name + "_type").c_str()); + const char *title = + msOWSLookupMetadata(metadata, "A", (name + "_title").c_str()); + const char *type = + msOWSLookupMetadata(metadata, "A", (name + "_type").c_str()); - link = { - { "href", href }, - { "title", title?title:href }, - { "type", type?type:"text/html" } - }; + link = {{"href", href}, + {"title", title ? title : href}, + {"type", type ? type : "text/html"}}; return link; } -static const char* getCollectionDescription(layerObj* layer) -{ - const char *description = msOWSLookupMetadata(&(layer->metadata), "A", "description"); - if(!description) description = msOWSLookupMetadata(&(layer->metadata), "OF", "abstract"); // fallback on abstract - if(!description) description = ""; // finally a warning... +static const char *getCollectionDescription(layerObj *layer) { + const char *description = + msOWSLookupMetadata(&(layer->metadata), "A", "description"); + if (!description) + description = msOWSLookupMetadata(&(layer->metadata), "OF", + "abstract"); // fallback on abstract + if (!description) + description = + ""; // finally + // a + // warning... return description; } -static const char* getCollectionTitle(layerObj* layer) -{ - const char* title = msOWSLookupMetadata(&(layer->metadata), "AOF", "title"); - if(!title) title = layer->name; // revert to layer name if no title found - return title; +static const char *getCollectionTitle(layerObj *layer) { + const char *title = msOWSLookupMetadata(&(layer->metadata), "AOF", "title"); + if (!title) + title = layer->name; // revert to layer name if no title found + return title; } -static int getGeometryPrecision(mapObj *map, layerObj *layer) -{ - int geometry_precision = OGCAPI_DEFAULT_GEOMETRY_PRECISION; - if(msOWSLookupMetadata(&(layer->metadata), "AF", "geometry_precision")) { - geometry_precision = atoi(msOWSLookupMetadata(&(layer->metadata), "AF", "geometry_precision")); - } else if(msOWSLookupMetadata(&map->web.metadata, "AF", "geometry_precision")) { - geometry_precision = atoi(msOWSLookupMetadata(&map->web.metadata, "AF", "geometry_precision")); - } - return geometry_precision; +static int getGeometryPrecision(mapObj *map, layerObj *layer) { + int geometry_precision = OGCAPI_DEFAULT_GEOMETRY_PRECISION; + if (msOWSLookupMetadata(&(layer->metadata), "AF", "geometry_precision")) { + geometry_precision = atoi( + msOWSLookupMetadata(&(layer->metadata), "AF", "geometry_precision")); + } else if (msOWSLookupMetadata(&map->web.metadata, "AF", + "geometry_precision")) { + geometry_precision = atoi( + msOWSLookupMetadata(&map->web.metadata, "AF", "geometry_precision")); + } + return geometry_precision; } -static json getCollection(mapObj *map, layerObj *layer, OGCAPIFormat format) -{ +static json getCollection(mapObj *map, layerObj *layer, OGCAPIFormat format) { json collection; // empty (null) rectObj bbox; - if(!map || !layer) return collection; + if (!map || !layer) + return collection; - if(!includeLayer(map, layer)) return collection; + if (!includeLayer(map, layer)) + return collection; // initialize some things std::string api_root = getApiRootUrl(map); - if(msOWSGetLayerExtent(map, layer, "AOF", &bbox) == MS_SUCCESS) { + if (msOWSGetLayerExtent(map, layer, "AOF", &bbox) == MS_SUCCESS) { if (layer->projection.numargs > 0) msOWSProjectToWGS84(&layer->projection, &bbox); else if (map->projection.numargs > 0) msOWSProjectToWGS84(&map->projection, &bbox); else - throw std::runtime_error("Unable to transform bounding box, no projection defined."); + throw std::runtime_error( + "Unable to transform bounding box, no projection defined."); } else { - throw std::runtime_error("Unable to get collection bounding box."); // might be too harsh since extent is optional + throw std::runtime_error( + "Unable to get collection bounding box."); // might be too harsh since + // extent is optional } const char *description = getCollectionDescription(layer); @@ -632,69 +656,64 @@ static json getCollection(mapObj *map, layerObj *layer, OGCAPIFormat format) const int geometry_precision = getGeometryPrecision(map, layer); // build collection object - collection = { - { "id", id }, - { "description", description }, - { "title", title }, - { "extent", { - { "spatial", { - { "bbox", {{ round_down(bbox.minx, geometry_precision), - round_down(bbox.miny, geometry_precision), - round_up(bbox.maxx, geometry_precision), - round_up(bbox.maxy, geometry_precision) }}}, - { "crs", "http://www.opengis.net/def/crs/OGC/1.3/CRS84" } - } - } - } - }, - { "links", { - { - { "rel", format==OGCAPIFormat::JSON?"self":"alternate" }, - { "type", OGCAPI_MIMETYPE_JSON }, - { "title", "This collection as JSON" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + "?f=json" } - },{ - { "rel", format==OGCAPIFormat::HTML?"self":"alternate" }, - { "type", OGCAPI_MIMETYPE_HTML }, - { "title", "This collection as HTML" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + "?f=html" } - },{ - { "rel", "items" }, - { "type", OGCAPI_MIMETYPE_GEOJSON }, - { "title", "Items for this collection as GeoJSON" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + "/items?f=json" } - },{ - { "rel", "items" }, - { "type", OGCAPI_MIMETYPE_HTML }, - { "title", "Items for this collection as HTML" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + "/items?f=html" } - } - - } - }, - { "itemType", "feature" } - }; + collection = {{"id", id}, + {"description", description}, + {"title", title}, + {"extent", + {{"spatial", + {{"bbox", + {{round_down(bbox.minx, geometry_precision), + round_down(bbox.miny, geometry_precision), + round_up(bbox.maxx, geometry_precision), + round_up(bbox.maxy, geometry_precision)}}}, + {"crs", "http://www.opengis.net/def/crs/OGC/1.3/CRS84"}}}}}, + {"links", + {{{"rel", format == OGCAPIFormat::JSON ? "self" : "alternate"}, + {"type", OGCAPI_MIMETYPE_JSON}, + {"title", "This collection as JSON"}, + {"href", api_root + "/collections/" + + std::string(id_encoded) + "?f=json"}}, + {{"rel", format == OGCAPIFormat::HTML ? "self" : "alternate"}, + {"type", OGCAPI_MIMETYPE_HTML}, + {"title", "This collection as HTML"}, + {"href", api_root + "/collections/" + + std::string(id_encoded) + "?f=html"}}, + {{"rel", "items"}, + {"type", OGCAPI_MIMETYPE_GEOJSON}, + {"title", "Items for this collection as GeoJSON"}, + {"href", api_root + "/collections/" + + std::string(id_encoded) + "/items?f=json"}}, + {{"rel", "items"}, + {"type", OGCAPI_MIMETYPE_HTML}, + {"title", "Items for this collection as HTML"}, + {"href", api_root + "/collections/" + + std::string(id_encoded) + "/items?f=html"}} + + }}, + {"itemType", "feature"}}; msFree(id_encoded); // done // handle optional configuration (keywords and links) const char *value = msOWSLookupMetadata(&(layer->metadata), "A", "keywords"); - if(!value) value = msOWSLookupMetadata(&(layer->metadata), "OF", "keywordlist"); // fallback on keywordlist - if(value) { + if (!value) + value = msOWSLookupMetadata(&(layer->metadata), "OF", + "keywordlist"); // fallback on keywordlist + if (value) { std::vector keywords = msStringSplit(value, ','); - for(std::string keyword : keywords) { + for (std::string keyword : keywords) { collection["keywords"].push_back(keyword); } } value = msOWSLookupMetadata(&(layer->metadata), "A", "links"); - if(value) { + if (value) { std::vector names = msStringSplit(value, ','); - for(std::string name : names) { + for (std::string name : names) { try { json link = getLink(&(layer->metadata), name); collection["links"].push_back(link); - } catch(const std::runtime_error &e) { + } catch (const std::runtime_error &e) { throw e; } } @@ -707,20 +726,26 @@ static json getCollection(mapObj *map, layerObj *layer, OGCAPIFormat format) ** Output stuff... */ -static void outputJson(const json& j, const char *mimetype) -{ +static void outputJson(const json &j, const char *mimetype) { + std::string js; + + try { + js = j.dump(); + } catch (...) { + outputError(OGCAPI_CONFIG_ERROR, "Invalid UTF-8 data, check encoding."); + return; + } + msIO_setHeader("Content-Type", "%s", mimetype); msIO_sendHeaders(); - msIO_printf("%s\n", j.dump().c_str()); + msIO_printf("%s\n", js.c_str()); } -static void outputTemplate(const char *directory, const char *filename, const json& j, const char *mimetype) -{ +static void outputTemplate(const char *directory, const char *filename, + const json &j, const char *mimetype) { std::string _directory(directory); std::string _filename(filename); - Environment env {_directory}; // catch - - // somehow need to limit include processing to the directory + Environment env{_directory}; // catch // ERB-style instead of Mustache (we'll see) // env.set_expression("<%=", "%>"); @@ -731,22 +756,32 @@ static void outputTemplate(const char *directory, const char *filename, const js // - contains (substring) // - URL encode + try { + std::string js = j.dump(); + } catch (...) { + outputError(OGCAPI_CONFIG_ERROR, "Invalid UTF-8 data, check encoding."); + return; + } + try { Template t = env.parse_template(_filename); // catch std::string result = env.render(t, j); msIO_setHeader("Content-Type", "%s", mimetype); msIO_sendHeaders(); - msIO_printf("%s\n", result.c_str()); - } catch(const inja::RenderError &e) { - outputError(OGCAPI_CONFIG_ERROR, "Template rendering error. " + std::string(e.what()) + " (" + std::string(filename) + ")."); + msIO_printf("%s\n", result.c_str()); + } catch (const inja::RenderError &e) { + outputError(OGCAPI_CONFIG_ERROR, "Template rendering error. " + + std::string(e.what()) + " (" + + std::string(filename) + ")."); return; - } - catch (const inja::InjaError& e) { - outputError(OGCAPI_CONFIG_ERROR, "InjaError error. " + std::string(e.what()) + " (" + std::string(filename) + ")." - + " (" + std::string(directory) + ")."); - return; - } catch(...) { + } catch (const inja::InjaError &e) { + outputError(OGCAPI_CONFIG_ERROR, "InjaError error. " + + std::string(e.what()) + " (" + + std::string(filename) + ")." + " (" + + std::string(directory) + ")."); + return; + } catch (...) { outputError(OGCAPI_SERVER_ERROR, "General template handling error."); return; } @@ -755,19 +790,22 @@ static void outputTemplate(const char *directory, const char *filename, const js /* ** Generic response outputr. */ -static void outputResponse(mapObj *map, cgiRequestObj *request, OGCAPIFormat format, const char *filename, const json& response) -{ +static void outputResponse(mapObj *map, cgiRequestObj *request, + OGCAPIFormat format, const char *filename, + const json &response) { const char *path = NULL; char fullpath[MS_MAXPATHLEN]; - if(format == OGCAPIFormat::JSON) { + if (format == OGCAPIFormat::JSON) { outputJson(response, OGCAPI_MIMETYPE_JSON); - } else if(format == OGCAPIFormat::GeoJSON) { + } else if (format == OGCAPIFormat::GeoJSON) { outputJson(response, OGCAPI_MIMETYPE_GEOJSON); - } else if(format == OGCAPIFormat::OpenAPI_V3) { + } else if (format == OGCAPIFormat::OpenAPI_V3) { outputJson(response, OGCAPI_MIMETYPE_OPENAPI_V3); - } else if(format == OGCAPIFormat::HTML) { - if((path = getTemplateDirectory(map, "html_template_directory", "OGCAPI_HTML_TEMPLATE_DIRECTORY")) == NULL) { + } else if (format == OGCAPIFormat::HTML) { + if ((path = getTemplateDirectory(map, "html_template_directory", + "OGCAPI_HTML_TEMPLATE_DIRECTORY")) == + NULL) { outputError(OGCAPI_CONFIG_ERROR, "Template directory not set."); return; // bail } @@ -775,36 +813,39 @@ static void outputResponse(mapObj *map, cgiRequestObj *request, OGCAPIFormat for json j; - j["response"] = response; // nest the response so we could write the whole object in the template + j["response"] = response; // nest the response so we could write the whole + // object in the template // extend the JSON with a few things that we need for templating - j["template"] = { - { "path", json::array() }, - { "params", json::object() }, - { "api_root", getApiRootUrl(map) }, - { "title", getTitle(map) }, - { "tags", json::object() } - }; + j["template"] = {{"path", json::array()}, + {"params", json::object()}, + {"api_root", getApiRootUrl(map)}, + {"title", getTitle(map)}, + {"tags", json::object()}}; // api path - for( int i=0; iapi_path_length; i++ ) + for (int i = 0; i < request->api_path_length; i++) j["template"]["path"].push_back(request->api_path[i]); // parameters (optional) - for( int i=0; iNumParams; i++) { - if(request->ParamValues[i] && strlen(request->ParamValues[i]) > 0) { // skip empty params - j["template"]["params"].update({{ request->ParamNames[i], request->ParamValues[i] }}); + for (int i = 0; i < request->NumParams; i++) { + if (request->ParamValues[i] && + strlen(request->ParamValues[i]) > 0) { // skip empty params + j["template"]["params"].update( + {{request->ParamNames[i], request->ParamValues[i]}}); } } // add custom tags (optional) - const char *tags = msOWSLookupMetadata(&(map->web.metadata), "A", "html_tags"); - if(tags) { + const char *tags = + msOWSLookupMetadata(&(map->web.metadata), "A", "html_tags"); + if (tags) { std::vector names = msStringSplit(tags, ','); - for(std::string name : names) { - const char *value = msOWSLookupMetadata(&(map->web.metadata), "A", ("tag_" + name).c_str()); - if(value) { - j["template"]["tags"].update({{ name, value }}); // add object + for (std::string name : names) { + const char *value = msOWSLookupMetadata(&(map->web.metadata), "A", + ("tag_" + name).c_str()); + if (value) { + j["template"]["tags"].update({{name, value}}); // add object } } } @@ -818,77 +859,72 @@ static void outputResponse(mapObj *map, cgiRequestObj *request, OGCAPIFormat for /* ** Process stuff... */ -static int processLandingRequest(mapObj *map, cgiRequestObj *request, OGCAPIFormat format) -{ +static int processLandingRequest(mapObj *map, cgiRequestObj *request, + OGCAPIFormat format) { json response; // define ambiguous elements - const char *description = msOWSLookupMetadata(&(map->web.metadata), "A", "description"); - if(!description) description = msOWSLookupMetadata(&(map->web.metadata), "OF", "abstract"); // fallback on abstract if necessary + const char *description = + msOWSLookupMetadata(&(map->web.metadata), "A", "description"); + if (!description) + description = + msOWSLookupMetadata(&(map->web.metadata), "OF", + "abstract"); // fallback on abstract if necessary // define api root url std::string api_root = getApiRootUrl(map); // build response object // - consider conditionally excluding links for HTML format - response = { - { "title", getTitle(map) }, - { "description", description?description:"" }, - { "links", { - { - { "rel", format==OGCAPIFormat::JSON?"self":"alternate" }, - { "type", OGCAPI_MIMETYPE_JSON }, - { "title", "This document as JSON" }, - { "href", api_root + "?f=json" } - },{ - { "rel", format==OGCAPIFormat::HTML?"self":"alternate" }, - { "type", OGCAPI_MIMETYPE_HTML }, - { "title", "This document as HTML" }, - { "href", api_root + "?f=html" } - },{ - { "rel", "conformance" }, - { "type", OGCAPI_MIMETYPE_JSON }, - { "title", "OCG API conformance classes implemented by this server (JSON)" }, - { "href", api_root + "/conformance?f=json" } - },{ - { "rel", "conformance" }, - { "type", OGCAPI_MIMETYPE_HTML }, - { "title", "OCG API conformance classes implemented by this server" }, - { "href", api_root + "/conformance?f=html" } - },{ - { "rel", "data" }, - { "type", OGCAPI_MIMETYPE_JSON }, - { "title", "Information about feature collections available from this server (JSON)" }, - { "href", api_root + "/collections?f=json" } - },{ - { "rel", "data" }, - { "type", OGCAPI_MIMETYPE_HTML }, - { "title", "Information about feature collections available from this server" }, - { "href", api_root + "/collections?f=html" } - },{ - { "rel", "service-desc" }, - { "type", OGCAPI_MIMETYPE_OPENAPI_V3 }, - { "title", "OpenAPI document" }, - { "href", api_root + "/api?f=json" } - },{ - { "rel", "service-doc" }, - { "type", OGCAPI_MIMETYPE_HTML }, - { "title", "API documentation" }, - { "href", api_root + "/api?f=html" } - } - } - } - }; + response = { + {"title", getTitle(map)}, + {"description", description ? description : ""}, + {"links", + {{{"rel", format == OGCAPIFormat::JSON ? "self" : "alternate"}, + {"type", OGCAPI_MIMETYPE_JSON}, + {"title", "This document as JSON"}, + {"href", api_root + "?f=json"}}, + {{"rel", format == OGCAPIFormat::HTML ? "self" : "alternate"}, + {"type", OGCAPI_MIMETYPE_HTML}, + {"title", "This document as HTML"}, + {"href", api_root + "?f=html"}}, + {{"rel", "conformance"}, + {"type", OGCAPI_MIMETYPE_JSON}, + {"title", + "OCG API conformance classes implemented by this server (JSON)"}, + {"href", api_root + "/conformance?f=json"}}, + {{"rel", "conformance"}, + {"type", OGCAPI_MIMETYPE_HTML}, + {"title", "OCG API conformance classes implemented by this server"}, + {"href", api_root + "/conformance?f=html"}}, + {{"rel", "data"}, + {"type", OGCAPI_MIMETYPE_JSON}, + {"title", "Information about feature collections available from this " + "server (JSON)"}, + {"href", api_root + "/collections?f=json"}}, + {{"rel", "data"}, + {"type", OGCAPI_MIMETYPE_HTML}, + {"title", + "Information about feature collections available from this server"}, + {"href", api_root + "/collections?f=html"}}, + {{"rel", "service-desc"}, + {"type", OGCAPI_MIMETYPE_OPENAPI_V3}, + {"title", "OpenAPI document"}, + {"href", api_root + "/api?f=json"}}, + {{"rel", "service-doc"}, + {"type", OGCAPI_MIMETYPE_HTML}, + {"title", "API documentation"}, + {"href", api_root + "/api?f=html"}}}}}; // handle custom links (optional) const char *links = msOWSLookupMetadata(&(map->web.metadata), "A", "links"); - if(links) { + if (links) { std::vector names = msStringSplit(links, ','); - for(std::string name : names) { + for (std::string name : names) { try { json link = getLink(&(map->web.metadata), name); response["links"].push_back(link); - } catch(const std::runtime_error &e) { + } catch (const std::runtime_error &e) { outputError(OGCAPI_CONFIG_ERROR, std::string(e.what())); return MS_SUCCESS; } @@ -899,29 +935,31 @@ static int processLandingRequest(mapObj *map, cgiRequestObj *request, OGCAPIForm return MS_SUCCESS; } -static int processConformanceRequest(mapObj *map, cgiRequestObj *request, OGCAPIFormat format) -{ +static int processConformanceRequest(mapObj *map, cgiRequestObj *request, + OGCAPIFormat format) { json response; - + // build response object response = { - { "conformsTo", { - "http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/core", - "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections", - "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core", - "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30", - "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/html", - "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson", - } - } - }; - - outputResponse(map, request, format, OGCAPI_TEMPLATE_HTML_CONFORMANCE, response); + {"conformsTo", + { + "http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/core", + "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections", + "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core", + "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30", + "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/html", + "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson", + }}}; + + outputResponse(map, request, format, OGCAPI_TEMPLATE_HTML_CONFORMANCE, + response); return MS_SUCCESS; } -static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, const char *collectionId, const char *featureId, OGCAPIFormat format) -{ +static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, + const char *collectionId, + const char *featureId, + OGCAPIFormat format) { json response; int i; layerObj *layer; @@ -932,19 +970,20 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co int numberMatched = 0; // find the right layer - for(i=0; inumlayers; i++) { - if(strcmp(map->layers[i]->name, collectionId) == 0) break; // match + for (i = 0; i < map->numlayers; i++) { + if (strcmp(map->layers[i]->name, collectionId) == 0) + break; // match } - if(i == map->numlayers) { // invalid collectionId + if (i == map->numlayers) { // invalid collectionId outputError(OGCAPI_NOT_FOUND_ERROR, "Invalid collection."); return MS_SUCCESS; } layer = map->layers[i]; // for convenience - layer->status = MS_ON; // force on (do we need to save and reset?) + layer->status = MS_ON; // force on (do we need to save and reset?) - if(!includeLayer(map, layer)) { + if (!includeLayer(map, layer)) { outputError(OGCAPI_NOT_FOUND_ERROR, "Invalid collection."); return MS_SUCCESS; } @@ -952,20 +991,21 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co // // handle parameters specific to this endpoint // - if(getLimit(map, request, layer, &limit) != MS_SUCCESS) { + if (getLimit(map, request, layer, &limit) != MS_SUCCESS) { outputError(OGCAPI_PARAM_ERROR, "Bad value for limit."); return MS_SUCCESS; } - if(!getBbox(map, request, &bbox)) { + if (!getBbox(map, request, &bbox)) { outputError(OGCAPI_PARAM_ERROR, "Bad value for bbox."); return MS_SUCCESS; } int offset = 0; - if(featureId) { - const char *featureIdItem = msOWSLookupMetadata(&(layer->metadata), "AGFO", "featureid"); - if(featureIdItem == NULL) { + if (featureId) { + const char *featureIdItem = + msOWSLookupMetadata(&(layer->metadata), "AGFO", "featureid"); + if (featureIdItem == NULL) { outputError(OGCAPI_CONFIG_ERROR, "Missing required featureid metadata."); return MS_SUCCESS; } @@ -973,8 +1013,11 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co // TODO: does featureIdItem exist in the data? // optional validation - const char *featureIdValidation = msLookupHashTable(&(layer->validation), featureIdItem); - if(featureIdValidation && msValidateParameter(featureId, featureIdValidation, NULL, NULL, NULL) != MS_SUCCESS) { + const char *featureIdValidation = + msLookupHashTable(&(layer->validation), featureIdItem); + if (featureIdValidation && + msValidateParameter(featureId, featureIdValidation, NULL, NULL, NULL) != + MS_SUCCESS) { outputError(OGCAPI_NOT_FOUND_ERROR, "Invalid feature id."); return MS_SUCCESS; } @@ -989,32 +1032,30 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co map->query.filter.type = MS_STRING; map->query.filter.string = strdup(featureId); - if(msExecuteQuery(map) != MS_SUCCESS) { + if (msExecuteQuery(map) != MS_SUCCESS) { outputError(OGCAPI_NOT_FOUND_ERROR, "Collection items id query failed."); return MS_SUCCESS; } - if(!layer->resultcache || layer->resultcache->numresults != 1) { + if (!layer->resultcache || layer->resultcache->numresults != 1) { outputError(OGCAPI_NOT_FOUND_ERROR, "Collection items id query failed."); return MS_SUCCESS; } } else { // bbox query - const char *compliance_mode = msOWSLookupMetadata(&(map->web.metadata), "A", "compliance_mode"); - if(compliance_mode != NULL && strcasecmp(compliance_mode, "true") == 0) { - for(int j=0; jNumParams; j++) { - const char* paramName = request->ParamNames[j]; - if (strcmp(paramName, "f") == 0 || - strcmp(paramName, "bbox") == 0 || + const char *compliance_mode = + msOWSLookupMetadata(&(map->web.metadata), "A", "compliance_mode"); + if (compliance_mode != NULL && strcasecmp(compliance_mode, "true") == 0) { + for (int j = 0; j < request->NumParams; j++) { + const char *paramName = request->ParamNames[j]; + if (strcmp(paramName, "f") == 0 || strcmp(paramName, "bbox") == 0 || strcmp(paramName, "datetime") == 0 || strcmp(paramName, "limit") == 0 || - strcmp(paramName, "offset") == 0) - { + strcmp(paramName, "offset") == 0) { // ok - } - else - { - outputError(OGCAPI_PARAM_ERROR, + } else { + outputError( + OGCAPI_PARAM_ERROR, (std::string("Unknown query parameter: ") + paramName).c_str()); return MS_SUCCESS; } @@ -1028,50 +1069,49 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co map->query.only_cache_result_count = MS_TRUE; // get number matched - if(msExecuteQuery(map) != MS_SUCCESS) { + if (msExecuteQuery(map) != MS_SUCCESS) { outputError(OGCAPI_NOT_FOUND_ERROR, "Collection items query failed."); return MS_SUCCESS; } - if(!layer->resultcache) { + if (!layer->resultcache) { outputError(OGCAPI_NOT_FOUND_ERROR, "Collection items query failed."); return MS_SUCCESS; } numberMatched = layer->resultcache->numresults; - if( numberMatched > 0 ) { - map->query.only_cache_result_count = MS_FALSE; - map->query.maxfeatures = limit; - - const char* offsetStr = getRequestParameter(request, "offset"); - if( offsetStr ) - { - if( msStringToInt(offsetStr, &offset, 10) != MS_SUCCESS ) - { - outputError(OGCAPI_PARAM_ERROR, "Bad value for offset."); - return MS_SUCCESS; - } - - if(offset < 0 || offset >= numberMatched) { - outputError(OGCAPI_PARAM_ERROR, "Offset out of range."); - return MS_SUCCESS; - } + if (numberMatched > 0) { + map->query.only_cache_result_count = MS_FALSE; + map->query.maxfeatures = limit; - // msExecuteQuery() use a 1-based offst convention, whereas the API - // uses a 0-based offset convention. - map->query.startindex = 1 + offset; + const char *offsetStr = getRequestParameter(request, "offset"); + if (offsetStr) { + if (msStringToInt(offsetStr, &offset, 10) != MS_SUCCESS) { + outputError(OGCAPI_PARAM_ERROR, "Bad value for offset."); + return MS_SUCCESS; } - if(msExecuteQuery(map) != MS_SUCCESS) { - outputError(OGCAPI_NOT_FOUND_ERROR, "Collection items query failed."); + if (offset < 0 || offset >= numberMatched) { + outputError(OGCAPI_PARAM_ERROR, "Offset out of range."); return MS_SUCCESS; } + + // msExecuteQuery() use a 1-based offset convention, whereas the API + // uses a 0-based offset convention. + map->query.startindex = 1 + offset; + layer->startindex = 1 + offset; + } + + if (msExecuteQuery(map) != MS_SUCCESS) { + outputError(OGCAPI_NOT_FOUND_ERROR, "Collection items query failed."); + return MS_SUCCESS; + } } } // build response object - if(!featureId) { + if (!featureId) { std::string api_root = getApiRootUrl(map); const char *id = layer->name; char *id_encoded = msEncodeUrl(id); // free after use @@ -1080,49 +1120,46 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co extra_kvp += "&offset=" + std::to_string(offset); response = { - { "type", "FeatureCollection" }, - { "numberMatched", numberMatched }, - { "numberReturned", layer->resultcache->numresults }, - { "features", json::array() }, - { "links", { - { - { "rel", format==OGCAPIFormat::JSON?"self":"alternate" }, - { "type", OGCAPI_MIMETYPE_GEOJSON }, - { "title", "Items for this collection as GeoJSON" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + "/items?f=json" + extra_kvp } - },{ - { "rel", format==OGCAPIFormat::HTML?"self":"alternate" }, - { "type", OGCAPI_MIMETYPE_HTML }, - { "title", "Items for this collection as HTML" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + "/items?f=html" + extra_kvp } - } - }} - }; - - if( offset + layer->resultcache->numresults < numberMatched ) - { - response["links"].push_back({ - { "rel", "next" }, - { "type", format==OGCAPIFormat::JSON? OGCAPI_MIMETYPE_GEOJSON : OGCAPI_MIMETYPE_HTML }, - { "title", "next page" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + - "/items?f=" + (format==OGCAPIFormat::JSON? "json" : "html") + - "&limit=" + std::to_string(limit) + - "&offset=" + std::to_string(offset + limit) } - }); + {"type", "FeatureCollection"}, + {"numberMatched", numberMatched}, + {"numberReturned", layer->resultcache->numresults}, + {"features", json::array()}, + {"links", + {{{"rel", format == OGCAPIFormat::JSON ? "self" : "alternate"}, + {"type", OGCAPI_MIMETYPE_GEOJSON}, + {"title", "Items for this collection as GeoJSON"}, + {"href", api_root + "/collections/" + std::string(id_encoded) + + "/items?f=json" + extra_kvp}}, + {{"rel", format == OGCAPIFormat::HTML ? "self" : "alternate"}, + {"type", OGCAPI_MIMETYPE_HTML}, + {"title", "Items for this collection as HTML"}, + {"href", api_root + "/collections/" + std::string(id_encoded) + + "/items?f=html" + extra_kvp}}}}}; + + if (offset + layer->resultcache->numresults < numberMatched) { + response["links"].push_back( + {{"rel", "next"}, + {"type", format == OGCAPIFormat::JSON ? OGCAPI_MIMETYPE_GEOJSON + : OGCAPI_MIMETYPE_HTML}, + {"title", "next page"}, + {"href", + api_root + "/collections/" + std::string(id_encoded) + + "/items?f=" + (format == OGCAPIFormat::JSON ? "json" : "html") + + "&limit=" + std::to_string(limit) + + "&offset=" + std::to_string(offset + limit)}}); } - if( offset > 0 ) - { - response["links"].push_back({ - { "rel", "prev" }, - { "type", format==OGCAPIFormat::JSON? OGCAPI_MIMETYPE_GEOJSON : OGCAPI_MIMETYPE_HTML }, - { "title", "previous page" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + - "/items?f=" + (format==OGCAPIFormat::JSON? "json" : "html") + - "&limit=" + std::to_string(limit) + - "&offset=" + std::to_string(MS_MAX(0, (offset - limit))) } - }); + if (offset > 0) { + response["links"].push_back( + {{"rel", "prev"}, + {"type", format == OGCAPIFormat::JSON ? OGCAPI_MIMETYPE_GEOJSON + : OGCAPI_MIMETYPE_HTML}, + {"title", "previous page"}, + {"href", + api_root + "/collections/" + std::string(id_encoded) + + "/items?f=" + (format == OGCAPIFormat::JSON ? "json" : "html") + + "&limit=" + std::to_string(limit) + + "&offset=" + std::to_string(MS_MAX(0, (offset - limit)))}}); } msFree(id_encoded); // done @@ -1137,10 +1174,11 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co gmlItemListObj *items = msGMLGetItems(layer, "AG"); gmlConstantListObj *constants = msGMLGetConstants(layer, "AG"); - if(!items || !constants) { + if (!items || !constants) { msGMLFreeItems(items); msGMLFreeConstants(constants); - outputError(OGCAPI_SERVER_ERROR, "Error fetching layer attribute metadata."); + outputError(OGCAPI_SERVER_ERROR, + "Error fetching layer attribute metadata."); return MS_SUCCESS; } @@ -1148,34 +1186,38 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co // reprojection to EPSG:4326 (if necessary) reprojectionObj *reprojector = NULL; - if(layer->projection.numargs > 0) { - if(msProjectionsDiffer(&(layer->projection), &(map->latlon))) { - reprojector = msProjectCreateReprojector(&(layer->projection), &(map->latlon)); - if(reprojector == NULL) { + if (layer->projection.numargs > 0) { + if (msProjectionsDiffer(&(layer->projection), &(map->latlon))) { + reprojector = + msProjectCreateReprojector(&(layer->projection), &(map->latlon)); + if (reprojector == NULL) { msGMLFreeItems(items); msGMLFreeConstants(constants); outputError(OGCAPI_SERVER_ERROR, "Error creating re-projector."); return MS_SUCCESS; } } - } else if(map->projection.numargs > 0) { - if(msProjectionsDiffer(&(map->projection), &(map->latlon))) { - reprojector = msProjectCreateReprojector(&(map->projection), &(map->latlon)); - if(reprojector == NULL) { - msGMLFreeItems(items); + } else if (map->projection.numargs > 0) { + if (msProjectionsDiffer(&(map->projection), &(map->latlon))) { + reprojector = + msProjectCreateReprojector(&(map->projection), &(map->latlon)); + if (reprojector == NULL) { + msGMLFreeItems(items); msGMLFreeConstants(constants); - outputError(OGCAPI_SERVER_ERROR, "Error creating re-projector."); + outputError(OGCAPI_SERVER_ERROR, "Error creating re-projector."); return MS_SUCCESS; } } } else { - outputError(OGCAPI_CONFIG_ERROR, "Unable to transform geometries, no projection defined."); + outputError(OGCAPI_CONFIG_ERROR, + "Unable to transform geometries, no projection defined."); return MS_SUCCESS; } - for(i=0; iresultcache->numresults; i++) { - int status = msLayerGetShape(layer, &shape, &(layer->resultcache->results[i])); - if(status != MS_SUCCESS) { + for (i = 0; i < layer->resultcache->numresults; i++) { + int status = + msLayerGetShape(layer, &shape, &(layer->resultcache->results[i])); + if (status != MS_SUCCESS) { msGMLFreeItems(items); msGMLFreeConstants(constants); msProjectDestroyReprojector(reprojector); @@ -1183,9 +1225,9 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co return MS_SUCCESS; } - if(reprojector) { + if (reprojector) { status = msProjectShapeEx(reprojector, &shape); - if(status != MS_SUCCESS) { + if (status != MS_SUCCESS) { msGMLFreeItems(items); msGMLFreeConstants(constants); msProjectDestroyReprojector(reprojector); @@ -1196,8 +1238,9 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co } try { - json feature = getFeature(layer, &shape, items, constants, geometry_precision); - if(featureId) { + json feature = + getFeature(layer, &shape, items, constants, geometry_precision); + if (featureId) { response = feature; } else { response["features"].push_back(feature); @@ -1207,7 +1250,8 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co msGMLFreeConstants(constants); msProjectDestroyReprojector(reprojector); msFreeShape(&shape); - outputError(OGCAPI_SERVER_ERROR, "Error getting feature. " + std::string(e.what())); + outputError(OGCAPI_SERVER_ERROR, + "Error getting feature. " + std::string(e.what())); return MS_SUCCESS; } @@ -1220,87 +1264,84 @@ static int processCollectionItemsRequest(mapObj *map, cgiRequestObj *request, co } // extend the response a bit for templating (HERE) - if(format == OGCAPIFormat::HTML) { + if (format == OGCAPIFormat::HTML) { const char *title = getCollectionTitle(layer); const char *id = layer->name; - response["collection"] = { - { "id", id }, - { "title", title?title:"" } - }; + response["collection"] = {{"id", id}, {"title", title ? title : ""}}; } - if(featureId) - { + if (featureId) { std::string api_root = getApiRootUrl(map); const char *id = layer->name; char *id_encoded = msEncodeUrl(id); // free after use response["links"] = { - { - { "rel", format==OGCAPIFormat::JSON?"self":"alternate" }, - { "type", OGCAPI_MIMETYPE_GEOJSON }, - { "title", "This document as GeoJSON" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + - "/items/" + featureId + "?f=json" } - },{ - { "rel", format==OGCAPIFormat::HTML?"self":"alternate" }, - { "type", OGCAPI_MIMETYPE_HTML }, - { "title", "This document as HTML" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + - "/items/" + featureId + "?f=html" } - },{ - { "rel", "collection" }, - { "type", OGCAPI_MIMETYPE_JSON }, - { "title", "This collection as JSON" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + "?f=json" } - },{ - { "rel", "collection" }, - { "type", OGCAPI_MIMETYPE_HTML }, - { "title", "This collection as HTML" }, - { "href", api_root + "/collections/" + std::string(id_encoded) + "?f=html" } - } - }; + {{"rel", format == OGCAPIFormat::JSON ? "self" : "alternate"}, + {"type", OGCAPI_MIMETYPE_GEOJSON}, + {"title", "This document as GeoJSON"}, + {"href", api_root + "/collections/" + std::string(id_encoded) + + "/items/" + featureId + "?f=json"}}, + {{"rel", format == OGCAPIFormat::HTML ? "self" : "alternate"}, + {"type", OGCAPI_MIMETYPE_HTML}, + {"title", "This document as HTML"}, + {"href", api_root + "/collections/" + std::string(id_encoded) + + "/items/" + featureId + "?f=html"}}, + {{"rel", "collection"}, + {"type", OGCAPI_MIMETYPE_JSON}, + {"title", "This collection as JSON"}, + {"href", + api_root + "/collections/" + std::string(id_encoded) + "?f=json"}}, + {{"rel", "collection"}, + {"type", OGCAPI_MIMETYPE_HTML}, + {"title", "This collection as HTML"}, + {"href", + api_root + "/collections/" + std::string(id_encoded) + "?f=html"}}}; msFree(id_encoded); - outputResponse(map, request, format, OGCAPI_TEMPLATE_HTML_COLLECTION_ITEM, response); - } - else - outputResponse(map, request, format, OGCAPI_TEMPLATE_HTML_COLLECTION_ITEMS, response); + outputResponse(map, request, format, OGCAPI_TEMPLATE_HTML_COLLECTION_ITEM, + response); + } else + outputResponse(map, request, format, OGCAPI_TEMPLATE_HTML_COLLECTION_ITEMS, + response); return MS_SUCCESS; } -static int processCollectionRequest(mapObj *map, cgiRequestObj *request, const char *collectionId, OGCAPIFormat format) -{ +static int processCollectionRequest(mapObj *map, cgiRequestObj *request, + const char *collectionId, + OGCAPIFormat format) { json response; int l; - for(l=0; lnumlayers; l++) { - if(strcmp(map->layers[l]->name, collectionId) == 0) break; // match + for (l = 0; l < map->numlayers; l++) { + if (strcmp(map->layers[l]->name, collectionId) == 0) + break; // match } - if(l == map->numlayers) { // invalid collectionId + if (l == map->numlayers) { // invalid collectionId outputError(OGCAPI_NOT_FOUND_ERROR, "Invalid collection."); return MS_SUCCESS; } try { response = getCollection(map, map->layers[l], format); - if(response.is_null()) { // same as not found + if (response.is_null()) { // same as not found outputError(OGCAPI_NOT_FOUND_ERROR, "Invalid collection."); return MS_SUCCESS; } } catch (const std::runtime_error &e) { - outputError(OGCAPI_CONFIG_ERROR, "Error getting collection. " + std::string(e.what())); + outputError(OGCAPI_CONFIG_ERROR, + "Error getting collection. " + std::string(e.what())); return MS_SUCCESS; } - outputResponse(map, request, format, OGCAPI_TEMPLATE_HTML_COLLECTION, response); + outputResponse(map, request, format, OGCAPI_TEMPLATE_HTML_COLLECTION, + response); return MS_SUCCESS; } -static int processCollectionsRequest(mapObj *map, cgiRequestObj *request, OGCAPIFormat format) -{ +static int processCollectionsRequest(mapObj *map, cgiRequestObj *request, + OGCAPIFormat format) { json response; int i; @@ -1308,297 +1349,326 @@ static int processCollectionsRequest(mapObj *map, cgiRequestObj *request, OGCAPI std::string api_root = getApiRootUrl(map); // build response object - response = { - { "links", { - { - { "rel", format==OGCAPIFormat::JSON?"self":"alternate" }, - { "type", OGCAPI_MIMETYPE_JSON }, - { "title", "This document as JSON" }, - { "href", api_root + "/collections?f=json" } - },{ - { "rel", format==OGCAPIFormat::HTML?"self":"alternate" }, - { "type", OGCAPI_MIMETYPE_HTML }, - { "title", "This document as HTML" }, - { "href", api_root + "/collections?f=html" } - } - } - },{ - "collections", json::array() - } - }; - - for(i=0; inumlayers; i++) { + response = {{"links", + {{{"rel", format == OGCAPIFormat::JSON ? "self" : "alternate"}, + {"type", OGCAPI_MIMETYPE_JSON}, + {"title", "This document as JSON"}, + {"href", api_root + "/collections?f=json"}}, + {{"rel", format == OGCAPIFormat::HTML ? "self" : "alternate"}, + {"type", OGCAPI_MIMETYPE_HTML}, + {"title", "This document as HTML"}, + {"href", api_root + "/collections?f=html"}}}}, + {"collections", json::array()}}; + + for (i = 0; i < map->numlayers; i++) { try { json collection = getCollection(map, map->layers[i], format); - if(!collection.is_null()) response["collections"].push_back(collection); + if (!collection.is_null()) + response["collections"].push_back(collection); } catch (const std::runtime_error &e) { - outputError(OGCAPI_CONFIG_ERROR, "Error getting collection." + std::string(e.what())); + outputError(OGCAPI_CONFIG_ERROR, + "Error getting collection." + std::string(e.what())); return MS_SUCCESS; } } - outputResponse(map, request, format, OGCAPI_TEMPLATE_HTML_COLLECTIONS, response); + outputResponse(map, request, format, OGCAPI_TEMPLATE_HTML_COLLECTIONS, + response); return MS_SUCCESS; } -static int processApiRequest(mapObj *map, cgiRequestObj *request, OGCAPIFormat format) -{ - // Strongly inspired from https://github.com/geopython/pygeoapi/blob/master/pygeoapi/openapi.py +static int processApiRequest(mapObj *map, cgiRequestObj *request, + OGCAPIFormat format) { + // Strongly inspired from + // https://github.com/geopython/pygeoapi/blob/master/pygeoapi/openapi.py json response; response = { - { "openapi", "3.0.2" }, - { "tags", json::array() }, + {"openapi", "3.0.2"}, + {"tags", json::array()}, }; response["info"] = { - { "title", getTitle(map) }, - { "version", getWebMetadata(map, "A", "version", "1.0.0") }, + {"title", getTitle(map)}, + {"version", getWebMetadata(map, "A", "version", "1.0.0")}, }; - for( const char* item: { "description", "termsOfService" }) { - const char* value = getWebMetadata(map, "AO", item, nullptr); - if( value ) { - response["info"][item] = value; - } + for (const char *item : {"description", "termsOfService"}) { + const char *value = getWebMetadata(map, "AO", item, nullptr); + if (value) { + response["info"][item] = value; + } } - for( const auto& pair: { - std::make_pair("name", "contactperson"), - std::make_pair("url", "contacturl"), - std::make_pair("email", "contactelectronicmailaddress"), - }) { - const char* value = getWebMetadata(map, "AO", pair.second, nullptr); - if( value ) { - response["info"]["contact"][pair.first] = value; - } + for (const auto &pair : { + std::make_pair("name", "contactperson"), + std::make_pair("url", "contacturl"), + std::make_pair("email", "contactelectronicmailaddress"), + }) { + const char *value = getWebMetadata(map, "AO", pair.second, nullptr); + if (value) { + response["info"]["contact"][pair.first] = value; + } } - for( const auto& pair: { - std::make_pair("name", "licensename"), - std::make_pair("url", "licenseurl"), - }) { - const char* value = getWebMetadata(map, "AO", pair.second, nullptr); - if( value ) { - response["info"]["license"][pair.first] = value; - } + for (const auto &pair : { + std::make_pair("name", "licensename"), + std::make_pair("url", "licenseurl"), + }) { + const char *value = getWebMetadata(map, "AO", pair.second, nullptr); + if (value) { + response["info"]["license"][pair.first] = value; + } } { - const char* value = getWebMetadata(map, "AO", "keywords", nullptr); - if( value ) { - response["info"]["x-keywords"] = value; - } + const char *value = getWebMetadata(map, "AO", "keywords", nullptr); + if (value) { + response["info"]["x-keywords"] = value; + } } json server; server["url"] = getApiRootUrl(map); { - const char* value = getWebMetadata(map, "AO", "server_description", nullptr); - if( value ) { - server["description"] = value; - } + const char *value = + getWebMetadata(map, "AO", "server_description", nullptr); + if (value) { + server["description"] = value; + } } response["servers"].push_back(server); - const std::string oapif_yaml_url = "http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/ogcapi-features-1.yaml"; + const std::string oapif_yaml_url = + "http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/" + "ogcapi-features-1.yaml"; json paths; paths["/"]["get"] = { - { "summary", "Landing page" }, - { "description", "Landing page" }, - { "tags", { "server" } }, - { "operationId", "getLandingPage" }, - { "parameters", { - {{ "$ref", "#/components/parameters/f"}}, - }}, - { "responses", { - { "200", {{"$ref", oapif_yaml_url + "#/components/responses/LandingPage"}} }, - { "400", {{"$ref", oapif_yaml_url + "#/components/responses/InvalidParameter"}} }, - { "500", {{"$ref", oapif_yaml_url + "#/components/responses/ServerError"}} } - }} - }; + {"summary", "Landing page"}, + {"description", "Landing page"}, + {"tags", {"server"}}, + {"operationId", "getLandingPage"}, + {"parameters", + { + {{"$ref", "#/components/parameters/f"}}, + }}, + {"responses", + {{"200", + {{"$ref", oapif_yaml_url + "#/components/responses/LandingPage"}}}, + {"400", + {{"$ref", + oapif_yaml_url + "#/components/responses/InvalidParameter"}}}, + {"500", + {{"$ref", oapif_yaml_url + "#/components/responses/ServerError"}}}}}}; paths["/api"]["get"] = { - { "summary", "API documentation" }, - { "description", "API documentation" }, - { "tags", { "server" } }, - { "operationId", "getOpenapi" }, - { "parameters", { - {{ "$ref", "#/components/parameters/f"}}, - }}, - { "responses", { - { "200", {{"$ref", "#/components/responses/200"}} }, - { "400", {{"$ref", oapif_yaml_url + "#/components/responses/InvalidParameter"}} }, - { "default", {{"$ref", "#/components/responses/default"}} } - }} - }; + {"summary", "API documentation"}, + {"description", "API documentation"}, + {"tags", {"server"}}, + {"operationId", "getOpenapi"}, + {"parameters", + { + {{"$ref", "#/components/parameters/f"}}, + }}, + {"responses", + {{"200", {{"$ref", "#/components/responses/200"}}}, + {"400", + {{"$ref", + oapif_yaml_url + "#/components/responses/InvalidParameter"}}}, + {"default", {{"$ref", "#/components/responses/default"}}}}}}; paths["/conformance"]["get"] = { - { "summary", "API conformance definition" }, - { "description", "API conformance definition" }, - { "tags", { "server" } }, - { "operationId", "getConformanceDeclaration" }, - { "parameters", { - {{ "$ref", "#/components/parameters/f"}}, - }}, - { "responses", { - { "200", {{"$ref", oapif_yaml_url + "#/components/responses/ConformanceDeclaration"}} }, - { "400", {{"$ref", oapif_yaml_url + "#/components/responses/InvalidParameter"}} }, - { "500", {{"$ref", oapif_yaml_url + "#/components/responses/ServerError"}} } - }} - }; + {"summary", "API conformance definition"}, + {"description", "API conformance definition"}, + {"tags", {"server"}}, + {"operationId", "getConformanceDeclaration"}, + {"parameters", + { + {{"$ref", "#/components/parameters/f"}}, + }}, + {"responses", + {{"200", + {{"$ref", + oapif_yaml_url + "#/components/responses/ConformanceDeclaration"}}}, + {"400", + {{"$ref", + oapif_yaml_url + "#/components/responses/InvalidParameter"}}}, + {"500", + {{"$ref", oapif_yaml_url + "#/components/responses/ServerError"}}}}}}; paths["/collections"]["get"] = { - { "summary", "Collections" }, - { "description", "Collections" }, - { "tags", { "server" } }, - { "operationId", "getCollections" }, - { "parameters", { - {{ "$ref", "#/components/parameters/f"}}, - }}, - { "responses", { - { "200", {{"$ref", oapif_yaml_url + "#/components/responses/Collections"}} }, - { "400", {{"$ref", oapif_yaml_url + "#/components/responses/InvalidParameter"}} }, - { "500", {{"$ref", oapif_yaml_url + "#/components/responses/ServerError"}} } - }} - }; - - for(int i=0; inumlayers; i++) { - layerObj* layer = map->layers[i]; - if(!includeLayer(map, layer)) { - continue; - } + {"summary", "Collections"}, + {"description", "Collections"}, + {"tags", {"server"}}, + {"operationId", "getCollections"}, + {"parameters", + { + {{"$ref", "#/components/parameters/f"}}, + }}, + {"responses", + {{"200", + {{"$ref", oapif_yaml_url + "#/components/responses/Collections"}}}, + {"400", + {{"$ref", + oapif_yaml_url + "#/components/responses/InvalidParameter"}}}, + {"500", + {{"$ref", oapif_yaml_url + "#/components/responses/ServerError"}}}}}}; + + for (int i = 0; i < map->numlayers; i++) { + layerObj *layer = map->layers[i]; + if (!includeLayer(map, layer)) { + continue; + } - json collection_get = { - { "summary", std::string("Get ") + getCollectionTitle(layer) + " metadata" }, - { "description", getCollectionDescription(layer) }, - { "tags", { layer->name } }, - { "operationId", "describe" + std::string(layer->name) + "Collection" }, - { "parameters", { - {{ "$ref", "#/components/parameters/f"}}, - }}, - { "responses", { - { "200", {{"$ref", oapif_yaml_url + "#/components/responses/Collection"}} }, - { "400", {{"$ref", oapif_yaml_url + "#/components/responses/InvalidParameter"}} }, - { "500", {{"$ref", oapif_yaml_url + "#/components/responses/ServerError"}} } - }} - }; - - std::string collectionNamePath("/collections/"); - collectionNamePath += layer->name; - paths[collectionNamePath]["get"] = collection_get; - - // check metadata, layer then map - const char* max_limit_str = msOWSLookupMetadata(&(layer->metadata), "A", "max_limit"); - if(max_limit_str == nullptr) - max_limit_str = msOWSLookupMetadata(&(map->web.metadata), "A", "max_limit"); - const int max_limit = max_limit_str ? atoi(max_limit_str) : OGCAPI_MAX_LIMIT; - const int default_limit = getDefaultLimit(map, layer); - - json items_get = { - { "summary", std::string("Get ") + getCollectionTitle(layer) + " items" }, - { "description", getCollectionDescription(layer) }, - { "tags", { layer->name } }, - { "operationId", "get" + std::string(layer->name) + "Features" }, - { "parameters", { - {{ "$ref", "#/components/parameters/f"}}, - {{ "$ref", oapif_yaml_url + "#/components/parameters/bbox"}}, - {{ "$ref", oapif_yaml_url + "#/components/parameters/datetime"}}, - {{ "$ref", "#/components/parameters/offset"}}, - }}, - { "responses", { - { "200", {{"$ref", oapif_yaml_url + "#/components/responses/Features"}} }, - { "400", {{"$ref", oapif_yaml_url + "#/components/responses/InvalidParameter"}} }, - { "500", {{"$ref", oapif_yaml_url + "#/components/responses/ServerError"}} } - }} - }; - - json param_limit = { - { "name", "limit"}, - { "in", "query"}, - { "description", "The optional limit parameter limits the number of items that are presented in the response document."}, - { "required", false}, - { "schema", { - { "type", "integer"}, - { "minimum", 1}, - { "maximum", max_limit}, - { "default", default_limit}, - }}, - { "style", "form" }, - { "explode", false }, - }; - items_get["parameters"].emplace_back(param_limit); - - std::string itemsPath(collectionNamePath + "/items"); - paths[itemsPath]["get"] = items_get; - - json feature_id_get = { - { "summary", std::string("Get ") + getCollectionTitle(layer) + " item by id" }, - { "description", getCollectionDescription(layer) }, - { "tags", { layer->name } }, - { "operationId", "get" + std::string(layer->name) + "Feature" }, - { "parameters", { - {{ "$ref", "#/components/parameters/f"}}, - {{ "$ref", oapif_yaml_url + "#/components/parameters/featureId"}}, - }}, - { "responses", { - { "200", {{"$ref", oapif_yaml_url + "#/components/responses/Feature"}} }, - { "400", {{"$ref", oapif_yaml_url + "#/components/responses/InvalidParameter"}} }, - { "404", {{"$ref", oapif_yaml_url + "#/components/responses/NotFound"}} }, - { "500", {{"$ref", oapif_yaml_url + "#/components/responses/ServerError"}} } - }} - }; - std::string itemsFeatureIdPath(collectionNamePath + "/items/{featureId}"); - paths[itemsFeatureIdPath]["get"] = feature_id_get; + json collection_get = { + {"summary", + std::string("Get ") + getCollectionTitle(layer) + " metadata"}, + {"description", getCollectionDescription(layer)}, + {"tags", {layer->name}}, + {"operationId", "describe" + std::string(layer->name) + "Collection"}, + {"parameters", + { + {{"$ref", "#/components/parameters/f"}}, + }}, + {"responses", + {{"200", + {{"$ref", oapif_yaml_url + "#/components/responses/Collection"}}}, + {"400", + {{"$ref", + oapif_yaml_url + "#/components/responses/InvalidParameter"}}}, + {"500", + {{"$ref", + oapif_yaml_url + "#/components/responses/ServerError"}}}}}}; + + std::string collectionNamePath("/collections/"); + collectionNamePath += layer->name; + paths[collectionNamePath]["get"] = collection_get; + + // check metadata, layer then map + const char *max_limit_str = + msOWSLookupMetadata(&(layer->metadata), "A", "max_limit"); + if (max_limit_str == nullptr) + max_limit_str = + msOWSLookupMetadata(&(map->web.metadata), "A", "max_limit"); + const int max_limit = + max_limit_str ? atoi(max_limit_str) : OGCAPI_MAX_LIMIT; + const int default_limit = getDefaultLimit(map, layer); + + json items_get = { + {"summary", std::string("Get ") + getCollectionTitle(layer) + " items"}, + {"description", getCollectionDescription(layer)}, + {"tags", {layer->name}}, + {"operationId", "get" + std::string(layer->name) + "Features"}, + {"parameters", + { + {{"$ref", "#/components/parameters/f"}}, + {{"$ref", oapif_yaml_url + "#/components/parameters/bbox"}}, + {{"$ref", oapif_yaml_url + "#/components/parameters/datetime"}}, + {{"$ref", "#/components/parameters/offset"}}, + }}, + {"responses", + {{"200", + {{"$ref", oapif_yaml_url + "#/components/responses/Features"}}}, + {"400", + {{"$ref", + oapif_yaml_url + "#/components/responses/InvalidParameter"}}}, + {"500", + {{"$ref", + oapif_yaml_url + "#/components/responses/ServerError"}}}}}}; + + json param_limit = { + {"name", "limit"}, + {"in", "query"}, + {"description", "The optional limit parameter limits the number of " + "items that are presented in the response document."}, + {"required", false}, + {"schema", + { + {"type", "integer"}, + {"minimum", 1}, + {"maximum", max_limit}, + {"default", default_limit}, + }}, + {"style", "form"}, + {"explode", false}, + }; + items_get["parameters"].emplace_back(param_limit); + + std::string itemsPath(collectionNamePath + "/items"); + paths[itemsPath]["get"] = items_get; + + json feature_id_get = { + {"summary", + std::string("Get ") + getCollectionTitle(layer) + " item by id"}, + {"description", getCollectionDescription(layer)}, + {"tags", {layer->name}}, + {"operationId", "get" + std::string(layer->name) + "Feature"}, + {"parameters", + { + {{"$ref", "#/components/parameters/f"}}, + {{"$ref", oapif_yaml_url + "#/components/parameters/featureId"}}, + }}, + {"responses", + {{"200", + {{"$ref", oapif_yaml_url + "#/components/responses/Feature"}}}, + {"400", + {{"$ref", + oapif_yaml_url + "#/components/responses/InvalidParameter"}}}, + {"404", + {{"$ref", oapif_yaml_url + "#/components/responses/NotFound"}}}, + {"500", + {{"$ref", + oapif_yaml_url + "#/components/responses/ServerError"}}}}}}; + std::string itemsFeatureIdPath(collectionNamePath + "/items/{featureId}"); + paths[itemsFeatureIdPath]["get"] = feature_id_get; } response["paths"] = paths; json components; - components["responses"]["200"] = { - { "description", "successful operation" } - }; + components["responses"]["200"] = {{"description", "successful operation"}}; components["responses"]["default"] = { - { "description", "unexpected error" }, - { "content", { - { "application/json", { - { "schema", { - { "$ref", "https://raw.githubusercontent.com/opengeospatial/ogcapi-processes/master/core/openapi/schemas/exception.yaml" } - }} - }} - }} - }; + {"description", "unexpected error"}, + {"content", + {{"application/json", + {{"schema", + {{"$ref", "https://raw.githubusercontent.com/opengeospatial/" + "ogcapi-processes/master/core/openapi/schemas/" + "exception.yaml"}}}}}}}}; json parameters; parameters["f"] = { - { "name", "f"}, - { "in", "query"}, - { "description", "The optional f parameter indicates the output format which the server shall provide as part of the response document. The default format is GeoJSON."}, - { "required", false}, - { "schema", { - { "type", "string"}, - {"enum", {"json", "html"}}, - {"default", "json"} - }}, - { "style", "form" }, - { "explode", false }, + {"name", "f"}, + {"in", "query"}, + {"description", "The optional f parameter indicates the output format " + "which the server shall provide as part of the response " + "document. The default format is GeoJSON."}, + {"required", false}, + {"schema", + {{"type", "string"}, {"enum", {"json", "html"}}, {"default", "json"}}}, + {"style", "form"}, + {"explode", false}, }; parameters["offset"] = { - { "name", "offset"}, - { "in", "query"}, - { "description", "The optional offset parameter indicates the index within the result set from which the server shall begin presenting results in the response document. The first element has an index of 0 (default)."}, - { "required", false}, - { "schema", { - { "type", "integer"}, - { "minimum", 0}, - { "default", 0}, - }}, - { "style", "form" }, - { "explode", false }, + {"name", "offset"}, + {"in", "query"}, + {"description", + "The optional offset parameter indicates the index within the result " + "set from which the server shall begin presenting results in the " + "response document. The first element has an index of 0 (default)."}, + {"required", false}, + {"schema", + { + {"type", "integer"}, + {"minimum", 0}, + {"default", 0}, + }}, + {"style", "form"}, + {"explode", false}, }; components["parameters"] = parameters; @@ -1608,21 +1678,22 @@ static int processApiRequest(mapObj *map, cgiRequestObj *request, OGCAPIFormat f // TODO: "tags" array ? outputResponse(map, request, - format == OGCAPIFormat::JSON ? OGCAPIFormat::OpenAPI_V3 : format, + format == OGCAPIFormat::JSON ? OGCAPIFormat::OpenAPI_V3 + : format, OGCAPI_TEMPLATE_HTML_OPENAPI, response); return MS_SUCCESS; } #endif -int msOGCAPIDispatchRequest(mapObj *map, cgiRequestObj *request) -{ +int msOGCAPIDispatchRequest(mapObj *map, cgiRequestObj *request) { #ifdef USE_OGCAPI_SVR // make sure ogcapi requests are enabled for this map int status = msOWSRequestIsEnabled(map, NULL, "AO", "OGCAPI", MS_FALSE); - if(status != MS_TRUE) { - msSetError(MS_OGCAPIERR, "OGC API requests are not enabled.", "msCGIDispatchAPIRequest()"); + if (status != MS_TRUE) { + msSetError(MS_OGCAPIERR, "OGC API requests are not enabled.", + "msCGIDispatchAPIRequest()"); return MS_FAILURE; // let normal error handling take over } @@ -1630,27 +1701,25 @@ int msOGCAPIDispatchRequest(mapObj *map, cgiRequestObj *request) const char *p = getRequestParameter(request, "f"); // if f= query parameter is not specified, use HTTP Accept header if available - if( p == nullptr ) - { - const char* accept = getenv("HTTP_ACCEPT"); - if( accept ) - { - if( strcmp(accept, "*/*") == 0 ) - p = OGCAPI_MIMETYPE_JSON; - else - p = accept; - } + if (p == nullptr) { + const char *accept = getenv("HTTP_ACCEPT"); + if (accept) { + if (strcmp(accept, "*/*") == 0) + p = OGCAPI_MIMETYPE_JSON; + else + p = accept; + } } - if(p && (strcmp(p, "json") == 0 || - strstr(p, OGCAPI_MIMETYPE_JSON) != nullptr || - strstr(p, OGCAPI_MIMETYPE_GEOJSON) != nullptr || - strstr(p, OGCAPI_MIMETYPE_OPENAPI_V3) != nullptr)) { + if (p && + (strcmp(p, "json") == 0 || strstr(p, OGCAPI_MIMETYPE_JSON) != nullptr || + strstr(p, OGCAPI_MIMETYPE_GEOJSON) != nullptr || + strstr(p, OGCAPI_MIMETYPE_OPENAPI_V3) != nullptr)) { format = OGCAPIFormat::JSON; - } else if(p && (strcmp(p, "html") == 0 || - strstr(p, OGCAPI_MIMETYPE_HTML) != nullptr)) { + } else if (p && (strcmp(p, "html") == 0 || + strstr(p, OGCAPI_MIMETYPE_HTML) != nullptr)) { format = OGCAPIFormat::HTML; - } else if(p) { + } else if (p) { std::string errorMsg("Unsupported format requested: "); errorMsg += p; outputError(OGCAPI_PARAM_ERROR, errorMsg.c_str()); @@ -1659,47 +1728,57 @@ int msOGCAPIDispatchRequest(mapObj *map, cgiRequestObj *request) format = OGCAPIFormat::HTML; // default for now } - if(request->api_path_length == 2) { + if (request->api_path_length == 2) { return processLandingRequest(map, request, format); - } else if(request->api_path_length == 3) { + } else if (request->api_path_length == 3) { - if(strcmp(request->api_path[2], "conformance") == 0) { + if (strcmp(request->api_path[2], "conformance") == 0) { return processConformanceRequest(map, request, format); - } else if(strcmp(request->api_path[2], "conformance.html") == 0) { + } else if (strcmp(request->api_path[2], "conformance.html") == 0) { return processConformanceRequest(map, request, OGCAPIFormat::HTML); - } else if(strcmp(request->api_path[2], "collections") == 0) { + } else if (strcmp(request->api_path[2], "collections") == 0) { return processCollectionsRequest(map, request, format); - } else if(strcmp(request->api_path[2], "collections.html") == 0) { + } else if (strcmp(request->api_path[2], "collections.html") == 0) { return processCollectionsRequest(map, request, OGCAPIFormat::HTML); - } else if(strcmp(request->api_path[2], "api") == 0) { + } else if (strcmp(request->api_path[2], "api") == 0) { return processApiRequest(map, request, format); } - } else if(request->api_path_length == 4) { + } else if (request->api_path_length == 4) { - if(strcmp(request->api_path[2], "collections") == 0) { // next argument (3) is collectionId - return processCollectionRequest(map, request, request->api_path[3], format); + if (strcmp(request->api_path[2], "collections") == + 0) { // next argument (3) is collectionId + return processCollectionRequest(map, request, request->api_path[3], + format); } - } else if(request->api_path_length == 5) { + } else if (request->api_path_length == 5) { - if(strcmp(request->api_path[2], "collections") == 0 && strcmp(request->api_path[4], "items") == 0) { // middle argument (3) is the collectionId - return processCollectionItemsRequest(map, request, request->api_path[3], NULL, format); + if (strcmp(request->api_path[2], "collections") == 0 && + strcmp(request->api_path[4], "items") == + 0) { // middle argument (3) is the collectionId + return processCollectionItemsRequest(map, request, request->api_path[3], + NULL, format); } - } else if(request->api_path_length == 6) { + } else if (request->api_path_length == 6) { - if(strcmp(request->api_path[2], "collections") == 0 && strcmp(request->api_path[4], "items") == 0) { // middle argument (3) is the collectionId, last argument (5) is featureId - return processCollectionItemsRequest(map, request, request->api_path[3], request->api_path[5], format); + if (strcmp(request->api_path[2], "collections") == 0 && + strcmp(request->api_path[4], "items") == + 0) { // middle argument (3) is the collectionId, last argument (5) + // is featureId + return processCollectionItemsRequest(map, request, request->api_path[3], + request->api_path[5], format); } } outputError(OGCAPI_NOT_FOUND_ERROR, "Invalid API path."); return MS_SUCCESS; // avoid any downstream MapServer processing #else - msSetError(MS_OGCAPIERR, "OGC API server support is not enabled.", "msOGCAPIDispatchRequest()"); + msSetError(MS_OGCAPIERR, "OGC API server support is not enabled.", + "msOGCAPIDispatchRequest()"); return MS_FAILURE; #endif } diff --git a/mapogcapi.h b/mapogcapi.h index a9f22d44c1..e2ce43b26e 100644 --- a/mapogcapi.h +++ b/mapogcapi.h @@ -6,7 +6,7 @@ * Author: Steve Lime and the MapServer team. * ********************************************************************** - * Copyright (c) 1996-2005 Regents of the University of Minnesota. + * Copyright (c) 1996-2005 Regents of the University of Minnesota. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -29,13 +29,13 @@ #ifndef MAPOGCAPI_H #define MAPOGCAPI_H -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif int msOGCAPIDispatchRequest(mapObj *map, cgiRequestObj *request); -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/mapogcfilter.cpp b/mapogcfilter.cpp index 5bfd2b997b..c3c0f65ee4 100644 --- a/mapogcfilter.cpp +++ b/mapogcfilter.cpp @@ -43,25 +43,26 @@ static int FLTHasUniqueTopLevelDuringFilter(FilterEncodingNode *psFilterNode); #endif #if !(defined(_WIN32) && !defined(__CYGWIN__)) -static inline void IGUR_double(double ignored) { (void)ignored; } /* Ignore GCC Unused Result */ +static inline void IGUR_double(double ignored) { + (void)ignored; +} /* Ignore GCC Unused Result */ #endif -int FLTIsNumeric(const char *pszValue) -{ +int FLTIsNumeric(const char *pszValue) { if (pszValue != NULL && *pszValue != '\0' && !isspace(*pszValue)) { /*the regex seems to have a problem on windows when mapserver is built using PHP regex*/ #if defined(_WIN32) && !defined(__CYGWIN__) - int i = 0, nLength=0, bString=0; + int i = 0, nLength = 0, bString = 0; nLength = strlen(pszValue); - for (i=0; iconnectiontype == MS_POSTGIS || lp->connectiontype == MS_ORACLESPATIAL || + if (lp->connectiontype == MS_POSTGIS || + lp->connectiontype == MS_ORACLESPATIAL || lp->connectiontype == MS_PLUGIN) { pszFinalExpression = msStrdup("("); - pszFinalExpression = msStringConcatenate(pszFinalExpression, pszExpression); + pszFinalExpression = + msStringConcatenate(pszFinalExpression, pszExpression); pszFinalExpression = msStringConcatenate(pszFinalExpression, ")"); } else if (lp->connectiontype == MS_OGR) { pszFinalExpression = msStrdup(pszExpression); if (lp->filter.type != MS_EXPRESSION) { bConcatWhere = 1; } else { - if (lp->filter.string && EQUALN(lp->filter.string,"WHERE ",6)) { + if (lp->filter.string && EQUALN(lp->filter.string, "WHERE ", 6)) { bHasAWhere = 1; - bConcatWhere =1; + bConcatWhere = 1; } } @@ -115,7 +118,7 @@ int FLTApplyExpressionToLayer(layerObj *lp, const char *pszExpression) if (lp->filter.string && lp->filter.type == MS_EXPRESSION) { pszBuffer = msStringConcatenate(pszBuffer, "(("); if (bHasAWhere) - pszBuffer = msStringConcatenate(pszBuffer, lp->filter.string+6); + pszBuffer = msStringConcatenate(pszBuffer, lp->filter.string + 6); else pszBuffer = msStringConcatenate(pszBuffer, lp->filter.string); pszBuffer = msStringConcatenate(pszBuffer, ") and "); @@ -124,7 +127,7 @@ int FLTApplyExpressionToLayer(layerObj *lp, const char *pszExpression) pszBuffer = msStringConcatenate(pszBuffer, pszFinalExpression); - if(lp->filter.string && lp->filter.type == MS_EXPRESSION) + if (lp->filter.string && lp->filter.type == MS_EXPRESSION) pszBuffer = msStringConcatenate(pszBuffer, ")"); /*assuming that expression was properly escaped @@ -135,7 +138,6 @@ int FLTApplyExpressionToLayer(layerObj *lp, const char *pszExpression) */ msLoadExpressionString(&lp->filter, pszBuffer); - msFree(pszFinalExpression); if (pszBuffer) @@ -147,26 +149,26 @@ int FLTApplyExpressionToLayer(layerObj *lp, const char *pszExpression) return MS_FALSE; } -char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char *value, int forcecharcter) -{ +char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, + const char *value, int forcecharcter) { int bIscharacter; - char *pszExpression = NULL, *pszEscapedStr=NULL, *pszTmpExpression=NULL; - char **paszElements = NULL, **papszRangeElements=NULL; - int numelements,i,nrangeelements; + char *pszExpression = NULL, *pszEscapedStr = NULL, *pszTmpExpression = NULL; + char **paszElements = NULL, **papszRangeElements = NULL; + int numelements, i, nrangeelements; /* double minval, maxval; */ if (lp && item && value) { if (strstr(value, "/") == NULL) { /*value(s)*/ - paszElements = msStringSplit (value, ',', &numelements); + paszElements = msStringSplit(value, ',', &numelements); if (paszElements && numelements > 0) { if (forcecharcter) bIscharacter = MS_TRUE; else - bIscharacter= !FLTIsNumeric(paszElements[0]); + bIscharacter = !FLTIsNumeric(paszElements[0]); pszTmpExpression = msStringConcatenate(pszTmpExpression, "("); - for (i=0; i 0) { pszTmpExpression = msStringConcatenate(pszTmpExpression, "("); - for (i=0; i 0) { pszTmpExpression = msStringConcatenate(pszTmpExpression, "("); if (nrangeelements == 2 || nrangeelements == 3) { @@ -227,9 +231,10 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char pszTmpExpression = msStringConcatenate(pszTmpExpression, " >= "); pszEscapedStr = msLayerEscapeSQLParam(lp, papszRangeElements[0]); - pszTmpExpression = msStringConcatenate(pszTmpExpression, pszEscapedStr); + pszTmpExpression = + msStringConcatenate(pszTmpExpression, pszEscapedStr); msFree(pszEscapedStr); - pszEscapedStr=NULL; + pszEscapedStr = NULL; pszTmpExpression = msStringConcatenate(pszTmpExpression, " AND "); @@ -242,9 +247,10 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char pszTmpExpression = msStringConcatenate(pszTmpExpression, " <= "); pszEscapedStr = msLayerEscapeSQLParam(lp, papszRangeElements[1]); - pszTmpExpression = msStringConcatenate(pszTmpExpression, pszEscapedStr); + pszTmpExpression = + msStringConcatenate(pszTmpExpression, pszEscapedStr); msFree(pszEscapedStr); - pszEscapedStr=NULL; + pszEscapedStr = NULL; pszTmpExpression = msStringConcatenate(pszTmpExpression, ")"); } else if (nrangeelements == 1) { @@ -258,9 +264,10 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char pszTmpExpression = msStringConcatenate(pszTmpExpression, " = "); pszEscapedStr = msLayerEscapeSQLParam(lp, papszRangeElements[0]); - pszTmpExpression = msStringConcatenate(pszTmpExpression, pszEscapedStr); + pszTmpExpression = + msStringConcatenate(pszTmpExpression, pszEscapedStr); msFree(pszEscapedStr); - pszEscapedStr=NULL; + pszEscapedStr = NULL; pszTmpExpression = msStringConcatenate(pszTmpExpression, ")"); } @@ -268,10 +275,10 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char if (pszExpression != NULL) pszExpression = msStringConcatenate(pszExpression, " OR "); - pszExpression = msStringConcatenate(pszExpression, pszTmpExpression); + pszExpression = + msStringConcatenate(pszExpression, pszTmpExpression); msFree(pszTmpExpression); pszTmpExpression = NULL; - } msFreeCharArray(papszRangeElements, nrangeelements); } @@ -285,21 +292,19 @@ char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char } int FLTogrConvertGeometry(OGRGeometryH hGeometry, shapeObj *psShape, - OGRwkbGeometryType nType) -{ + OGRwkbGeometryType nType) { return msOGRGeometryToShape(hGeometry, psShape, nType); } -static -int FLTShapeFromGMLTree(CPLXMLNode *psTree, shapeObj *psShape , char **ppszSRS) -{ +static int FLTShapeFromGMLTree(CPLXMLNode *psTree, shapeObj *psShape, + char **ppszSRS) { const char *pszSRS = NULL; if (psTree && psShape) { CPLXMLNode *psNext = psTree->psNext; OGRGeometryH hGeometry = NULL; psTree->psNext = NULL; - hGeometry = OGR_G_CreateFromGMLTree(psTree ); + hGeometry = OGR_G_CreateFromGMLTree(psTree); psTree->psNext = psNext; if (hGeometry) { @@ -309,7 +314,7 @@ int FLTShapeFromGMLTree(CPLXMLNode *psTree, shapeObj *psShape , char **ppszSRS) nType = wkbPolygon; else if (nType == wkbLineString25D || nType == wkbMultiLineString25D) nType = wkbLineString; - else if (nType == wkbPoint25D || nType == wkbMultiPoint25D) + else if (nType == wkbPoint25D || nType == wkbMultiPoint25D) nType = wkbPoint; FLTogrConvertGeometry(hGeometry, psShape, nType); @@ -326,8 +331,7 @@ int FLTShapeFromGMLTree(CPLXMLNode *psTree, shapeObj *psShape , char **ppszSRS) return MS_FALSE; } -int FLTGetGeosOperator(char *pszValue) -{ +int FLTGetGeosOperator(char *pszValue) { if (!pszValue) return -1; @@ -356,8 +360,7 @@ int FLTGetGeosOperator(char *pszValue) return -1; } -int FLTIsGeosNode(char *pszValue) -{ +int FLTIsGeosNode(char *pszValue) { if (FLTGetGeosOperator(pszValue) == -1) return MS_FALSE; @@ -369,8 +372,7 @@ int FLTIsGeosNode(char *pszValue) /* */ /* Filter encoding with only attribute queries */ /************************************************************************/ -int FLTIsSimpleFilterNoSpatial(FilterEncodingNode *psNode) -{ +int FLTIsSimpleFilterNoSpatial(FilterEncodingNode *psNode) { if (FLTIsSimpleFilter(psNode) && FLTNumberOfFilterType(psNode, "BBOX") == 0) return MS_TRUE; @@ -381,8 +383,8 @@ int FLTIsSimpleFilterNoSpatial(FilterEncodingNode *psNode) /* FLTApplySimpleSQLFilter() */ /************************************************************************/ -int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, int iLayerIndex) -{ +int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, + int iLayerIndex) { layerObj *lp = NULL; char *szExpression = NULL; rectObj sQueryRect = map->extent; @@ -390,34 +392,37 @@ int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, int iLayerI projectionObj sProjTmp; char *pszBuffer = NULL; int bConcatWhere = 0; - int bHasAWhere =0; + int bHasAWhere = 0; char *pszTmp = NULL, *pszTmp2 = NULL; char *tmpfilename = NULL; - const char* pszTimeField = NULL; - const char* pszTimeValue = NULL; + const char *pszTimeField = NULL; + const char *pszTimeValue = NULL; lp = (GET_LAYER(map, iLayerIndex)); /* if there is a bbox use it */ szEPSG = FLTGetBBOX(psNode, &sQueryRect); - if(szEPSG && map->projection.numargs > 0) { + if (szEPSG && map->projection.numargs > 0) { msInitProjection(&sProjTmp); msProjectionInheritContextFrom(&sProjTmp, &map->projection); - /* Use the non EPSG variant since axis swapping is done in FLTDoAxisSwappingIfNecessary */ + /* Use the non EPSG variant since axis swapping is done in + * FLTDoAxisSwappingIfNecessary */ if (msLoadProjectionString(&sProjTmp, szEPSG) == 0) { msProjectRect(&sProjTmp, &map->projection, &sQueryRect); } msFreeProjection(&sProjTmp); } - - if( lp->connectiontype == MS_OGR ) { + + if (lp->connectiontype == MS_OGR) { pszTimeValue = FLTGetDuring(psNode, &pszTimeField); } /* make sure that the layer can be queried*/ - if (!lp->_template) lp->_template = msStrdup("ttt.html"); + if (!lp->_template) + lp->_template = msStrdup("ttt.html"); - /* if there is no class, create at least one, so that query by rect would work */ + /* if there is no class, create at least one, so that query by rect would work + */ if (lp->numclasses == 0) { if (msGrowLayerClasses(lp) == NULL) return MS_FAILURE; @@ -426,7 +431,8 @@ int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, int iLayerI bConcatWhere = 0; bHasAWhere = 0; - if (lp->connectiontype == MS_POSTGIS || lp->connectiontype == MS_ORACLESPATIAL || + if (lp->connectiontype == MS_POSTGIS || + lp->connectiontype == MS_ORACLESPATIAL || lp->connectiontype == MS_PLUGIN) { szExpression = FLTGetSQLExpression(psNode, lp); if (szExpression) { @@ -440,24 +446,23 @@ int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, int iLayerI /* concatenates the WHERE clause for OGR layers. This only applies if the expression was empty or not of an expression string. If there is an sql type expression, it is assumed to have the WHERE clause. - If it is an expression and does not have a WHERE it is assumed to be a mapserver - type expression*/ + If it is an expression and does not have a WHERE it is assumed to be a + mapserver type expression*/ else if (lp->connectiontype == MS_OGR) { if (lp->filter.type != MS_EXPRESSION) { szExpression = FLTGetSQLExpression(psNode, lp); bConcatWhere = 1; } else { - if (lp->filter.string && EQUALN(lp->filter.string,"WHERE ",6)) { + if (lp->filter.string && EQUALN(lp->filter.string, "WHERE ", 6)) { szExpression = FLTGetSQLExpression(psNode, lp); bHasAWhere = 1; - bConcatWhere =1; + bConcatWhere = 1; } else { szExpression = FLTGetCommonExpression(psNode, lp); } } } else { szExpression = FLTGetCommonExpression(psNode, lp); - } if (szExpression) { @@ -469,7 +474,7 @@ int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, int iLayerI if (lp->filter.string && lp->filter.type == MS_EXPRESSION) { pszBuffer = msStringConcatenate(pszBuffer, "(("); if (bHasAWhere) - pszBuffer = msStringConcatenate(pszBuffer, lp->filter.string+6); + pszBuffer = msStringConcatenate(pszBuffer, lp->filter.string + 6); else pszBuffer = msStringConcatenate(pszBuffer, lp->filter.string); pszBuffer = msStringConcatenate(pszBuffer, ") and "); @@ -478,15 +483,15 @@ int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, int iLayerI pszBuffer = msStringConcatenate(pszBuffer, szExpression); - if(lp->filter.string && lp->filter.type == MS_EXPRESSION) + if (lp->filter.string && lp->filter.type == MS_EXPRESSION) pszBuffer = msStringConcatenate(pszBuffer, ")"); msLoadExpressionString(&lp->filter, pszBuffer); free(szExpression); } - + if (pszTimeField && pszTimeValue) - msLayerSetTimeFilter(lp, pszTimeValue, pszTimeField); + msLayerSetTimeFilter(lp, pszTimeValue, pszTimeField); if (pszBuffer) free(pszBuffer); @@ -496,23 +501,27 @@ int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, int iLayerI map->query.layer = lp->index; map->query.rect = sQueryRect; - if(map->debug == MS_DEBUGLEVEL_VVV) { + if (map->debug == MS_DEBUGLEVEL_VVV) { tmpfilename = msTmpFile(map, map->mappath, NULL, "_filter.map"); if (tmpfilename == NULL) { - tmpfilename = msTmpFile(map, NULL, NULL, "_filter.map" ); + tmpfilename = msTmpFile(map, NULL, NULL, "_filter.map"); } if (tmpfilename) { - msSaveMap(map,tmpfilename); - msDebug("FLTApplySimpleSQLFilter(): Map file after Filter was applied %s\n", tmpfilename); + msSaveMap(map, tmpfilename); + msDebug( + "FLTApplySimpleSQLFilter(): Map file after Filter was applied %s\n", + tmpfilename); msFree(tmpfilename); } } - /*for oracle connection, if we have a simple filter with no spatial constraints - we should set the connection function to NONE to have a better performance + /*for oracle connection, if we have a simple filter with no spatial + constraints we should set the connection function to NONE to have a better + performance (#2725)*/ - if (lp->connectiontype == MS_ORACLESPATIAL && FLTIsSimpleFilterNoSpatial(psNode)) { + if (lp->connectiontype == MS_ORACLESPATIAL && + FLTIsSimpleFilterNoSpatial(psNode)) { if (strcasestr(lp->data, "USING") == 0) lp->data = msStringConcatenate(lp->data, " USING NONE"); else if (strcasestr(lp->data, "NONE") == 0) { @@ -552,74 +561,66 @@ int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, int iLayerI /* */ /* Split filters separated by parentheses into an array of strings. */ /************************************************************************/ -char** FLTSplitFilters(const char* pszStr, int* pnTokens) -{ - const char* pszTokenBegin; - char** papszRet = NULL; - int nTokens = 0; - char chStringQuote = '\0'; - int nXMLIndent = 0; - int bInBracket = FALSE; +char **FLTSplitFilters(const char *pszStr, int *pnTokens) { + const char *pszTokenBegin; + char **papszRet = NULL; + int nTokens = 0; + char chStringQuote = '\0'; + int nXMLIndent = 0; + int bInBracket = FALSE; - if( *pszStr != '(' ) - { - *pnTokens = 0; - return NULL; + if (*pszStr != '(') { + *pnTokens = 0; + return NULL; + } + pszStr++; + pszTokenBegin = pszStr; + while (*pszStr != '\0') { + /* Ignore any character until end of quoted string */ + if (chStringQuote != '\0') { + if (*pszStr == chStringQuote) + chStringQuote = 0; } - pszStr ++; - pszTokenBegin = pszStr; - while( *pszStr != '\0' ) - { - /* Ignore any character until end of quoted string */ - if( chStringQuote != '\0' ) - { - if( *pszStr == chStringQuote ) - chStringQuote = 0; - } - /* Detect begin of quoted string only for an XML attribute, i.e. between < and > */ - else if( bInBracket && (*pszStr == '\'' || *pszStr == '"') ) - { - chStringQuote = *pszStr; - } - /* Begin of XML element */ - else if( *pszStr == '<' ) - { - bInBracket = TRUE; - if( pszStr[1] == '/' ) - nXMLIndent --; - else if( pszStr[1] != '!' ) - nXMLIndent ++; - } - /* case */ - else if (*pszStr == '/' && pszStr[1] == '>' ) - { - bInBracket = FALSE; - nXMLIndent --; - pszStr ++; - } - /* End of XML element */ - else if( *pszStr == '>' ) - { - bInBracket = FALSE; - } - /* Only detect and of filter when XML indentation goes back to zero */ - else if( nXMLIndent == 0 && *pszStr == ')' ) - { - papszRet = (char**) msSmallRealloc(papszRet, sizeof(char*) * (nTokens + 1)); - papszRet[nTokens] = msStrdup(pszTokenBegin); - papszRet[nTokens][pszStr - pszTokenBegin] = '\0'; - nTokens ++; - if( pszStr[1] != '(' ) - { - break; - } - pszStr ++; - pszTokenBegin = pszStr + 1; - } - pszStr ++; + /* Detect begin of quoted string only for an XML attribute, i.e. between < + and > */ + else if (bInBracket && (*pszStr == '\'' || *pszStr == '"')) { + chStringQuote = *pszStr; + } + /* Begin of XML element */ + else if (*pszStr == '<') { + bInBracket = TRUE; + if (pszStr[1] == '/') + nXMLIndent--; + else if (pszStr[1] != '!') + nXMLIndent++; } - *pnTokens = nTokens; - return papszRet; + /* case */ + else if (*pszStr == '/' && pszStr[1] == '>') { + bInBracket = FALSE; + nXMLIndent--; + pszStr++; + } + /* End of XML element */ + else if (*pszStr == '>') { + bInBracket = FALSE; + } + /* Only detect and of filter when XML indentation goes back to zero */ + else if (nXMLIndent == 0 && *pszStr == ')') { + papszRet = + (char **)msSmallRealloc(papszRet, sizeof(char *) * (nTokens + 1)); + papszRet[nTokens] = msStrdup(pszTokenBegin); + papszRet[nTokens][pszStr - pszTokenBegin] = '\0'; + nTokens++; + if (pszStr[1] != '(') { + break; + } + pszStr++; + pszTokenBegin = pszStr + 1; + } + pszStr++; + } + *pnTokens = nTokens; + return papszRet; } /************************************************************************/ @@ -627,8 +628,7 @@ char** FLTSplitFilters(const char* pszStr, int* pnTokens) /* */ /* Filter encoding with only attribute queries and only one bbox. */ /************************************************************************/ -int FLTIsSimpleFilter(FilterEncodingNode *psNode) -{ +int FLTIsSimpleFilter(FilterEncodingNode *psNode) { if (FLTValidForBBoxFilter(psNode)) { if (FLTNumberOfFilterType(psNode, "DWithin") == 0 && FLTNumberOfFilterType(psNode, "Intersect") == 0 && @@ -653,18 +653,18 @@ int FLTIsSimpleFilter(FilterEncodingNode *psNode) /* Use the filter encoding node to create mapserver expressions */ /* and apply it to the layer. */ /************************************************************************/ -int FLTApplyFilterToLayer(FilterEncodingNode *psNode, mapObj *map, int iLayerIndex) -{ +int FLTApplyFilterToLayer(FilterEncodingNode *psNode, mapObj *map, + int iLayerIndex) { layerObj *layer = GET_LAYER(map, iLayerIndex); - if ( ! layer->vtable) { - int rv = msInitializeVirtualTable(layer); + if (!layer->vtable) { + int rv = msInitializeVirtualTable(layer); if (rv != MS_SUCCESS) return rv; } - if( !layer->vtable ) - return MS_FAILURE; - return layer->vtable->LayerApplyFilterToLayer(psNode, map, iLayerIndex); + if (!layer->vtable) + return MS_FAILURE; + return layer->vtable->LayerApplyFilterToLayer(psNode, map, iLayerIndex); } /************************************************************************/ @@ -672,43 +672,38 @@ int FLTApplyFilterToLayer(FilterEncodingNode *psNode, mapObj *map, int iLayerInd /* */ /* Helper function for layer virtual table architecture */ /************************************************************************/ -int FLTLayerApplyCondSQLFilterToLayer(FilterEncodingNode *psNode, mapObj *map, int iLayerIndex) -{ +int FLTLayerApplyCondSQLFilterToLayer(FilterEncodingNode *psNode, mapObj *map, + int iLayerIndex) { return FLTLayerApplyPlainFilterToLayer(psNode, map, iLayerIndex); } - /************************************************************************/ /* FLTGetTopBBOX */ /* */ /* Return the "top" BBOX if there's a unique one. */ /************************************************************************/ -static int FLTGetTopBBOXInternal(FilterEncodingNode *psNode, FilterEncodingNode** ppsTopBBOX, int *pnCount) -{ +static int FLTGetTopBBOXInternal(FilterEncodingNode *psNode, + FilterEncodingNode **ppsTopBBOX, + int *pnCount) { if (psNode->pszValue && strcasecmp(psNode->pszValue, "BBOX") == 0) { - (*pnCount) ++; - if( *pnCount == 1 ) - { + (*pnCount)++; + if (*pnCount == 1) { *ppsTopBBOX = psNode; return TRUE; } *ppsTopBBOX = NULL; return FALSE; - } - else if (psNode->pszValue && strcasecmp(psNode->pszValue, "AND") == 0) { + } else if (psNode->pszValue && strcasecmp(psNode->pszValue, "AND") == 0) { return FLTGetTopBBOXInternal(psNode->psLeftNode, ppsTopBBOX, pnCount) && FLTGetTopBBOXInternal(psNode->psRightNode, ppsTopBBOX, pnCount); - } - else - { + } else { return TRUE; } } -static FilterEncodingNode* FLTGetTopBBOX(FilterEncodingNode *psNode) -{ +static FilterEncodingNode *FLTGetTopBBOX(FilterEncodingNode *psNode) { int nCount = 0; - FilterEncodingNode* psTopBBOX = NULL; + FilterEncodingNode *psTopBBOX = NULL; FLTGetTopBBOXInternal(psNode, &psTopBBOX, &nCount); return psTopBBOX; } @@ -722,20 +717,18 @@ static FilterEncodingNode* FLTGetTopBBOX(FilterEncodingNode *psNode) /* they should not issue a spatial filter. */ /************************************************************************/ -int FLTLayerSetInvalidRectIfSupported(layerObj* lp, - rectObj* rect) -{ - const char* pszUseDefaultExtent = msOWSLookupMetadata(&(lp->metadata), "F", - "use_default_extent_for_getfeature"); - if( pszUseDefaultExtent && !CSLTestBoolean(pszUseDefaultExtent) && - (lp->connectiontype == MS_OGR || - ((lp->connectiontype == MS_PLUGIN) && (strstr(lp->plugin_library,"msplugin_mssql2008") != NULL))) ) - { - const rectObj rectInvalid = MS_INIT_INVALID_RECT; - *rect = rectInvalid; - return MS_TRUE; - } - return MS_FALSE; +int FLTLayerSetInvalidRectIfSupported(layerObj *lp, rectObj *rect) { + const char *pszUseDefaultExtent = msOWSLookupMetadata( + &(lp->metadata), "F", "use_default_extent_for_getfeature"); + if (pszUseDefaultExtent && !CSLTestBoolean(pszUseDefaultExtent) && + (lp->connectiontype == MS_OGR || + ((lp->connectiontype == MS_PLUGIN) && + (strstr(lp->plugin_library, "msplugin_mssql2008") != NULL)))) { + const rectObj rectInvalid = MS_INIT_INVALID_RECT; + *rect = rectInvalid; + return MS_TRUE; + } + return MS_FALSE; } /************************************************************************/ @@ -744,38 +737,34 @@ int FLTLayerSetInvalidRectIfSupported(layerObj* lp, /* Helper function for layer virtual table architecture */ /************************************************************************/ int FLTLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, - int iLayerIndex) -{ - char *pszExpression =NULL; - int status =MS_FALSE; - layerObj* lp = GET_LAYER(map, iLayerIndex); + int iLayerIndex) { + char *pszExpression = NULL; + int status = MS_FALSE; + layerObj *lp = GET_LAYER(map, iLayerIndex); - pszExpression = FLTGetCommonExpression(psNode, lp); + pszExpression = FLTGetCommonExpression(psNode, lp); if (pszExpression) { - FilterEncodingNode* psTopBBOX; + FilterEncodingNode *psTopBBOX; rectObj rect = map->extent; FLTLayerSetInvalidRectIfSupported(lp, &rect); psTopBBOX = FLTGetTopBBOX(psNode); - if( psTopBBOX ) - { + if (psTopBBOX) { int can_remove_expression = MS_TRUE; - const char* pszEPSG = FLTGetBBOX(psNode, &rect); - if(pszEPSG && map->projection.numargs > 0) { + const char *pszEPSG = FLTGetBBOX(psNode, &rect); + if (pszEPSG && map->projection.numargs > 0) { projectionObj sProjTmp; msInitProjection(&sProjTmp); msProjectionInheritContextFrom(&sProjTmp, &map->projection); - /* Use the non EPSG variant since axis swapping is done in FLTDoAxisSwappingIfNecessary */ + /* Use the non EPSG variant since axis swapping is done in + * FLTDoAxisSwappingIfNecessary */ if (msLoadProjectionString(&sProjTmp, pszEPSG) == 0) { rectObj oldRect = rect; msProjectRect(&sProjTmp, &map->projection, &rect); /* If reprojection is involved, do not remove the expression */ - if( rect.minx != oldRect.minx || - rect.miny != oldRect.miny || - rect.maxx != oldRect.maxx || - rect.maxy != oldRect.maxy ) - { + if (rect.minx != oldRect.minx || rect.miny != oldRect.miny || + rect.maxx != oldRect.maxx || rect.maxy != oldRect.maxy) { can_remove_expression = MS_FALSE; } } @@ -784,19 +773,21 @@ int FLTLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, /* Small optimization: if the query is just a BBOX, then do a */ /* msQueryByRect() */ - if( psTopBBOX == psNode && can_remove_expression ) - { + if (psTopBBOX == psNode && can_remove_expression) { msFree(pszExpression); pszExpression = NULL; } } - if(map->debug == MS_DEBUGLEVEL_VVV) - { - if( pszExpression ) - msDebug("FLTLayerApplyPlainFilterToLayer(): %s, rect=%.15g,%.15g,%.15g,%.15g\n", pszExpression, rect.minx, rect.miny, rect.maxx, rect.maxy); + if (map->debug == MS_DEBUGLEVEL_VVV) { + if (pszExpression) + msDebug("FLTLayerApplyPlainFilterToLayer(): %s, " + "rect=%.15g,%.15g,%.15g,%.15g\n", + pszExpression, rect.minx, rect.miny, rect.maxx, rect.maxy); else - msDebug("FLTLayerApplyPlainFilterToLayer(): rect=%.15g,%.15g,%.15g,%.15g\n", rect.minx, rect.miny, rect.maxx, rect.maxy); + msDebug( + "FLTLayerApplyPlainFilterToLayer(): rect=%.15g,%.15g,%.15g,%.15g\n", + rect.minx, rect.miny, rect.maxx, rect.maxy); } status = FLTApplyFilterToLayerCommonExpressionWithRect(map, iLayerIndex, @@ -807,8 +798,6 @@ int FLTLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, return status; } - - /************************************************************************/ /* FilterNode *FLTPaserFilterEncoding(char *szXMLString) */ /* */ @@ -819,9 +808,8 @@ int FLTLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, /* Calling function should use FreeFilterEncodingNode function */ /* to free memeory. */ /************************************************************************/ -FilterEncodingNode *FLTParseFilterEncoding(const char *szXMLString) -{ - CPLXMLNode *psRoot = NULL, *psChild=NULL, *psFilter=NULL; +FilterEncodingNode *FLTParseFilterEncoding(const char *szXMLString) { + CPLXMLNode *psRoot = NULL, *psChild = NULL, *psFilter = NULL; FilterEncodingNode *psFilterNode = NULL; if (szXMLString == NULL || strlen(szXMLString) == 0 || @@ -830,7 +818,7 @@ FilterEncodingNode *FLTParseFilterEncoding(const char *szXMLString) psRoot = CPLParseXMLString(szXMLString); - if( psRoot == NULL) + if (psRoot == NULL) return NULL; /* strip namespaces. We srtip all name spaces (#1350)*/ @@ -840,9 +828,8 @@ FilterEncodingNode *FLTParseFilterEncoding(const char *szXMLString) /* get the root element (Filter). */ /* -------------------------------------------------------------------- */ psFilter = CPLGetXMLNode(psRoot, "=Filter"); - if (!psFilter) - { - CPLDestroyXMLNode( psRoot ); + if (!psFilter) { + CPLDestroyXMLNode(psRoot); return NULL; } @@ -856,7 +843,7 @@ FilterEncodingNode *FLTParseFilterEncoding(const char *szXMLString) psChild = psChild->psNext; } - CPLDestroyXMLNode( psRoot ); + CPLDestroyXMLNode(psRoot); /* -------------------------------------------------------------------- */ /* validate the node tree to make sure that all the nodes are valid.*/ @@ -866,11 +853,9 @@ FilterEncodingNode *FLTParseFilterEncoding(const char *szXMLString) return NULL; } - return psFilterNode; } - /************************************************************************/ /* int FLTValidFilterNode(FilterEncodingNode *psFilterNode) */ /* */ @@ -879,8 +864,7 @@ FilterEncodingNode *FLTParseFilterEncoding(const char *szXMLString) /* could be incorrect if the filter string sent is corrupted */ /* (eg missing a value :) */ /************************************************************************/ -int FLTValidFilterNode(FilterEncodingNode *psFilterNode) -{ +int FLTValidFilterNode(FilterEncodingNode *psFilterNode) { if (!psFilterNode) return 0; @@ -902,11 +886,10 @@ int FLTValidFilterNode(FilterEncodingNode *psFilterNode) /* FLTIsGeometryFilterNodeType */ /************************************************************************/ -static int FLTIsGeometryFilterNodeType(int eType) -{ - return (eType == FILTER_NODE_TYPE_GEOMETRY_POINT || - eType == FILTER_NODE_TYPE_GEOMETRY_LINE || - eType == FILTER_NODE_TYPE_GEOMETRY_POLYGON); +static int FLTIsGeometryFilterNodeType(int eType) { + return (eType == FILTER_NODE_TYPE_GEOMETRY_POINT || + eType == FILTER_NODE_TYPE_GEOMETRY_LINE || + eType == FILTER_NODE_TYPE_GEOMETRY_POLYGON); } /************************************************************************/ @@ -914,8 +897,7 @@ static int FLTIsGeometryFilterNodeType(int eType) /* */ /* recursive freeing of Filter Encoding nodes. */ /************************************************************************/ -void FLTFreeFilterEncodingNode(FilterEncodingNode *psFilterNode) -{ +void FLTFreeFilterEncodingNode(FilterEncodingNode *psFilterNode) { if (psFilterNode) { if (psFilterNode->psLeftNode) { FLTFreeFilterEncodingNode(psFilterNode->psLeftNode); @@ -927,46 +909,43 @@ void FLTFreeFilterEncodingNode(FilterEncodingNode *psFilterNode) } if (psFilterNode->pszSRS) - free( psFilterNode->pszSRS); + free(psFilterNode->pszSRS); - if( psFilterNode->pOther ) { + if (psFilterNode->pOther) { if (psFilterNode->pszValue != NULL && strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0) { - FEPropertyIsLike* propIsLike = (FEPropertyIsLike *)psFilterNode->pOther; - if( propIsLike->pszWildCard ) - free( propIsLike->pszWildCard ); - if( propIsLike->pszSingleChar ) - free( propIsLike->pszSingleChar ); - if( propIsLike->pszEscapeChar ) - free( propIsLike->pszEscapeChar ); + FEPropertyIsLike *propIsLike = (FEPropertyIsLike *)psFilterNode->pOther; + if (propIsLike->pszWildCard) + free(propIsLike->pszWildCard); + if (propIsLike->pszSingleChar) + free(propIsLike->pszSingleChar); + if (propIsLike->pszEscapeChar) + free(propIsLike->pszEscapeChar); } else if (FLTIsGeometryFilterNodeType(psFilterNode->eType)) { msFreeShape((shapeObj *)(psFilterNode->pOther)); } /* else */ /* TODO free pOther special fields */ - free( psFilterNode->pOther ); + free(psFilterNode->pOther); } /* Cannot free pszValue before, 'cause we are testing it above */ - if( psFilterNode->pszValue ) - free( psFilterNode->pszValue ); + if (psFilterNode->pszValue) + free(psFilterNode->pszValue); free(psFilterNode); } } - /************************************************************************/ /* FLTCreateFilterEncodingNode */ /* */ /* return a FilterEncoding node. */ /************************************************************************/ -FilterEncodingNode *FLTCreateFilterEncodingNode(void) -{ +FilterEncodingNode *FLTCreateFilterEncodingNode(void) { FilterEncodingNode *psFilterNode = NULL; - psFilterNode = - (FilterEncodingNode *)malloc(sizeof (FilterEncodingNode)); + psFilterNode = (FilterEncodingNode *)malloc(sizeof(FilterEncodingNode)); psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; psFilterNode->pszValue = NULL; psFilterNode->pOther = NULL; @@ -977,8 +956,7 @@ FilterEncodingNode *FLTCreateFilterEncodingNode(void) return psFilterNode; } -FilterEncodingNode *FLTCreateBinaryCompFilterEncodingNode(void) -{ +FilterEncodingNode *FLTCreateBinaryCompFilterEncodingNode(void) { FilterEncodingNode *psFilterNode = NULL; psFilterNode = FLTCreateFilterEncodingNode(); @@ -990,97 +968,88 @@ FilterEncodingNode *FLTCreateBinaryCompFilterEncodingNode(void) return psFilterNode; } - /************************************************************************/ /* FLTFindGeometryNode */ /* */ /************************************************************************/ -static CPLXMLNode* FLTFindGeometryNode(CPLXMLNode* psXMLNode, - int* pbPoint, - int* pbLine, - int* pbPolygon) -{ - CPLXMLNode *psGMLElement = NULL; +static CPLXMLNode *FLTFindGeometryNode(CPLXMLNode *psXMLNode, int *pbPoint, + int *pbLine, int *pbPolygon) { + CPLXMLNode *psGMLElement = NULL; - psGMLElement = CPLGetXMLNode(psXMLNode, "Point"); - if (!psGMLElement) - psGMLElement = CPLGetXMLNode(psXMLNode, "PointType"); + psGMLElement = CPLGetXMLNode(psXMLNode, "Point"); + if (!psGMLElement) + psGMLElement = CPLGetXMLNode(psXMLNode, "PointType"); + if (psGMLElement) + *pbPoint = 1; + else { + psGMLElement = CPLGetXMLNode(psXMLNode, "Polygon"); if (psGMLElement) - *pbPoint =1; - else { - psGMLElement= CPLGetXMLNode(psXMLNode, "Polygon"); - if (psGMLElement) - *pbPolygon = 1; - else if ((psGMLElement= CPLGetXMLNode(psXMLNode, "MultiPolygon"))) - *pbPolygon = 1; - else if ((psGMLElement= CPLGetXMLNode(psXMLNode, "Surface"))) - *pbPolygon = 1; - else if ((psGMLElement= CPLGetXMLNode(psXMLNode, "MultiSurface"))) - *pbPolygon = 1; - else if ((psGMLElement= CPLGetXMLNode(psXMLNode, "Box"))) - *pbPolygon = 1; - else if ((psGMLElement= CPLGetXMLNode(psXMLNode, "Envelope"))) - *pbPolygon = 1; - else if ((psGMLElement= CPLGetXMLNode(psXMLNode, "LineString"))) - *pbLine = 1; - else if ((psGMLElement= CPLGetXMLNode(psXMLNode, "MultiLineString"))) - *pbLine = 1; - else if ((psGMLElement= CPLGetXMLNode(psXMLNode, "Curve"))) - *pbLine = 1; - else if ((psGMLElement= CPLGetXMLNode(psXMLNode, "MultiCurve"))) - *pbLine = 1; - else if ((psGMLElement= CPLGetXMLNode(psXMLNode, "MultiPoint"))) - *pbPoint = 1; - } - return psGMLElement; + *pbPolygon = 1; + else if ((psGMLElement = CPLGetXMLNode(psXMLNode, "MultiPolygon"))) + *pbPolygon = 1; + else if ((psGMLElement = CPLGetXMLNode(psXMLNode, "Surface"))) + *pbPolygon = 1; + else if ((psGMLElement = CPLGetXMLNode(psXMLNode, "MultiSurface"))) + *pbPolygon = 1; + else if ((psGMLElement = CPLGetXMLNode(psXMLNode, "Box"))) + *pbPolygon = 1; + else if ((psGMLElement = CPLGetXMLNode(psXMLNode, "Envelope"))) + *pbPolygon = 1; + else if ((psGMLElement = CPLGetXMLNode(psXMLNode, "LineString"))) + *pbLine = 1; + else if ((psGMLElement = CPLGetXMLNode(psXMLNode, "MultiLineString"))) + *pbLine = 1; + else if ((psGMLElement = CPLGetXMLNode(psXMLNode, "Curve"))) + *pbLine = 1; + else if ((psGMLElement = CPLGetXMLNode(psXMLNode, "MultiCurve"))) + *pbLine = 1; + else if ((psGMLElement = CPLGetXMLNode(psXMLNode, "MultiPoint"))) + *pbPoint = 1; + } + return psGMLElement; } /************************************************************************/ /* FLTGetPropertyName */ /************************************************************************/ -static const char* FLTGetPropertyName(CPLXMLNode* psXMLNode) -{ - const char* pszPropertyName; +static const char *FLTGetPropertyName(CPLXMLNode *psXMLNode) { + const char *pszPropertyName; - pszPropertyName = CPLGetXMLValue(psXMLNode, "PropertyName", NULL); - if( pszPropertyName == NULL ) /* FE 2.0 ? */ - pszPropertyName = CPLGetXMLValue(psXMLNode, "ValueReference", NULL); - return pszPropertyName; + pszPropertyName = CPLGetXMLValue(psXMLNode, "PropertyName", NULL); + if (pszPropertyName == NULL) /* FE 2.0 ? */ + pszPropertyName = CPLGetXMLValue(psXMLNode, "ValueReference", NULL); + return pszPropertyName; } /************************************************************************/ /* FLTGetFirstChildNode */ /************************************************************************/ -static CPLXMLNode* FLTGetFirstChildNode(CPLXMLNode* psXMLNode) -{ - if( psXMLNode == NULL ) - return NULL; - psXMLNode = psXMLNode->psChild; - while( psXMLNode != NULL ) - { - if( psXMLNode->eType == CXT_Element ) - return psXMLNode; - psXMLNode = psXMLNode->psNext; - } +static CPLXMLNode *FLTGetFirstChildNode(CPLXMLNode *psXMLNode) { + if (psXMLNode == NULL) return NULL; + psXMLNode = psXMLNode->psChild; + while (psXMLNode != NULL) { + if (psXMLNode->eType == CXT_Element) + return psXMLNode; + psXMLNode = psXMLNode->psNext; + } + return NULL; } /************************************************************************/ /* FLTGetNextSibblingNode */ /************************************************************************/ -static CPLXMLNode* FLTGetNextSibblingNode(CPLXMLNode* psXMLNode) -{ - if( psXMLNode == NULL ) - return NULL; - psXMLNode = psXMLNode->psNext; - while( psXMLNode != NULL ) - { - if( psXMLNode->eType == CXT_Element ) - return psXMLNode; - psXMLNode = psXMLNode->psNext; - } +static CPLXMLNode *FLTGetNextSibblingNode(CPLXMLNode *psXMLNode) { + if (psXMLNode == NULL) return NULL; + psXMLNode = psXMLNode->psNext; + while (psXMLNode != NULL) { + if (psXMLNode->eType == CXT_Element) + return psXMLNode; + psXMLNode = psXMLNode->psNext; + } + return NULL; } /************************************************************************/ @@ -1090,15 +1059,14 @@ static CPLXMLNode* FLTGetNextSibblingNode(CPLXMLNode* psXMLNode) /* contents into the Filter Encoding node structure. */ /************************************************************************/ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, - CPLXMLNode *psXMLNode) -{ + CPLXMLNode *psXMLNode) { char *pszTmp = NULL; - FilterEncodingNode *psCurFilNode= NULL; + FilterEncodingNode *psCurFilNode = NULL; CPLXMLNode *psCurXMLNode = NULL; CPLXMLNode *psTmpNode = NULL; CPLXMLNode *psFeatureIdNode = NULL; - const char *pszFeatureId=NULL; - char *pszFeatureIdList=NULL; + const char *pszFeatureId = NULL; + char *pszFeatureIdList = NULL; if (psFilterNode && psXMLNode && psXMLNode->pszValue) { psFilterNode->pszValue = msStrdup(psXMLNode->pszValue); @@ -1125,11 +1093,11 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, psFilterNode->eType = FILTER_NODE_TYPE_LOGICAL; if (strcasecmp(psFilterNode->pszValue, "AND") == 0 || strcasecmp(psFilterNode->pszValue, "OR") == 0) { - CPLXMLNode* psFirstNode = FLTGetFirstChildNode(psXMLNode); - CPLXMLNode* psSecondNode = FLTGetNextSibblingNode(psFirstNode); + CPLXMLNode *psFirstNode = FLTGetFirstChildNode(psXMLNode); + CPLXMLNode *psSecondNode = FLTGetNextSibblingNode(psFirstNode); if (psFirstNode && psSecondNode) { /*2 operators */ - CPLXMLNode* psNextNode = FLTGetNextSibblingNode(psSecondNode); + CPLXMLNode *psNextNode = FLTGetNextSibblingNode(psSecondNode); if (psNextNode == NULL) { psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); FLTInsertElementInNode(psFilterNode->psLeftNode, psFirstNode); @@ -1138,14 +1106,15 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, } else { psCurXMLNode = psFirstNode; psCurFilNode = psFilterNode; - while(psCurXMLNode) { + while (psCurXMLNode) { psNextNode = FLTGetNextSibblingNode(psCurXMLNode); if (FLTGetNextSibblingNode(psNextNode)) { psCurFilNode->psLeftNode = FLTCreateFilterEncodingNode(); FLTInsertElementInNode(psCurFilNode->psLeftNode, psCurXMLNode); psCurFilNode->psRightNode = FLTCreateFilterEncodingNode(); psCurFilNode->psRightNode->eType = FILTER_NODE_TYPE_LOGICAL; - psCurFilNode->psRightNode->pszValue = msStrdup(psFilterNode->pszValue); + psCurFilNode->psRightNode->pszValue = + msStrdup(psFilterNode->pszValue); psCurFilNode = psCurFilNode->psRightNode; psCurXMLNode = psNextNode; @@ -1159,21 +1128,18 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, } } } - } - else + } else psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } else if (strcasecmp(psFilterNode->pszValue, "NOT") == 0) { - CPLXMLNode* psFirstNode = FLTGetFirstChildNode(psXMLNode); + CPLXMLNode *psFirstNode = FLTGetFirstChildNode(psXMLNode); if (psFirstNode) { psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); - FLTInsertElementInNode(psFilterNode->psLeftNode, - psFirstNode); - } - else + FLTInsertElementInNode(psFilterNode->psLeftNode, psFirstNode); + } else psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } else psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; - }/* end if is logical */ + } /* end if is logical */ /* -------------------------------------------------------------------- */ /* Spatial Filter. */ /* BBOX : */ @@ -1217,7 +1183,8 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, /* */ /* Intersect */ /* */ - /* type="ogc:BinarySpatialOpType" substitutionGroup="ogc:spatialOps"/>*/ + /* type="ogc:BinarySpatialOpType" + substitutionGroup="ogc:spatialOps"/>*/ /* */ @@ -1240,9 +1207,9 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, if (strcasecmp(psXMLNode->pszValue, "BBOX") == 0) { char *pszSRS = NULL; - const char* pszPropertyName = NULL; - CPLXMLNode *psBox = NULL, *psEnvelope=NULL; - rectObj sBox = {0,0,0,0}; + const char *pszPropertyName = NULL; + CPLXMLNode *psBox = NULL, *psEnvelope = NULL; + rectObj sBox = {0, 0, 0, 0}; int bCoordinatesValid = 0; @@ -1263,12 +1230,12 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, psFilterNode->pszSRS = pszSRS; psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); - psFilterNode->psLeftNode->eType = FILTER_NODE_TYPE_PROPERTYNAME; + psFilterNode->psLeftNode->eType = FILTER_NODE_TYPE_PROPERTYNAME; /* PropertyName is optional since FE 1.1.0, in which case */ /* the BBOX must apply to all geometry fields. As we support */ /* currently only one geometry field, this doesn't make much */ /* difference to further processing. */ - if( pszPropertyName != NULL ) { + if (pszPropertyName != NULL) { psFilterNode->psLeftNode->pszValue = msStrdup(pszPropertyName); } @@ -1276,11 +1243,11 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, psFilterNode->psRightNode = FLTCreateFilterEncodingNode(); psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_BBOX; psFilterNode->psRightNode->pOther = - (rectObj *)msSmallMalloc(sizeof(rectObj)); + (rectObj *)msSmallMalloc(sizeof(rectObj)); ((rectObj *)psFilterNode->psRightNode->pOther)->minx = sBox.minx; ((rectObj *)psFilterNode->psRightNode->pOther)->miny = sBox.miny; ((rectObj *)psFilterNode->psRightNode->pOther)->maxx = sBox.maxx; - ((rectObj *)psFilterNode->psRightNode->pOther)->maxy = sBox.maxy; + ((rectObj *)psFilterNode->psRightNode->pOther)->maxy = sBox.maxy; } else { msFree(pszSRS); psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; @@ -1292,27 +1259,27 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, shapeObj *psShape = NULL; int bPoint = 0, bLine = 0, bPolygon = 0; const char *pszUnits = NULL; - const char* pszDistance = NULL; - const char* pszPropertyName; + const char *pszDistance = NULL; + const char *pszPropertyName; char *pszSRS = NULL; - CPLXMLNode *psGMLElement = NULL, *psDistance=NULL; + CPLXMLNode *psGMLElement = NULL, *psDistance = NULL; pszPropertyName = FLTGetPropertyName(psXMLNode); - psGMLElement = FLTFindGeometryNode(psXMLNode, &bPoint, &bLine, &bPolygon); + psGMLElement = + FLTFindGeometryNode(psXMLNode, &bPoint, &bLine, &bPolygon); psDistance = CPLGetXMLNode(psXMLNode, "Distance"); - if( psDistance != NULL ) - pszDistance = CPLGetXMLValue(psDistance, NULL, NULL ); - if (pszPropertyName != NULL && psGMLElement && psDistance != NULL ) { + if (psDistance != NULL) + pszDistance = CPLGetXMLValue(psDistance, NULL, NULL); + if (pszPropertyName != NULL && psGMLElement && psDistance != NULL) { pszUnits = CPLGetXMLValue(psDistance, "units", NULL); - if( pszUnits == NULL ) /* FE 2.0 */ - pszUnits = CPLGetXMLValue(psDistance, "uom", NULL); + if (pszUnits == NULL) /* FE 2.0 */ + pszUnits = CPLGetXMLValue(psDistance, "uom", NULL); psShape = (shapeObj *)msSmallMalloc(sizeof(shapeObj)); msInitShape(psShape); - if (FLTShapeFromGMLTree(psGMLElement, psShape, &pszSRS)) - { + if (FLTShapeFromGMLTree(psGMLElement, psShape, &pszSRS)) { /*set the srs if available*/ if (pszSRS) psFilterNode->pszSRS = pszSRS; @@ -1323,24 +1290,26 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, psFilterNode->psRightNode = FLTCreateFilterEncodingNode(); if (bPoint) - psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_GEOMETRY_POINT; + psFilterNode->psRightNode->eType = + FILTER_NODE_TYPE_GEOMETRY_POINT; else if (bLine) psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_GEOMETRY_LINE; else if (bPolygon) - psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_GEOMETRY_POLYGON; + psFilterNode->psRightNode->eType = + FILTER_NODE_TYPE_GEOMETRY_POLYGON; psFilterNode->psRightNode->pOther = (shapeObj *)psShape; /*the value will be distance;units*/ psFilterNode->psRightNode->pszValue = msStrdup(pszDistance); if (pszUnits) { - psFilterNode->psRightNode->pszValue= msStringConcatenate(psFilterNode->psRightNode->pszValue, ";"); - psFilterNode->psRightNode->pszValue= msStringConcatenate(psFilterNode->psRightNode->pszValue, pszUnits); + psFilterNode->psRightNode->pszValue = + msStringConcatenate(psFilterNode->psRightNode->pszValue, ";"); + psFilterNode->psRightNode->pszValue = msStringConcatenate( + psFilterNode->psRightNode->pszValue, pszUnits); } - } - else - { - free(psShape); - msFree(pszSRS); - psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; + } else { + free(psShape); + msFree(pszSRS); + psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } } else psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; @@ -1354,21 +1323,21 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, strcasecmp(psXMLNode->pszValue, "Contains") == 0 || strcasecmp(psXMLNode->pszValue, "Overlaps") == 0) { shapeObj *psShape = NULL; - int bLine = 0, bPolygon = 0, bPoint=0; + int bLine = 0, bPolygon = 0, bPoint = 0; char *pszSRS = NULL; - const char* pszPropertyName; + const char *pszPropertyName; CPLXMLNode *psGMLElement = NULL; pszPropertyName = FLTGetPropertyName(psXMLNode); - psGMLElement = FLTFindGeometryNode(psXMLNode, &bPoint, &bLine, &bPolygon); + psGMLElement = + FLTFindGeometryNode(psXMLNode, &bPoint, &bLine, &bPolygon); if (pszPropertyName != NULL && psGMLElement) { psShape = (shapeObj *)msSmallMalloc(sizeof(shapeObj)); msInitShape(psShape); - if (FLTShapeFromGMLTree(psGMLElement, psShape, &pszSRS)) - { + if (FLTShapeFromGMLTree(psGMLElement, psShape, &pszSRS)) { /*set the srs if available*/ if (pszSRS) psFilterNode->pszSRS = pszSRS; @@ -1379,27 +1348,25 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, psFilterNode->psRightNode = FLTCreateFilterEncodingNode(); if (bPoint) - psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_GEOMETRY_POINT; + psFilterNode->psRightNode->eType = + FILTER_NODE_TYPE_GEOMETRY_POINT; else if (bLine) psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_GEOMETRY_LINE; else if (bPolygon) - psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_GEOMETRY_POLYGON; + psFilterNode->psRightNode->eType = + FILTER_NODE_TYPE_GEOMETRY_POLYGON; psFilterNode->psRightNode->pOther = (shapeObj *)psShape; - } - else - { - free(psShape); - msFree(pszSRS); - psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; + } else { + free(psShape); + msFree(pszSRS); + psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } } else psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } - - }/* end of is spatial */ - + } /* end of is spatial */ /* -------------------------------------------------------------------- */ /* Comparison Filter */ @@ -1417,29 +1384,30 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, /* */ /* -------------------------------------------------------------------- */ if (FLTIsBinaryComparisonFilterType(psXMLNode->pszValue)) { - const char* pszPropertyName = FLTGetPropertyName(psXMLNode); - if (pszPropertyName != NULL ) { + const char *pszPropertyName = FLTGetPropertyName(psXMLNode); + if (pszPropertyName != NULL) { psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); psFilterNode->psLeftNode->eType = FILTER_NODE_TYPE_PROPERTYNAME; psFilterNode->psLeftNode->pszValue = msStrdup(pszPropertyName); - psTmpNode = CPLSearchXMLNode(psXMLNode, "Literal"); + psTmpNode = CPLSearchXMLNode(psXMLNode, "Literal"); if (psTmpNode) { - const char* pszLiteral = CPLGetXMLValue(psTmpNode, NULL, NULL); + const char *pszLiteral = CPLGetXMLValue(psTmpNode, NULL, NULL); psFilterNode->psRightNode = FLTCreateBinaryCompFilterEncodingNode(); psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_LITERAL; if (pszLiteral != NULL) { - const char* pszMatchCase; + const char *pszMatchCase; psFilterNode->psRightNode->pszValue = msStrdup(pszLiteral); - + pszMatchCase = CPLGetXMLValue(psXMLNode, "matchCase", NULL); /*check if the matchCase attribute is set*/ - if( pszMatchCase != NULL && strcasecmp( pszMatchCase, "false") == 0) { + if (pszMatchCase != NULL && + strcasecmp(pszMatchCase, "false") == 0) { (*(int *)psFilterNode->psRightNode->pOther) = 1; } @@ -1451,7 +1419,8 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, psFilterNode->psRightNode->pszValue = NULL; } } - if (psFilterNode->psLeftNode == NULL || psFilterNode->psRightNode == NULL) + if (psFilterNode->psLeftNode == NULL || + psFilterNode->psRightNode == NULL) psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } @@ -1474,27 +1443,26 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, /* */ /* -------------------------------------------------------------------- */ else if (strcasecmp(psXMLNode->pszValue, "PropertyIsBetween") == 0) { - const char* pszPropertyName = FLTGetPropertyName(psXMLNode); - CPLXMLNode* psLowerBoundary = CPLGetXMLNode(psXMLNode, "LowerBoundary"); - CPLXMLNode* psUpperBoundary = CPLGetXMLNode(psXMLNode, "UpperBoundary"); - const char* pszLowerNode = NULL; - const char* pszUpperNode = NULL; - if( psLowerBoundary != NULL ) - { + const char *pszPropertyName = FLTGetPropertyName(psXMLNode); + CPLXMLNode *psLowerBoundary = CPLGetXMLNode(psXMLNode, "LowerBoundary"); + CPLXMLNode *psUpperBoundary = CPLGetXMLNode(psXMLNode, "UpperBoundary"); + const char *pszLowerNode = NULL; + const char *pszUpperNode = NULL; + if (psLowerBoundary != NULL) { /* check if the is there */ if (CPLGetXMLNode(psLowerBoundary, "Literal") != NULL) pszLowerNode = CPLGetXMLValue(psLowerBoundary, "Literal", NULL); else pszLowerNode = CPLGetXMLValue(psLowerBoundary, NULL, NULL); } - if( psUpperBoundary != NULL ) - { - if (CPLGetXMLNode(psUpperBoundary, "Literal") != NULL) + if (psUpperBoundary != NULL) { + if (CPLGetXMLNode(psUpperBoundary, "Literal") != NULL) pszUpperNode = CPLGetXMLValue(psUpperBoundary, "Literal", NULL); else pszUpperNode = CPLGetXMLValue(psUpperBoundary, NULL, NULL); } - if (pszPropertyName != NULL && pszLowerNode != NULL && pszUpperNode != NULL) { + if (pszPropertyName != NULL && pszLowerNode != NULL && + pszUpperNode != NULL) { psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); psFilterNode->psLeftNode->eType = FILTER_NODE_TYPE_PROPERTYNAME; @@ -1504,19 +1472,20 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_BOUNDARY; /* adding a ; between bounary values */ - const int nStrLength = strlen(pszLowerNode) + strlen(pszUpperNode) + 2; + const int nStrLength = + strlen(pszLowerNode) + strlen(pszUpperNode) + 2; psFilterNode->psRightNode->pszValue = - (char *)malloc(sizeof(char)*(nStrLength)); - strcpy( psFilterNode->psRightNode->pszValue, pszLowerNode); + (char *)malloc(sizeof(char) * (nStrLength)); + strcpy(psFilterNode->psRightNode->pszValue, pszLowerNode); strlcat(psFilterNode->psRightNode->pszValue, ";", nStrLength); - strlcat(psFilterNode->psRightNode->pszValue, pszUpperNode, nStrLength); - + strlcat(psFilterNode->psRightNode->pszValue, pszUpperNode, + nStrLength); } else psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; - }/* end of PropertyIsBetween */ + } /* end of PropertyIsBetween */ /* -------------------------------------------------------------------- */ /* PropertyIsLike */ /* */ @@ -1528,17 +1497,18 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, /* */ /* -------------------------------------------------------------------- */ else if (strcasecmp(psXMLNode->pszValue, "PropertyIsLike") == 0) { - const char* pszPropertyName = FLTGetPropertyName(psXMLNode); - const char* pszLiteral = CPLGetXMLValue(psXMLNode, "Literal", NULL); - const char* pszWildCard = CPLGetXMLValue(psXMLNode, "wildCard", NULL); - const char* pszSingleChar = CPLGetXMLValue(psXMLNode, "singleChar", NULL); - const char* pszEscapeChar = CPLGetXMLValue(psXMLNode, "escape", NULL); - if( pszEscapeChar == NULL ) - pszEscapeChar = CPLGetXMLValue(psXMLNode, "escapeChar", NULL); + const char *pszPropertyName = FLTGetPropertyName(psXMLNode); + const char *pszLiteral = CPLGetXMLValue(psXMLNode, "Literal", NULL); + const char *pszWildCard = CPLGetXMLValue(psXMLNode, "wildCard", NULL); + const char *pszSingleChar = + CPLGetXMLValue(psXMLNode, "singleChar", NULL); + const char *pszEscapeChar = CPLGetXMLValue(psXMLNode, "escape", NULL); + if (pszEscapeChar == NULL) + pszEscapeChar = CPLGetXMLValue(psXMLNode, "escapeChar", NULL); if (pszPropertyName != NULL && pszLiteral != NULL && - pszWildCard != NULL && pszSingleChar != NULL && pszEscapeChar != NULL) - { - FEPropertyIsLike* propIsLike; + pszWildCard != NULL && pszSingleChar != NULL && + pszEscapeChar != NULL) { + FEPropertyIsLike *propIsLike; propIsLike = (FEPropertyIsLike *)malloc(sizeof(FEPropertyIsLike)); @@ -1550,11 +1520,13 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, pszTmp = (char *)CPLGetXMLValue(psXMLNode, "matchCase", NULL); if (pszTmp && strcasecmp(pszTmp, "false") == 0) { - propIsLike->bCaseInsensitive =1; + propIsLike->bCaseInsensitive = 1; } - /* -------------------------------------------------------------------- */ - /* Create left and right node for the attribute and the value. */ - /* -------------------------------------------------------------------- */ + /* -------------------------------------------------------------------- + */ + /* Create left and right node for the attribute and the value. */ + /* -------------------------------------------------------------------- + */ psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); psFilterNode->psLeftNode->pszValue = msStrdup(pszPropertyName); @@ -1571,24 +1543,22 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, } else if (strcasecmp(psXMLNode->pszValue, "PropertyIsNull") == 0) { - const char* pszPropertyName = FLTGetPropertyName(psXMLNode); - if( pszPropertyName != NULL ) - { - psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); - psFilterNode->psLeftNode->pszValue = msStrdup(pszPropertyName); - psFilterNode->psLeftNode->eType = FILTER_NODE_TYPE_PROPERTYNAME; - } else + const char *pszPropertyName = FLTGetPropertyName(psXMLNode); + if (pszPropertyName != NULL) { + psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); + psFilterNode->psLeftNode->pszValue = msStrdup(pszPropertyName); + psFilterNode->psLeftNode->eType = FILTER_NODE_TYPE_PROPERTYNAME; + } else psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } else if (strcasecmp(psXMLNode->pszValue, "PropertyIsNil") == 0) { - const char* pszPropertyName = FLTGetPropertyName(psXMLNode); - if( pszPropertyName != NULL ) - { - psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); - psFilterNode->psLeftNode->pszValue = msStrdup(pszPropertyName); - psFilterNode->psLeftNode->eType = FILTER_NODE_TYPE_PROPERTYNAME; - } else + const char *pszPropertyName = FLTGetPropertyName(psXMLNode); + if (pszPropertyName != NULL) { + psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); + psFilterNode->psLeftNode->pszValue = msStrdup(pszPropertyName); + psFilterNode->psLeftNode->eType = FILTER_NODE_TYPE_PROPERTYNAME; + } else psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } } @@ -1627,19 +1597,20 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, if (pszFeatureIdList) pszFeatureIdList = msStringConcatenate(pszFeatureIdList, ","); - pszFeatureIdList = msStringConcatenate(pszFeatureIdList, pszFeatureId); + pszFeatureIdList = + msStringConcatenate(pszFeatureIdList, pszFeatureId); } psFeatureIdNode = psFeatureIdNode->psNext; } if (pszFeatureIdList) { msFree(psFilterNode->pszValue); - psFilterNode->pszValue = msStrdup(pszFeatureIdList); + psFilterNode->pszValue = msStrdup(pszFeatureIdList); msFree(pszFeatureIdList); } else psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } - + /* -------------------------------------------------------------------- */ /* Temporal Filter. */ /* @@ -1664,58 +1635,59 @@ void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, psFilterNode->eType = FILTER_NODE_TYPE_TEMPORAL; if (strcasecmp(psXMLNode->pszValue, "During") == 0) { - const char* pszPropertyName = NULL; - const char* pszBeginTime; - const char* pszEndTime; + const char *pszPropertyName = NULL; + const char *pszBeginTime; + const char *pszEndTime; pszPropertyName = FLTGetPropertyName(psXMLNode); - pszBeginTime = CPLGetXMLValue(psXMLNode, "TimePeriod.begin.TimeInstant.timePosition", NULL); - if( pszBeginTime == NULL ) - pszBeginTime = CPLGetXMLValue(psXMLNode, "TimePeriod.beginPosition", NULL); - pszEndTime = CPLGetXMLValue(psXMLNode, "TimePeriod.end.TimeInstant.timePosition", NULL); - if( pszEndTime == NULL ) - pszEndTime = CPLGetXMLValue(psXMLNode, "TimePeriod.endPosition", NULL); + pszBeginTime = CPLGetXMLValue( + psXMLNode, "TimePeriod.begin.TimeInstant.timePosition", NULL); + if (pszBeginTime == NULL) + pszBeginTime = + CPLGetXMLValue(psXMLNode, "TimePeriod.beginPosition", NULL); + pszEndTime = CPLGetXMLValue( + psXMLNode, "TimePeriod.end.TimeInstant.timePosition", NULL); + if (pszEndTime == NULL) + pszEndTime = + CPLGetXMLValue(psXMLNode, "TimePeriod.endPosition", NULL); if (pszPropertyName && pszBeginTime && pszEndTime && - strchr(pszBeginTime, '\'') == NULL && strchr(pszBeginTime, '\\') == NULL && - strchr(pszEndTime, '\'') == NULL && strchr(pszEndTime, '\\') == NULL && + strchr(pszBeginTime, '\'') == NULL && + strchr(pszBeginTime, '\\') == NULL && + strchr(pszEndTime, '\'') == NULL && + strchr(pszEndTime, '\\') == NULL && msTimeGetResolution(pszBeginTime) >= 0 && msTimeGetResolution(pszEndTime) >= 0) { psFilterNode->psLeftNode = FLTCreateFilterEncodingNode(); - psFilterNode->psLeftNode->eType = FILTER_NODE_TYPE_PROPERTYNAME; + psFilterNode->psLeftNode->eType = FILTER_NODE_TYPE_PROPERTYNAME; psFilterNode->psLeftNode->pszValue = msStrdup(pszPropertyName); psFilterNode->psRightNode = FLTCreateFilterEncodingNode(); psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_TIME_PERIOD; - psFilterNode->psRightNode->pszValue = static_cast(msSmallMalloc( strlen(pszBeginTime) + strlen(pszEndTime) + 2 )); - sprintf(psFilterNode->psRightNode->pszValue, "%s/%s", pszBeginTime, pszEndTime); - } - else + psFilterNode->psRightNode->pszValue = static_cast( + msSmallMalloc(strlen(pszBeginTime) + strlen(pszEndTime) + 2)); + sprintf(psFilterNode->psRightNode->pszValue, "%s/%s", pszBeginTime, + pszEndTime); + } else psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } else { psFilterNode->eType = FILTER_NODE_TYPE_UNDEFINED; } - }/* end of is temporal */ - - - + } /* end of is temporal */ } } - /************************************************************************/ /* int FLTIsLogicalFilterType((char *pszValue) */ /* */ /* return TRUE if the value of the node is of logical filter */ /* encoding type. */ /************************************************************************/ -int FLTIsLogicalFilterType(const char *pszValue) -{ +int FLTIsLogicalFilterType(const char *pszValue) { if (pszValue) { - if (strcasecmp(pszValue, "AND") == 0 || - strcasecmp(pszValue, "OR") == 0 || + if (strcasecmp(pszValue, "AND") == 0 || strcasecmp(pszValue, "OR") == 0 || strcasecmp(pszValue, "NOT") == 0) return MS_TRUE; } @@ -1728,8 +1700,7 @@ int FLTIsLogicalFilterType(const char *pszValue) /* */ /* Binary comparison filter type. */ /************************************************************************/ -int FLTIsBinaryComparisonFilterType(const char *pszValue) -{ +int FLTIsBinaryComparisonFilterType(const char *pszValue) { if (pszValue) { if (strcasecmp(pszValue, "PropertyIsEqualTo") == 0 || strcasecmp(pszValue, "PropertyIsNotEqualTo") == 0 || @@ -1749,8 +1720,7 @@ int FLTIsBinaryComparisonFilterType(const char *pszValue) /* return TRUE if the value of the node is of comparison filter */ /* encoding type. */ /************************************************************************/ -int FLTIsComparisonFilterType(const char *pszValue) -{ +int FLTIsComparisonFilterType(const char *pszValue) { if (pszValue) { if (FLTIsBinaryComparisonFilterType(pszValue) || strcasecmp(pszValue, "PropertyIsLike") == 0 || @@ -1769,8 +1739,7 @@ int FLTIsComparisonFilterType(const char *pszValue) /* return TRUE if the value of the node is of featureid filter */ /* encoding type. */ /************************************************************************/ -int FLTIsFeatureIdFilterType(const char *pszValue) -{ +int FLTIsFeatureIdFilterType(const char *pszValue) { if (pszValue && (strcasecmp(pszValue, "FeatureId") == 0 || strcasecmp(pszValue, "GmlObjectId") == 0 || strcasecmp(pszValue, "ResourceId") == 0)) @@ -1786,21 +1755,20 @@ int FLTIsFeatureIdFilterType(const char *pszValue) /* return TRUE if the value of the node is of spatial filter */ /* encoding type. */ /************************************************************************/ -int FLTIsSpatialFilterType(const char *pszValue) -{ +int FLTIsSpatialFilterType(const char *pszValue) { if (pszValue) { - if ( strcasecmp(pszValue, "BBOX") == 0 || - strcasecmp(pszValue, "DWithin") == 0 || - strcasecmp(pszValue, "Intersect") == 0 || - strcasecmp(pszValue, "Intersects") == 0 || - strcasecmp(pszValue, "Equals") == 0 || - strcasecmp(pszValue, "Disjoint") == 0 || - strcasecmp(pszValue, "Touches") == 0 || - strcasecmp(pszValue, "Crosses") == 0 || - strcasecmp(pszValue, "Within") == 0 || - strcasecmp(pszValue, "Contains") == 0 || - strcasecmp(pszValue, "Overlaps") == 0 || - strcasecmp(pszValue, "Beyond") == 0) + if (strcasecmp(pszValue, "BBOX") == 0 || + strcasecmp(pszValue, "DWithin") == 0 || + strcasecmp(pszValue, "Intersect") == 0 || + strcasecmp(pszValue, "Intersects") == 0 || + strcasecmp(pszValue, "Equals") == 0 || + strcasecmp(pszValue, "Disjoint") == 0 || + strcasecmp(pszValue, "Touches") == 0 || + strcasecmp(pszValue, "Crosses") == 0 || + strcasecmp(pszValue, "Within") == 0 || + strcasecmp(pszValue, "Contains") == 0 || + strcasecmp(pszValue, "Overlaps") == 0 || + strcasecmp(pszValue, "Beyond") == 0) return MS_TRUE; } @@ -1813,10 +1781,9 @@ int FLTIsSpatialFilterType(const char *pszValue) /* return TRUE if the value of the node is of temporal filter */ /* encoding type. */ /************************************************************************/ -int FLTIsTemporalFilterType(const char *pszValue) -{ +int FLTIsTemporalFilterType(const char *pszValue) { if (pszValue) { - if ( strcasecmp(pszValue, "During") == 0 ) + if (strcasecmp(pszValue, "During") == 0) return MS_TRUE; } @@ -1829,8 +1796,7 @@ int FLTIsTemporalFilterType(const char *pszValue) /* Verfify if the value of the node is one of the supported */ /* filter type. */ /************************************************************************/ -int FLTIsSupportedFilterType(CPLXMLNode *psXMLNode) -{ +int FLTIsSupportedFilterType(CPLXMLNode *psXMLNode) { if (psXMLNode) { if (FLTIsLogicalFilterType(psXMLNode->pszValue) || FLTIsSpatialFilterType(psXMLNode->pszValue) || @@ -1849,15 +1815,15 @@ int FLTIsSupportedFilterType(CPLXMLNode *psXMLNode) /* Loop trhough the nodes and return the number of nodes of */ /* specified value. */ /************************************************************************/ -int FLTNumberOfFilterType(FilterEncodingNode *psFilterNode, const char *szType) -{ +int FLTNumberOfFilterType(FilterEncodingNode *psFilterNode, + const char *szType) { int nCount = 0; - int nLeftNode=0 , nRightNode = 0; + int nLeftNode = 0, nRightNode = 0; if (!psFilterNode || !szType || !psFilterNode->pszValue) return 0; - if (strcasecmp(psFilterNode->pszValue, (char*)szType) == 0) + if (strcasecmp(psFilterNode->pszValue, (char *)szType) == 0) nCount++; if (psFilterNode->psLeftNode) @@ -1872,9 +1838,6 @@ int FLTNumberOfFilterType(FilterEncodingNode *psFilterNode, const char *szType) return nCount; } - - - /************************************************************************/ /* FLTValidForBBoxFilter */ /* */ @@ -1886,7 +1849,8 @@ int FLTNumberOfFilterType(FilterEncodingNode *psFilterNode, const char *szType) /* eg 1: */ /* */ /* Geometry */ -/* */ +/* */ /* 13.0983,31.5899 35.5472,42.8143*/ /* */ /* */ @@ -1896,7 +1860,8 @@ int FLTNumberOfFilterType(FilterEncodingNode *psFilterNode, const char *szType) /* */ /* */ /* Geometry */ -/* */ +/* */ /* 13.0983,31.5899 35.5472,42.8143*/ /* */ /* */ @@ -1908,8 +1873,7 @@ int FLTNumberOfFilterType(FilterEncodingNode *psFilterNode, const char *szType) /* */ /* */ /************************************************************************/ -int FLTValidForBBoxFilter(FilterEncodingNode *psFilterNode) -{ +int FLTValidForBBoxFilter(FilterEncodingNode *psFilterNode) { int nCount = 0; if (!psFilterNode || !psFilterNode->pszValue) @@ -1962,8 +1926,7 @@ static int FLTHasUniqueTopLevelDuringFilter(FilterEncodingNode *psFilterNode) } #endif -int FLTIsLineFilter(FilterEncodingNode *psFilterNode) -{ +int FLTIsLineFilter(FilterEncodingNode *psFilterNode) { if (!psFilterNode || !psFilterNode->pszValue) return 0; @@ -1975,8 +1938,7 @@ int FLTIsLineFilter(FilterEncodingNode *psFilterNode) return 0; } -int FLTIsPolygonFilter(FilterEncodingNode *psFilterNode) -{ +int FLTIsPolygonFilter(FilterEncodingNode *psFilterNode) { if (!psFilterNode || !psFilterNode->pszValue) return 0; @@ -1988,8 +1950,7 @@ int FLTIsPolygonFilter(FilterEncodingNode *psFilterNode) return 0; } -int FLTIsPointFilter(FilterEncodingNode *psFilterNode) -{ +int FLTIsPointFilter(FilterEncodingNode *psFilterNode) { if (!psFilterNode || !psFilterNode->pszValue) return 0; @@ -2001,8 +1962,7 @@ int FLTIsPointFilter(FilterEncodingNode *psFilterNode) return 0; } -int FLTIsBBoxFilter(FilterEncodingNode *psFilterNode) -{ +int FLTIsBBoxFilter(FilterEncodingNode *psFilterNode) { if (!psFilterNode || !psFilterNode->pszValue) return 0; @@ -2013,8 +1973,7 @@ int FLTIsBBoxFilter(FilterEncodingNode *psFilterNode) } shapeObj *FLTGetShape(FilterEncodingNode *psFilterNode, double *pdfDistance, - int *pnUnit) -{ + int *pnUnit) { char **tokens = NULL; int nTokens = 0; FilterEncodingNode *psNode = psFilterNode; @@ -2033,7 +1992,7 @@ shapeObj *FLTGetShape(FilterEncodingNode *psFilterNode, double *pdfDistance, if unit is there syntax is "URI#unit" (eg http://..../#m) or just "unit" */ - tokens = msStringSplit(psNode->pszValue,';', &nTokens); + tokens = msStringSplit(psNode->pszValue, ';', &nTokens); if (tokens && nTokens >= 1) { *pdfDistance = atof(tokens[0]); @@ -2041,41 +2000,40 @@ shapeObj *FLTGetShape(FilterEncodingNode *psFilterNode, double *pdfDistance, szUnitStr = msStrdup(tokens[1]); msFreeCharArray(tokens, nTokens); nTokens = 0; - tokens = msStringSplit(szUnitStr,'#', &nTokens); + tokens = msStringSplit(szUnitStr, '#', &nTokens); msFree(szUnitStr); if (tokens && nTokens >= 1) { - if (nTokens ==1) + if (nTokens == 1) szUnit = tokens[0]; else szUnit = tokens[1]; - if (strcasecmp(szUnit,"m") == 0 || - strcasecmp(szUnit,"meters") == 0 ) + if (strcasecmp(szUnit, "m") == 0 || + strcasecmp(szUnit, "meters") == 0) *pnUnit = MS_METERS; - else if (strcasecmp(szUnit,"km") == 0 || - strcasecmp(szUnit,"kilometers") == 0) + else if (strcasecmp(szUnit, "km") == 0 || + strcasecmp(szUnit, "kilometers") == 0) *pnUnit = MS_KILOMETERS; - else if (strcasecmp(szUnit,"NM") == 0 || - strcasecmp(szUnit,"nauticalmiles") == 0) + else if (strcasecmp(szUnit, "NM") == 0 || + strcasecmp(szUnit, "nauticalmiles") == 0) *pnUnit = MS_NAUTICALMILES; - else if (strcasecmp(szUnit,"mi") == 0 || - strcasecmp(szUnit,"miles") == 0) + else if (strcasecmp(szUnit, "mi") == 0 || + strcasecmp(szUnit, "miles") == 0) *pnUnit = MS_MILES; - else if (strcasecmp(szUnit,"in") == 0 || - strcasecmp(szUnit,"inches") == 0) + else if (strcasecmp(szUnit, "in") == 0 || + strcasecmp(szUnit, "inches") == 0) *pnUnit = MS_INCHES; - else if (strcasecmp(szUnit,"ft") == 0 || - strcasecmp(szUnit,"feet") == 0) + else if (strcasecmp(szUnit, "ft") == 0 || + strcasecmp(szUnit, "feet") == 0) *pnUnit = MS_FEET; - else if (strcasecmp(szUnit,"deg") == 0 || - strcasecmp(szUnit,"dd") == 0) + else if (strcasecmp(szUnit, "deg") == 0 || + strcasecmp(szUnit, "dd") == 0) *pnUnit = MS_DD; - else if (strcasecmp(szUnit,"px") == 0) + else if (strcasecmp(szUnit, "px") == 0) *pnUnit = MS_PIXELS; - } } - } + } msFreeCharArray(tokens, nTokens); } @@ -2092,43 +2050,43 @@ shapeObj *FLTGetShape(FilterEncodingNode *psFilterNode, double *pdfDistance, /* first bbox node found. The retrun value is the epsg code of */ /* the bbox. */ /************************************************************************/ -const char *FLTGetBBOX(FilterEncodingNode *psFilterNode, rectObj *psRect) -{ +const char *FLTGetBBOX(FilterEncodingNode *psFilterNode, rectObj *psRect) { const char *pszReturn = NULL; if (!psFilterNode || !psRect) return NULL; - if (psFilterNode->pszValue && strcasecmp(psFilterNode->pszValue, "BBOX") == 0) { + if (psFilterNode->pszValue && + strcasecmp(psFilterNode->pszValue, "BBOX") == 0) { if (psFilterNode->psRightNode && psFilterNode->psRightNode->pOther) { - rectObj* pRect= (rectObj *)psFilterNode->psRightNode->pOther; + rectObj *pRect = (rectObj *)psFilterNode->psRightNode->pOther; psRect->minx = pRect->minx; psRect->miny = pRect->miny; psRect->maxx = pRect->maxx; psRect->maxy = pRect->maxy; return psFilterNode->pszSRS; - } } else { pszReturn = FLTGetBBOX(psFilterNode->psLeftNode, psRect); if (pszReturn) return pszReturn; else - return FLTGetBBOX(psFilterNode->psRightNode, psRect); + return FLTGetBBOX(psFilterNode->psRightNode, psRect); } return pszReturn; } -const char* FLTGetDuring(FilterEncodingNode *psFilterNode, const char** ppszTimeField) -{ +const char *FLTGetDuring(FilterEncodingNode *psFilterNode, + const char **ppszTimeField) { const char *pszReturn = NULL; if (!psFilterNode || !ppszTimeField) return NULL; - if (psFilterNode->pszValue && strcasecmp(psFilterNode->pszValue, "During") == 0) { + if (psFilterNode->pszValue && + strcasecmp(psFilterNode->pszValue, "During") == 0) { *ppszTimeField = psFilterNode->psLeftNode->pszValue; return psFilterNode->psRightNode->pszValue; } else { @@ -2136,7 +2094,7 @@ const char* FLTGetDuring(FilterEncodingNode *psFilterNode, const char** ppszTime if (pszReturn) return pszReturn; else - return FLTGetDuring(psFilterNode->psRightNode, ppszTimeField); + return FLTGetDuring(psFilterNode->psRightNode, ppszTimeField); } return pszReturn; @@ -2147,59 +2105,52 @@ const char* FLTGetDuring(FilterEncodingNode *psFilterNode, const char** ppszTime /* */ /* Build SQL expressions from the mapserver nodes. */ /************************************************************************/ -char *FLTGetSQLExpression(FilterEncodingNode *psFilterNode, layerObj *lp) -{ +char *FLTGetSQLExpression(FilterEncodingNode *psFilterNode, layerObj *lp) { char *pszExpression = NULL; if (psFilterNode == NULL || lp == NULL) return NULL; if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON) { - if ( psFilterNode->psLeftNode && psFilterNode->psRightNode) { + if (psFilterNode->psLeftNode && psFilterNode->psRightNode) { if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue)) { + pszExpression = FLTGetBinaryComparisonSQLExpresssion(psFilterNode, lp); + } else if (strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0) { pszExpression = - FLTGetBinaryComparisonSQLExpresssion(psFilterNode, lp); - } else if (strcasecmp(psFilterNode->pszValue, - "PropertyIsBetween") == 0) { - pszExpression = - FLTGetIsBetweenComparisonSQLExpresssion(psFilterNode, lp); - } else if (strcasecmp(psFilterNode->pszValue, - "PropertyIsLike") == 0) { - pszExpression = - FLTGetIsLikeComparisonSQLExpression(psFilterNode, lp); - + FLTGetIsBetweenComparisonSQLExpresssion(psFilterNode, lp); + } else if (strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0) { + pszExpression = FLTGetIsLikeComparisonSQLExpression(psFilterNode, lp); } } } else if (psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL) { if (strcasecmp(psFilterNode->pszValue, "AND") == 0 || strcasecmp(psFilterNode->pszValue, "OR") == 0) { - pszExpression = - FLTGetLogicalComparisonSQLExpresssion(psFilterNode, lp); + pszExpression = FLTGetLogicalComparisonSQLExpresssion(psFilterNode, lp); } else if (strcasecmp(psFilterNode->pszValue, "NOT") == 0) { - pszExpression = - FLTGetLogicalComparisonSQLExpresssion(psFilterNode, lp); - + pszExpression = FLTGetLogicalComparisonSQLExpresssion(psFilterNode, lp); } } else if (psFilterNode->eType == FILTER_NODE_TYPE_SPATIAL) { /* TODO */ } else if (psFilterNode->eType == FILTER_NODE_TYPE_FEATUREID) { -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) if (psFilterNode->pszValue) { - const char *pszAttribute = msOWSLookupMetadata(&(lp->metadata), "OFG", "featureid"); + const char *pszAttribute = + msOWSLookupMetadata(&(lp->metadata), "OFG", "featureid"); if (pszAttribute) { int nTokens = 0; - char **tokens = msStringSplit(psFilterNode->pszValue,',', &nTokens); + char **tokens = msStringSplit(psFilterNode->pszValue, ',', &nTokens); int bString = 0; if (tokens && nTokens > 0) { - for (int i=0; iconnectiontype == MS_OGR || lp->connectiontype == MS_POSTGIS ) - snprintf(szTmp, sizeof(szTmp), "(CAST(%s AS CHARACTER(255)) = '%s')" , pszAttribute, pszEscapedStr); + if (bString) { + if (lp->connectiontype == MS_OGR || + lp->connectiontype == MS_POSTGIS) + snprintf(szTmp, sizeof(szTmp), + "(CAST(%s AS CHARACTER(255)) = '%s')", pszAttribute, + pszEscapedStr); else - snprintf(szTmp, sizeof(szTmp), "(%s = '%s')" , pszAttribute, pszEscapedStr); - } - else - snprintf(szTmp, sizeof(szTmp), "(%s = %s)" , pszAttribute, pszEscapedStr); + snprintf(szTmp, sizeof(szTmp), "(%s = '%s')", pszAttribute, + pszEscapedStr); + } else + snprintf(szTmp, sizeof(szTmp), "(%s = %s)", pszAttribute, + pszEscapedStr); msFree(pszEscapedStr); - pszEscapedStr=NULL; + pszEscapedStr = NULL; if (pszExpression != NULL) pszExpression = msStringConcatenate(pszExpression, " OR "); @@ -2230,9 +2184,8 @@ char *FLTGetSQLExpression(FilterEncodingNode *psFilterNode, layerObj *lp) pszExpression = msStringConcatenate(pszExpression, szTmp); } - - msFreeCharArray(tokens, nTokens); } + msFreeCharArray(tokens, nTokens); } /*opening and closing brackets*/ if (pszExpression) @@ -2244,9 +2197,8 @@ char *FLTGetSQLExpression(FilterEncodingNode *psFilterNode, layerObj *lp) return NULL; #endif - } - else if ( lp->connectiontype != MS_OGR && - psFilterNode->eType == FILTER_NODE_TYPE_TEMPORAL ) + } else if (lp->connectiontype != MS_OGR && + psFilterNode->eType == FILTER_NODE_TYPE_TEMPORAL) pszExpression = msStrdup(FLTGetTimeExpression(psFilterNode, lp).c_str()); return pszExpression; @@ -2258,8 +2210,7 @@ char *FLTGetSQLExpression(FilterEncodingNode *psFilterNode, layerObj *lp) /* Return the expression for logical comparison expression. */ /************************************************************************/ char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, - layerObj *lp) -{ + layerObj *lp) { char *pszBuffer = NULL; char *pszTmp = NULL; @@ -2287,10 +2238,10 @@ char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, /* ==================================================================== */ /* special case for temporal filter node (OGR layer only) */ /* ==================================================================== */ - else if (lp->connectiontype == MS_OGR && - psFilterNode->psLeftNode && psFilterNode->psRightNode && - (psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_TEMPORAL || - psFilterNode->psRightNode->eType == FILTER_NODE_TYPE_TEMPORAL) ) { + else if (lp->connectiontype == MS_OGR && psFilterNode->psLeftNode && + psFilterNode->psRightNode && + (psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_TEMPORAL || + psFilterNode->psRightNode->eType == FILTER_NODE_TYPE_TEMPORAL)) { if (psFilterNode->psLeftNode->eType != FILTER_NODE_TYPE_TEMPORAL) pszTmp = FLTGetSQLExpression(psFilterNode->psLeftNode, lp); else @@ -2302,7 +2253,7 @@ char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, pszBuffer = (char *)malloc(sizeof(char) * (strlen(pszTmp) + 1)); sprintf(pszBuffer, "%s", pszTmp); } - + /* -------------------------------------------------------------------- */ /* OR and AND */ /* -------------------------------------------------------------------- */ @@ -2311,9 +2262,8 @@ char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, if (!pszTmp) return NULL; - pszBuffer = (char *)malloc(sizeof(char) * - (strlen(pszTmp) + - strlen(psFilterNode->pszValue) + 5)); + pszBuffer = (char *)malloc( + sizeof(char) * (strlen(pszTmp) + strlen(psFilterNode->pszValue) + 5)); pszBuffer[0] = '\0'; strcat(pszBuffer, " ("); strcat(pszBuffer, pszTmp); @@ -2321,7 +2271,7 @@ char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, strcat(pszBuffer, psFilterNode->pszValue); strcat(pszBuffer, " "); - free( pszTmp ); + free(pszTmp); const size_t nTmp = strlen(pszBuffer); pszTmp = FLTGetSQLExpression(psFilterNode->psRightNode, lp); @@ -2330,8 +2280,8 @@ char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, return NULL; } - pszBuffer = (char *)msSmallRealloc(pszBuffer, - sizeof(char) * (strlen(pszTmp) + nTmp +3)); + pszBuffer = (char *)msSmallRealloc( + pszBuffer, sizeof(char) * (strlen(pszTmp) + nTmp + 3)); strcat(pszBuffer, pszTmp); strcat(pszBuffer, ") "); } @@ -2344,7 +2294,7 @@ char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, if (!pszTmp) return NULL; - pszBuffer = (char *)malloc(sizeof(char) * (strlen(pszTmp) + 9)); + pszBuffer = (char *)malloc(sizeof(char) * (strlen(pszTmp) + 9)); pszBuffer[0] = '\0'; strcat(pszBuffer, " (NOT "); @@ -2356,30 +2306,26 @@ char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, /* -------------------------------------------------------------------- */ /* Cleanup. */ /* -------------------------------------------------------------------- */ - if( pszTmp != NULL ) - free( pszTmp ); + if (pszTmp != NULL) + free(pszTmp); return pszBuffer; - } - /************************************************************************/ /* FLTGetBinaryComparisonSQLExpresssion */ /* */ /* Return the expression for a binary comparison filter node. */ /************************************************************************/ char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, - layerObj *lp) -{ + layerObj *lp) { const size_t bufferSize = 1024; char szBuffer[1024]; - int bString=0; + int bString = 0; char szTmp[256]; - char* pszEscapedStr = NULL; + char *pszEscapedStr = NULL; szBuffer[0] = '\0'; - if (!psFilterNode || ! - FLTIsBinaryComparisonFilterType(psFilterNode->pszValue)) + if (!psFilterNode || !FLTIsBinaryComparisonFilterType(psFilterNode->pszValue)) return NULL; /* -------------------------------------------------------------------- */ @@ -2388,10 +2334,11 @@ char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, /* -------------------------------------------------------------------- */ bString = 0; if (psFilterNode->psRightNode->pszValue) { - const char* pszOFGType; - snprintf(szTmp, sizeof(szTmp), "%s_type", psFilterNode->psLeftNode->pszValue); + const char *pszOFGType; + snprintf(szTmp, sizeof(szTmp), "%s_type", + psFilterNode->psLeftNode->pszValue); pszOFGType = msOWSLookupMetadata(&(lp->metadata), "OFG", szTmp); - if (pszOFGType!= NULL && strcasecmp(pszOFGType, "Character") == 0) + if (pszOFGType != NULL && strcasecmp(pszOFGType, "Character") == 0) bString = 1; else if (FLTIsNumeric(psFilterNode->psRightNode->pszValue) == MS_FALSE) @@ -2402,21 +2349,18 @@ char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, if (psFilterNode->psRightNode->pszValue == NULL) bString = 1; - /*opening bracket*/ strlcat(szBuffer, " (", bufferSize); - pszEscapedStr = msLayerEscapePropertyName(lp, psFilterNode->psLeftNode->pszValue); - + pszEscapedStr = + msLayerEscapePropertyName(lp, psFilterNode->psLeftNode->pszValue); /* attribute */ /*case insensitive set ? */ - if (bString && - strcasecmp(psFilterNode->pszValue, - "PropertyIsEqualTo") == 0 && + if (bString && strcasecmp(psFilterNode->pszValue, "PropertyIsEqualTo") == 0 && psFilterNode->psRightNode->pOther && (*(int *)psFilterNode->psRightNode->pOther) == 1) { - snprintf(szTmp, sizeof(szTmp), "lower(%s) ", pszEscapedStr); + snprintf(szTmp, sizeof(szTmp), "lower(%s) ", pszEscapedStr); strlcat(szBuffer, szTmp, bufferSize); } else strlcat(szBuffer, pszEscapedStr, bufferSize); @@ -2424,22 +2368,17 @@ char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, msFree(pszEscapedStr); pszEscapedStr = NULL; - /* logical operator */ - if (strcasecmp(psFilterNode->pszValue, - "PropertyIsEqualTo") == 0) + if (strcasecmp(psFilterNode->pszValue, "PropertyIsEqualTo") == 0) strlcat(szBuffer, "=", bufferSize); - else if (strcasecmp(psFilterNode->pszValue, - "PropertyIsNotEqualTo") == 0) + else if (strcasecmp(psFilterNode->pszValue, "PropertyIsNotEqualTo") == 0) strlcat(szBuffer, "<>", bufferSize); - else if (strcasecmp(psFilterNode->pszValue, - "PropertyIsLessThan") == 0) + else if (strcasecmp(psFilterNode->pszValue, "PropertyIsLessThan") == 0) strlcat(szBuffer, "<", bufferSize); - else if (strcasecmp(psFilterNode->pszValue, - "PropertyIsGreaterThan") == 0) + else if (strcasecmp(psFilterNode->pszValue, "PropertyIsGreaterThan") == 0) strlcat(szBuffer, ">", bufferSize); - else if (strcasecmp(psFilterNode->pszValue, - "PropertyIsLessThanOrEqualTo") == 0) + else if (strcasecmp(psFilterNode->pszValue, "PropertyIsLessThanOrEqualTo") == + 0) strlcat(szBuffer, "<=", bufferSize); else if (strcasecmp(psFilterNode->pszValue, "PropertyIsGreaterThanOrEqualTo") == 0) @@ -2449,14 +2388,13 @@ char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, /* value */ - if (bString && - psFilterNode->psRightNode->pszValue && - strcasecmp(psFilterNode->pszValue, - "PropertyIsEqualTo") == 0 && + if (bString && psFilterNode->psRightNode->pszValue && + strcasecmp(psFilterNode->pszValue, "PropertyIsEqualTo") == 0 && psFilterNode->psRightNode->pOther && (*(int *)psFilterNode->psRightNode->pOther) == 1) { - char* pszEscapedStr; - pszEscapedStr = msLayerEscapeSQLParam(lp, psFilterNode->psRightNode->pszValue); + char *pszEscapedStr; + pszEscapedStr = + msLayerEscapeSQLParam(lp, psFilterNode->psRightNode->pszValue); snprintf(szTmp, sizeof(szTmp), "lower('%s') ", pszEscapedStr); msFree(pszEscapedStr); strlcat(szBuffer, szTmp, bufferSize); @@ -2466,18 +2404,18 @@ char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, if (psFilterNode->psRightNode->pszValue) { if (bString) { - char* pszEscapedStr; - pszEscapedStr = msLayerEscapeSQLParam(lp, psFilterNode->psRightNode->pszValue); + char *pszEscapedStr; + pszEscapedStr = + msLayerEscapeSQLParam(lp, psFilterNode->psRightNode->pszValue); strlcat(szBuffer, pszEscapedStr, bufferSize); msFree(pszEscapedStr); - pszEscapedStr=NULL; + pszEscapedStr = NULL; } else strlcat(szBuffer, psFilterNode->psRightNode->pszValue, bufferSize); } if (bString) strlcat(szBuffer, "'", bufferSize); - } /*closing bracket*/ strlcat(szBuffer, ") ", bufferSize); @@ -2485,29 +2423,27 @@ char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, return msStrdup(szBuffer); } - /************************************************************************/ /* FLTGetIsBetweenComparisonSQLExpresssion */ /* */ /* Build an SQL expresssion for IsBteween Filter. */ /************************************************************************/ char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, - layerObj *lp) -{ + layerObj *lp) { const size_t bufferSize = 1024; char szBuffer[1024]; char **aszBounds = NULL; int nBounds = 0; - int bString=0; + int bString = 0; char szTmp[256]; - char* pszEscapedStr; + char *pszEscapedStr; szBuffer[0] = '\0'; if (!psFilterNode || !(strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0)) return NULL; - if (!psFilterNode->psLeftNode || !psFilterNode->psRightNode ) + if (!psFilterNode->psLeftNode || !psFilterNode->psRightNode) return NULL; /* -------------------------------------------------------------------- */ @@ -2524,10 +2460,11 @@ char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, /* -------------------------------------------------------------------- */ bString = 0; if (aszBounds[0]) { - const char* pszOFGType; - snprintf(szTmp, sizeof(szTmp), "%s_type", psFilterNode->psLeftNode->pszValue); + const char *pszOFGType; + snprintf(szTmp, sizeof(szTmp), "%s_type", + psFilterNode->psLeftNode->pszValue); pszOFGType = msOWSLookupMetadata(&(lp->metadata), "OFG", szTmp); - if (pszOFGType!= NULL && strcasecmp(pszOFGType, "Character") == 0) + if (pszOFGType != NULL && strcasecmp(pszOFGType, "Character") == 0) bString = 1; else if (FLTIsNumeric(aszBounds[0]) == MS_FALSE) bString = 1; @@ -2539,7 +2476,6 @@ char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, } } - /* -------------------------------------------------------------------- */ /* build expresssion. */ /* -------------------------------------------------------------------- */ @@ -2547,7 +2483,8 @@ char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, strlcat(szBuffer, " (", bufferSize); /* attribute */ - pszEscapedStr = msLayerEscapePropertyName(lp, psFilterNode->psLeftNode->pszValue); + pszEscapedStr = + msLayerEscapePropertyName(lp, psFilterNode->psLeftNode->pszValue); strlcat(szBuffer, pszEscapedStr, bufferSize); msFree(pszEscapedStr); @@ -2558,27 +2495,27 @@ char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, /*bound 1*/ if (bString) - strlcat(szBuffer,"'", bufferSize); - pszEscapedStr = msLayerEscapeSQLParam( lp, aszBounds[0]); + strlcat(szBuffer, "'", bufferSize); + pszEscapedStr = msLayerEscapeSQLParam(lp, aszBounds[0]); strlcat(szBuffer, pszEscapedStr, bufferSize); msFree(pszEscapedStr); - pszEscapedStr=NULL; + pszEscapedStr = NULL; if (bString) - strlcat(szBuffer,"'", bufferSize); + strlcat(szBuffer, "'", bufferSize); strlcat(szBuffer, " AND ", bufferSize); /*bound 2*/ if (bString) strlcat(szBuffer, "'", bufferSize); - pszEscapedStr = msLayerEscapeSQLParam( lp, aszBounds[1]); + pszEscapedStr = msLayerEscapeSQLParam(lp, aszBounds[1]); strlcat(szBuffer, pszEscapedStr, bufferSize); msFree(pszEscapedStr); - pszEscapedStr=NULL; + pszEscapedStr = NULL; if (bString) - strlcat(szBuffer,"'", bufferSize); + strlcat(szBuffer, "'", bufferSize); /*closing paranthesis*/ strlcat(szBuffer, ")", bufferSize); @@ -2594,8 +2531,7 @@ char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, /* Build an sql expression for IsLike filter. */ /************************************************************************/ char *FLTGetIsLikeComparisonSQLExpression(FilterEncodingNode *psFilterNode, - layerObj *lp) -{ + layerObj *lp) { const size_t bufferSize = 1024; char szBuffer[1024]; char *pszValue = NULL; @@ -2605,11 +2541,11 @@ char *FLTGetIsLikeComparisonSQLExpression(FilterEncodingNode *psFilterNode, const char *pszEscape = NULL; char szTmp[4]; - int nLength=0, i=0, j=0; - int bCaseInsensitive = 0; + int nLength = 0, i = 0, j = 0; + int bCaseInsensitive = 0; char *pszEscapedStr = NULL; - FEPropertyIsLike* propIsLike; + FEPropertyIsLike *propIsLike; if (!psFilterNode || !psFilterNode->pOther || !psFilterNode->psLeftNode || !psFilterNode->psRightNode || !psFilterNode->psRightNode->pszValue) @@ -2621,27 +2557,28 @@ char *FLTGetIsLikeComparisonSQLExpression(FilterEncodingNode *psFilterNode, pszEscape = propIsLike->pszEscapeChar; bCaseInsensitive = propIsLike->bCaseInsensitive; - if (!pszWild || strlen(pszWild) == 0 || - !pszSingle || strlen(pszSingle) == 0 || - !pszEscape || strlen(pszEscape) == 0) + if (!pszWild || strlen(pszWild) == 0 || !pszSingle || + strlen(pszSingle) == 0 || !pszEscape || strlen(pszEscape) == 0) return NULL; if (pszEscape[0] == '\'') { /* This might be valid, but the risk of SQL injection is too high */ /* and the below code is not ready for that */ /* Someone who does this has clearly suspect intentions ! */ - msSetError(MS_MISCERR, "Single quote character is not allowed as an escaping character.", - "FLTGetIsLikeComparisonSQLExpression()"); + msSetError( + MS_MISCERR, + "Single quote character is not allowed as an escaping character.", + "FLTGetIsLikeComparisonSQLExpression()"); return NULL; } - szBuffer[0] = '\0'; /*opening bracket*/ strlcat(szBuffer, " (", bufferSize); /* attribute name */ - pszEscapedStr = msLayerEscapePropertyName(lp, psFilterNode->psLeftNode->pszValue); + pszEscapedStr = + msLayerEscapePropertyName(lp, psFilterNode->psLeftNode->pszValue); strlcat(szBuffer, pszEscapedStr, bufferSize); msFree(pszEscapedStr); @@ -2658,13 +2595,11 @@ char *FLTGetIsLikeComparisonSQLExpression(FilterEncodingNode *psFilterNode, pszValue = psFilterNode->psRightNode->pszValue; nLength = strlen(pszValue); - pszEscapedStr = (char*) msSmallMalloc( 3 * nLength + 1); + pszEscapedStr = (char *)msSmallMalloc(3 * nLength + 1); - for (i=0, j=0; iconnectiontype != MS_OGR) { if (lp->connectiontype == MS_POSTGIS && pszEscape[0] == '\\') - strlcat(szBuffer, " escape E'", bufferSize); + strlcat(szBuffer, " escape E'", bufferSize); else - strlcat(szBuffer, " escape '", bufferSize); + strlcat(szBuffer, " escape '", bufferSize); szTmp[0] = pszEscape[0]; if (pszEscape[0] == '\\') { szTmp[1] = '\\'; @@ -2710,9 +2645,9 @@ char *FLTGetIsLikeComparisonSQLExpression(FilterEncodingNode *psFilterNode, szTmp[2] = '\0'; } - strlcat(szBuffer, szTmp, bufferSize); + strlcat(szBuffer, szTmp, bufferSize); } - strlcat(szBuffer, ") ", bufferSize); + strlcat(szBuffer, ") ", bufferSize); return msStrdup(szBuffer); } @@ -2723,8 +2658,7 @@ char *FLTGetIsLikeComparisonSQLExpression(FilterEncodingNode *psFilterNode, /* Utility function to see if a spatial filter is included in */ /* the node. */ /************************************************************************/ -int FLTHasSpatialFilter(FilterEncodingNode *psNode) -{ +int FLTHasSpatialFilter(FilterEncodingNode *psNode) { int bResult = MS_FALSE; if (!psNode) @@ -2746,41 +2680,36 @@ int FLTHasSpatialFilter(FilterEncodingNode *psNode) FLTIsLineFilter(psNode) || FLTIsPolygonFilter(psNode)) return MS_TRUE; - return MS_FALSE; } - /************************************************************************/ /* FLTCreateFeatureIdFilterEncoding */ /* */ /* Utility function to create a filter node of FeatureId type. */ /************************************************************************/ -FilterEncodingNode *FLTCreateFeatureIdFilterEncoding(const char *pszString) -{ +FilterEncodingNode *FLTCreateFeatureIdFilterEncoding(const char *pszString) { FilterEncodingNode *psFilterNode = NULL; if (pszString) { psFilterNode = FLTCreateFilterEncodingNode(); psFilterNode->eType = FILTER_NODE_TYPE_FEATUREID; - psFilterNode->pszValue = msStrdup(pszString); + psFilterNode->pszValue = msStrdup(pszString); return psFilterNode; } return NULL; } - /************************************************************************/ /* FLTParseGMLBox */ /* */ /* Parse gml box. Used for FE 1.0 */ /************************************************************************/ -int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS) -{ +int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS) { int bCoordinatesValid = 0; CPLXMLNode *psCoordinates = NULL; CPLXMLNode *psCoord1 = NULL, *psCoord2 = NULL; - char **papszCoords=NULL, **papszMin=NULL, **papszMax = NULL; + char **papszCoords = NULL, **papszMin = NULL, **papszMax = NULL; int nCoords = 0, nCoordsMin = 0, nCoordsMax = 0; const char *pszTmpCoord = NULL; const char *pszSRS = NULL; @@ -2795,11 +2724,11 @@ int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS) psCoordinates = CPLGetXMLNode(psBox, "coordinates"); pszTS = CPLGetXMLValue(psCoordinates, "ts", NULL); - if( pszTS == NULL ) - pszTS = " "; + if (pszTS == NULL) + pszTS = " "; pszCS = CPLGetXMLValue(psCoordinates, "cs", NULL); - if( pszCS == NULL ) - pszCS = ","; + if (pszCS == NULL) + pszCS = ","; pszTmpCoord = CPLGetXMLValue(psCoordinates, NULL, NULL); if (pszTmpCoord) { @@ -2810,11 +2739,11 @@ int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS) papszMax = msStringSplit(papszCoords[1], pszCS[0], &nCoordsMax); } if (papszMax && nCoordsMax == 2) { - bCoordinatesValid =1; - minx = atof(papszMin[0]); - miny = atof(papszMin[1]); - maxx = atof(papszMax[0]); - maxy = atof(papszMax[1]); + bCoordinatesValid = 1; + minx = atof(papszMin[0]); + miny = atof(papszMin[1]); + maxx = atof(papszMax[0]); + maxy = atof(papszMax[1]); } msFreeCharArray(papszMin, nCoordsMin); @@ -2826,8 +2755,8 @@ int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS) psCoord1 = CPLGetXMLNode(psBox, "coord"); psCoord2 = FLTGetNextSibblingNode(psCoord1); if (psCoord1 && psCoord2 && strcmp(psCoord2->pszValue, "coord") == 0) { - const char* pszX = CPLGetXMLValue(psCoord1, "X", NULL); - const char* pszY = CPLGetXMLValue(psCoord1, "Y", NULL); + const char *pszX = CPLGetXMLValue(psCoord1, "X", NULL); + const char *pszY = CPLGetXMLValue(psCoord1, "Y", NULL); if (pszX && pszY) { minx = atof(pszX); miny = atof(pszY); @@ -2841,16 +2770,15 @@ int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS) } } } - } } if (bCoordinatesValid) { - psBbox->minx = minx; - psBbox->miny = miny; + psBbox->minx = minx; + psBbox->miny = miny; - psBbox->maxx = maxx; - psBbox->maxy = maxy; + psBbox->maxx = maxx; + psBbox->maxy = maxy; } return bCoordinatesValid; @@ -2860,21 +2788,20 @@ int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS) /* */ /* Utility function to parse a gml:Envelope (used for SOS and FE1.1)*/ /************************************************************************/ -int FLTParseGMLEnvelope(CPLXMLNode *psRoot, rectObj *psBbox, char **ppszSRS) -{ - CPLXMLNode *psUpperCorner=NULL, *psLowerCorner=NULL; - const char *pszLowerCorner=NULL, *pszUpperCorner=NULL; +int FLTParseGMLEnvelope(CPLXMLNode *psRoot, rectObj *psBbox, char **ppszSRS) { + CPLXMLNode *psUpperCorner = NULL, *psLowerCorner = NULL; + const char *pszLowerCorner = NULL, *pszUpperCorner = NULL; int bValid = 0; char **tokens; int n; if (psRoot && psBbox && psRoot->eType == CXT_Element && - EQUAL(psRoot->pszValue,"Envelope")) { + EQUAL(psRoot->pszValue, "Envelope")) { /*Get the srs if available*/ if (ppszSRS) { - const char* pszSRS = CPLGetXMLValue(psRoot, "srsName", NULL); - if( pszSRS != NULL ) - *ppszSRS = msStrdup(pszSRS); + const char *pszSRS = CPLGetXMLValue(psRoot, "srsName", NULL); + if (pszSRS != NULL) + *ppszSRS = msStrdup(pszSRS); } psLowerCorner = CPLSearchXMLNode(psRoot, "lowerCorner"); psUpperCorner = CPLSearchXMLNode(psRoot, "upperCorner"); @@ -2910,20 +2837,18 @@ int FLTParseGMLEnvelope(CPLXMLNode *psRoot, rectObj *psBbox, char **ppszSRS) /* FLTNeedSRSSwapping */ /************************************************************************/ -static int FLTNeedSRSSwapping( mapObj *map, const char* pszSRS ) -{ - int bNeedSwapping = MS_FALSE; - projectionObj sProjTmp; - msInitProjection(&sProjTmp); - if( map ) - { - msProjectionInheritContextFrom(&sProjTmp, &map->projection); - } - if (msLoadProjectionStringEPSG(&sProjTmp, pszSRS) == 0) { - bNeedSwapping = msIsAxisInvertedProj(&sProjTmp); - } - msFreeProjection(&sProjTmp); - return bNeedSwapping; +static int FLTNeedSRSSwapping(mapObj *map, const char *pszSRS) { + int bNeedSwapping = MS_FALSE; + projectionObj sProjTmp; + msInitProjection(&sProjTmp); + if (map) { + msProjectionInheritContextFrom(&sProjTmp, &map->projection); + } + if (msLoadProjectionStringEPSG(&sProjTmp, pszSRS) == 0) { + bNeedSwapping = msIsAxisInvertedProj(&sProjTmp); + } + msFreeProjection(&sProjTmp); + return bNeedSwapping; } /************************************************************************/ @@ -2935,55 +2860,46 @@ static int FLTNeedSRSSwapping( mapObj *map, const char* pszSRS ) /* caller will have to determine its value from a more general */ /* context. */ /************************************************************************/ -void FLTDoAxisSwappingIfNecessary(mapObj *map, - FilterEncodingNode *psFilterNode, - int bDefaultSRSNeedsAxisSwapping) -{ - if( psFilterNode == NULL ) - return; - - if( psFilterNode->eType == FILTER_NODE_TYPE_SPATIAL && - psFilterNode->psRightNode->eType == FILTER_NODE_TYPE_BBOX ) - { - rectObj* rect = (rectObj *)psFilterNode->psRightNode->pOther; - const char* pszSRS = psFilterNode->pszSRS; - if( (pszSRS != NULL && FLTNeedSRSSwapping(map, pszSRS)) || - (pszSRS == NULL && bDefaultSRSNeedsAxisSwapping) ) - { - double tmp; - - tmp = rect->minx; - rect->minx = rect->miny; - rect->miny = tmp; - - tmp = rect->maxx; - rect->maxx = rect->maxy; - rect->maxy = tmp; - } - } - else if( psFilterNode->eType == FILTER_NODE_TYPE_SPATIAL && - FLTIsGeometryFilterNodeType(psFilterNode->psRightNode->eType) ) - { - shapeObj* shape = (shapeObj *)(psFilterNode->psRightNode->pOther); - const char* pszSRS = psFilterNode->pszSRS; - if( (pszSRS != NULL && FLTNeedSRSSwapping(map, pszSRS)) || - (pszSRS == NULL && bDefaultSRSNeedsAxisSwapping) ) - { - msAxisSwapShape(shape); - } +void FLTDoAxisSwappingIfNecessary(mapObj *map, FilterEncodingNode *psFilterNode, + int bDefaultSRSNeedsAxisSwapping) { + if (psFilterNode == NULL) + return; + + if (psFilterNode->eType == FILTER_NODE_TYPE_SPATIAL && + psFilterNode->psRightNode->eType == FILTER_NODE_TYPE_BBOX) { + rectObj *rect = (rectObj *)psFilterNode->psRightNode->pOther; + const char *pszSRS = psFilterNode->pszSRS; + if ((pszSRS != NULL && FLTNeedSRSSwapping(map, pszSRS)) || + (pszSRS == NULL && bDefaultSRSNeedsAxisSwapping)) { + double tmp; + + tmp = rect->minx; + rect->minx = rect->miny; + rect->miny = tmp; + + tmp = rect->maxx; + rect->maxx = rect->maxy; + rect->maxy = tmp; } - else - { - FLTDoAxisSwappingIfNecessary(map, psFilterNode->psLeftNode, bDefaultSRSNeedsAxisSwapping); - FLTDoAxisSwappingIfNecessary(map, psFilterNode->psRightNode, bDefaultSRSNeedsAxisSwapping); + } else if (psFilterNode->eType == FILTER_NODE_TYPE_SPATIAL && + FLTIsGeometryFilterNodeType(psFilterNode->psRightNode->eType)) { + shapeObj *shape = (shapeObj *)(psFilterNode->psRightNode->pOther); + const char *pszSRS = psFilterNode->pszSRS; + if ((pszSRS != NULL && FLTNeedSRSSwapping(map, pszSRS)) || + (pszSRS == NULL && bDefaultSRSNeedsAxisSwapping)) { + msAxisSwapShape(shape); } + } else { + FLTDoAxisSwappingIfNecessary(map, psFilterNode->psLeftNode, + bDefaultSRSNeedsAxisSwapping); + FLTDoAxisSwappingIfNecessary(map, psFilterNode->psRightNode, + bDefaultSRSNeedsAxisSwapping); + } } - static void FLTReplacePropertyName(FilterEncodingNode *psFilterNode, const char *pszOldName, - const char *pszNewName) -{ + const char *pszNewName) { if (psFilterNode && pszOldName && pszNewName) { if (psFilterNode->eType == FILTER_NODE_TYPE_PROPERTYNAME) { if (psFilterNode->pszValue && @@ -2993,45 +2909,39 @@ static void FLTReplacePropertyName(FilterEncodingNode *psFilterNode, } } if (psFilterNode->psLeftNode) - FLTReplacePropertyName(psFilterNode->psLeftNode, pszOldName, - pszNewName); + FLTReplacePropertyName(psFilterNode->psLeftNode, pszOldName, pszNewName); if (psFilterNode->psRightNode) - FLTReplacePropertyName(psFilterNode->psRightNode, pszOldName, - pszNewName); + FLTReplacePropertyName(psFilterNode->psRightNode, pszOldName, pszNewName); } } - -static int FLTIsGMLDefaultProperty(const char* pszName) -{ - return (strcmp(pszName, "gml:name") == 0 || - strcmp(pszName, "gml:description") == 0 || - strcmp(pszName, "gml:descriptionReference") == 0 || - strcmp(pszName, "gml:identifier") == 0 || - strcmp(pszName, "gml:boundedBy") == 0 || - strcmp(pszName, "@gml:id") == 0); +static int FLTIsGMLDefaultProperty(const char *pszName) { + return (strcmp(pszName, "gml:name") == 0 || + strcmp(pszName, "gml:description") == 0 || + strcmp(pszName, "gml:descriptionReference") == 0 || + strcmp(pszName, "gml:identifier") == 0 || + strcmp(pszName, "gml:boundedBy") == 0 || + strcmp(pszName, "@gml:id") == 0); } -static void FLTStripNameSpacesFromPropertyName(FilterEncodingNode *psFilterNode) -{ - char **tokens=NULL; - int n=0; +static void +FLTStripNameSpacesFromPropertyName(FilterEncodingNode *psFilterNode) { + char **tokens = NULL; + int n = 0; if (psFilterNode) { if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON && psFilterNode->psLeftNode != NULL && psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_PROPERTYNAME && - FLTIsGMLDefaultProperty(psFilterNode->psLeftNode->pszValue) ) - { - return; + FLTIsGMLDefaultProperty(psFilterNode->psLeftNode->pszValue)) { + return; } if (psFilterNode->eType == FILTER_NODE_TYPE_PROPERTYNAME) { - if (psFilterNode->pszValue && - strstr(psFilterNode->pszValue, ":")) { + if (psFilterNode->pszValue && strstr(psFilterNode->pszValue, ":")) { tokens = msStringSplit(psFilterNode->pszValue, ':', &n); - if (tokens && n==2) { + if (tokens && n == 2) { msFree(psFilterNode->pszValue); psFilterNode->pszValue = msStrdup(tokens[1]); } @@ -3043,34 +2953,32 @@ static void FLTStripNameSpacesFromPropertyName(FilterEncodingNode *psFilterNode) if (psFilterNode->psRightNode) FLTStripNameSpacesFromPropertyName(psFilterNode->psRightNode); } - } static void FLTRemoveGroupName(FilterEncodingNode *psFilterNode, - gmlGroupListObj* groupList) -{ + gmlGroupListObj *groupList) { int i; if (psFilterNode) { if (psFilterNode->eType == FILTER_NODE_TYPE_PROPERTYNAME) { - if( psFilterNode->pszValue != NULL ) - { - const char* pszPropertyName = psFilterNode->pszValue; - const char* pszSlash = strchr(pszPropertyName, '/'); - if( pszSlash != NULL ) { - const char* pszColon = strchr(pszPropertyName, ':'); - if( pszColon != NULL && pszColon < pszSlash ) - pszPropertyName = pszColon + 1; - for(i=0;inumgroups;i++) { - const char* pszGroupName = groupList->groups[i].name; + if (psFilterNode->pszValue != NULL) { + const char *pszPropertyName = psFilterNode->pszValue; + const char *pszSlash = strchr(pszPropertyName, '/'); + if (pszSlash != NULL) { + const char *pszColon = strchr(pszPropertyName, ':'); + if (pszColon != NULL && pszColon < pszSlash) + pszPropertyName = pszColon + 1; + for (i = 0; i < groupList->numgroups; i++) { + const char *pszGroupName = groupList->groups[i].name; size_t nGroupNameLen = strlen(pszGroupName); - if(strncasecmp(pszPropertyName, pszGroupName, nGroupNameLen) == 0 && - pszPropertyName[nGroupNameLen] == '/') { - char* pszTmp; + if (strncasecmp(pszPropertyName, pszGroupName, nGroupNameLen) == + 0 && + pszPropertyName[nGroupNameLen] == '/') { + char *pszTmp; pszPropertyName = pszPropertyName + nGroupNameLen + 1; pszColon = strchr(pszPropertyName, ':'); - if( pszColon != NULL ) + if (pszColon != NULL) pszPropertyName = pszColon + 1; pszTmp = msStrdup(pszPropertyName); msFree(psFilterNode->pszValue); @@ -3087,7 +2995,6 @@ static void FLTRemoveGroupName(FilterEncodingNode *psFilterNode, if (psFilterNode->psRightNode) FLTRemoveGroupName(psFilterNode->psRightNode, groupList); } - } /************************************************************************/ @@ -3097,10 +3004,11 @@ static void FLTRemoveGroupName(FilterEncodingNode *psFilterNode, /* with their internal name. */ /************************************************************************/ void FLTPreParseFilterForAliasAndGroup(FilterEncodingNode *psFilterNode, - mapObj *map, int i, const char *namespaces) -{ -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) - if (psFilterNode && map && i>=0 && inumlayers) { + mapObj *map, int i, + const char *namespaces) { +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) + if (psFilterNode && map && i >= 0 && i < map->numlayers) { /*strip name spaces before hand*/ FLTStripNameSpacesFromPropertyName(psFilterNode); @@ -3108,24 +3016,26 @@ void FLTPreParseFilterForAliasAndGroup(FilterEncodingNode *psFilterNode, int layerWasOpened = msLayerIsOpen(lp); if (msLayerOpen(lp) == MS_SUCCESS && msLayerGetItems(lp) == MS_SUCCESS) { - /* Remove group names from property names if using groupname/itemname syntax */ - gmlGroupListObj* groupList = msGMLGetGroups(lp, namespaces); - if( groupList && groupList->numgroups > 0 ) + /* Remove group names from property names if using groupname/itemname + * syntax */ + gmlGroupListObj *groupList = msGMLGetGroups(lp, namespaces); + if (groupList && groupList->numgroups > 0) FLTRemoveGroupName(psFilterNode, groupList); msGMLFreeGroups(groupList); - for(i=0; inumitems; i++) { + for (i = 0; i < lp->numitems; i++) { if (!lp->items[i] || strlen(lp->items[i]) <= 0) continue; char szTmp[256]; snprintf(szTmp, sizeof(szTmp), "%s_alias", lp->items[i]); - const char *pszFullName = msOWSLookupMetadata(&(lp->metadata), namespaces, szTmp); + const char *pszFullName = + msOWSLookupMetadata(&(lp->metadata), namespaces, szTmp); if (pszFullName) { - FLTReplacePropertyName(psFilterNode, pszFullName, - lp->items[i]); + FLTReplacePropertyName(psFilterNode, pszFullName, lp->items[i]); } } - if (!layerWasOpened) /* do not close the layer if it has been opened somewhere else (paging?) */ + if (!layerWasOpened) /* do not close the layer if it has been opened + somewhere else (paging?) */ msLayerClose(lp); } } @@ -3142,48 +3052,43 @@ void FLTPreParseFilterForAliasAndGroup(FilterEncodingNode *psFilterNode, /* Check that FeatureId filters match features in the active */ /* layer. */ /************************************************************************/ -int FLTCheckFeatureIdFilters(FilterEncodingNode *psFilterNode, - mapObj *map, int i) -{ - int status = MS_SUCCESS; - - if (psFilterNode->eType == FILTER_NODE_TYPE_FEATUREID) - { - char** tokens; - int nTokens = 0; - layerObj* lp; - int j; - - lp = GET_LAYER(map, i); - tokens = msStringSplit(psFilterNode->pszValue,',', &nTokens); - for (j=0; j(pszDot - pszId) != strlen(lp->name) || - strncasecmp(pszId, lp->name, strlen(lp->name)) != 0 ) - { - msSetError(MS_MISCERR, "Feature id %s not consistent with feature type name %s.", - "FLTPreParseFilterForAlias()", pszId, lp->name); - status = MS_FAILURE; - break; - } - } +int FLTCheckFeatureIdFilters(FilterEncodingNode *psFilterNode, mapObj *map, + int i) { + int status = MS_SUCCESS; + + if (psFilterNode->eType == FILTER_NODE_TYPE_FEATUREID) { + char **tokens; + int nTokens = 0; + layerObj *lp; + int j; + + lp = GET_LAYER(map, i); + tokens = msStringSplit(psFilterNode->pszValue, ',', &nTokens); + for (j = 0; j < nTokens; j++) { + const char *pszId = tokens[j]; + const char *pszDot = strrchr(pszId, '.'); + if (pszDot) { + if (static_cast(pszDot - pszId) != strlen(lp->name) || + strncasecmp(pszId, lp->name, strlen(lp->name)) != 0) { + msSetError(MS_MISCERR, + "Feature id %s not consistent with feature type name %s.", + "FLTPreParseFilterForAlias()", pszId, lp->name); + status = MS_FAILURE; + break; } - msFreeCharArray(tokens, nTokens); + } } + msFreeCharArray(tokens, nTokens); + } - if (psFilterNode->psLeftNode) - { - status = FLTCheckFeatureIdFilters(psFilterNode->psLeftNode, map, i); - if( status == MS_SUCCESS ) - { - if (psFilterNode->psRightNode) - status = FLTCheckFeatureIdFilters(psFilterNode->psRightNode, map, i); - } + if (psFilterNode->psLeftNode) { + status = FLTCheckFeatureIdFilters(psFilterNode->psLeftNode, map, i); + if (status == MS_SUCCESS) { + if (psFilterNode->psRightNode) + status = FLTCheckFeatureIdFilters(psFilterNode->psRightNode, map, i); } - return status; + } + return status; } /************************************************************************/ @@ -3192,33 +3097,29 @@ int FLTCheckFeatureIdFilters(FilterEncodingNode *psFilterNode, /* Check that the operand of a comparison operator is valid */ /* Currently only detects use of boundedBy in a binary comparison */ /************************************************************************/ -int FLTCheckInvalidOperand(FilterEncodingNode *psFilterNode) -{ - int status = MS_SUCCESS; - - if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON && - psFilterNode->psLeftNode != NULL && - psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_PROPERTYNAME) - { - if( strcmp(psFilterNode->psLeftNode->pszValue, "gml:boundedBy") == 0 && - strcmp(psFilterNode->pszValue, "PropertyIsNull") != 0 && - strcmp(psFilterNode->pszValue, "PropertyIsNil") != 0 ) - { - msSetError(MS_MISCERR, "Operand '%s' is invalid in comparison.", - "FLTCheckInvalidOperand()", psFilterNode->psLeftNode->pszValue); - return MS_FAILURE; - } +int FLTCheckInvalidOperand(FilterEncodingNode *psFilterNode) { + int status = MS_SUCCESS; + + if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON && + psFilterNode->psLeftNode != NULL && + psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_PROPERTYNAME) { + if (strcmp(psFilterNode->psLeftNode->pszValue, "gml:boundedBy") == 0 && + strcmp(psFilterNode->pszValue, "PropertyIsNull") != 0 && + strcmp(psFilterNode->pszValue, "PropertyIsNil") != 0) { + msSetError(MS_MISCERR, "Operand '%s' is invalid in comparison.", + "FLTCheckInvalidOperand()", + psFilterNode->psLeftNode->pszValue); + return MS_FAILURE; } - if (psFilterNode->psLeftNode) - { - status = FLTCheckInvalidOperand(psFilterNode->psLeftNode); - if( status == MS_SUCCESS ) - { - if (psFilterNode->psRightNode) - status = FLTCheckInvalidOperand(psFilterNode->psRightNode); - } + } + if (psFilterNode->psLeftNode) { + status = FLTCheckInvalidOperand(psFilterNode->psLeftNode); + if (status == MS_SUCCESS) { + if (psFilterNode->psRightNode) + status = FLTCheckInvalidOperand(psFilterNode->psRightNode); } - return status; + } + return status; } /************************************************************************/ @@ -3227,49 +3128,45 @@ int FLTCheckInvalidOperand(FilterEncodingNode *psFilterNode) /* HACK for PropertyIsNull processing. PostGIS & Spatialite only */ /* for now. */ /************************************************************************/ -int FLTProcessPropertyIsNull(FilterEncodingNode *psFilterNode, - mapObj *map, int i) -{ - int status = MS_SUCCESS; - - if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON && - psFilterNode->psLeftNode != NULL && - psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_PROPERTYNAME && - strcmp(psFilterNode->pszValue, "PropertyIsNull") == 0 && - !FLTIsGMLDefaultProperty(psFilterNode->psLeftNode->pszValue) ) - { - layerObj* lp; - int layerWasOpened; - - lp = GET_LAYER(map, i); - layerWasOpened = msLayerIsOpen(lp); - - /* Horrible HACK to compensate for the lack of null testing in MapServer */ - if( (lp->connectiontype == MS_POSTGIS || - (lp->connectiontype == MS_OGR && msOGRSupportsIsNull(lp))) && - strcmp(psFilterNode->pszValue, "PropertyIsNull") == 0 ) - { - msFree(psFilterNode->pszValue); - psFilterNode->pszValue = msStrdup("PropertyIsEqualTo"); - psFilterNode->psRightNode = FLTCreateBinaryCompFilterEncodingNode(); - psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_LITERAL; - psFilterNode->psRightNode->pszValue = msStrdup("_MAPSERVER_NULL_"); - } - - if (!layerWasOpened) /* do not close the layer if it has been opened somewhere else (paging?) */ - msLayerClose(lp); +int FLTProcessPropertyIsNull(FilterEncodingNode *psFilterNode, mapObj *map, + int i) { + int status = MS_SUCCESS; + + if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON && + psFilterNode->psLeftNode != NULL && + psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_PROPERTYNAME && + strcmp(psFilterNode->pszValue, "PropertyIsNull") == 0 && + !FLTIsGMLDefaultProperty(psFilterNode->psLeftNode->pszValue)) { + layerObj *lp; + int layerWasOpened; + + lp = GET_LAYER(map, i); + layerWasOpened = msLayerIsOpen(lp); + + /* Horrible HACK to compensate for the lack of null testing in MapServer */ + if ((lp->connectiontype == MS_POSTGIS || + (lp->connectiontype == MS_OGR && msOGRSupportsIsNull(lp))) && + strcmp(psFilterNode->pszValue, "PropertyIsNull") == 0) { + msFree(psFilterNode->pszValue); + psFilterNode->pszValue = msStrdup("PropertyIsEqualTo"); + psFilterNode->psRightNode = FLTCreateBinaryCompFilterEncodingNode(); + psFilterNode->psRightNode->eType = FILTER_NODE_TYPE_LITERAL; + psFilterNode->psRightNode->pszValue = msStrdup("_MAPSERVER_NULL_"); } - if (psFilterNode->psLeftNode) - { - status = FLTProcessPropertyIsNull(psFilterNode->psLeftNode, map, i); - if( status == MS_SUCCESS ) - { - if (psFilterNode->psRightNode) - status = FLTProcessPropertyIsNull(psFilterNode->psRightNode, map, i); - } + if (!layerWasOpened) /* do not close the layer if it has been opened + somewhere else (paging?) */ + msLayerClose(lp); + } + + if (psFilterNode->psLeftNode) { + status = FLTProcessPropertyIsNull(psFilterNode->psLeftNode, map, i); + if (status == MS_SUCCESS) { + if (psFilterNode->psRightNode) + status = FLTProcessPropertyIsNull(psFilterNode->psRightNode, map, i); } - return status; + } + return status; } /************************************************************************/ @@ -3277,65 +3174,62 @@ int FLTProcessPropertyIsNull(FilterEncodingNode *psFilterNode, /* */ /* Check that property names are known */ /************************************************************************/ -int FLTCheckInvalidProperty(FilterEncodingNode *psFilterNode, - mapObj *map, int i) -{ - int status = MS_SUCCESS; - - if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON && - psFilterNode->psLeftNode != NULL && - psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_PROPERTYNAME) - { - layerObj* lp; - int layerWasOpened; - int bFound = MS_FALSE; - - if ((strcmp(psFilterNode->pszValue, "PropertyIsNull") == 0 || - strcmp(psFilterNode->pszValue, "PropertyIsNil") == 0) && - FLTIsGMLDefaultProperty(psFilterNode->psLeftNode->pszValue) ) - { - return MS_SUCCESS; - } +int FLTCheckInvalidProperty(FilterEncodingNode *psFilterNode, mapObj *map, + int i) { + int status = MS_SUCCESS; + + if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON && + psFilterNode->psLeftNode != NULL && + psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_PROPERTYNAME) { + layerObj *lp; + int layerWasOpened; + int bFound = MS_FALSE; + + if ((strcmp(psFilterNode->pszValue, "PropertyIsNull") == 0 || + strcmp(psFilterNode->pszValue, "PropertyIsNil") == 0) && + FLTIsGMLDefaultProperty(psFilterNode->psLeftNode->pszValue)) { + return MS_SUCCESS; + } - lp = GET_LAYER(map, i); - layerWasOpened = msLayerIsOpen(lp); - if ((layerWasOpened || msLayerOpen(lp) == MS_SUCCESS) - && msLayerGetItems(lp) == MS_SUCCESS) { - int i; - gmlItemListObj* items = msGMLGetItems(lp, "G"); - for(i=0; inumitems; i++) { - if (!items->items[i].name || strlen(items->items[i].name) == 0 || - !items->items[i].visible) - continue; - if (strcasecmp(items->items[i].name, psFilterNode->psLeftNode->pszValue) == 0) { - bFound = MS_TRUE; - break; - } - } - msGMLFreeItems(items); + lp = GET_LAYER(map, i); + layerWasOpened = msLayerIsOpen(lp); + if ((layerWasOpened || msLayerOpen(lp) == MS_SUCCESS) && + msLayerGetItems(lp) == MS_SUCCESS) { + int i; + gmlItemListObj *items = msGMLGetItems(lp, "G"); + for (i = 0; i < items->numitems; i++) { + if (!items->items[i].name || strlen(items->items[i].name) == 0 || + !items->items[i].visible) + continue; + if (strcasecmp(items->items[i].name, + psFilterNode->psLeftNode->pszValue) == 0) { + bFound = MS_TRUE; + break; } + } + msGMLFreeItems(items); + } - if (!layerWasOpened) /* do not close the layer if it has been opened somewhere else (paging?) */ - msLayerClose(lp); + if (!layerWasOpened) /* do not close the layer if it has been opened + somewhere else (paging?) */ + msLayerClose(lp); - if( !bFound ) - { - msSetError(MS_MISCERR, "Property '%s' is unknown.", - "FLTCheckInvalidProperty()", psFilterNode->psLeftNode->pszValue); - return MS_FAILURE; - } + if (!bFound) { + msSetError(MS_MISCERR, "Property '%s' is unknown.", + "FLTCheckInvalidProperty()", + psFilterNode->psLeftNode->pszValue); + return MS_FAILURE; } + } - if (psFilterNode->psLeftNode) - { - status = FLTCheckInvalidProperty(psFilterNode->psLeftNode, map, i); - if( status == MS_SUCCESS ) - { - if (psFilterNode->psRightNode) - status = FLTCheckInvalidProperty(psFilterNode->psRightNode, map, i); - } + if (psFilterNode->psLeftNode) { + status = FLTCheckInvalidProperty(psFilterNode->psLeftNode, map, i); + if (status == MS_SUCCESS) { + if (psFilterNode->psRightNode) + status = FLTCheckInvalidProperty(psFilterNode->psRightNode, map, i); } - return status; + } + return status; } /************************************************************************/ @@ -3349,160 +3243,179 @@ int FLTCheckInvalidProperty(FilterEncodingNode *psFilterNode, /* that the filter evaluates to FALSE, or MS_TRUE that it */ /* evaluates to TRUE */ /************************************************************************/ -FilterEncodingNode* FLTSimplify(FilterEncodingNode *psFilterNode, - int* pnEvaluation) -{ - *pnEvaluation = -1; +FilterEncodingNode *FLTSimplify(FilterEncodingNode *psFilterNode, + int *pnEvaluation) { + *pnEvaluation = -1; + + /* There are no nullable or nillable property in WFS currently */ + /* except gml:name or gml:description that are null */ + if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON && + (strcmp(psFilterNode->pszValue, "PropertyIsNull") == 0 || + strcmp(psFilterNode->pszValue, "PropertyIsNil") == 0) && + psFilterNode->psLeftNode != NULL && + psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_PROPERTYNAME) { + if (strcmp(psFilterNode->pszValue, "PropertyIsNull") == 0 && + FLTIsGMLDefaultProperty(psFilterNode->psLeftNode->pszValue) && + strcmp(psFilterNode->psLeftNode->pszValue, "@gml:id") != 0 && + strcmp(psFilterNode->psLeftNode->pszValue, "gml:boundedBy") != 0) + *pnEvaluation = MS_TRUE; + else + *pnEvaluation = MS_FALSE; + FLTFreeFilterEncodingNode(psFilterNode); + return NULL; + } - /* There are no nullable or nillable property in WFS currently */ - /* except gml:name or gml:description that are null */ - if( psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON && - (strcmp(psFilterNode->pszValue, "PropertyIsNull") == 0 || - strcmp(psFilterNode->pszValue, "PropertyIsNil") == 0 ) && - psFilterNode->psLeftNode != NULL && - psFilterNode->psLeftNode->eType == FILTER_NODE_TYPE_PROPERTYNAME ) - { - if( strcmp(psFilterNode->pszValue, "PropertyIsNull") == 0 && - FLTIsGMLDefaultProperty(psFilterNode->psLeftNode->pszValue) && - strcmp(psFilterNode->psLeftNode->pszValue, "@gml:id") != 0 && - strcmp(psFilterNode->psLeftNode->pszValue, "gml:boundedBy") != 0) - *pnEvaluation = MS_TRUE; - else - *pnEvaluation = MS_FALSE; - FLTFreeFilterEncodingNode(psFilterNode); - return NULL; + if (psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL && + strcasecmp(psFilterNode->pszValue, "NOT") == 0 && + psFilterNode->psLeftNode != NULL) { + int nEvaluation; + psFilterNode->psLeftNode = + FLTSimplify(psFilterNode->psLeftNode, &nEvaluation); + if (psFilterNode->psLeftNode == NULL) { + *pnEvaluation = 1 - nEvaluation; + FLTFreeFilterEncodingNode(psFilterNode); + return NULL; } + } - if( psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL && - strcasecmp(psFilterNode->pszValue, "NOT") == 0 && - psFilterNode->psLeftNode != NULL ) - { - int nEvaluation; - psFilterNode->psLeftNode = FLTSimplify(psFilterNode->psLeftNode, - &nEvaluation); - if( psFilterNode->psLeftNode == NULL ) - { - *pnEvaluation = 1 - nEvaluation; - FLTFreeFilterEncodingNode(psFilterNode); - return NULL; - } + if (psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL && + (strcasecmp(psFilterNode->pszValue, "AND") == 0 || + strcasecmp(psFilterNode->pszValue, "OR") == 0) && + psFilterNode->psLeftNode != NULL && psFilterNode->psRightNode != NULL) { + FilterEncodingNode *psOtherNode; + int nEvaluation; + int nExpectedValForFastExit; + psFilterNode->psLeftNode = + FLTSimplify(psFilterNode->psLeftNode, &nEvaluation); + + if (strcasecmp(psFilterNode->pszValue, "AND") == 0) + nExpectedValForFastExit = MS_FALSE; + else + nExpectedValForFastExit = MS_TRUE; + + if (psFilterNode->psLeftNode == NULL) { + if (nEvaluation == nExpectedValForFastExit) { + *pnEvaluation = nEvaluation; + FLTFreeFilterEncodingNode(psFilterNode); + return NULL; + } + psOtherNode = psFilterNode->psRightNode; + psFilterNode->psRightNode = NULL; + FLTFreeFilterEncodingNode(psFilterNode); + return FLTSimplify(psOtherNode, pnEvaluation); } - if( psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL && - (strcasecmp(psFilterNode->pszValue, "AND") == 0 || - strcasecmp(psFilterNode->pszValue, "OR") == 0) && - psFilterNode->psLeftNode != NULL && - psFilterNode->psRightNode != NULL ) - { - FilterEncodingNode* psOtherNode; - int nEvaluation; - int nExpectedValForFastExit; - psFilterNode->psLeftNode = FLTSimplify(psFilterNode->psLeftNode, - &nEvaluation); - - if( strcasecmp(psFilterNode->pszValue, "AND") == 0 ) - nExpectedValForFastExit = MS_FALSE; - else - nExpectedValForFastExit = MS_TRUE; - - if( psFilterNode->psLeftNode == NULL ) - { - if( nEvaluation == nExpectedValForFastExit ) - { - *pnEvaluation = nEvaluation; - FLTFreeFilterEncodingNode(psFilterNode); - return NULL; - } - psOtherNode = psFilterNode->psRightNode; - psFilterNode->psRightNode = NULL; - FLTFreeFilterEncodingNode(psFilterNode); - return FLTSimplify(psOtherNode, pnEvaluation); - } - - psFilterNode->psRightNode = FLTSimplify(psFilterNode->psRightNode, - &nEvaluation); - if( psFilterNode->psRightNode == NULL ) - { - if( nEvaluation == nExpectedValForFastExit ) - { - *pnEvaluation = nEvaluation; - FLTFreeFilterEncodingNode(psFilterNode); - return NULL; - } - psOtherNode = psFilterNode->psLeftNode; - psFilterNode->psLeftNode = NULL; - FLTFreeFilterEncodingNode(psFilterNode); - return FLTSimplify(psOtherNode, pnEvaluation); - } + psFilterNode->psRightNode = + FLTSimplify(psFilterNode->psRightNode, &nEvaluation); + if (psFilterNode->psRightNode == NULL) { + if (nEvaluation == nExpectedValForFastExit) { + *pnEvaluation = nEvaluation; + FLTFreeFilterEncodingNode(psFilterNode); + return NULL; + } + psOtherNode = psFilterNode->psLeftNode; + psFilterNode->psLeftNode = NULL; + FLTFreeFilterEncodingNode(psFilterNode); + return FLTSimplify(psOtherNode, pnEvaluation); } + } - return psFilterNode; + return psFilterNode; } - #ifdef USE_LIBXML2 -xmlNodePtr FLTGetCapabilities(xmlNsPtr psNsParent, xmlNsPtr psNsOgc, int bTemporal) -{ - xmlNodePtr psRootNode = NULL, psNode = NULL, psSubNode = NULL, psSubSubNode = NULL; +xmlNodePtr FLTGetCapabilities(xmlNsPtr psNsParent, xmlNsPtr psNsOgc, + int bTemporal) { + xmlNodePtr psRootNode = NULL, psNode = NULL, psSubNode = NULL, + psSubSubNode = NULL; psRootNode = xmlNewNode(psNsParent, BAD_CAST "Filter_Capabilities"); - psNode = xmlNewChild(psRootNode, psNsOgc, BAD_CAST "Spatial_Capabilities", NULL); + psNode = + xmlNewChild(psRootNode, psNsOgc, BAD_CAST "Spatial_Capabilities", NULL); psSubNode = xmlNewChild(psNode, psNsOgc, BAD_CAST "GeometryOperands", NULL); - xmlNewChild(psSubNode, psNsOgc, BAD_CAST "GeometryOperand", BAD_CAST "gml:Point"); - xmlNewChild(psSubNode, psNsOgc, BAD_CAST "GeometryOperand", BAD_CAST "gml:LineString"); - xmlNewChild(psSubNode, psNsOgc, BAD_CAST "GeometryOperand", BAD_CAST "gml:Polygon"); - xmlNewChild(psSubNode, psNsOgc, BAD_CAST "GeometryOperand", BAD_CAST "gml:Envelope"); + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "GeometryOperand", + BAD_CAST "gml:Point"); + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "GeometryOperand", + BAD_CAST "gml:LineString"); + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "GeometryOperand", + BAD_CAST "gml:Polygon"); + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "GeometryOperand", + BAD_CAST "gml:Envelope"); psSubNode = xmlNewChild(psNode, psNsOgc, BAD_CAST "SpatialOperators", NULL); #ifdef USE_GEOS - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "Equals"); - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "Disjoint"); - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "Touches"); - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "Within"); - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "Overlaps"); - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "Crosses"); - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "Intersects"); - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "Contains"); - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "DWithin"); - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "Beyond"); #endif - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "SpatialOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "BBOX"); if (bTemporal) { - psNode = xmlNewChild(psRootNode, psNsOgc, BAD_CAST "Temporal_Capabilities", NULL); + psNode = xmlNewChild(psRootNode, psNsOgc, BAD_CAST "Temporal_Capabilities", + NULL); psSubNode = xmlNewChild(psNode, psNsOgc, BAD_CAST "TemporalOperands", NULL); - xmlNewChild(psSubNode, psNsOgc, BAD_CAST "TemporalOperand", BAD_CAST "gml:TimePeriod"); - xmlNewChild(psSubNode, psNsOgc, BAD_CAST "TemporalOperand", BAD_CAST "gml:TimeInstant"); - - psSubNode = xmlNewChild(psNode, psNsOgc, BAD_CAST "TemporalOperators", NULL); - psSubSubNode = xmlNewChild(psSubNode, psNsOgc, BAD_CAST "TemporalOperator", NULL); + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "TemporalOperand", + BAD_CAST "gml:TimePeriod"); + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "TemporalOperand", + BAD_CAST "gml:TimeInstant"); + + psSubNode = + xmlNewChild(psNode, psNsOgc, BAD_CAST "TemporalOperators", NULL); + psSubSubNode = + xmlNewChild(psSubNode, psNsOgc, BAD_CAST "TemporalOperator", NULL); xmlNewProp(psSubSubNode, BAD_CAST "name", BAD_CAST "TM_Equals"); } - psNode = xmlNewChild(psRootNode, psNsOgc, BAD_CAST "Scalar_Capabilities", NULL); + psNode = + xmlNewChild(psRootNode, psNsOgc, BAD_CAST "Scalar_Capabilities", NULL); xmlNewChild(psNode, psNsOgc, BAD_CAST "LogicalOperators", NULL); psNode = xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperators", NULL); - xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", BAD_CAST "LessThan"); - xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", BAD_CAST "GreaterThan"); - xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", BAD_CAST "LessThanEqualTo"); - xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", BAD_CAST "GreaterThanEqualTo"); - xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", BAD_CAST "EqualTo"); - xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", BAD_CAST "NotEqualTo"); + xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", + BAD_CAST "LessThan"); + xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", + BAD_CAST "GreaterThan"); + xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", + BAD_CAST "LessThanEqualTo"); + xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", + BAD_CAST "GreaterThanEqualTo"); + xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", + BAD_CAST "EqualTo"); + xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", + BAD_CAST "NotEqualTo"); xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", BAD_CAST "Like"); - xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", BAD_CAST "Between"); + xmlNewChild(psNode, psNsOgc, BAD_CAST "ComparisonOperator", + BAD_CAST "Between"); psNode = xmlNewChild(psRootNode, psNsOgc, BAD_CAST "Id_Capabilities", NULL); xmlNewChild(psNode, psNsOgc, BAD_CAST "EID", NULL); diff --git a/mapogcfilter.h b/mapogcfilter.h index 75a16b4053..ba08b3ac5c 100644 --- a/mapogcfilter.h +++ b/mapogcfilter.h @@ -36,8 +36,8 @@ #ifdef USE_LIBXML2 -#include -#include +#include +#include #endif #ifdef __cplusplus @@ -48,26 +48,32 @@ typedef struct { char *pszWildCard; char *pszSingleChar; char *pszEscapeChar; - int bCaseInsensitive; + int bCaseInsensitive; } FEPropertyIsLike; /* -------------------------------------------------------------------- */ /* prototypes. */ /* -------------------------------------------------------------------- */ MS_DLL_EXPORT int FLTIsNumeric(const char *pszValue); -MS_DLL_EXPORT int FLTApplyExpressionToLayer(layerObj *lp, const char *pszExpression); -MS_DLL_EXPORT char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char *value, int forcecharcter); - -MS_DLL_EXPORT FilterEncodingNode *FLTParseFilterEncoding(const char *szXMLString); +MS_DLL_EXPORT int FLTApplyExpressionToLayer(layerObj *lp, + const char *pszExpression); +MS_DLL_EXPORT char *FLTGetExpressionForValuesRanges(layerObj *lp, + const char *item, + const char *value, + int forcecharcter); + +MS_DLL_EXPORT FilterEncodingNode * +FLTParseFilterEncoding(const char *szXMLString); MS_DLL_EXPORT FilterEncodingNode *FLTCreateFilterEncodingNode(void); -MS_DLL_EXPORT char** FLTSplitFilters(const char* pszStr, int* pnTokens); +MS_DLL_EXPORT char **FLTSplitFilters(const char *pszStr, int *pnTokens); MS_DLL_EXPORT int FLTApplyFilterToLayer(FilterEncodingNode *psNode, mapObj *map, int iLayerIndex); -MS_DLL_EXPORT int FLTLayerApplyCondSQLFilterToLayer(FilterEncodingNode *psNode, mapObj *map, - int iLayerIndex); -MS_DLL_EXPORT int FLTLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, - int iLayerIndex); +MS_DLL_EXPORT int FLTLayerApplyCondSQLFilterToLayer(FilterEncodingNode *psNode, + mapObj *map, + int iLayerIndex); +MS_DLL_EXPORT int FLTLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, + mapObj *map, int iLayerIndex); MS_DLL_EXPORT void FLTFreeFilterEncodingNode(FilterEncodingNode *psFilterNode); @@ -80,11 +86,12 @@ MS_DLL_EXPORT int FLTIsPointFilter(FilterEncodingNode *psFilterNode); MS_DLL_EXPORT int FLTIsLineFilter(FilterEncodingNode *psFilterNode); MS_DLL_EXPORT int FLTIsPolygonFilter(FilterEncodingNode *psFilterNode); -MS_DLL_EXPORT int FLTValidForPropertyIsLikeFilter(FilterEncodingNode *psFilterNode); +MS_DLL_EXPORT int +FLTValidForPropertyIsLikeFilter(FilterEncodingNode *psFilterNode); MS_DLL_EXPORT int FLTIsOnlyPropertyIsLike(FilterEncodingNode *psFilterNode); MS_DLL_EXPORT void FLTInsertElementInNode(FilterEncodingNode *psFilterNode, - CPLXMLNode *psXMLNode); + CPLXMLNode *psXMLNode); MS_DLL_EXPORT int FLTIsLogicalFilterType(const char *pszValue); MS_DLL_EXPORT int FLTIsBinaryComparisonFilterType(const char *pszValue); MS_DLL_EXPORT int FLTIsComparisonFilterType(const char *pszValue); @@ -93,60 +100,81 @@ MS_DLL_EXPORT int FLTIsSpatialFilterType(const char *pszValue); MS_DLL_EXPORT int FLTIsTemporalFilterType(const char *pszValue); MS_DLL_EXPORT int FLTIsSupportedFilterType(CPLXMLNode *psXMLNode); -MS_DLL_EXPORT const char *FLTGetBBOX(FilterEncodingNode *psFilterNode, rectObj *psRect); -const char* FLTGetDuring(FilterEncodingNode *psFilterNode, const char** ppszTimeField); +MS_DLL_EXPORT const char *FLTGetBBOX(FilterEncodingNode *psFilterNode, + rectObj *psRect); +const char *FLTGetDuring(FilterEncodingNode *psFilterNode, + const char **ppszTimeField); -MS_DLL_EXPORT shapeObj *FLTGetShape(FilterEncodingNode *psFilterNode, double *pdfDistance, - int *pnUnit); +MS_DLL_EXPORT shapeObj *FLTGetShape(FilterEncodingNode *psFilterNode, + double *pdfDistance, int *pnUnit); MS_DLL_EXPORT int FLTHasSpatialFilter(FilterEncodingNode *psFilterNode); - /*SQL expressions related functions.*/ -MS_DLL_EXPORT int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, - int iLayerIndex); - -MS_DLL_EXPORT char *FLTGetSQLExpression(FilterEncodingNode *psFilterNode,layerObj *lp); -MS_DLL_EXPORT char *FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp); -MS_DLL_EXPORT char *FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp); -MS_DLL_EXPORT char *FLTGetIsLikeComparisonSQLExpression(FilterEncodingNode *psFilterNode, layerObj *lp); - -MS_DLL_EXPORT char *FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, - layerObj *lp); +MS_DLL_EXPORT int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, + mapObj *map, int iLayerIndex); + +MS_DLL_EXPORT char *FLTGetSQLExpression(FilterEncodingNode *psFilterNode, + layerObj *lp); +MS_DLL_EXPORT char * +FLTGetBinaryComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, + layerObj *lp); +MS_DLL_EXPORT char * +FLTGetIsBetweenComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, + layerObj *lp); +MS_DLL_EXPORT char * +FLTGetIsLikeComparisonSQLExpression(FilterEncodingNode *psFilterNode, + layerObj *lp); + +MS_DLL_EXPORT char * +FLTGetLogicalComparisonSQLExpresssion(FilterEncodingNode *psFilterNode, + layerObj *lp); MS_DLL_EXPORT int FLTIsSimpleFilter(FilterEncodingNode *psFilterNode); -MS_DLL_EXPORT FilterEncodingNode *FLTCreateFeatureIdFilterEncoding(const char *pszString); +MS_DLL_EXPORT FilterEncodingNode * +FLTCreateFeatureIdFilterEncoding(const char *pszString); -MS_DLL_EXPORT int FLTParseGMLEnvelope(CPLXMLNode *psRoot, rectObj *psBbox, char **ppszSRS); -MS_DLL_EXPORT int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, char **ppszSRS); +MS_DLL_EXPORT int FLTParseGMLEnvelope(CPLXMLNode *psRoot, rectObj *psBbox, + char **ppszSRS); +MS_DLL_EXPORT int FLTParseGMLBox(CPLXMLNode *psBox, rectObj *psBbox, + char **ppszSRS); /*common-expressions*/ -MS_DLL_EXPORT char *FLTGetCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp); -MS_DLL_EXPORT int FLTApplyFilterToLayerCommonExpression(mapObj *map, int iLayerIndex, const char *pszExpression); +MS_DLL_EXPORT char *FLTGetCommonExpression(FilterEncodingNode *psFilterNode, + layerObj *lp); +MS_DLL_EXPORT int +FLTApplyFilterToLayerCommonExpression(mapObj *map, int iLayerIndex, + const char *pszExpression); #ifdef USE_LIBXML2 -MS_DLL_EXPORT xmlNodePtr FLTGetCapabilities(xmlNsPtr psNsParent, xmlNsPtr psNsOgc, int bTemporal); +MS_DLL_EXPORT xmlNodePtr FLTGetCapabilities(xmlNsPtr psNsParent, + xmlNsPtr psNsOgc, int bTemporal); #endif -void FLTDoAxisSwappingIfNecessary(mapObj *map, FilterEncodingNode *psFilterNode, int bDefaultSRSNeedsAxisSwapping); +void FLTDoAxisSwappingIfNecessary(mapObj *map, FilterEncodingNode *psFilterNode, + int bDefaultSRSNeedsAxisSwapping); void FLTPreParseFilterForAliasAndGroup(FilterEncodingNode *psFilterNode, - mapObj *map, int i, const char *namespaces); -int FLTCheckFeatureIdFilters(FilterEncodingNode *psFilterNode, - mapObj *map, int i); + mapObj *map, int i, + const char *namespaces); +int FLTCheckFeatureIdFilters(FilterEncodingNode *psFilterNode, mapObj *map, + int i); int FLTCheckInvalidOperand(FilterEncodingNode *psFilterNode); -int FLTCheckInvalidProperty(FilterEncodingNode *psFilterNode, - mapObj *map, int i); -FilterEncodingNode* FLTSimplify(FilterEncodingNode *psFilterNode, - int* pnEvaluation); -int FLTApplyFilterToLayerCommonExpressionWithRect(mapObj *map, int iLayerIndex, const char *pszExpression, rectObj rect); -int FLTProcessPropertyIsNull(FilterEncodingNode *psFilterNode, - mapObj *map, int i); -int FLTLayerSetInvalidRectIfSupported(layerObj* lp, rectObj* rect); +int FLTCheckInvalidProperty(FilterEncodingNode *psFilterNode, mapObj *map, + int i); +FilterEncodingNode *FLTSimplify(FilterEncodingNode *psFilterNode, + int *pnEvaluation); +int FLTApplyFilterToLayerCommonExpressionWithRect(mapObj *map, int iLayerIndex, + const char *pszExpression, + rectObj rect); +int FLTProcessPropertyIsNull(FilterEncodingNode *psFilterNode, mapObj *map, + int i); +int FLTLayerSetInvalidRectIfSupported(layerObj *lp, rectObj *rect); #ifdef __cplusplus } -std::string FLTGetTimeExpression(FilterEncodingNode *psFilterNode, layerObj *lp); +std::string FLTGetTimeExpression(FilterEncodingNode *psFilterNode, + layerObj *lp); #endif diff --git a/mapogcfiltercommon.cpp b/mapogcfiltercommon.cpp index f73d47b0db..bc06a1f3f2 100644 --- a/mapogcfiltercommon.cpp +++ b/mapogcfiltercommon.cpp @@ -34,22 +34,27 @@ #include -static std::string FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode) -{ - /* From http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04 */ +static std::string +FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode) { + /* From + * http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04 + */ /* also add double quote because we are within a string */ - const char* pszRegexSpecialCharsAndDoubleQuote = "\\^${[().*+?|\""; + const char *pszRegexSpecialCharsAndDoubleQuote = "\\^${[().*+?|\""; - if (!psFilterNode || !psFilterNode->pOther || !psFilterNode->psLeftNode || !psFilterNode->psRightNode || !psFilterNode->psRightNode->pszValue) + if (!psFilterNode || !psFilterNode->pOther || !psFilterNode->psLeftNode || + !psFilterNode->psRightNode || !psFilterNode->psRightNode->pszValue) return std::string(); - const FEPropertyIsLike* propIsLike = (const FEPropertyIsLike *)psFilterNode->pOther; - const char* pszWild = propIsLike->pszWildCard; - const char* pszSingle = propIsLike->pszSingleChar; - const char* pszEscape = propIsLike->pszEscapeChar; + const FEPropertyIsLike *propIsLike = + (const FEPropertyIsLike *)psFilterNode->pOther; + const char *pszWild = propIsLike->pszWildCard; + const char *pszSingle = propIsLike->pszSingleChar; + const char *pszEscape = propIsLike->pszEscapeChar; const bool bCaseInsensitive = propIsLike->bCaseInsensitive != 0; - if (!pszWild || strlen(pszWild) == 0 || !pszSingle || strlen(pszSingle) == 0 || !pszEscape || strlen(pszEscape) == 0) + if (!pszWild || strlen(pszWild) == 0 || !pszSingle || + strlen(pszSingle) == 0 || !pszEscape || strlen(pszEscape) == 0) return std::string(); /* -------------------------------------------------------------------- */ @@ -61,62 +66,61 @@ static std::string FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *ps expr += psFilterNode->psLeftNode->pszValue; /* #3521 */ - if (bCaseInsensitive ) + if (bCaseInsensitive) expr += "]\" ~* \""; else expr += "]\" ~ \""; - const char* pszValue = psFilterNode->psRightNode->pszValue; + const char *pszValue = psFilterNode->psRightNode->pszValue; const size_t nLength = strlen(pszValue); if (nLength > 0) { expr += '^'; } - for (size_t i=0; ipsLeftNode == NULL || psFilterNode->psRightNode == NULL ) +static std::string +FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode *psFilterNode, + layerObj *lp) { + if (psFilterNode->psLeftNode == NULL || psFilterNode->psRightNode == NULL) return std::string(); /* -------------------------------------------------------------------- */ @@ -147,8 +152,9 @@ static std::string FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode bool bString = false; bool bDateTime = false; - const char* pszType = msOWSLookupMetadata(&(lp->metadata), "OFG", - (std::string(psFilterNode->psLeftNode->pszValue)+ "_type").c_str()); + const char *pszType = msOWSLookupMetadata( + &(lp->metadata), "OFG", + (std::string(psFilterNode->psLeftNode->pszValue) + "_type").c_str()); if (pszType != NULL && (strcasecmp(pszType, "Character") == 0)) bString = true; else if (pszType != NULL && (strcasecmp(pszType, "Date") == 0)) @@ -157,8 +163,8 @@ static std::string FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode bString = true; if (!bString && !bDateTime) { - if (FLTIsNumeric(bounds[1].c_str()) == MS_FALSE) - bString = true; + if (FLTIsNumeric(bounds[1].c_str()) == MS_FALSE) + bString = true; } std::string expr; @@ -182,8 +188,7 @@ static std::string FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode if (bString) { expr += '\"'; - } - else if (bDateTime) { + } else if (bDateTime) { expr += '`'; } @@ -191,8 +196,7 @@ static std::string FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode if (bString) { expr += '\"'; - } - else if (bDateTime) { + } else if (bDateTime) { expr += '`'; } @@ -215,8 +219,7 @@ static std::string FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode if (bString) { expr += '\"'; - } - else if (bDateTime) { + } else if (bDateTime) { expr += '`'; } @@ -224,8 +227,7 @@ static std::string FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode if (bString) { expr += '\"'; - } - else if (bDateTime) { + } else if (bDateTime) { expr += '`'; } expr += ')'; @@ -233,9 +235,9 @@ static std::string FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode return expr; } -static -std::string FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp) -{ +static std::string +FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterNode, + layerObj *lp) { /* -------------------------------------------------------------------- */ /* check if the value is a numeric value or alphanumeric. If it */ /* is alphanumeric, add quotes around attribute and values. */ @@ -243,11 +245,12 @@ std::string FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterN bool bString = false; bool bDateTime = false; if (psFilterNode->psRightNode->pszValue) { - const char* pszType = msOWSLookupMetadata(&(lp->metadata), "OFG", + const char *pszType = msOWSLookupMetadata( + &(lp->metadata), "OFG", (std::string(psFilterNode->psLeftNode->pszValue) + "_type").c_str()); - if (pszType!= NULL && (strcasecmp(pszType, "Character") == 0)) + if (pszType != NULL && (strcasecmp(pszType, "Character") == 0)) bString = true; - else if (pszType!= NULL && (strcasecmp(pszType, "Date") == 0)) + else if (pszType != NULL && (strcasecmp(pszType, "Date") == 0)) bDateTime = true; else if (FLTIsNumeric(psFilterNode->psRightNode->pszValue) == MS_FALSE) bString = true; @@ -255,7 +258,8 @@ std::string FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterN /* specical case to be able to have empty strings in the expression. */ /* propertyislike is always treated as string */ - if (psFilterNode->psRightNode->pszValue == NULL || strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0) + if (psFilterNode->psRightNode->pszValue == NULL || + strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0) bString = true; /* attribute */ @@ -265,7 +269,7 @@ std::string FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterN else expr = "(["; expr += psFilterNode->psLeftNode->pszValue; - + if (bString) expr += "]\" "; else @@ -273,7 +277,8 @@ std::string FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterN if (strcasecmp(psFilterNode->pszValue, "PropertyIsEqualTo") == 0) { /* case insensitive set ? */ - if (psFilterNode->psRightNode->pOther && (*(int *)psFilterNode->psRightNode->pOther) == 1) + if (psFilterNode->psRightNode->pOther && + (*(int *)psFilterNode->psRightNode->pOther) == 1) expr += "=*"; else expr += "="; @@ -283,9 +288,11 @@ std::string FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterN expr += "<"; else if (strcasecmp(psFilterNode->pszValue, "PropertyIsGreaterThan") == 0) expr += ">"; - else if (strcasecmp(psFilterNode->pszValue, "PropertyIsLessThanOrEqualTo") == 0) + else if (strcasecmp(psFilterNode->pszValue, "PropertyIsLessThanOrEqualTo") == + 0) expr += "<="; - else if (strcasecmp(psFilterNode->pszValue, "PropertyIsGreaterThanOrEqualTo") == 0) + else if (strcasecmp(psFilterNode->pszValue, + "PropertyIsGreaterThanOrEqualTo") == 0) expr += ">="; else if (strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0) expr += "~"; @@ -294,8 +301,7 @@ std::string FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterN /* value */ if (bString) { expr += "\""; - } - else if (bDateTime) { + } else if (bDateTime) { expr += "`"; } @@ -305,8 +311,7 @@ std::string FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterN if (bString) { expr += "\""; - } - else if (bDateTime) { + } else if (bDateTime) { expr += "`"; } @@ -315,15 +320,15 @@ std::string FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterN return expr; } -static -std::string FLTGetLogicalComparisonCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp) -{ +static std::string +FLTGetLogicalComparisonCommonExpression(FilterEncodingNode *psFilterNode, + layerObj *lp) { std::string expr; /* -------------------------------------------------------------------- */ /* OR and AND */ /* -------------------------------------------------------------------- */ if (psFilterNode->psLeftNode && psFilterNode->psRightNode) { - char* pszTmp = FLTGetCommonExpression(psFilterNode->psLeftNode, lp); + char *pszTmp = FLTGetCommonExpression(psFilterNode->psLeftNode, lp); if (!pszTmp) return std::string(); @@ -346,8 +351,9 @@ std::string FLTGetLogicalComparisonCommonExpression(FilterEncodingNode *psFilter /* -------------------------------------------------------------------- */ /* NOT */ /* -------------------------------------------------------------------- */ - else if (psFilterNode->psLeftNode && strcasecmp(psFilterNode->pszValue, "NOT") == 0) { - char* pszTmp = FLTGetCommonExpression(psFilterNode->psLeftNode, lp); + else if (psFilterNode->psLeftNode && + strcasecmp(psFilterNode->pszValue, "NOT") == 0) { + char *pszTmp = FLTGetCommonExpression(psFilterNode->psLeftNode, lp); if (!pszTmp) return std::string(); @@ -360,12 +366,12 @@ std::string FLTGetLogicalComparisonCommonExpression(FilterEncodingNode *psFilter return expr; } -static -std::string FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, layerObj *lp) -{ +static std::string +FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, + layerObj *lp) { std::string expr; double dfDistance = -1; - shapeObj *psTmpShape=NULL; + shapeObj *psTmpShape = NULL; bool bBBoxQuery = false; bool bAlreadyReprojected = false; @@ -379,28 +385,28 @@ std::string FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, char szPolygon[512]; snprintf(szPolygon, sizeof(szPolygon), - "POLYGON((%.18f %.18f,%.18f %.18f,%.18f %.18f,%.18f %.18f,%.18f %.18f))", - sQueryRect.minx, sQueryRect.miny, - sQueryRect.minx, sQueryRect.maxy, - sQueryRect.maxx, sQueryRect.maxy, - sQueryRect.maxx, sQueryRect.miny, + "POLYGON((%.18f %.18f,%.18f %.18f,%.18f %.18f,%.18f %.18f,%.18f " + "%.18f))", + sQueryRect.minx, sQueryRect.miny, sQueryRect.minx, sQueryRect.maxy, + sQueryRect.maxx, sQueryRect.maxy, sQueryRect.maxx, sQueryRect.miny, sQueryRect.minx, sQueryRect.miny); psTmpShape = msShapeFromWKT(szPolygon); - /* + /* ** This is a horrible hack to deal with world-extent requests and - ** reprojection. msProjectRect() detects if reprojection from longlat to - ** projected SRS, and in that case it transforms the bbox to -1e-15,-1e-15,1e15,1e15 + ** reprojection. msProjectRect() detects if reprojection from longlat to + ** projected SRS, and in that case it transforms the bbox to + *-1e-15,-1e-15,1e15,1e15 ** to ensure that all features are returned. ** - ** Make wfs_200_cite_filter_bbox_world.xml and wfs_200_cite_postgis_bbox_world.xml pass + ** Make wfs_200_cite_filter_bbox_world.xml and + *wfs_200_cite_postgis_bbox_world.xml pass */ if (fabs(sQueryRect.minx - -180.0) < 1e-5 && fabs(sQueryRect.miny - -90.0) < 1e-5 && fabs(sQueryRect.maxx - 180.0) < 1e-5 && - fabs(sQueryRect.maxy - 90.0) < 1e-5) - { + fabs(sQueryRect.maxy - 90.0) < 1e-5) { if (lp->projection.numargs > 0) { projectionObj sProjTmp; if (psNode->pszSRS) { @@ -408,7 +414,8 @@ std::string FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, msProjectionInheritContextFrom(&sProjTmp, &lp->projection); } if (psNode->pszSRS) { - /* Use the non EPSG variant since axis swapping is done in FLTDoAxisSwappingIfNecessary */ + /* Use the non EPSG variant since axis swapping is done in + * FLTDoAxisSwappingIfNecessary */ if (msLoadProjectionString(&sProjTmp, psNode->pszSRS) == 0) { msProjectRect(&sProjTmp, &lp->projection, &sQueryRect); } @@ -420,7 +427,7 @@ std::string FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, if (sQueryRect.minx <= -1e14) { msFreeShape(psTmpShape); msFree(psTmpShape); - psTmpShape = (shapeObj*) msSmallMalloc(sizeof(shapeObj)); + psTmpShape = (shapeObj *)msSmallMalloc(sizeof(shapeObj)); msInitShape(psTmpShape); msRectToPolygon(sQueryRect, psTmpShape); bAlreadyReprojected = true; @@ -431,20 +438,27 @@ std::string FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, } else { /* other geos type operations */ - /* project shape to layer projection. If the proj is not part of the filter query, - assume that the cooredinates are in the map projection */ + /* project shape to layer projection. If the proj is not part of the filter + query, assume that the cooredinates are in the map projection */ int nUnit = -1; - shapeObj* psQueryShape = FLTGetShape(psNode, &dfDistance, &nUnit); + shapeObj *psQueryShape = FLTGetShape(psNode, &dfDistance, &nUnit); - if ((strcasecmp(psNode->pszValue, "DWithin") == 0 || strcasecmp(psNode->pszValue, "Beyond") == 0 ) && dfDistance > 0) { + if ((strcasecmp(psNode->pszValue, "DWithin") == 0 || + strcasecmp(psNode->pszValue, "Beyond") == 0) && + dfDistance > 0) { int nLayerUnit = lp->units; - if(nLayerUnit == -1) nLayerUnit = GetMapserverUnitUsingProj(&lp->projection); - if(nLayerUnit == -1) nLayerUnit = lp->map->units; - if(nLayerUnit == -1) nLayerUnit = GetMapserverUnitUsingProj(&lp->map->projection); + if (nLayerUnit == -1) + nLayerUnit = GetMapserverUnitUsingProj(&lp->projection); + if (nLayerUnit == -1) + nLayerUnit = lp->map->units; + if (nLayerUnit == -1) + nLayerUnit = GetMapserverUnitUsingProj(&lp->map->projection); if (nUnit >= 0 && nUnit != nLayerUnit) - dfDistance *= msInchesPerUnit(nUnit,0)/msInchesPerUnit(nLayerUnit,0); /* target is layer units */ + dfDistance *= + msInchesPerUnit(nUnit, 0) / + msInchesPerUnit(nLayerUnit, 0); /* target is layer units */ } psTmpShape = psQueryShape; @@ -462,7 +476,8 @@ std::string FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, msProjectionInheritContextFrom(&sProjTmp, &lp->projection); } if (psNode->pszSRS) { - /* Use the non EPSG variant since axis swapping is done in FLTDoAxisSwappingIfNecessary */ + /* Use the non EPSG variant since axis swapping is done in + * FLTDoAxisSwappingIfNecessary */ if (msLoadProjectionString(&sProjTmp, psNode->pszSRS) == 0) { msProjectShape(&sProjTmp, &lp->projection, psTmpShape); } @@ -486,13 +501,15 @@ std::string FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, expr += "([shape],fromText('"; /* filter geometry */ - char* pszWktText = msGEOSShapeToWKT(psTmpShape); + char *pszWktText = msGEOSShapeToWKT(psTmpShape); expr += pszWktText ? pszWktText : "Cannot translate shape to WKT"; expr += "')"; msGEOSFreeWKT(pszWktText); - /* (optional) beyond/dwithin distance, always 0.0 since we apply the distance as a buffer earlier */ - if ((strcasecmp(psNode->pszValue, "DWithin") == 0 || strcasecmp(psNode->pszValue, "Beyond") == 0)) { + /* (optional) beyond/dwithin distance, always 0.0 since we apply the + * distance as a buffer earlier */ + if ((strcasecmp(psNode->pszValue, "DWithin") == 0 || + strcasecmp(psNode->pszValue, "Beyond") == 0)) { char szBuffer[256]; sprintf(szBuffer, ",%g", dfDistance); expr += szBuffer; @@ -513,29 +530,32 @@ std::string FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, return expr; } -static std::string FLTGetFeatureIdCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp) -{ +static std::string +FLTGetFeatureIdCommonExpression(FilterEncodingNode *psFilterNode, + layerObj *lp) { std::string expr; -#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || defined(USE_SOS_SVR) +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) if (psFilterNode->pszValue) { - const char* pszAttribute = msOWSLookupMetadata(&(lp->metadata), "OFG", "featureid"); + const char *pszAttribute = + msOWSLookupMetadata(&(lp->metadata), "OFG", "featureid"); if (pszAttribute) { - const auto tokens = msStringSplit(psFilterNode->pszValue,','); + const auto tokens = msStringSplit(psFilterNode->pszValue, ','); if (!tokens.empty()) { - for (size_t i=0; i < tokens.size(); i++) { - const char* pszId = tokens[i].c_str(); - const char* pszDot = strrchr(pszId, '.'); - if( pszDot ) + for (size_t i = 0; i < tokens.size(); i++) { + const char *pszId = tokens[i].c_str(); + const char *pszDot = strrchr(pszId, '.'); + if (pszDot) pszId = pszDot + 1; bool bString = false; if (i == 0) { - if(FLTIsNumeric(pszId) == MS_FALSE) + if (FLTIsNumeric(pszId) == MS_FALSE) bString = true; } - if (!expr.empty()) + if (!expr.empty()) expr += " OR "; else expr = '('; @@ -566,14 +586,14 @@ static std::string FLTGetFeatureIdCommonExpression(FilterEncodingNode *psFilterN return expr; } -std::string FLTGetTimeExpression(FilterEncodingNode *psFilterNode, layerObj *lp) -{ +std::string FLTGetTimeExpression(FilterEncodingNode *psFilterNode, + layerObj *lp) { if (lp == NULL) return std::string(); std::string expr; - const char* pszTimeField = nullptr; - const char* pszTimeValue = FLTGetDuring(psFilterNode, &pszTimeField); + const char *pszTimeField = nullptr; + const char *pszTimeValue = FLTGetDuring(psFilterNode, &pszTimeField); if (pszTimeField && pszTimeValue) { expressionObj old_filter; msInitExpression(&old_filter); @@ -589,28 +609,34 @@ std::string FLTGetTimeExpression(FilterEncodingNode *psFilterNode, layerObj *lp) return expr; } -char *FLTGetCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp) -{ +char *FLTGetCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp) { char *pszExpression = NULL; if (!psFilterNode) return NULL; if (psFilterNode->eType == FILTER_NODE_TYPE_COMPARISON) { - if ( psFilterNode->psLeftNode && psFilterNode->psRightNode) { + if (psFilterNode->psLeftNode && psFilterNode->psRightNode) { if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue)) - pszExpression = msStrdup(FLTGetBinaryComparisonCommonExpression(psFilterNode, lp).c_str()); + pszExpression = msStrdup( + FLTGetBinaryComparisonCommonExpression(psFilterNode, lp).c_str()); else if (strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0) - pszExpression = msStrdup(FLTGetIsLikeComparisonCommonExpression(psFilterNode).c_str()); + pszExpression = msStrdup( + FLTGetIsLikeComparisonCommonExpression(psFilterNode).c_str()); else if (strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0) - pszExpression = msStrdup(FLTGetIsBetweenComparisonCommonExpresssion(psFilterNode, lp).c_str()); + pszExpression = msStrdup( + FLTGetIsBetweenComparisonCommonExpresssion(psFilterNode, lp) + .c_str()); } } else if (psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL) { - pszExpression = msStrdup(FLTGetLogicalComparisonCommonExpression(psFilterNode, lp).c_str()); + pszExpression = msStrdup( + FLTGetLogicalComparisonCommonExpression(psFilterNode, lp).c_str()); } else if (psFilterNode->eType == FILTER_NODE_TYPE_SPATIAL) { - pszExpression = msStrdup(FLTGetSpatialComparisonCommonExpression(psFilterNode, lp).c_str()); - } else if (psFilterNode->eType == FILTER_NODE_TYPE_FEATUREID) { - pszExpression = msStrdup(FLTGetFeatureIdCommonExpression(psFilterNode, lp).c_str()); + pszExpression = msStrdup( + FLTGetSpatialComparisonCommonExpression(psFilterNode, lp).c_str()); + } else if (psFilterNode->eType == FILTER_NODE_TYPE_FEATUREID) { + pszExpression = + msStrdup(FLTGetFeatureIdCommonExpression(psFilterNode, lp).c_str()); } else if (psFilterNode->eType == FILTER_NODE_TYPE_TEMPORAL) { pszExpression = msStrdup(FLTGetTimeExpression(psFilterNode, lp).c_str()); } @@ -618,14 +644,16 @@ char *FLTGetCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp) return pszExpression; } -int FLTApplyFilterToLayerCommonExpression(mapObj *map, int iLayerIndex, const char *pszExpression) -{ - return FLTApplyFilterToLayerCommonExpressionWithRect(map, iLayerIndex, pszExpression, map->extent); +int FLTApplyFilterToLayerCommonExpression(mapObj *map, int iLayerIndex, + const char *pszExpression) { + return FLTApplyFilterToLayerCommonExpressionWithRect( + map, iLayerIndex, pszExpression, map->extent); } /* rect must be in map->projection */ -int FLTApplyFilterToLayerCommonExpressionWithRect(mapObj *map, int iLayerIndex, const char *pszExpression, rectObj rect) -{ +int FLTApplyFilterToLayerCommonExpressionWithRect(mapObj *map, int iLayerIndex, + const char *pszExpression, + rectObj rect) { int retval; const int save_startindex = map->query.startindex; @@ -633,7 +661,8 @@ int FLTApplyFilterToLayerCommonExpressionWithRect(mapObj *map, int iLayerIndex, const int save_only_cache_result_count = map->query.only_cache_result_count; const int save_cache_shapes = map->query.cache_shapes; const int save_max_cached_shape_count = map->query.max_cached_shape_count; - const int save_max_cached_shape_ram_amount = map->query.max_cached_shape_ram_amount; + const int save_max_cached_shape_ram_amount = + map->query.max_cached_shape_ram_amount; msInitQuery(&(map->query)); map->query.startindex = save_startindex; map->query.maxfeatures = save_maxfeatures; @@ -647,17 +676,14 @@ int FLTApplyFilterToLayerCommonExpressionWithRect(mapObj *map, int iLayerIndex, map->query.rect = rect; - if( pszExpression ) - { + if (pszExpression) { map->query.type = MS_QUERY_BY_FILTER; msInitExpression(&map->query.filter); map->query.filter.string = msStrdup(pszExpression); map->query.filter.type = MS_EXPRESSION; /* a logical expression */ retval = msQueryByFilter(map); - } - else - { + } else { map->query.type = MS_QUERY_BY_RECT; retval = msQueryByRect(map); } diff --git a/mapogcsld.c b/mapogcsld.c index 3de1eb66d8..52559cc19a 100644 --- a/mapogcsld.c +++ b/mapogcsld.c @@ -36,7 +36,9 @@ extern int yyparse(parseObj *); #if defined(USE_CURL) -static inline void IGUR_sizet(size_t ignored) { (void)ignored; } /* Ignore GCC Unused Result */ +static inline void IGUR_sizet(size_t ignored) { + (void)ignored; +} /* Ignore GCC Unused Result */ #endif #define SLD_LINE_SYMBOL_NAME "sld_line_symbol" @@ -62,56 +64,72 @@ static inline void IGUR_sizet(size_t ignored) { (void)ignored; } /* Ignore GCC /* used to do the match. */ /************************************************************************/ int msSLDApplySLDURL(mapObj *map, const char *szURL, int iLayer, - const char *pszStyleLayerName, char **ppszLayerNames) -{ + const char *pszStyleLayerName, char **ppszLayerNames) { /* needed for libcurl function msHTTPGetFile in maphttp.c */ #if defined(USE_CURL) char *pszSLDTmpFile = NULL; int status = 0; - char *pszSLDbuf=NULL; + char *pszSLDbuf = NULL; FILE *fp = NULL; int nStatus = MS_FAILURE; if (map && szURL) { - map->sldurl = (char*)szURL; + map->sldurl = (char *)szURL; pszSLDTmpFile = msTmpFile(map, map->mappath, NULL, "sld.xml"); if (pszSLDTmpFile == NULL) { - pszSLDTmpFile = msTmpFile(map, NULL, NULL, "sld.xml" ); + pszSLDTmpFile = msTmpFile(map, NULL, NULL, "sld.xml"); } if (pszSLDTmpFile == NULL) { - msSetError(MS_WMSERR, "Could not determine temporary file. Please make sure that the temporary path is set. The temporary path can be defined for example by setting TEMPPATH in the map file. Please check the MapServer documentation on temporary path settings.", "msSLDApplySLDURL()"); + msSetError( + MS_WMSERR, + "Could not determine temporary file. Please make sure that the " + "temporary path is set. The temporary path can be defined for " + "example by setting TEMPPATH in the map file. Please check the " + "MapServer documentation on temporary path settings.", + "msSLDApplySLDURL()"); } else { int nMaxRemoteSLDBytes; - const char *pszMaxRemoteSLDBytes = msOWSLookupMetadata(&(map->web.metadata), "MO", "remote_sld_max_bytes"); - if(!pszMaxRemoteSLDBytes) { - nMaxRemoteSLDBytes = 1024*1024; /* 1 megaByte */ + const char *pszMaxRemoteSLDBytes = msOWSLookupMetadata( + &(map->web.metadata), "MO", "remote_sld_max_bytes"); + if (!pszMaxRemoteSLDBytes) { + nMaxRemoteSLDBytes = 1024 * 1024; /* 1 megaByte */ } else { nMaxRemoteSLDBytes = atoi(pszMaxRemoteSLDBytes); } - if (msHTTPGetFile(szURL, pszSLDTmpFile, &status,-1, 0, 0, nMaxRemoteSLDBytes) == MS_SUCCESS) { + if (msHTTPGetFile(szURL, pszSLDTmpFile, &status, -1, 0, 0, + nMaxRemoteSLDBytes) == MS_SUCCESS) { if ((fp = fopen(pszSLDTmpFile, "rb")) != NULL) { - int nBufsize=0; + int nBufsize = 0; fseek(fp, 0, SEEK_END); nBufsize = ftell(fp); - if(nBufsize > 0) { + if (nBufsize > 0) { rewind(fp); - pszSLDbuf = (char*)malloc((nBufsize+1)*sizeof(char)); + pszSLDbuf = (char *)malloc((nBufsize + 1) * sizeof(char)); IGUR_sizet(fread(pszSLDbuf, 1, nBufsize, fp)); pszSLDbuf[nBufsize] = '\0'; } else { - msSetError(MS_WMSERR, "Could not open SLD %s as it appears empty", "msSLDApplySLDURL", szURL); + msSetError(MS_WMSERR, "Could not open SLD %s as it appears empty", + "msSLDApplySLDURL", szURL); } fclose(fp); unlink(pszSLDTmpFile); } } else { unlink(pszSLDTmpFile); - msSetError(MS_WMSERR, "Could not open SLD %s and save it in a temporary file. Please make sure that the sld url is valid and that the temporary path is set. The temporary path can be defined for example by setting TEMPPATH in the map file. Please check the MapServer documentation on temporary path settings.", "msSLDApplySLDURL", szURL); + msSetError( + MS_WMSERR, + "Could not open SLD %s and save it in a temporary file. Please " + "make sure that the sld url is valid and that the temporary path " + "is set. The temporary path can be defined for example by setting " + "TEMPPATH in the map file. Please check the MapServer " + "documentation on temporary path settings.", + "msSLDApplySLDURL", szURL); } msFree(pszSLDTmpFile); if (pszSLDbuf) - nStatus = msSLDApplySLD(map, pszSLDbuf, iLayer, pszStyleLayerName, ppszLayerNames); + nStatus = msSLDApplySLD(map, pszSLDbuf, iLayer, pszStyleLayerName, + ppszLayerNames); } map->sldurl = NULL; } @@ -121,54 +139,58 @@ int msSLDApplySLDURL(mapObj *map, const char *szURL, int iLayer, return nStatus; #else - msSetError(MS_MISCERR, "WMS/WFS client support is not enabled .", "msSLDApplySLDURL()"); - return(MS_FAILURE); + msSetError(MS_MISCERR, "WMS/WFS client support is not enabled .", + "msSLDApplySLDURL()"); + return (MS_FAILURE); #endif } -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) /* -------------------------------------------------------------------- */ /* If the same layer is given more that once, we need to */ /* duplicate it. */ /* -------------------------------------------------------------------- */ -static void msSLDApplySLD_DuplicateLayers(mapObj *map, int nSLDLayers, layerObj *pasSLDLayers) -{ - int m; - for (m=0; mvtable) { - if( msInitializeVirtualTable(psTmpLayer) != MS_SUCCESS ) { - MS_REFCNT_DECR(psTmpLayer); - continue; - } +static void msSLDApplySLD_DuplicateLayers(mapObj *map, int nSLDLayers, + layerObj *pasSLDLayers) { + int m; + for (m = 0; m < nSLDLayers; m++) { + int l; + int nIndex = msGetLayerIndex(map, pasSLDLayers[m].name); + if (pasSLDLayers[m].name == NULL) + continue; + if (nIndex < 0) + continue; + for (l = m + 1; l < nSLDLayers; l++) { + if (pasSLDLayers[l].name == NULL) + continue; + if (strcasecmp(pasSLDLayers[m].name, pasSLDLayers[l].name) == 0) { + layerObj *psTmpLayer = (layerObj *)malloc(sizeof(layerObj)); + char tmpId[128]; + + initLayer(psTmpLayer, map); + msCopyLayer(psTmpLayer, GET_LAYER(map, nIndex)); + /* open the source layer */ + if (!psTmpLayer->vtable) { + if (msInitializeVirtualTable(psTmpLayer) != MS_SUCCESS) { + MS_REFCNT_DECR(psTmpLayer); + continue; } - - /*make the name unique*/ - snprintf(tmpId, sizeof(tmpId), "%lx_%x_%d",(long)time(NULL),(int)getpid(), - map->numlayers); - if (psTmpLayer->name) - msFree(psTmpLayer->name); - psTmpLayer->name = msStrdup(tmpId); - msFree(pasSLDLayers[l].name); - pasSLDLayers[l].name = msStrdup(tmpId); - msInsertLayer(map, psTmpLayer, -1); - MS_REFCNT_DECR(psTmpLayer); } + + /*make the name unique*/ + snprintf(tmpId, sizeof(tmpId), "%lx_%x_%d", (long)time(NULL), + (int)getpid(), map->numlayers); + if (psTmpLayer->name) + msFree(psTmpLayer->name); + psTmpLayer->name = msStrdup(tmpId); + msFree(pasSLDLayers[l].name); + pasSLDLayers[l].name = msStrdup(tmpId); + msInsertLayer(map, psTmpLayer, -1); + MS_REFCNT_DECR(psTmpLayer); } } + } } #endif @@ -180,33 +202,34 @@ static void msSLDApplySLD_DuplicateLayers(mapObj *map, int nSLDLayers, layerObj /* they have the same name, copy the classes associated with */ /* the SLD layers onto the map layers. */ /************************************************************************/ -int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer, const char *pszStyleLayerName, char **ppszLayerNames) -{ -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) +int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer, + const char *pszStyleLayerName, char **ppszLayerNames) { +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) int nSLDLayers = 0; layerObj *pasSLDLayers = NULL; int nStatus = MS_SUCCESS; /*const char *pszSLDNotSupported = NULL;*/ pasSLDLayers = msSLDParseSLD(map, psSLDXML, &nSLDLayers); - if( pasSLDLayers == NULL ) { - errorObj* psError = msGetErrorObj(); - if( psError && psError->code != MS_NOERR ) + if (pasSLDLayers == NULL) { + errorObj *psError = msGetErrorObj(); + if (psError && psError->code != MS_NOERR) return MS_FAILURE; } - if (pasSLDLayers && nSLDLayers>0) { + if (pasSLDLayers && nSLDLayers > 0) { int i; msSLDApplySLD_DuplicateLayers(map, nSLDLayers, pasSLDLayers); - for (i=0; inumlayers; i++) { + for (i = 0; i < map->numlayers; i++) { layerObj *lp = NULL; const char *pszWMSLayerName = NULL; int j; int bUseSpecificLayer = 0; - if (iLayer >=0 && iLayer< map->numlayers) { + if (iLayer >= 0 && iLayer < map->numlayers) { i = iLayer; bUseSpecificLayer = 1; } @@ -216,31 +239,36 @@ int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer, const char *psz /* compare layer name to wms_name as well */ pszWMSLayerName = msOWSLookupMetadata(&(lp->metadata), "MO", "name"); - for (j=0; jname && pszStyleLayerName == NULL && ((strcasecmp(lp->name, sldLayer->name) == 0 || - (pszWMSLayerName && strcasecmp(pszWMSLayerName, sldLayer->name) == 0))|| - (lp->group && - strcasecmp(lp->group, sldLayer->name) == 0))) || + (pszWMSLayerName && + strcasecmp(pszWMSLayerName, sldLayer->name) == 0)) || + (lp->group && strcasecmp(lp->group, sldLayer->name) == 0))) || (bUseSpecificLayer && pszStyleLayerName && sldLayer->name && strcasecmp(sldLayer->name, pszStyleLayerName) == 0)) { #ifdef notdef - /*this is a test code if we decide to flag some layers as not supporting SLD*/ - pszSLDNotSupported = msOWSLookupMetadata(&(lp->metadata), "M", "SLD_NOT_SUPPORTED"); + /*this is a test code if we decide to flag some layers as not + * supporting SLD*/ + pszSLDNotSupported = + msOWSLookupMetadata(&(lp->metadata), "M", "SLD_NOT_SUPPORTED"); if (pszSLDNotSupported) { - msSetError(MS_WMSERR, "Layer %s does not support SLD", "msSLDApplySLD", sldLayer->name); + msSetError(MS_WMSERR, "Layer %s does not support SLD", + "msSLDApplySLD", sldLayer->name); nsStatus = MS_FAILURE; goto sld_cleanup; } #endif - if ( sldLayer->numclasses > 0) { + if (sldLayer->numclasses > 0) { int iClass = 0; int k; int bSLDHasNamedClass = MS_FALSE; @@ -248,17 +276,17 @@ int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer, const char *psz lp->type = sldLayer->type; lp->rendermode = MS_ALL_MATCHING_CLASSES; - for (k=0; k < sldLayer->numclasses; k++) { - if( sldLayer->class[k]->group ) { - bSLDHasNamedClass = MS_TRUE; - break; - } + for (k = 0; k < sldLayer->numclasses; k++) { + if (sldLayer->class[k] -> group) { + bSLDHasNamedClass = MS_TRUE; + break; + } } - for(k=0; knumclasses; k++) { + for (k = 0; k < lp->numclasses; k++) { if (lp->class[k] != NULL) { - lp->class[k]->layer=NULL; - if (freeClass(lp->class[k]) == MS_SUCCESS ) { + lp->class[k]->layer = NULL; + if (freeClass(lp->class[k]) == MS_SUCCESS) { msFree(lp->class[k]); lp->class[k] = NULL; } @@ -266,55 +294,58 @@ int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer, const char *psz } lp->numclasses = 0; - if( bSLDHasNamedClass ) { - if( sldLayer->classgroup ) { - /* Set the class group to the class that has UserStyle.IsDefault */ - msFree( lp->classgroup); - lp->classgroup = msStrdup(sldLayer->classgroup); - } - } - else { - /*unset the classgroup on the layer if it was set. This allows the layer to render - with all the classes defined in the SLD*/ - msFree(lp->classgroup); - lp->classgroup = NULL; + if (bSLDHasNamedClass && sldLayer->classgroup) { + /* Set the class group to the class that has UserStyle.IsDefault + */ + msFree(lp->classgroup); + lp->classgroup = msStrdup(sldLayer->classgroup); + } else { + /*unset the classgroup on the layer if it was set. This allows the + layer to render with all the classes defined in the SLD*/ + msFree(lp->classgroup); + lp->classgroup = NULL; } - for (k=0; k < sldLayer->numclasses; k++) { + for (k = 0; k < sldLayer->numclasses; k++) { if (msGrowLayerClasses(lp) == NULL) return MS_FAILURE; initClass(lp->class[iClass]); - msCopyClass(lp->class[iClass], - sldLayer->class[k], NULL); + msCopyClass(lp->class[iClass], sldLayer -> class[k], NULL); lp->class[iClass]->layer = lp; lp->numclasses++; - /*aliases may have been used as part of the sld text symbolizer for - label element. Try to process it if that is the case #3114*/ - if (msLayerOpen(lp) == MS_SUCCESS && - msLayerGetItems(lp) == MS_SUCCESS) { - if (lp->class[iClass]->text.string) { + /*aliases may have been used as part of the sld text symbolizer + for label element. Try to process it if that is the case #3114*/ + if (msLayerOpen(lp) == MS_SUCCESS) { + if (msLayerGetItems(lp) == MS_SUCCESS && + lp->class[iClass] -> text.string) { int z; - for(z=0; znumitems; z++) { - const char* pszFullName; + for (z = 0; z < lp->numitems; z++) { + const char *pszFullName; char szTmp[512]; - char* pszTmp1; + char *pszTmp1; if (!lp->items[z] || strlen(lp->items[z]) == 0) continue; snprintf(szTmp, sizeof(szTmp), "%s_alias", lp->items[z]); - pszFullName = msOWSLookupMetadata(&(lp->metadata), "G", szTmp); - pszTmp1 = msStrdup( lp->class[iClass]->text.string); - if (pszFullName != NULL && (strstr(pszTmp1, pszFullName) != NULL)) { - char *tmpstr1= msReplaceSubstring(pszTmp1, pszFullName, lp->items[z]); - char* pszTmp2 = (char *)malloc(sizeof(char)*(strlen(tmpstr1)+3)); - sprintf(pszTmp2,"(%s)",tmpstr1); - msLoadExpressionString(&(lp->class[iClass]->text), pszTmp2); + pszFullName = + msOWSLookupMetadata(&(lp->metadata), "G", szTmp); + pszTmp1 = msStrdup(lp->class[iClass] -> text.string); + if (pszFullName != NULL && + (strstr(pszTmp1, pszFullName) != NULL)) { + char *tmpstr1 = msReplaceSubstring(pszTmp1, pszFullName, + lp->items[z]); + char *pszTmp2 = + (char *)malloc(sizeof(char) * (strlen(tmpstr1) + 3)); + sprintf(pszTmp2, "(%s)", tmpstr1); + msLoadExpressionString(&(lp->class[iClass] -> text), + pszTmp2); msFree(pszTmp2); } msFree(pszTmp1); } } + msLayerClose(lp); } iClass++; @@ -323,14 +354,14 @@ int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer, const char *psz /*this is probably an SLD that uses Named styles*/ if (sldLayer->classgroup) { int k; - for (k=0; knumclasses; k++) { - if (lp->class[k]->group && - strcasecmp(lp->class[k]->group, - sldLayer->classgroup) == 0) + for (k = 0; k < lp->numclasses; k++) { + if (lp->class[k] -> group && + strcasecmp(lp->class[k] -> group, + sldLayer -> classgroup) == 0) break; } if (k < lp->numclasses) { - msFree( lp->classgroup); + msFree(lp->classgroup); lp->classgroup = msStrdup(sldLayer->classgroup); } else { /* TODO we throw an exception ?*/ @@ -352,79 +383,81 @@ int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer, const char *psz } /* opacity for sld raster */ - if (lp->type == MS_LAYER_RASTER && - sldLayer->compositer && sldLayer->compositer->opacity != 100) + if (lp->type == MS_LAYER_RASTER && sldLayer->compositer && + sldLayer->compositer->opacity != 100) msSetLayerOpacity(lp, sldLayer->compositer->opacity); /* mark as auto-generate SLD */ if (lp->connectiontype == MS_WMS) - msInsertHashTable(&(lp->metadata), - "wms_sld_body", "auto" ); + msInsertHashTable(&(lp->metadata), "wms_sld_body", "auto"); /* The SLD might have a FeatureTypeConstraint */ - if( sldLayer->filter.type == MS_EXPRESSION ) - { - if( lp->filter.string && lp->filter.type == MS_EXPRESSION ) - { - char* pszBuffer = msStringConcatenate(NULL, "(("); - pszBuffer = msStringConcatenate(pszBuffer, lp->filter.string); - pszBuffer = msStringConcatenate(pszBuffer, ") AND ("); - pszBuffer = msStringConcatenate(pszBuffer, sldLayer->filter.string); - pszBuffer = msStringConcatenate(pszBuffer, "))"); - msFreeExpression(&lp->filter); - msInitExpression(&lp->filter); - lp->filter.string = pszBuffer; - lp->filter.type = MS_EXPRESSION; - } - else - { - msFreeExpression(&lp->filter); - msInitExpression(&lp->filter); - lp->filter.string = msStrdup(sldLayer->filter.string); - lp->filter.type = MS_EXPRESSION; - } + if (sldLayer->filter.type == MS_EXPRESSION) { + if (lp->filter.string && lp->filter.type == MS_EXPRESSION) { + char *pszBuffer = msStringConcatenate(NULL, "(("); + pszBuffer = msStringConcatenate(pszBuffer, lp->filter.string); + pszBuffer = msStringConcatenate(pszBuffer, ") AND ("); + pszBuffer = + msStringConcatenate(pszBuffer, sldLayer->filter.string); + pszBuffer = msStringConcatenate(pszBuffer, "))"); + msFreeExpression(&lp->filter); + msInitExpression(&lp->filter); + lp->filter.string = pszBuffer; + lp->filter.type = MS_EXPRESSION; + } else { + msFreeExpression(&lp->filter); + msInitExpression(&lp->filter); + lp->filter.string = msStrdup(sldLayer->filter.string); + lp->filter.type = MS_EXPRESSION; + } } - /*in some cases it would make sense to concatenate all the class expressions and use it to set the filter on the layer. This could increase performance. Will do it for db types layers #2840*/ - if (lp->filter.string == NULL || (lp->filter.string && lp->filter.type == MS_STRING && !lp->filteritem)) { - if (lp->connectiontype == MS_POSTGIS || lp->connectiontype == MS_ORACLESPATIAL || lp->connectiontype == MS_PLUGIN) { - if (lp->numclasses > 0) { - /* check first that all classes have an expression type. That is - the only way we can concatenate them and set the filter - expression */ - int k; - for (k=0; knumclasses; k++) { - if (lp->class[k]->expression.type != MS_EXPRESSION) - break; + if (lp->filter.string == NULL || + (lp->filter.string && lp->filter.type == MS_STRING && + !lp->filteritem)) { + if (lp->connectiontype == MS_POSTGIS || + lp->connectiontype == MS_ORACLESPATIAL || + lp->connectiontype == MS_PLUGIN) { + if (lp->numclasses > 0) { + /* check first that all classes have an expression type. That is + the only way we can concatenate them and set the filter + expression */ + int k; + for (k = 0; k < lp->numclasses; k++) { + if (lp->class[k] -> expression.type != MS_EXPRESSION) + break; + } + if (k == lp->numclasses) { + char szTmp[512]; + char *pszBuffer = NULL; + for (k = 0; k < lp->numclasses; k++) { + if (pszBuffer == NULL) + snprintf(szTmp, sizeof(szTmp), "%s", + "(("); /* we a building a string expression, + explicitly set type below */ + else + snprintf(szTmp, sizeof(szTmp), "%s", " OR "); + + pszBuffer = msStringConcatenate(pszBuffer, szTmp); + pszBuffer = msStringConcatenate( + pszBuffer, lp->class[k] -> expression.string); } - if (k == lp->numclasses) { - char szTmp[512]; - char* pszBuffer = NULL; - for (k=0; knumclasses; k++) { - if (pszBuffer == NULL) - snprintf(szTmp, sizeof(szTmp), "%s", "(("); /* we a building a string expression, explicitly set type below */ - else - snprintf(szTmp, sizeof(szTmp), "%s", " OR "); - - pszBuffer = msStringConcatenate(pszBuffer, szTmp); - pszBuffer = msStringConcatenate(pszBuffer, lp->class[k]->expression.string); - } - snprintf(szTmp, sizeof(szTmp), "%s", "))"); - pszBuffer =msStringConcatenate(pszBuffer, szTmp); + snprintf(szTmp, sizeof(szTmp), "%s", "))"); + pszBuffer = msStringConcatenate(pszBuffer, szTmp); - msFreeExpression(&lp->filter); - msInitExpression(&lp->filter); - lp->filter.string = msStrdup(pszBuffer); - lp->filter.type = MS_EXPRESSION; + msFreeExpression(&lp->filter); + msInitExpression(&lp->filter); + lp->filter.string = msStrdup(pszBuffer); + lp->filter.type = MS_EXPRESSION; - msFree(pszBuffer); - } + msFree(pszBuffer); } } + } } break; } @@ -439,38 +472,36 @@ int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer, const char *psz /* -------------------------------------------------------------------- */ if (ppszLayerNames) { char *pszTmp = NULL; - for (i=0; idebug == MS_DEBUGLEVEL_VVV) { - char* tmpfilename = msTmpFile(map, map->mappath, NULL, "_sld.map"); + if (map->debug == MS_DEBUGLEVEL_VVV) { + char *tmpfilename = msTmpFile(map, map->mappath, NULL, "_sld.map"); if (tmpfilename == NULL) { - tmpfilename = msTmpFile(map, NULL, NULL, "_sld.map" ); + tmpfilename = msTmpFile(map, NULL, NULL, "_sld.map"); } if (tmpfilename) { - msSaveMap(map,tmpfilename); + msSaveMap(map, tmpfilename); msDebug("msApplySLD(): Map file after SLD was applied %s", tmpfilename); msFree(tmpfilename); } @@ -478,32 +509,26 @@ int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer, const char *psz return nStatus; #else - msSetError(MS_MISCERR, "OWS support is not available.", - "msSLDApplySLD()"); - return(MS_FAILURE); + msSetError(MS_MISCERR, "OWS support is not available.", "msSLDApplySLD()"); + return (MS_FAILURE); #endif } - - -static CPLXMLNode* FindNextChild(CPLXMLNode* psNode, const char* pszChildName) -{ - while( psNode ) - { - if( psNode->eType == CXT_Element && - strcasecmp(psNode->pszValue, pszChildName) == 0 ) - { - return psNode; - } - psNode = psNode->psNext; +static CPLXMLNode *FindNextChild(CPLXMLNode *psNode, const char *pszChildName) { + while (psNode) { + if (psNode->eType == CXT_Element && + strcasecmp(psNode->pszValue, pszChildName) == 0) { + return psNode; } - return NULL; + psNode = psNode->psNext; + } + return NULL; } -#define LOOP_ON_CHILD_ELEMENT(psParent_, psChild_, pszChildName_) \ - for( psChild_ = FindNextChild(psParent_->psChild, pszChildName_); \ - psChild_ != NULL; \ - psChild_ = FindNextChild(psChild_->psNext, pszChildName_) ) +#define LOOP_ON_CHILD_ELEMENT(psParent_, psChild_, pszChildName_) \ + for (psChild_ = FindNextChild(psParent_->psChild, pszChildName_); \ + psChild_ != NULL; \ + psChild_ = FindNextChild(psChild_->psNext, pszChildName_)) /************************************************************************/ /* msSLDParseSLD */ @@ -514,15 +539,13 @@ static CPLXMLNode* FindNextChild(CPLXMLNode* psNode, const char* pszChildName) /* Returns an array of mapserver layers. The pnLayres if */ /* provided will indicate the size of the returned array. */ /************************************************************************/ -layerObj *msSLDParseSLD(mapObj *map, const char *psSLDXML, int *pnLayers) -{ +layerObj *msSLDParseSLD(mapObj *map, const char *psSLDXML, int *pnLayers) { CPLXMLNode *psRoot = NULL; CPLXMLNode *psSLD, *psNamedLayer; layerObj *pasLayers = NULL; int iLayer = 0; int nLayers = 0; - if (map == NULL || psSLDXML == NULL || strlen(psSLDXML) == 0 || (strstr(psSLDXML, "StyledLayerDescriptor") == NULL)) { msSetError(MS_WMSERR, "Invalid SLD document", ""); @@ -530,7 +553,7 @@ layerObj *msSLDParseSLD(mapObj *map, const char *psSLDXML, int *pnLayers) } psRoot = CPLParseXMLString(psSLDXML); - if( psRoot == NULL) { + if (psRoot == NULL) { msSetError(MS_WMSERR, "Invalid SLD document : %s", "", psSLDXML); return NULL; } @@ -541,7 +564,6 @@ layerObj *msSLDParseSLD(mapObj *map, const char *psSLDXML, int *pnLayers) CPLStripXMLNamespace(psRoot, "gml", 1); CPLStripXMLNamespace(psRoot, "se", 1); - /* -------------------------------------------------------------------- */ /* get the root element (StyledLayerDescriptor). */ /* -------------------------------------------------------------------- */ @@ -554,35 +576,31 @@ layerObj *msSLDParseSLD(mapObj *map, const char *psSLDXML, int *pnLayers) /* -------------------------------------------------------------------- */ /* Parse the named layers. */ /* -------------------------------------------------------------------- */ - LOOP_ON_CHILD_ELEMENT(psSLD, psNamedLayer, "NamedLayer") - { - nLayers++; - } + LOOP_ON_CHILD_ELEMENT(psSLD, psNamedLayer, "NamedLayer") { nLayers++; } if (nLayers > 0) - pasLayers = (layerObj *)malloc(sizeof(layerObj)*nLayers); + pasLayers = (layerObj *)malloc(sizeof(layerObj) * nLayers); else return NULL; - LOOP_ON_CHILD_ELEMENT(psSLD, psNamedLayer, "NamedLayer") - { - CPLXMLNode* psName = CPLGetXMLNode(psNamedLayer, "Name"); - initLayer(&pasLayers[iLayer], map); - - if (psName && psName->psChild && psName->psChild->pszValue) - pasLayers[iLayer].name = msStrdup(psName->psChild->pszValue); - - if( msSLDParseNamedLayer(psNamedLayer, &pasLayers[iLayer]) != MS_SUCCESS ) { - int i; - for (i=0; i<=iLayer; i++) - freeLayer(&pasLayers[i]); - msFree(pasLayers); - nLayers = 0; - pasLayers = NULL; - break; - } + LOOP_ON_CHILD_ELEMENT(psSLD, psNamedLayer, "NamedLayer") { + CPLXMLNode *psName = CPLGetXMLNode(psNamedLayer, "Name"); + initLayer(&pasLayers[iLayer], map); - iLayer++; + if (psName && psName->psChild && psName->psChild->pszValue) + pasLayers[iLayer].name = msStrdup(psName->psChild->pszValue); + + if (msSLDParseNamedLayer(psNamedLayer, &pasLayers[iLayer]) != MS_SUCCESS) { + int i; + for (i = 0; i <= iLayer; i++) + freeLayer(&pasLayers[i]); + msFree(pasLayers); + nLayers = 0; + pasLayers = NULL; + break; + } + + iLayer++; } if (pnLayers) @@ -594,89 +612,80 @@ layerObj *msSLDParseSLD(mapObj *map, const char *psSLDXML, int *pnLayers) return pasLayers; } - /************************************************************************/ /* _SLDApplyRuleValues */ /* */ /* Utility function to set the scale, title/name for the */ /* classes created by a Rule. */ /************************************************************************/ -void _SLDApplyRuleValues(CPLXMLNode *psRule, layerObj *psLayer, - int nNewClasses) -{ - CPLXMLNode *psMinScale=NULL, *psMaxScale=NULL; - CPLXMLNode *psName=NULL, *psTitle=NULL; - double dfMinScale=0, dfMaxScale=0; - char *pszName=NULL, *pszTitle=NULL; +void _SLDApplyRuleValues(CPLXMLNode *psRule, layerObj *psLayer, + int nNewClasses) { + CPLXMLNode *psMinScale = NULL, *psMaxScale = NULL; + CPLXMLNode *psName = NULL, *psTitle = NULL; + double dfMinScale = 0, dfMaxScale = 0; + char *pszName = NULL, *pszTitle = NULL; if (psRule && psLayer && nNewClasses > 0) { /* -------------------------------------------------------------------- */ /* parse minscale and maxscale. */ /* -------------------------------------------------------------------- */ - psMinScale = CPLGetXMLNode(psRule, - "MinScaleDenominator"); - if (psMinScale && psMinScale->psChild && - psMinScale->psChild->pszValue) + psMinScale = CPLGetXMLNode(psRule, "MinScaleDenominator"); + if (psMinScale && psMinScale->psChild && psMinScale->psChild->pszValue) dfMinScale = atof(psMinScale->psChild->pszValue); - psMaxScale = CPLGetXMLNode(psRule, - "MaxScaleDenominator"); - if (psMaxScale && psMaxScale->psChild && - psMaxScale->psChild->pszValue) + psMaxScale = CPLGetXMLNode(psRule, "MaxScaleDenominator"); + if (psMaxScale && psMaxScale->psChild && psMaxScale->psChild->pszValue) dfMaxScale = atof(psMaxScale->psChild->pszValue); /* -------------------------------------------------------------------- */ /* parse name and title. */ /* -------------------------------------------------------------------- */ psName = CPLGetXMLNode(psRule, "Name"); - if (psName && psName->psChild && - psName->psChild->pszValue) + if (psName && psName->psChild && psName->psChild->pszValue) pszName = psName->psChild->pszValue; psTitle = CPLGetXMLNode(psRule, "Title"); - if (psTitle && psTitle->psChild && - psTitle->psChild->pszValue) + if (psTitle && psTitle->psChild && psTitle->psChild->pszValue) pszTitle = psTitle->psChild->pszValue; /* -------------------------------------------------------------------- */ /* set the scale to all the classes created by the rule. */ /* -------------------------------------------------------------------- */ if (dfMinScale > 0 || dfMaxScale > 0) { - for (int i=0; i 0) - psLayer->class[psLayer->numclasses-1-i]->minscaledenom = dfMinScale; + psLayer->class[psLayer->numclasses - 1 - i]->minscaledenom = + dfMinScale; if (dfMaxScale) - psLayer->class[psLayer->numclasses-1-i]->maxscaledenom = dfMaxScale; + psLayer->class[psLayer->numclasses - 1 - i]->maxscaledenom = + dfMaxScale; } } /* -------------------------------------------------------------------- */ /* set name and title to the classes created by the rule. */ /* -------------------------------------------------------------------- */ - for (int i=0; iclass[psLayer->numclasses-1-i]->name) { + for (int i = 0; i < nNewClasses; i++) { + if (!psLayer->class[psLayer->numclasses - 1 - i] -> name) { if (pszName) - psLayer->class[psLayer->numclasses-1-i]->name = msStrdup(pszName); + psLayer->class[psLayer->numclasses - 1 - i]->name = msStrdup(pszName); else if (pszTitle) - psLayer->class[psLayer->numclasses-1-i]->name = msStrdup(pszTitle); - else - { + psLayer->class[psLayer->numclasses - 1 - i]->name = + msStrdup(pszTitle); + else { // Build a name from layer and class info char szTmp[256]; snprintf(szTmp, sizeof(szTmp), "%s#%d", psLayer->name, - psLayer->numclasses-1-i); - psLayer->class[psLayer->numclasses-1-i]->name = msStrdup(szTmp); + psLayer->numclasses - 1 - i); + psLayer->class[psLayer->numclasses - 1 - i]->name = msStrdup(szTmp); } } } if (pszTitle) { - for (int i=0; iclass[psLayer->numclasses-1-i]->title = - msStrdup(pszTitle); + for (int i = 0; i < nNewClasses; i++) { + psLayer->class[psLayer->numclasses - 1 - i]->title = msStrdup(pszTitle); } } - } - } /************************************************************************/ @@ -685,72 +694,72 @@ void _SLDApplyRuleValues(CPLXMLNode *psRule, layerObj *psLayer, /* Get a common expression valid from the filter valid for the */ /* temporary layer. */ /************************************************************************/ -static char* msSLDGetCommonExpressionFromFilter(CPLXMLNode* psFilter, - layerObj *psLayer) -{ - char *pszExpression = NULL; - CPLXMLNode *psTmpNextNode = NULL; - CPLXMLNode *psTmpNode = NULL; - FilterEncodingNode *psNode = NULL; - char *pszTmpFilter = NULL; - layerObj *psCurrentLayer = NULL; - const char *pszWmsName=NULL; - const char *key=NULL; - - /* clone the tree and set the next node to null */ - /* so we only have the Filter node */ - psTmpNode = CPLCloneXMLTree(psFilter); - psTmpNextNode = psTmpNode->psNext; - psTmpNode->psNext = NULL; - pszTmpFilter = CPLSerializeXMLTree(psTmpNode); - psTmpNode->psNext = psTmpNextNode; - CPLDestroyXMLNode(psTmpNode); - - if (pszTmpFilter) { - psNode = FLTParseFilterEncoding(pszTmpFilter); - - CPLFree(pszTmpFilter); - } - - if (psNode) { - int j; - - /*preparse the filter for possible gml aliases set on the layer's metadata: - "gml_NA3DESC_alias" "alias_name" and filter could be - alias_name #3079*/ - for (j=0; jmap->numlayers; j++) { - psCurrentLayer = GET_LAYER(psLayer->map, j); - - pszWmsName = msOWSLookupMetadata(&(psCurrentLayer->metadata), "MO", "name"); - - if ((psCurrentLayer->name && psLayer->name && - strcasecmp(psCurrentLayer->name, psLayer->name) == 0) || - (psCurrentLayer->group && psLayer->name && - strcasecmp(psCurrentLayer->group, psLayer->name) == 0) || - (psLayer->name && pszWmsName && - strcasecmp(pszWmsName, psLayer->name) == 0)) - break; - } - if (j < psLayer->map->numlayers) { - /*make sure that the tmp layer has all the metadata that - the original layer has, allowing to do parsing for - such things as gml_attribute_type #3052*/ - while (1) { - key = msNextKeyFromHashTable(&psCurrentLayer->metadata, key); - if (!key) - break; - else - msInsertHashTable(&psLayer->metadata, key, - msLookupHashTable(&psCurrentLayer->metadata, key)); - } - FLTPreParseFilterForAliasAndGroup(psNode, psLayer->map, j, "G"); - } +static char *msSLDGetCommonExpressionFromFilter(CPLXMLNode *psFilter, + layerObj *psLayer) { + char *pszExpression = NULL; + CPLXMLNode *psTmpNextNode = NULL; + CPLXMLNode *psTmpNode = NULL; + FilterEncodingNode *psNode = NULL; + char *pszTmpFilter = NULL; + layerObj *psCurrentLayer = NULL; + const char *pszWmsName = NULL; + const char *key = NULL; + + /* clone the tree and set the next node to null */ + /* so we only have the Filter node */ + psTmpNode = CPLCloneXMLTree(psFilter); + psTmpNextNode = psTmpNode->psNext; + psTmpNode->psNext = NULL; + pszTmpFilter = CPLSerializeXMLTree(psTmpNode); + psTmpNode->psNext = psTmpNextNode; + CPLDestroyXMLNode(psTmpNode); + + if (pszTmpFilter) { + psNode = FLTParseFilterEncoding(pszTmpFilter); + + CPLFree(pszTmpFilter); + } - pszExpression = FLTGetCommonExpression(psNode, psLayer); - FLTFreeFilterEncodingNode(psNode); + if (psNode) { + int j; + + /*preparse the filter for possible gml aliases set on the layer's metadata: + "gml_NA3DESC_alias" "alias_name" and filter could be + alias_name #3079*/ + for (j = 0; j < psLayer->map->numlayers; j++) { + psCurrentLayer = GET_LAYER(psLayer->map, j); + + pszWmsName = + msOWSLookupMetadata(&(psCurrentLayer->metadata), "MO", "name"); + + if ((psCurrentLayer->name && psLayer->name && + strcasecmp(psCurrentLayer->name, psLayer->name) == 0) || + (psCurrentLayer->group && psLayer->name && + strcasecmp(psCurrentLayer->group, psLayer->name) == 0) || + (psLayer->name && pszWmsName && + strcasecmp(pszWmsName, psLayer->name) == 0)) + break; + } + if (j < psLayer->map->numlayers) { + /*make sure that the tmp layer has all the metadata that + the original layer has, allowing to do parsing for + such things as gml_attribute_type #3052*/ + while (1) { + key = msNextKeyFromHashTable(&psCurrentLayer->metadata, key); + if (!key) + break; + else + msInsertHashTable(&psLayer->metadata, key, + msLookupHashTable(&psCurrentLayer->metadata, key)); + } + FLTPreParseFilterForAliasAndGroup(psNode, psLayer->map, j, "G"); } - return pszExpression; + pszExpression = FLTGetCommonExpression(psNode, psLayer); + FLTFreeFilterEncodingNode(psNode); + } + + return pszExpression; } /************************************************************************/ @@ -759,94 +768,85 @@ static char* msSLDGetCommonExpressionFromFilter(CPLXMLNode* psFilter, /* Parse UserStyle node. */ /************************************************************************/ -static void msSLDParseUserStyle(CPLXMLNode* psUserStyle, layerObj *psLayer) -{ - CPLXMLNode *psFeatureTypeStyle; - const char* pszUserStyleName = CPLGetXMLValue(psUserStyle, "Name", NULL); - if( pszUserStyleName ) - { - const char* pszIsDefault = CPLGetXMLValue(psUserStyle, "IsDefault", "0"); - if( EQUAL(pszIsDefault, "true") || EQUAL(pszIsDefault, "1") ) - { - msFree(psLayer->classgroup); - psLayer->classgroup = msStrdup(pszUserStyleName); - } +static void msSLDParseUserStyle(CPLXMLNode *psUserStyle, layerObj *psLayer) { + CPLXMLNode *psFeatureTypeStyle; + const char *pszUserStyleName = CPLGetXMLValue(psUserStyle, "Name", NULL); + if (pszUserStyleName) { + const char *pszIsDefault = CPLGetXMLValue(psUserStyle, "IsDefault", "0"); + if (EQUAL(pszIsDefault, "true") || EQUAL(pszIsDefault, "1")) { + msFree(psLayer->classgroup); + psLayer->classgroup = msStrdup(pszUserStyleName); } + } - LOOP_ON_CHILD_ELEMENT(psUserStyle, psFeatureTypeStyle, - "FeatureTypeStyle") - { - CPLXMLNode* psRule; + LOOP_ON_CHILD_ELEMENT(psUserStyle, psFeatureTypeStyle, "FeatureTypeStyle") { + CPLXMLNode *psRule; - /* -------------------------------------------------------------------- */ - /* Parse rules with no Else filter. */ - /* -------------------------------------------------------------------- */ - LOOP_ON_CHILD_ELEMENT(psFeatureTypeStyle, psRule, "Rule") - { - CPLXMLNode *psFilter = NULL; - CPLXMLNode *psElseFilter = NULL; - int nNewClasses=0, nClassBeforeFilter=0, nClassAfterFilter=0; - int nClassAfterRule=0, nClassBeforeRule=0; - - /* used for scale setting */ - nClassBeforeRule = psLayer->numclasses; - - psElseFilter = CPLGetXMLNode(psRule, "ElseFilter"); - nClassBeforeFilter = psLayer->numclasses; - if (psElseFilter == NULL) - msSLDParseRule(psRule, psLayer, pszUserStyleName); - nClassAfterFilter = psLayer->numclasses; - - /* -------------------------------------------------------------------- */ - /* Parse the filter and apply it to the latest class created by */ - /* the rule. */ - /* NOTE : Spatial Filter is not supported. */ - /* -------------------------------------------------------------------- */ - psFilter = CPLGetXMLNode(psRule, "Filter"); - if (psFilter && psFilter->psChild && psFilter->psChild->pszValue) { - char* pszExpression = msSLDGetCommonExpressionFromFilter(psFilter, - psLayer); - if (pszExpression) { - int i; - nNewClasses = - nClassAfterFilter - nClassBeforeFilter; - for (i=0; i - class[psLayer->numclasses-1-i]-> - expression); - msFreeExpression(exp); - msInitExpression(exp); - exp->string = msStrdup(pszExpression); - exp->type = MS_EXPRESSION; - } - msFree(pszExpression); - pszExpression = NULL; - } - } - nClassAfterRule = psLayer->numclasses; - nNewClasses = nClassAfterRule - nClassBeforeRule; + /* -------------------------------------------------------------------- */ + /* Parse rules with no Else filter. */ + /* -------------------------------------------------------------------- */ + LOOP_ON_CHILD_ELEMENT(psFeatureTypeStyle, psRule, "Rule") { + CPLXMLNode *psFilter = NULL; + CPLXMLNode *psElseFilter = NULL; + int nNewClasses = 0, nClassBeforeFilter = 0, nClassAfterFilter = 0; + int nClassAfterRule = 0, nClassBeforeRule = 0; - /* apply scale and title to newly created classes */ - _SLDApplyRuleValues(psRule, psLayer, nNewClasses); + /* used for scale setting */ + nClassBeforeRule = psLayer->numclasses; - /* TODO : parse legendgraphic */ - } - /* -------------------------------------------------------------------- */ - /* First parse rules with the else filter. These rules will */ - /* create the classes that are placed at the end of class */ - /* list. (See how classes are applied to layers in function */ - /* msSLDApplySLD). */ - /* -------------------------------------------------------------------- */ - LOOP_ON_CHILD_ELEMENT(psFeatureTypeStyle, psRule, "Rule") - { - CPLXMLNode* psElseFilter = CPLGetXMLNode(psRule, "ElseFilter"); - if (psElseFilter) { - msSLDParseRule(psRule, psLayer, pszUserStyleName); - _SLDApplyRuleValues(psRule, psLayer, 1); - psLayer->class[psLayer->numclasses-1]->isfallback = TRUE; + psElseFilter = CPLGetXMLNode(psRule, "ElseFilter"); + nClassBeforeFilter = psLayer->numclasses; + if (psElseFilter == NULL) + msSLDParseRule(psRule, psLayer, pszUserStyleName); + nClassAfterFilter = psLayer->numclasses; + + /* -------------------------------------------------------------------- */ + /* Parse the filter and apply it to the latest class created by */ + /* the rule. */ + /* NOTE : Spatial Filter is not supported. */ + /* -------------------------------------------------------------------- */ + psFilter = CPLGetXMLNode(psRule, "Filter"); + if (psFilter && psFilter->psChild && psFilter->psChild->pszValue) { + char *pszExpression = + msSLDGetCommonExpressionFromFilter(psFilter, psLayer); + if (pszExpression) { + int i; + nNewClasses = nClassAfterFilter - nClassBeforeFilter; + for (i = 0; i < nNewClasses; i++) { + expressionObj *exp = + &(psLayer->class[psLayer->numclasses - 1 - i] -> expression); + msFreeExpression(exp); + msInitExpression(exp); + exp->string = msStrdup(pszExpression); + exp->type = MS_EXPRESSION; } + msFree(pszExpression); + pszExpression = NULL; } + } + nClassAfterRule = psLayer->numclasses; + nNewClasses = nClassAfterRule - nClassBeforeRule; + + /* apply scale and title to newly created classes */ + _SLDApplyRuleValues(psRule, psLayer, nNewClasses); + + /* TODO : parse legendgraphic */ + } + /* -------------------------------------------------------------------- */ + /* First parse rules with the else filter. These rules will */ + /* create the classes that are placed at the end of class */ + /* list. (See how classes are applied to layers in function */ + /* msSLDApplySLD). */ + /* -------------------------------------------------------------------- */ + LOOP_ON_CHILD_ELEMENT(psFeatureTypeStyle, psRule, "Rule") { + CPLXMLNode *psElseFilter = CPLGetXMLNode(psRule, "ElseFilter"); + if (psElseFilter) { + msSLDParseRule(psRule, psLayer, pszUserStyleName); + _SLDApplyRuleValues(psRule, psLayer, 1); + psLayer->class[psLayer->numclasses - 1]->isfallback = TRUE; + } } + } } /************************************************************************/ @@ -854,8 +854,7 @@ static void msSLDParseUserStyle(CPLXMLNode* psUserStyle, layerObj *psLayer) /* */ /* Parse NamedLayer root. */ /************************************************************************/ -int msSLDParseNamedLayer(CPLXMLNode *psRoot, layerObj *psLayer) -{ +int msSLDParseNamedLayer(CPLXMLNode *psRoot, layerObj *psLayer) { CPLXMLNode *psLayerFeatureConstraints = NULL; if (!psRoot || !psLayer) @@ -863,17 +862,16 @@ int msSLDParseNamedLayer(CPLXMLNode *psRoot, layerObj *psLayer) if (CPLGetXMLNode(psRoot, "UserStyle")) { CPLXMLNode *psUserStyle; - LOOP_ON_CHILD_ELEMENT(psRoot, psUserStyle, "UserStyle") - { - msSLDParseUserStyle(psUserStyle, psLayer); + LOOP_ON_CHILD_ELEMENT(psRoot, psUserStyle, "UserStyle") { + msSLDParseUserStyle(psUserStyle, psLayer); } } /* check for Named styles*/ else { - CPLXMLNode* psNamedStyle = CPLGetXMLNode(psRoot, "NamedStyle"); + CPLXMLNode *psNamedStyle = CPLGetXMLNode(psRoot, "NamedStyle"); if (psNamedStyle) { - CPLXMLNode* psSLDName = CPLGetXMLNode(psNamedStyle, "Name"); - if (psSLDName && psSLDName->psChild && psSLDName->psChild->pszValue) { + CPLXMLNode *psSLDName = CPLGetXMLNode(psNamedStyle, "Name"); + if (psSLDName && psSLDName->psChild && psSLDName->psChild->pszValue) { msFree(psLayer->classgroup); psLayer->classgroup = msStrdup(psSLDName->psChild->pszValue); } @@ -882,42 +880,48 @@ int msSLDParseNamedLayer(CPLXMLNode *psRoot, layerObj *psLayer) /* Deal with LayerFeatureConstraints */ psLayerFeatureConstraints = CPLGetXMLNode(psRoot, "LayerFeatureConstraints"); - if( psLayerFeatureConstraints != NULL ) { - CPLXMLNode* psIter = psLayerFeatureConstraints->psChild; - CPLXMLNode* psFeatureTypeConstraint = NULL; - for(; psIter != NULL; psIter = psIter->psNext ) { - if( psIter->eType == CXT_Element && - strcmp(psIter->pszValue, "FeatureTypeConstraint") == 0 ) { - if( psFeatureTypeConstraint == NULL ) { + if (psLayerFeatureConstraints != NULL) { + CPLXMLNode *psIter = psLayerFeatureConstraints->psChild; + CPLXMLNode *psFeatureTypeConstraint = NULL; + for (; psIter != NULL; psIter = psIter->psNext) { + if (psIter->eType == CXT_Element && + strcmp(psIter->pszValue, "FeatureTypeConstraint") == 0) { + if (psFeatureTypeConstraint == NULL) { psFeatureTypeConstraint = psIter; } else { - msSetError(MS_WMSERR, "Only one single FeatureTypeConstraint element " - "per LayerFeatureConstraints is supported", ""); + msSetError(MS_WMSERR, + "Only one single FeatureTypeConstraint element " + "per LayerFeatureConstraints is supported", + ""); return MS_FAILURE; } } } - if( psFeatureTypeConstraint != NULL ) { - CPLXMLNode* psFilter; - if( CPLGetXMLNode(psFeatureTypeConstraint, "FeatureTypeName") != NULL ) { - msSetError(MS_WMSERR, "FeatureTypeName element is not " - "supported in FeatureTypeConstraint", ""); + if (psFeatureTypeConstraint != NULL) { + CPLXMLNode *psFilter; + if (CPLGetXMLNode(psFeatureTypeConstraint, "FeatureTypeName") != NULL) { + msSetError(MS_WMSERR, + "FeatureTypeName element is not " + "supported in FeatureTypeConstraint", + ""); return MS_FAILURE; } - if( CPLGetXMLNode(psFeatureTypeConstraint, "Extent") != NULL ) { - msSetError(MS_WMSERR, "Extent element is not " - "supported in FeatureTypeConstraint", ""); + if (CPLGetXMLNode(psFeatureTypeConstraint, "Extent") != NULL) { + msSetError(MS_WMSERR, + "Extent element is not " + "supported in FeatureTypeConstraint", + ""); return MS_FAILURE; } psFilter = CPLGetXMLNode(psFeatureTypeConstraint, "Filter"); if (psFilter && psFilter->psChild && psFilter->psChild->pszValue) { - char* pszExpression = msSLDGetCommonExpressionFromFilter(psFilter, - psLayer); + char *pszExpression = + msSLDGetCommonExpressionFromFilter(psFilter, psLayer); if (pszExpression) { - msFreeExpression(&psLayer->filter); - msInitExpression(&psLayer->filter); - psLayer->filter.string = pszExpression; - psLayer->filter.type = MS_EXPRESSION; + msFreeExpression(&psLayer->filter); + msInitExpression(&psLayer->filter); + psLayer->filter.string = pszExpression; + psLayer->filter.type = MS_EXPRESSION; } } } @@ -926,21 +930,20 @@ int msSLDParseNamedLayer(CPLXMLNode *psRoot, layerObj *psLayer) return MS_SUCCESS; } - /************************************************************************/ /* msSLDParseRule() */ /* */ /* Parse a Rule node into classes for a specific layer. */ /************************************************************************/ -int msSLDParseRule(CPLXMLNode *psRoot, layerObj *psLayer, const char* pszUserStyleName) -{ +int msSLDParseRule(CPLXMLNode *psRoot, layerObj *psLayer, + const char *pszUserStyleName) { CPLXMLNode *psLineSymbolizer = NULL; CPLXMLNode *psPolygonSymbolizer = NULL; CPLXMLNode *psPointSymbolizer = NULL; CPLXMLNode *psTextSymbolizer = NULL; CPLXMLNode *psRasterSymbolizer = NULL; - int nSymbolizer=0; + int nSymbolizer = 0; if (!psRoot || !psLayer) return MS_FAILURE; @@ -952,52 +955,45 @@ int msSLDParseRule(CPLXMLNode *psRoot, layerObj *psLayer, const char* pszUserSty /* ==================================================================== */ /* Raster symbolizer */ - LOOP_ON_CHILD_ELEMENT(psRoot, psRasterSymbolizer, "RasterSymbolizer") - { + LOOP_ON_CHILD_ELEMENT(psRoot, psRasterSymbolizer, "RasterSymbolizer") { msSLDParseRasterSymbolizer(psRasterSymbolizer, psLayer, pszUserStyleName); /* cppcheck-suppress knownConditionTrueFalse */ - if (nSymbolizer == 0) - { + if (nSymbolizer == 0) { psLayer->type = MS_LAYER_RASTER; } } /* Polygon symbolizer */ - LOOP_ON_CHILD_ELEMENT(psRoot, psPolygonSymbolizer, "PolygonSymbolizer") - { + LOOP_ON_CHILD_ELEMENT(psRoot, psPolygonSymbolizer, "PolygonSymbolizer") { /* cppcheck-suppress knownConditionTrueFalse */ const int bNewClass = (nSymbolizer == 0); - msSLDParsePolygonSymbolizer(psPolygonSymbolizer, psLayer, - bNewClass, pszUserStyleName); + msSLDParsePolygonSymbolizer(psPolygonSymbolizer, psLayer, bNewClass, + pszUserStyleName); psLayer->type = MS_LAYER_POLYGON; nSymbolizer++; } /* line symbolizer */ - LOOP_ON_CHILD_ELEMENT(psRoot, psLineSymbolizer, "LineSymbolizer") - { + LOOP_ON_CHILD_ELEMENT(psRoot, psLineSymbolizer, "LineSymbolizer") { const int bNewClass = (nSymbolizer == 0); msSLDParseLineSymbolizer(psLineSymbolizer, psLayer, bNewClass, pszUserStyleName); - if (bNewClass) - { + if (bNewClass) { psLayer->type = MS_LAYER_LINE; } - if (psLayer->type == MS_LAYER_POLYGON) - { + if (psLayer->type == MS_LAYER_POLYGON) { const int nClassId = psLayer->numclasses - 1; - if (nClassId >= 0) - { + if (nClassId >= 0) { const int nStyleId = psLayer->class[nClassId]->numstyles - 1; - if (nStyleId >= 0) - { - styleObj * psStyle = psLayer->class[nClassId]->styles[nStyleId]; + if (nStyleId >= 0) { + styleObj *psStyle = psLayer->class[nClassId]->styles[nStyleId]; psStyle->outlinecolor = psStyle->color; - MS_INIT_COLOR(psStyle->color,-1,-1,-1,255); - MS_COPYSTRING(psStyle->exprBindings[MS_STYLE_BINDING_OUTLINECOLOR].string, + MS_INIT_COLOR(psStyle->color, -1, -1, -1, 255); + MS_COPYSTRING( + psStyle->exprBindings[MS_STYLE_BINDING_OUTLINECOLOR].string, psStyle->exprBindings[MS_STYLE_BINDING_COLOR].string); psStyle->exprBindings[MS_STYLE_BINDING_OUTLINECOLOR].type = - psStyle->exprBindings[MS_STYLE_BINDING_COLOR].type; + psStyle->exprBindings[MS_STYLE_BINDING_COLOR].type; msFreeExpression(&(psStyle->exprBindings[MS_STYLE_BINDING_COLOR])); msInitExpression(&(psStyle->exprBindings[MS_STYLE_BINDING_COLOR])); } @@ -1007,26 +1003,20 @@ int msSLDParseRule(CPLXMLNode *psRoot, layerObj *psLayer, const char* pszUserSty } /* Point Symbolizer */ - LOOP_ON_CHILD_ELEMENT(psRoot, psPointSymbolizer, "PointSymbolizer") - { + LOOP_ON_CHILD_ELEMENT(psRoot, psPointSymbolizer, "PointSymbolizer") { const int bNewClass = (nSymbolizer == 0); msSLDParsePointSymbolizer(psPointSymbolizer, psLayer, bNewClass, pszUserStyleName); - if (bNewClass) - { + if (bNewClass) { psLayer->type = MS_LAYER_POINT; } - if (psLayer->type == MS_LAYER_POLYGON - || psLayer->type == MS_LAYER_LINE - || psLayer->type == MS_LAYER_RASTER) - { + if (psLayer->type == MS_LAYER_POLYGON || psLayer->type == MS_LAYER_LINE || + psLayer->type == MS_LAYER_RASTER) { const int nClassId = psLayer->numclasses - 1; - if (nClassId >= 0) - { + if (nClassId >= 0) { const int nStyleId = psLayer->class[nClassId]->numstyles - 1; - if (nStyleId >= 0) - { - styleObj * psStyle = psLayer->class[nClassId]->styles[nStyleId]; + if (nStyleId >= 0) { + styleObj *psStyle = psLayer->class[nClassId]->styles[nStyleId]; msStyleSetGeomTransform(psStyle, "centroid"); } } @@ -1045,11 +1035,11 @@ int msSLDParseRule(CPLXMLNode *psRoot, layerObj *psLayer, const char* pszUserSty /* - If there are no other symbolizers, a new class will be */ /* created to contain the label object. */ /* ==================================================================== */ - LOOP_ON_CHILD_ELEMENT(psRoot, psTextSymbolizer, "TextSymbolizer") - { + LOOP_ON_CHILD_ELEMENT(psRoot, psTextSymbolizer, "TextSymbolizer") { if (nSymbolizer == 0) psLayer->type = MS_LAYER_POINT; - msSLDParseTextSymbolizer(psTextSymbolizer, psLayer, nSymbolizer > 0, pszUserStyleName); + msSLDParseTextSymbolizer(psTextSymbolizer, psLayer, nSymbolizer > 0, + pszUserStyleName); } return MS_SUCCESS; @@ -1059,56 +1049,57 @@ int msSLDParseRule(CPLXMLNode *psRoot, layerObj *psLayer, const char* pszUserSty /* getClassId() */ /************************************************************************/ -static int getClassId(layerObj *psLayer, - int bNewClass, - const char* pszUserStyleName) -{ - int nClassId; - if (bNewClass || psLayer->numclasses <= 0) { - if (msGrowLayerClasses(psLayer) == NULL) - return -1; - initClass(psLayer->class[psLayer->numclasses]); - nClassId = psLayer->numclasses; - if( pszUserStyleName ) - psLayer->class[nClassId]->group = msStrdup(pszUserStyleName); - psLayer->numclasses++; - } else { - nClassId = psLayer->numclasses-1; - } - return nClassId; +static int getClassId(layerObj *psLayer, int bNewClass, + const char *pszUserStyleName) { + int nClassId; + if (bNewClass || psLayer->numclasses <= 0) { + if (msGrowLayerClasses(psLayer) == NULL) + return -1; + initClass(psLayer->class[psLayer->numclasses]); + nClassId = psLayer->numclasses; + if (pszUserStyleName) + psLayer->class[nClassId]->group = msStrdup(pszUserStyleName); + psLayer->numclasses++; + } else { + nClassId = psLayer->numclasses - 1; + } + return nClassId; } /************************************************************************/ /* msSLDParseUomAttribute() */ /************************************************************************/ -int msSLDParseUomAttribute(CPLXMLNode *node, enum MS_UNITS * sizeunits) -{ - const struct - { +int msSLDParseUomAttribute(CPLXMLNode *node, enum MS_UNITS *sizeunits) { + const struct { enum MS_UNITS unit; - char * values[10]; - } known_uoms[] = - { - { MS_INCHES, { "inch", "inches", NULL } }, - { MS_FEET, { "foot", "feet", "http://www.opengeospatial.org/se/units/foot", NULL } }, - { MS_MILES, { "mile", "miles", NULL } }, - { MS_METERS, { "meter", "meters", "metre", "metres", "http://www.opengeospatial.org/se/units/metre", NULL } }, - { MS_KILOMETERS, { "kilometer", "kilometers", "kilometre", "kilometres", NULL } }, - { MS_DD, { "dd", NULL } }, - { MS_PIXELS, { "pixel", "pixels", "px", "http://www.opengeospatial.org/se/units/pixel", NULL } }, - { MS_PERCENTAGES, { "percent", "percents", "percentage", "percentages", NULL } }, - { MS_NAUTICALMILES, { "nauticalmile", "nauticalmiles", "nautical_mile", "nautical_miles", NULL } }, - { 0, { NULL } } - }; - - const char * uom = CPLGetXMLValue(node, "uom", NULL); - if (uom) - { - for (int i=0 ; known_uoms[i].values[0] ; i++) - for (int j=0 ; known_uoms[i].values[j] ; j++) - if (strcmp(uom,known_uoms[i].values[j]) == 0) - { + char *values[10]; + } known_uoms[] = { + {MS_INCHES, {"inch", "inches", NULL}}, + {MS_FEET, + {"foot", "feet", "http://www.opengeospatial.org/se/units/foot", NULL}}, + {MS_MILES, {"mile", "miles", NULL}}, + {MS_METERS, + {"meter", "meters", "metre", "metres", + "http://www.opengeospatial.org/se/units/metre", NULL}}, + {MS_KILOMETERS, + {"kilometer", "kilometers", "kilometre", "kilometres", NULL}}, + {MS_DD, {"dd", NULL}}, + {MS_PIXELS, + {"pixel", "pixels", "px", "http://www.opengeospatial.org/se/units/pixel", + NULL}}, + {MS_PERCENTAGES, + {"percent", "percents", "percentage", "percentages", NULL}}, + {MS_NAUTICALMILES, + {"nauticalmile", "nauticalmiles", "nautical_mile", "nautical_miles", + NULL}}, + {0, {NULL}}}; + + const char *uom = CPLGetXMLValue(node, "uom", NULL); + if (uom) { + for (int i = 0; known_uoms[i].values[0]; i++) + for (int j = 0; known_uoms[i].values[j]; j++) + if (strcmp(uom, known_uoms[i].values[j]) == 0) { // Match found *sizeunits = known_uoms[i].unit; return MS_SUCCESS; @@ -1121,7 +1112,6 @@ int msSLDParseUomAttribute(CPLXMLNode *node, enum MS_UNITS * sizeunits) return MS_SUCCESS; } - /************************************************************************/ /* msSLDParseLineSymbolizer() */ /* */ @@ -1167,47 +1157,46 @@ int msSLDParseUomAttribute(CPLXMLNode *node, enum MS_UNITS * sizeunits) /* ... */ /************************************************************************/ int msSLDParseLineSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, - int bNewClass, const char* pszUserStyleName) -{ - CPLXMLNode *psStroke=NULL, *psOffset=NULL; + int bNewClass, const char *pszUserStyleName) { + CPLXMLNode *psStroke = NULL, *psOffset = NULL; if (!psRoot || !psLayer) return MS_FAILURE; // Get uom if any, defaults to MS_PIXELS enum MS_UNITS sizeunits = MS_PIXELS; - if (msSLDParseUomAttribute(psRoot, &sizeunits) != MS_SUCCESS) - { - msSetError(MS_WMSERR, "Invalid uom attribute value.", "msSLDParsePolygonSymbolizer()"); + if (msSLDParseUomAttribute(psRoot, &sizeunits) != MS_SUCCESS) { + msSetError(MS_WMSERR, "Invalid uom attribute value.", + "msSLDParsePolygonSymbolizer()"); return MS_FAILURE; } - psStroke = CPLGetXMLNode(psRoot, "Stroke"); + psStroke = CPLGetXMLNode(psRoot, "Stroke"); if (psStroke) { int nClassId = getClassId(psLayer, bNewClass, pszUserStyleName); - if( nClassId < 0 ) - return MS_FAILURE; + if (nClassId < 0) + return MS_FAILURE; const int iStyle = psLayer->class[nClassId]->numstyles; msMaybeAllocateClassStyle(psLayer->class[nClassId], iStyle); psLayer->class[nClassId]->styles[iStyle]->sizeunits = sizeunits; - msSLDParseStroke(psStroke, psLayer->class[nClassId]->styles[iStyle], - psLayer->map, 0); + msSLDParseStroke(psStroke, psLayer->class[nClassId] -> styles[iStyle], + psLayer -> map, 0); /*parse PerpendicularOffset SLD 1.1.10*/ psOffset = CPLGetXMLNode(psRoot, "PerpendicularOffset"); if (psOffset && psOffset->psChild && psOffset->psChild->pszValue) { - psLayer->class[nClassId]->styles[iStyle]->offsetx = atoi(psOffset->psChild->pszValue); - psLayer->class[nClassId]->styles[iStyle]->offsety = MS_STYLE_SINGLE_SIDED_OFFSET; + psLayer->class[nClassId]->styles[iStyle]->offsetx = + atoi(psOffset->psChild->pszValue); + psLayer->class[nClassId]->styles[iStyle]->offsety = + MS_STYLE_SINGLE_SIDED_OFFSET; } } return MS_SUCCESS; } - - /************************************************************************/ /* void msSLDParseStroke(CPLXMLNode *psStroke, styleObj */ /* *psStyle, int iColorParam) */ @@ -1218,10 +1207,9 @@ int msSLDParseLineSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, /* 0 : for color */ /* 1 : outlinecolor */ /************************************************************************/ -int msSLDParseStroke(CPLXMLNode *psStroke, styleObj *psStyle, - mapObj *map, int iColorParam) -{ - CPLXMLNode *psCssParam = NULL, *psGraphicFill=NULL; +int msSLDParseStroke(CPLXMLNode *psStroke, styleObj *psStyle, mapObj *map, + int iColorParam) { + CPLXMLNode *psCssParam = NULL, *psGraphicFill = NULL; char *psStrkName = NULL; char *pszDashValue = NULL; @@ -1229,54 +1217,54 @@ int msSLDParseStroke(CPLXMLNode *psStroke, styleObj *psStyle, return MS_FAILURE; /* parse css parameters */ - psCssParam = CPLGetXMLNode(psStroke, "CssParameter"); + psCssParam = CPLGetXMLNode(psStroke, "CssParameter"); /*sld 1.1 used SvgParameter*/ if (psCssParam == NULL) - psCssParam = CPLGetXMLNode(psStroke, "SvgParameter"); + psCssParam = CPLGetXMLNode(psStroke, "SvgParameter"); while (psCssParam && psCssParam->pszValue && (strcasecmp(psCssParam->pszValue, "CssParameter") == 0 || strcasecmp(psCssParam->pszValue, "SvgParameter") == 0)) { - psStrkName = (char*)CPLGetXMLValue(psCssParam, "name", NULL); + psStrkName = (char *)CPLGetXMLValue(psCssParam, "name", NULL); if (psStrkName) { if (strcasecmp(psStrkName, "stroke") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { + if (psCssParam->psChild && psCssParam->psChild->psNext) { switch (iColorParam) { - case 0: - msSLDParseOgcExpression(psCssParam->psChild->psNext, - psStyle, MS_STYLE_BINDING_COLOR, MS_OBJ_STYLE); - break; - case 1: - msSLDParseOgcExpression(psCssParam->psChild->psNext, - psStyle, MS_STYLE_BINDING_OUTLINECOLOR, MS_OBJ_STYLE); - break; + case 0: + msSLDParseOgcExpression(psCssParam->psChild->psNext, psStyle, + MS_STYLE_BINDING_COLOR, MS_OBJ_STYLE); + break; + case 1: + msSLDParseOgcExpression(psCssParam->psChild->psNext, psStyle, + MS_STYLE_BINDING_OUTLINECOLOR, + MS_OBJ_STYLE); + break; } } } else if (strcasecmp(psStrkName, "stroke-width") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { + if (psCssParam->psChild && psCssParam->psChild->psNext) { msSLDParseOgcExpression(psCssParam->psChild->psNext, psStyle, MS_STYLE_BINDING_WIDTH, MS_OBJ_STYLE); } } else if (strcasecmp(psStrkName, "stroke-dasharray") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext && + if (psCssParam->psChild && psCssParam->psChild->psNext && psCssParam->psChild->psNext->pszValue) { int nDash = 0, i; char **aszValues = NULL; int nMaxDash; - if(pszDashValue) free(pszDashValue); /* free previous if multiple stroke-dasharray attributes were found */ - pszDashValue = - msStrdup(psCssParam->psChild->psNext->pszValue); + if (pszDashValue) + free(pszDashValue); /* free previous if multiple stroke-dasharray + attributes were found */ + pszDashValue = msStrdup(psCssParam->psChild->psNext->pszValue); aszValues = msStringSplit(pszDashValue, ' ', &nDash); if (nDash > 0) { nMaxDash = nDash; if (nDash > MS_MAXPATTERNLENGTH) - nMaxDash = MS_MAXPATTERNLENGTH; + nMaxDash = MS_MAXPATTERNLENGTH; psStyle->patternlength = nMaxDash; - for (i=0; ipattern[i] = atof(aszValues[i]); psStyle->linecap = MS_CJC_BUTT; @@ -1284,10 +1272,9 @@ int msSLDParseStroke(CPLXMLNode *psStroke, styleObj *psStyle, msFreeCharArray(aszValues, nDash); } } else if (strcasecmp(psStrkName, "stroke-opacity") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { - msSLDParseOgcExpression(psCssParam->psChild->psNext, - psStyle, MS_STYLE_BINDING_OPACITY, MS_OBJ_STYLE); + if (psCssParam->psChild && psCssParam->psChild->psNext) { + msSLDParseOgcExpression(psCssParam->psChild->psNext, psStyle, + MS_STYLE_BINDING_OPACITY, MS_OBJ_STYLE); } } } @@ -1299,10 +1286,10 @@ int msSLDParseStroke(CPLXMLNode *psStroke, styleObj *psStyle, /* TODO : It seems inconsistent to me since the only difference */ /* between them seems to be fill (fill) or not fill (stroke). And */ /* then again the fill parameter can be used inside both elements. */ - psGraphicFill = CPLGetXMLNode(psStroke, "GraphicFill"); + psGraphicFill = CPLGetXMLNode(psStroke, "GraphicFill"); if (psGraphicFill) msSLDParseGraphicFillOrStroke(psGraphicFill, pszDashValue, psStyle, map); - psGraphicFill = CPLGetXMLNode(psStroke, "GraphicStroke"); + psGraphicFill = CPLGetXMLNode(psStroke, "GraphicStroke"); if (psGraphicFill) msSLDParseGraphicFillOrStroke(psGraphicFill, pszDashValue, psStyle, map); @@ -1312,8 +1299,6 @@ int msSLDParseStroke(CPLXMLNode *psStroke, styleObj *psStyle, return MS_SUCCESS; } - - /************************************************************************/ /* int msSLDParseOgcExpression(CPLXMLNode *psRoot, styleObj *psStyle, */ /* enum MS_STYLE_BINDING_ENUM binding) */ @@ -1321,254 +1306,234 @@ int msSLDParseStroke(CPLXMLNode *psStroke, styleObj *psStyle, /* Parse an OGC expression in a */ /************************************************************************/ int msSLDParseOgcExpression(CPLXMLNode *psRoot, void *psObj, int binding, - enum objType objtype) -{ + enum objType objtype) { int status = MS_FAILURE; - const char * ops = "Add+Sub-Mul*Div/"; - styleObj * psStyle = psObj; - labelObj * psLabel = psObj; + const char *ops = "Add+Sub-Mul*Div/"; + styleObj *psStyle = psObj; + labelObj *psLabel = psObj; int lbinding; expressionObj *exprBindings; int *nexprbindings; enum { MS_STYLE_BASE = 0, MS_LABEL_BASE = 100 }; - switch (objtype) - { - case MS_OBJ_STYLE: - lbinding = binding + MS_STYLE_BASE; - exprBindings = psStyle->exprBindings; - nexprbindings = &psStyle->nexprbindings; + switch (objtype) { + case MS_OBJ_STYLE: + lbinding = binding + MS_STYLE_BASE; + exprBindings = psStyle->exprBindings; + nexprbindings = &psStyle->nexprbindings; + break; + case MS_OBJ_LABEL: + lbinding = binding + MS_LABEL_BASE; + exprBindings = psLabel->exprBindings; + nexprbindings = &psLabel->nexprbindings; + break; + default: + return MS_FAILURE; + break; + } + + switch (psRoot->eType) { + case CXT_Text: + // Parse a raw value + { + msStringBuffer *literal = msStringBufferAlloc(); + msStringBufferAppend(literal, "("); + msStringBufferAppend(literal, psRoot->pszValue); + msStringBufferAppend(literal, ")"); + msFreeExpression(&(exprBindings[binding])); + msInitExpression(&(exprBindings[binding])); + exprBindings[binding].string = + msStringBufferReleaseStringAndFree(literal); + exprBindings[binding].type = MS_STRING; + } + switch (lbinding) { + case MS_STYLE_BASE + MS_STYLE_BINDING_OFFSET_X: + psStyle->offsetx = atoi(psRoot->pszValue); + status = MS_SUCCESS; break; - case MS_OBJ_LABEL: - lbinding = binding + MS_LABEL_BASE; - exprBindings = psLabel->exprBindings; - nexprbindings = &psLabel->nexprbindings; + case MS_STYLE_BASE + MS_STYLE_BINDING_OFFSET_Y: + psStyle->offsety = atoi(psRoot->pszValue); + status = MS_SUCCESS; break; - default: - return MS_FAILURE; + case MS_STYLE_BASE + MS_STYLE_BINDING_ANGLE: + psStyle->angle = atof(psRoot->pszValue); + status = MS_SUCCESS; break; - } - - switch (psRoot->eType) - { - case CXT_Text: - // Parse a raw value - { - msStringBuffer * literal = msStringBufferAlloc(); - msStringBufferAppend(literal, "("); - msStringBufferAppend(literal, psRoot->pszValue); - msStringBufferAppend(literal, ")"); - msFreeExpression(&(exprBindings[binding])); - msInitExpression(&(exprBindings[binding])); - exprBindings[binding].string = - msStringBufferReleaseStringAndFree(literal); - exprBindings[binding].type = MS_STRING; + case MS_STYLE_BASE + MS_STYLE_BINDING_SIZE: + psStyle->size = atof(psRoot->pszValue); + status = MS_SUCCESS; + break; + case MS_STYLE_BASE + MS_STYLE_BINDING_WIDTH: + psStyle->width = atof(psRoot->pszValue); + status = MS_SUCCESS; + break; + case MS_STYLE_BASE + MS_STYLE_BINDING_OPACITY: + psStyle->opacity = atof(psRoot->pszValue) * 100; + status = MS_SUCCESS; + // Apply opacity as the alpha channel color(s) + if (psStyle->opacity < 100) { + int alpha = MS_NINT(psStyle->opacity * 2.55); + psStyle->color.alpha = alpha; + psStyle->outlinecolor.alpha = alpha; + psStyle->mincolor.alpha = alpha; + psStyle->maxcolor.alpha = alpha; } - switch (lbinding) - { - case MS_STYLE_BASE + MS_STYLE_BINDING_OFFSET_X: - psStyle->offsetx = atoi(psRoot->pszValue); - status = MS_SUCCESS; - break; - case MS_STYLE_BASE + MS_STYLE_BINDING_OFFSET_Y: - psStyle->offsety = atoi(psRoot->pszValue); - status = MS_SUCCESS; - break; - case MS_STYLE_BASE + MS_STYLE_BINDING_ANGLE: - psStyle->angle = atof(psRoot->pszValue); - status = MS_SUCCESS; - break; - case MS_STYLE_BASE + MS_STYLE_BINDING_SIZE: - psStyle->size = atof(psRoot->pszValue); - status = MS_SUCCESS; - break; - case MS_STYLE_BASE + MS_STYLE_BINDING_WIDTH: - psStyle->width = atof(psRoot->pszValue); - status = MS_SUCCESS; - break; - case MS_STYLE_BASE + MS_STYLE_BINDING_OPACITY: - psStyle->opacity = atof(psRoot->pszValue)*100; - status = MS_SUCCESS; - // Apply opacity as the alpha channel color(s) - if(psStyle->opacity < 100) - { - int alpha = MS_NINT(psStyle->opacity*2.55); - psStyle->color.alpha = alpha; - psStyle->outlinecolor.alpha = alpha; - psStyle->mincolor.alpha = alpha; - psStyle->maxcolor.alpha = alpha; - } - break; - case MS_STYLE_BASE + MS_STYLE_BINDING_COLOR: - if (strlen(psRoot->pszValue) == 7 && psRoot->pszValue[0] == '#') - { - psStyle->color.red = msHexToInt(psRoot->pszValue+1); - psStyle->color.green = msHexToInt(psRoot->pszValue+3); - psStyle->color.blue = msHexToInt(psRoot->pszValue+5); - status = MS_SUCCESS; - } - break; - case MS_STYLE_BASE + MS_STYLE_BINDING_OUTLINECOLOR: - if (strlen(psRoot->pszValue) == 7 && psRoot->pszValue[0] == '#') - { - psStyle->outlinecolor.red = msHexToInt(psRoot->pszValue+1); - psStyle->outlinecolor.green = msHexToInt(psRoot->pszValue+3); - psStyle->outlinecolor.blue = msHexToInt(psRoot->pszValue+5); - status = MS_SUCCESS; - } - break; - - case MS_LABEL_BASE + MS_LABEL_BINDING_SIZE: - psLabel->size = atof(psRoot->pszValue); - if (psLabel->size <= 0.0) - { - psLabel->size = 10.0; - } - status = MS_SUCCESS; - break; - case MS_LABEL_BASE + MS_LABEL_BINDING_ANGLE: - psLabel->angle = atof(psRoot->pszValue); - status = MS_SUCCESS; - break; - case MS_LABEL_BASE + MS_LABEL_BINDING_COLOR: - if (strlen(psRoot->pszValue) == 7 && psRoot->pszValue[0] == '#') - { - psLabel->color.red = msHexToInt(psRoot->pszValue+1); - psLabel->color.green = msHexToInt(psRoot->pszValue+3); - psLabel->color.blue= msHexToInt(psRoot->pszValue+5); - status = MS_SUCCESS; - } - break; - case MS_LABEL_BASE + MS_LABEL_BINDING_OUTLINECOLOR: - if (strlen(psRoot->pszValue) == 7 && psRoot->pszValue[0] == '#') - { - psLabel->outlinecolor.red = msHexToInt(psRoot->pszValue+1); - psLabel->outlinecolor.green = msHexToInt(psRoot->pszValue+3); - psLabel->outlinecolor.blue= msHexToInt(psRoot->pszValue+5); - status = MS_SUCCESS; - } - break; - default: - break; + break; + case MS_STYLE_BASE + MS_STYLE_BINDING_COLOR: + if (strlen(psRoot->pszValue) == 7 && psRoot->pszValue[0] == '#') { + psStyle->color.red = msHexToInt(psRoot->pszValue + 1); + psStyle->color.green = msHexToInt(psRoot->pszValue + 3); + psStyle->color.blue = msHexToInt(psRoot->pszValue + 5); + status = MS_SUCCESS; } break; - case CXT_Element: - if (strcasecmp(psRoot->pszValue,"Literal") == 0 && psRoot->psChild) - { - // Parse a element - status = msSLDParseOgcExpression(psRoot->psChild, psObj, binding, objtype); + case MS_STYLE_BASE + MS_STYLE_BINDING_OUTLINECOLOR: + if (strlen(psRoot->pszValue) == 7 && psRoot->pszValue[0] == '#') { + psStyle->outlinecolor.red = msHexToInt(psRoot->pszValue + 1); + psStyle->outlinecolor.green = msHexToInt(psRoot->pszValue + 3); + psStyle->outlinecolor.blue = msHexToInt(psRoot->pszValue + 5); + status = MS_SUCCESS; } - else if (strcasecmp(psRoot->pszValue,"PropertyName") == 0 - && psRoot->psChild) - { - // Parse a element - msStringBuffer * property = msStringBufferAlloc(); - const char * strDelim = ""; + break; - switch (lbinding) - { - case MS_STYLE_BASE + MS_STYLE_BINDING_COLOR: - case MS_STYLE_BASE + MS_STYLE_BINDING_OUTLINECOLOR: - case MS_LABEL_BASE + MS_LABEL_BINDING_COLOR: - case MS_LABEL_BASE + MS_LABEL_BINDING_OUTLINECOLOR: - strDelim = "\""; - /* FALLTHROUGH */ - default: - msStringBufferAppend(property, strDelim); - msStringBufferAppend(property, "["); - msStringBufferAppend(property, psRoot->psChild->pszValue); - msStringBufferAppend(property, "]"); - msStringBufferAppend(property, strDelim); - msInitExpression(&(exprBindings[binding])); - exprBindings[binding].string = - msStringBufferReleaseStringAndFree(property); - exprBindings[binding].type = MS_EXPRESSION; - (*nexprbindings)++; - break; - } + case MS_LABEL_BASE + MS_LABEL_BINDING_SIZE: + psLabel->size = atof(psRoot->pszValue); + if (psLabel->size <= 0.0) { + psLabel->size = 10.0; + } + status = MS_SUCCESS; + break; + case MS_LABEL_BASE + MS_LABEL_BINDING_ANGLE: + psLabel->angle = atof(psRoot->pszValue); + status = MS_SUCCESS; + break; + case MS_LABEL_BASE + MS_LABEL_BINDING_COLOR: + if (strlen(psRoot->pszValue) == 7 && psRoot->pszValue[0] == '#') { + psLabel->color.red = msHexToInt(psRoot->pszValue + 1); + psLabel->color.green = msHexToInt(psRoot->pszValue + 3); + psLabel->color.blue = msHexToInt(psRoot->pszValue + 5); status = MS_SUCCESS; } - else if (strcasecmp(psRoot->pszValue,"Function") == 0 - && psRoot->psChild - && CPLGetXMLValue(psRoot,"name",NULL) - && psRoot->psChild->psNext) - { - // Parse a element - msStringBuffer * function = msStringBufferAlloc(); - - // Parse function name - const char * funcname = CPLGetXMLValue(psRoot,"name",NULL); - msStringBufferAppend(function, funcname); - msStringBufferAppend(function, "("); + break; + case MS_LABEL_BASE + MS_LABEL_BINDING_OUTLINECOLOR: + if (strlen(psRoot->pszValue) == 7 && psRoot->pszValue[0] == '#') { + psLabel->outlinecolor.red = msHexToInt(psRoot->pszValue + 1); + psLabel->outlinecolor.green = msHexToInt(psRoot->pszValue + 3); + psLabel->outlinecolor.blue = msHexToInt(psRoot->pszValue + 5); + status = MS_SUCCESS; + } + break; + default: + break; + } + break; + case CXT_Element: + if (strcasecmp(psRoot->pszValue, "Literal") == 0 && psRoot->psChild) { + // Parse a element + status = + msSLDParseOgcExpression(psRoot->psChild, psObj, binding, objtype); + } else if (strcasecmp(psRoot->pszValue, "PropertyName") == 0 && + psRoot->psChild) { + // Parse a element + msStringBuffer *property = msStringBufferAlloc(); + const char *strDelim = ""; + + switch (lbinding) { + case MS_STYLE_BASE + MS_STYLE_BINDING_COLOR: + case MS_STYLE_BASE + MS_STYLE_BINDING_OUTLINECOLOR: + case MS_LABEL_BASE + MS_LABEL_BINDING_COLOR: + case MS_LABEL_BASE + MS_LABEL_BINDING_OUTLINECOLOR: + strDelim = "\""; + /* FALLTHROUGH */ + default: + msStringBufferAppend(property, strDelim); + msStringBufferAppend(property, "["); + msStringBufferAppend(property, psRoot->psChild->pszValue); + msStringBufferAppend(property, "]"); + msStringBufferAppend(property, strDelim); msInitExpression(&(exprBindings[binding])); - - // Parse arguments - char * sep =""; - for (CPLXMLNode * argument = psRoot->psChild->psNext ; argument ; argument = argument->psNext) - { - status = msSLDParseOgcExpression(argument, psObj, binding, objtype); - if (status != MS_SUCCESS) - break; - msStringBufferAppend(function, sep); - msStringBufferAppend(function, exprBindings[binding].string); - msFree(exprBindings[binding].string); - msInitExpression(&(exprBindings[binding])); - sep = ","; - } - msStringBufferAppend(function, ")"); exprBindings[binding].string = - msStringBufferReleaseStringAndFree(function); + msStringBufferReleaseStringAndFree(property); exprBindings[binding].type = MS_EXPRESSION; (*nexprbindings)++; - status = MS_SUCCESS; + break; } - else if (strstr(ops, psRoot->pszValue) - && psRoot->psChild && psRoot->psChild->psNext) - { - // Parse an arithmetic element , , , - const char operator[2] = { *(strstr(ops, psRoot->pszValue)+3), '\0' }; - msStringBuffer * expression = msStringBufferAlloc(); - - // Parse first operand - msStringBufferAppend(expression, "("); + status = MS_SUCCESS; + } else if (strcasecmp(psRoot->pszValue, "Function") == 0 && + psRoot->psChild && CPLGetXMLValue(psRoot, "name", NULL) && + psRoot->psChild->psNext) { + // Parse a element + msStringBuffer *function = msStringBufferAlloc(); + + // Parse function name + const char *funcname = CPLGetXMLValue(psRoot, "name", NULL); + msStringBufferAppend(function, funcname); + msStringBufferAppend(function, "("); + msInitExpression(&(exprBindings[binding])); + + // Parse arguments + char *sep = ""; + for (CPLXMLNode *argument = psRoot->psChild->psNext; argument; + argument = argument->psNext) { + status = msSLDParseOgcExpression(argument, psObj, binding, objtype); + if (status != MS_SUCCESS) + break; + msStringBufferAppend(function, sep); + msStringBufferAppend(function, exprBindings[binding].string); + msFree(exprBindings[binding].string); msInitExpression(&(exprBindings[binding])); - status = msSLDParseOgcExpression(psRoot->psChild, psObj, binding, objtype); - - // Parse second operand - if (status == MS_SUCCESS) - { + sep = ","; + } + msStringBufferAppend(function, ")"); + exprBindings[binding].string = + msStringBufferReleaseStringAndFree(function); + exprBindings[binding].type = MS_EXPRESSION; + (*nexprbindings)++; + status = MS_SUCCESS; + } else if (strstr(ops, psRoot->pszValue) && psRoot->psChild && + psRoot->psChild->psNext) { + // Parse an arithmetic element , , , + const char operator[2] = {*(strstr(ops, psRoot->pszValue) + 3), '\0'}; + msStringBuffer *expression = msStringBufferAlloc(); + + // Parse first operand + msStringBufferAppend(expression, "("); + msInitExpression(&(exprBindings[binding])); + status = + msSLDParseOgcExpression(psRoot->psChild, psObj, binding, objtype); + + // Parse second operand + if (status == MS_SUCCESS) { + msStringBufferAppend(expression, exprBindings[binding].string); + msStringBufferAppend(expression, operator); + msFree(exprBindings[binding].string); + msInitExpression(&(exprBindings[binding])); + status = msSLDParseOgcExpression(psRoot->psChild->psNext, psObj, + binding, objtype); + if (status == MS_SUCCESS) { msStringBufferAppend(expression, exprBindings[binding].string); - msStringBufferAppend(expression, operator); + msStringBufferAppend(expression, ")"); msFree(exprBindings[binding].string); - msInitExpression(&(exprBindings[binding])); - status = msSLDParseOgcExpression(psRoot->psChild->psNext, - psObj, binding, objtype); - if (status == MS_SUCCESS) - { - msStringBufferAppend(expression, exprBindings[binding].string); - msStringBufferAppend(expression, ")"); - msFree(exprBindings[binding].string); - exprBindings[binding].string = - msStringBufferReleaseStringAndFree(expression); - exprBindings[binding].type = MS_EXPRESSION; - (*nexprbindings)++; - } - } - if (status == MS_FAILURE) - { - msStringBufferFree(expression); - msInitExpression(&(exprBindings[binding])); + exprBindings[binding].string = + msStringBufferReleaseStringAndFree(expression); + expression = NULL; + exprBindings[binding].type = MS_EXPRESSION; + (*nexprbindings)++; } } - break; - default: - break; + if (expression != NULL) { + msStringBufferFree(expression); + msInitExpression(&(exprBindings[binding])); + } + } + break; + default: + break; } return status; } - /************************************************************************/ /* msSLDParsePolygonSymbolizer() */ /* */ @@ -1594,8 +1559,10 @@ int msSLDParseOgcExpression(CPLXMLNode *psRoot, void *psObj, int binding, /* */ /* */ /* Here, the CssParameter names are fill instead of stroke and */ -/* fill-opacity instead of stroke-opacity. None of the other CssParameters*/ -/* in Stroke are available for filling and the default value for the fill color in this context is 50% gray (value #808080).*/ +/* fill-opacity instead of stroke-opacity. None of the other + * CssParameters*/ +/* in Stroke are available for filling and the default value for the fill + * color in this context is 50% gray (value #808080).*/ /* */ /* */ /* */ @@ -1623,8 +1590,10 @@ int msSLDParseOgcExpression(CPLXMLNode *psRoot, void *psObj, int binding, /* */ /* */ /* */ -/* The default if neither an ExternalGraphic nor a Mark is specified is to use the default*/ -/* mark of a square with a 50%-gray fill and a black outline, with a size of 6 pixels.*/ +/* The default if neither an ExternalGraphic nor a Mark is specified is to + * use the default*/ +/* mark of a square with a 50%-gray fill and a black outline, with a size + * of 6 pixels.*/ /* */ /* */ /* */ @@ -1637,28 +1606,32 @@ int msSLDParseOgcExpression(CPLXMLNode *psRoot, void *psObj, int binding, /* */ /* */ /* */ -/* The WellKnownName element gives the well-known name of the shape of the mark.*/ +/* The WellKnownName element gives the well-known name of the shape of the + * mark.*/ /* Allowed values include at least square, circle, triangle, star, cross,*/ -/* and x, though map servers may draw a different symbol instead if they don't have a*/ -/* shape for all of these. The default WellKnownName is square. Renderings of these*/ -/* marks may be made solid or hollow depending on Fill and Stroke elements.*/ +/* and x, though map servers may draw a different symbol instead if they + * don't have a*/ +/* shape for all of these. The default WellKnownName is square. Renderings + * of these*/ +/* marks may be made solid or hollow depending on Fill and Stroke + * elements.*/ /* */ /************************************************************************/ int msSLDParsePolygonSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, - int bNewClass, const char* pszUserStyleName) -{ + int bNewClass, const char *pszUserStyleName) { CPLXMLNode *psFill, *psStroke; - CPLXMLNode *psDisplacement=NULL, *psDisplacementX=NULL, *psDisplacementY=NULL; - int nOffsetX=-1, nOffsetY=-1; + CPLXMLNode *psDisplacement = NULL, *psDisplacementX = NULL, + *psDisplacementY = NULL; + int nOffsetX = -1, nOffsetY = -1; if (!psRoot || !psLayer) return MS_FAILURE; // Get uom if any, defaults to MS_PIXELS enum MS_UNITS sizeunits = MS_PIXELS; - if (msSLDParseUomAttribute(psRoot, &sizeunits) != MS_SUCCESS) - { - msSetError(MS_WMSERR, "Invalid uom attribute value.", "msSLDParsePolygonSymbolizer()"); + if (msSLDParseUomAttribute(psRoot, &sizeunits) != MS_SUCCESS) { + msSetError(MS_WMSERR, "Invalid uom attribute value.", + "msSLDParsePolygonSymbolizer()"); return MS_FAILURE; } @@ -1668,29 +1641,26 @@ int msSLDParsePolygonSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, psDisplacementX = CPLGetXMLNode(psDisplacement, "DisplacementX"); psDisplacementY = CPLGetXMLNode(psDisplacement, "DisplacementY"); /* psCssParam->psChild->psNext->pszValue) */ - if (psDisplacementX && - psDisplacementX->psChild && - psDisplacementX->psChild->pszValue && - psDisplacementY && - psDisplacementY->psChild && - psDisplacementY->psChild->pszValue) { + if (psDisplacementX && psDisplacementX->psChild && + psDisplacementX->psChild->pszValue && psDisplacementY && + psDisplacementY->psChild && psDisplacementY->psChild->pszValue) { nOffsetX = atoi(psDisplacementX->psChild->pszValue); nOffsetY = atoi(psDisplacementY->psChild->pszValue); } } - psFill = CPLGetXMLNode(psRoot, "Fill"); + psFill = CPLGetXMLNode(psRoot, "Fill"); if (psFill) { const int nClassId = getClassId(psLayer, bNewClass, pszUserStyleName); - if( nClassId < 0 ) - return MS_FAILURE; + if (nClassId < 0) + return MS_FAILURE; const int iStyle = psLayer->class[nClassId]->numstyles; msMaybeAllocateClassStyle(psLayer->class[nClassId], iStyle); psLayer->class[nClassId]->styles[iStyle]->sizeunits = sizeunits; - msSLDParsePolygonFill(psFill, psLayer->class[nClassId]->styles[iStyle], - psLayer->map); + msSLDParsePolygonFill(psFill, psLayer->class[nClassId] -> styles[iStyle], + psLayer -> map); if (nOffsetX > 0 && nOffsetY > 0) { psLayer->class[nClassId]->styles[iStyle]->offsetx = nOffsetX; @@ -1699,7 +1669,7 @@ int msSLDParsePolygonSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, } /* stroke which corresponds to the outline in mapserver */ /* is drawn after the fill */ - psStroke = CPLGetXMLNode(psRoot, "Stroke"); + psStroke = CPLGetXMLNode(psRoot, "Stroke"); if (psStroke) { /* -------------------------------------------------------------------- */ /* there was a fill so add a style to the last class created */ @@ -1708,22 +1678,21 @@ int msSLDParsePolygonSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, int nClassId; int iStyle; if (psFill && psLayer->numclasses > 0) { - nClassId =psLayer->numclasses-1; + nClassId = psLayer->numclasses - 1; iStyle = psLayer->class[nClassId]->numstyles; msMaybeAllocateClassStyle(psLayer->class[nClassId], iStyle); psLayer->class[nClassId]->styles[iStyle]->sizeunits = sizeunits; } else { nClassId = getClassId(psLayer, bNewClass, pszUserStyleName); - if( nClassId < 0 ) + if (nClassId < 0) return MS_FAILURE; iStyle = psLayer->class[nClassId]->numstyles; msMaybeAllocateClassStyle(psLayer->class[nClassId], iStyle); psLayer->class[nClassId]->styles[iStyle]->sizeunits = sizeunits; - } - msSLDParseStroke(psStroke, psLayer->class[nClassId]->styles[iStyle], - psLayer->map, 1); + msSLDParseStroke(psStroke, psLayer->class[nClassId] -> styles[iStyle], + psLayer -> map, 1); if (nOffsetX > 0 && nOffsetY > 0) { psLayer->class[nClassId]->styles[iStyle]->offsetx = nOffsetX; @@ -1734,18 +1703,15 @@ int msSLDParsePolygonSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, return MS_SUCCESS; } - /************************************************************************/ /* void msSLDParsePolygonFill(CPLXMLNode *psFill, styleObj *psStyle, */ /* mapObj *map) */ /* */ /* Parse the Fill node for a polygon into a style. */ /************************************************************************/ -int msSLDParsePolygonFill(CPLXMLNode *psFill, styleObj *psStyle, - mapObj *map) -{ +int msSLDParsePolygonFill(CPLXMLNode *psFill, styleObj *psStyle, mapObj *map) { CPLXMLNode *psCssParam, *psGraphicFill; - char *psFillName=NULL; + char *psFillName = NULL; if (!psFill || !psStyle || !map) return MS_FAILURE; @@ -1755,27 +1721,25 @@ int msSLDParsePolygonFill(CPLXMLNode *psFill, styleObj *psStyle, psStyle->color.green = 128; psStyle->color.blue = 128; - psCssParam = CPLGetXMLNode(psFill, "CssParameter"); + psCssParam = CPLGetXMLNode(psFill, "CssParameter"); /*sld 1.1 used SvgParameter*/ if (psCssParam == NULL) - psCssParam = CPLGetXMLNode(psFill, "SvgParameter"); + psCssParam = CPLGetXMLNode(psFill, "SvgParameter"); while (psCssParam && psCssParam->pszValue && (strcasecmp(psCssParam->pszValue, "CssParameter") == 0 || strcasecmp(psCssParam->pszValue, "SvgParameter") == 0)) { - psFillName = (char*)CPLGetXMLValue(psCssParam, "name", NULL); + psFillName = (char *)CPLGetXMLValue(psCssParam, "name", NULL); if (psFillName) { if (strcasecmp(psFillName, "fill") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { - msSLDParseOgcExpression(psCssParam->psChild->psNext, - psStyle, MS_STYLE_BINDING_COLOR, MS_OBJ_STYLE); + if (psCssParam->psChild && psCssParam->psChild->psNext) { + msSLDParseOgcExpression(psCssParam->psChild->psNext, psStyle, + MS_STYLE_BINDING_COLOR, MS_OBJ_STYLE); } } else if (strcasecmp(psFillName, "fill-opacity") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { - msSLDParseOgcExpression(psCssParam->psChild->psNext, - psStyle, MS_STYLE_BINDING_OPACITY, MS_OBJ_STYLE); + if (psCssParam->psChild && psCssParam->psChild->psNext) { + msSLDParseOgcExpression(psCssParam->psChild->psNext, psStyle, + MS_STYLE_BINDING_OPACITY, MS_OBJ_STYLE); } } } @@ -1786,34 +1750,32 @@ int msSLDParsePolygonFill(CPLXMLNode *psFill, styleObj *psStyle, /* TODO : It seems inconsistent to me since the only diffrence */ /* between them seems to be fill (fill) or not fill (stroke). And */ /* then again the fill parameter can be used inside both elements. */ - psGraphicFill = CPLGetXMLNode(psFill, "GraphicFill"); + psGraphicFill = CPLGetXMLNode(psFill, "GraphicFill"); if (psGraphicFill) msSLDParseGraphicFillOrStroke(psGraphicFill, NULL, psStyle, map); - psGraphicFill = CPLGetXMLNode(psFill, "GraphicStroke"); + psGraphicFill = CPLGetXMLNode(psFill, "GraphicStroke"); if (psGraphicFill) msSLDParseGraphicFillOrStroke(psGraphicFill, NULL, psStyle, map); - return MS_SUCCESS; } - /************************************************************************/ /* msSLDParseGraphicFillOrStroke */ /* */ /* Parse the GraphicFill Or GraphicStroke node : look for a */ /* Marker symbol and set the style for that symbol. */ /************************************************************************/ -int msSLDParseGraphicFillOrStroke(CPLXMLNode *psRoot, - char *pszDashValue_unused, - styleObj *psStyle, mapObj *map) -{ +int msSLDParseGraphicFillOrStroke(CPLXMLNode *psRoot, char *pszDashValue_unused, + styleObj *psStyle, mapObj *map) { (void)pszDashValue_unused; - CPLXMLNode *psCssParam, *psGraphic, *psExternalGraphic, *psMark, *psSize, *psGap, *psInitialGap; + CPLXMLNode *psCssParam, *psGraphic, *psExternalGraphic, *psMark, *psSize, + *psGap, *psInitialGap; CPLXMLNode *psWellKnownName, *psStroke, *psFill; - CPLXMLNode *psDisplacement=NULL, *psDisplacementX=NULL, *psDisplacementY=NULL; - CPLXMLNode *psOpacity=NULL, *psRotation=NULL; - char *psName=NULL, *psValue = NULL; + CPLXMLNode *psDisplacement = NULL, *psDisplacementX = NULL, + *psDisplacementY = NULL; + CPLXMLNode *psOpacity = NULL, *psRotation = NULL; + char *psName = NULL, *psValue = NULL; char *pszSymbolName = NULL; int bFilled = 0; @@ -1821,69 +1783,64 @@ int msSLDParseGraphicFillOrStroke(CPLXMLNode *psRoot, return MS_FAILURE; /* ==================================================================== */ /* This a definition taken from the specification (11.3.2) : */ - /* Graphics can either be referenced from an external URL in a common format (such as*/ - /* GIF or SVG) or may be derived from a Mark. Multiple external URLs and marks may be*/ - /* referenced with the semantic that they all provide the equivalent graphic in different*/ + /* Graphics can either be referenced from an external URL in a common + * format (such as*/ + /* GIF or SVG) or may be derived from a Mark. Multiple external URLs and + * marks may be*/ + /* referenced with the semantic that they all provide the equivalent + * graphic in different*/ /* formats. */ /* */ /* For this reason, we only need to support one Mark and one */ /* ExtrnalGraphic ???? */ /* ==================================================================== */ - psGraphic = CPLGetXMLNode(psRoot, "Graphic"); + psGraphic = CPLGetXMLNode(psRoot, "Graphic"); if (psGraphic) { /* extract symbol size */ psSize = CPLGetXMLNode(psGraphic, "Size"); - if (psSize && psSize->psChild) - { - msSLDParseOgcExpression(psSize->psChild, - psStyle, MS_STYLE_BINDING_SIZE, MS_OBJ_STYLE); - } - else { + if (psSize && psSize->psChild) { + msSLDParseOgcExpression(psSize->psChild, psStyle, MS_STYLE_BINDING_SIZE, + MS_OBJ_STYLE); + } else { /*do not set a default for external symbols #2305*/ - psExternalGraphic = CPLGetXMLNode(psGraphic, "ExternalGraphic"); + psExternalGraphic = CPLGetXMLNode(psGraphic, "ExternalGraphic"); if (!psExternalGraphic) psStyle->size = 6; /* default value */ } /*SLD 1.1.0 extract opacity, rotation, displacement*/ psOpacity = CPLGetXMLNode(psGraphic, "Opacity"); - if (psOpacity && psOpacity->psChild) - { - msSLDParseOgcExpression(psOpacity->psChild, - psStyle, MS_STYLE_BINDING_OPACITY, MS_OBJ_STYLE); + if (psOpacity && psOpacity->psChild) { + msSLDParseOgcExpression(psOpacity->psChild, psStyle, + MS_STYLE_BINDING_OPACITY, MS_OBJ_STYLE); } psRotation = CPLGetXMLNode(psGraphic, "Rotation"); - if (psRotation && psRotation->psChild) - { - msSLDParseOgcExpression(psRotation->psChild, - psStyle, MS_STYLE_BINDING_ANGLE, MS_OBJ_STYLE); + if (psRotation && psRotation->psChild) { + msSLDParseOgcExpression(psRotation->psChild, psStyle, + MS_STYLE_BINDING_ANGLE, MS_OBJ_STYLE); } psDisplacement = CPLGetXMLNode(psGraphic, "Displacement"); - if (psDisplacement && psDisplacement->psChild) - { + if (psDisplacement && psDisplacement->psChild) { psDisplacementX = CPLGetXMLNode(psDisplacement, "DisplacementX"); - if (psDisplacementX && psDisplacementX->psChild) - { - msSLDParseOgcExpression(psDisplacementX->psChild, - psStyle, MS_STYLE_BINDING_OFFSET_X, MS_OBJ_STYLE); + if (psDisplacementX && psDisplacementX->psChild) { + msSLDParseOgcExpression(psDisplacementX->psChild, psStyle, + MS_STYLE_BINDING_OFFSET_X, MS_OBJ_STYLE); } psDisplacementY = CPLGetXMLNode(psDisplacement, "DisplacementY"); - if (psDisplacementY && psDisplacementY->psChild) - { - msSLDParseOgcExpression(psDisplacementY->psChild, - psStyle, MS_STYLE_BINDING_OFFSET_Y, MS_OBJ_STYLE); + if (psDisplacementY && psDisplacementY->psChild) { + msSLDParseOgcExpression(psDisplacementY->psChild, psStyle, + MS_STYLE_BINDING_OFFSET_Y, MS_OBJ_STYLE); } } /* extract symbol */ - psMark = CPLGetXMLNode(psGraphic, "Mark"); + psMark = CPLGetXMLNode(psGraphic, "Mark"); if (psMark) { pszSymbolName = NULL; - psWellKnownName = CPLGetXMLNode(psMark, "WellKnownName"); + psWellKnownName = CPLGetXMLNode(psMark, "WellKnownName"); if (psWellKnownName && psWellKnownName->psChild && psWellKnownName->psChild->pszValue) - pszSymbolName = - msStrdup(psWellKnownName->psChild->pszValue); + pszSymbolName = msStrdup(psWellKnownName->psChild->pszValue); /* default symbol is square */ @@ -1894,13 +1851,13 @@ int msSLDParseGraphicFillOrStroke(CPLXMLNode *psRoot, strcasecmp(pszSymbolName, "star") != 0 && strcasecmp(pszSymbolName, "cross") != 0 && strcasecmp(pszSymbolName, "x") != 0)) { - if (!pszSymbolName || !*pszSymbolName || msGetSymbolIndex(&map->symbolset, pszSymbolName, MS_FALSE) < 0) { + if (!pszSymbolName || !*pszSymbolName || + msGetSymbolIndex(&map->symbolset, pszSymbolName, MS_FALSE) < 0) { msFree(pszSymbolName); pszSymbolName = msStrdup("square"); } } - /* check if the symbol should be filled or not */ psFill = CPLGetXMLNode(psMark, "Fill"); psStroke = CPLGetXMLNode(psMark, "Stroke"); @@ -1912,30 +1869,25 @@ int msSLDParseGraphicFillOrStroke(CPLXMLNode *psRoot, bFilled = 0; if (psFill) { - psCssParam = CPLGetXMLNode(psFill, "CssParameter"); + psCssParam = CPLGetXMLNode(psFill, "CssParameter"); /*sld 1.1 used SvgParameter*/ if (psCssParam == NULL) - psCssParam = CPLGetXMLNode(psFill, "SvgParameter"); + psCssParam = CPLGetXMLNode(psFill, "SvgParameter"); while (psCssParam && psCssParam->pszValue && (strcasecmp(psCssParam->pszValue, "CssParameter") == 0 || strcasecmp(psCssParam->pszValue, "SvgParameter") == 0)) { - psName = - (char*)CPLGetXMLValue(psCssParam, "name", NULL); - if (psName && - strcasecmp(psName, "fill") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { - msSLDParseOgcExpression(psCssParam->psChild->psNext, - psStyle, MS_STYLE_BINDING_COLOR, MS_OBJ_STYLE); + psName = (char *)CPLGetXMLValue(psCssParam, "name", NULL); + if (psName && strcasecmp(psName, "fill") == 0) { + if (psCssParam->psChild && psCssParam->psChild->psNext) { + msSLDParseOgcExpression(psCssParam->psChild->psNext, psStyle, + MS_STYLE_BINDING_COLOR, MS_OBJ_STYLE); } - } else if (psName && - strcasecmp(psName, "fill-opacity") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { + } else if (psName && strcasecmp(psName, "fill-opacity") == 0) { + if (psCssParam->psChild && psCssParam->psChild->psNext) { psValue = psCssParam->psChild->psNext->pszValue; if (psValue) { - psStyle->color.alpha = (int)(atof(psValue)*255); + psStyle->color.alpha = (int)(atof(psValue) * 255); } } } @@ -1944,58 +1896,50 @@ int msSLDParseGraphicFillOrStroke(CPLXMLNode *psRoot, } } if (psStroke) { - psCssParam = CPLGetXMLNode(psStroke, "CssParameter"); + psCssParam = CPLGetXMLNode(psStroke, "CssParameter"); /*sld 1.1 used SvgParameter*/ if (psCssParam == NULL) - psCssParam = CPLGetXMLNode(psStroke, "SvgParameter"); + psCssParam = CPLGetXMLNode(psStroke, "SvgParameter"); while (psCssParam && psCssParam->pszValue && (strcasecmp(psCssParam->pszValue, "CssParameter") == 0 || strcasecmp(psCssParam->pszValue, "SvgParameter") == 0)) { - psName = - (char*)CPLGetXMLValue(psCssParam, "name", NULL); - if (psName && - strcasecmp(psName, "stroke") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { + psName = (char *)CPLGetXMLValue(psCssParam, "name", NULL); + if (psName && strcasecmp(psName, "stroke") == 0) { + if (psCssParam->psChild && psCssParam->psChild->psNext) { if (bFilled) { - msSLDParseOgcExpression(psCssParam->psChild->psNext, - psStyle, MS_STYLE_BINDING_OUTLINECOLOR, MS_OBJ_STYLE); + msSLDParseOgcExpression(psCssParam->psChild->psNext, psStyle, + MS_STYLE_BINDING_OUTLINECOLOR, + MS_OBJ_STYLE); } else { - msSLDParseOgcExpression(psCssParam->psChild->psNext, - psStyle, MS_STYLE_BINDING_COLOR, MS_OBJ_STYLE); + msSLDParseOgcExpression(psCssParam->psChild->psNext, psStyle, + MS_STYLE_BINDING_COLOR, MS_OBJ_STYLE); } } - } else if (psName && - strcasecmp(psName, "stroke-opacity") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { + } else if (psName && strcasecmp(psName, "stroke-opacity") == 0) { + if (psCssParam->psChild && psCssParam->psChild->psNext) { psValue = psCssParam->psChild->psNext->pszValue; if (psValue) { if (bFilled) { - psStyle->outlinecolor.alpha = (int)(atof(psValue)*255); + psStyle->outlinecolor.alpha = (int)(atof(psValue) * 255); } else { - psStyle->color.alpha = (int)(atof(psValue)*255); + psStyle->color.alpha = (int)(atof(psValue) * 255); } } } - } else if (psName && - strcasecmp(psName, "stroke-width") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { - msSLDParseOgcExpression(psCssParam->psChild->psNext, - psStyle, MS_STYLE_BINDING_WIDTH, MS_OBJ_STYLE); + } else if (psName && strcasecmp(psName, "stroke-width") == 0) { + if (psCssParam->psChild && psCssParam->psChild->psNext) { + msSLDParseOgcExpression(psCssParam->psChild->psNext, psStyle, + MS_STYLE_BINDING_WIDTH, MS_OBJ_STYLE); } } psCssParam = psCssParam->psNext; } } - } /* set the default color if color is not not already set */ - if ((psStyle->color.red < 0 || - psStyle->color.green == -1 || + if ((psStyle->color.red < 0 || psStyle->color.green == -1 || psStyle->color.blue == -1) && (psStyle->outlinecolor.red == -1 || psStyle->outlinecolor.green == -1 || @@ -2005,34 +1949,32 @@ int msSLDParseGraphicFillOrStroke(CPLXMLNode *psRoot, psStyle->color.blue = 128; } - /* Get the corresponding symbol id */ psStyle->symbol = msSLDGetMarkSymbol(map, pszSymbolName, bFilled); - if (psStyle->symbol > 0 && - psStyle->symbol < map->symbolset.numsymbols) + if (psStyle->symbol > 0 && psStyle->symbol < map->symbolset.numsymbols) psStyle->symbolname = - msStrdup(map->symbolset.symbol[psStyle->symbol]->name); + msStrdup(map->symbolset.symbol[psStyle->symbol]->name); } else { - psExternalGraphic = CPLGetXMLNode(psGraphic, "ExternalGraphic"); + psExternalGraphic = CPLGetXMLNode(psGraphic, "ExternalGraphic"); if (psExternalGraphic) msSLDParseExternalGraphic(psExternalGraphic, psStyle, map); } msFree(pszSymbolName); } - psGap = CPLGetXMLNode(psRoot, "Gap"); + psGap = CPLGetXMLNode(psRoot, "Gap"); if (psGap && psGap->psChild && psGap->psChild->pszValue) { psStyle->gap = atof(psGap->psChild->pszValue); } - psInitialGap = CPLGetXMLNode(psRoot, "InitialGap"); - if (psInitialGap && psInitialGap->psChild && psInitialGap->psChild->pszValue) { + psInitialGap = CPLGetXMLNode(psRoot, "InitialGap"); + if (psInitialGap && psInitialGap->psChild && + psInitialGap->psChild->pszValue) { psStyle->initialgap = atof(psInitialGap->psChild->pszValue); } return MS_SUCCESS; } - /************************************************************************/ /* msSLDGetMarkSymbol */ /* */ @@ -2040,8 +1982,7 @@ int msSLDParseGraphicFillOrStroke(CPLXMLNode *psRoot, /* square, circle, triangle, star, cross, x. */ /* If the symbol does not exist add it to the symbol list. */ /************************************************************************/ -int msSLDGetMarkSymbol(mapObj *map, char *pszSymbolName, int bFilled) -{ +int msSLDGetMarkSymbol(mapObj *map, char *pszSymbolName, int bFilled) { int nSymbolId = 0; symbolObj *psSymbol = NULL; @@ -2051,70 +1992,56 @@ int msSLDGetMarkSymbol(mapObj *map, char *pszSymbolName, int bFilled) if (strcasecmp(pszSymbolName, "square") == 0) { if (bFilled) nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_SQUARE_FILLED, - MS_FALSE); + SLD_MARK_SYMBOL_SQUARE_FILLED, MS_FALSE); else - nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_SQUARE, - MS_FALSE); + nSymbolId = + msGetSymbolIndex(&map->symbolset, SLD_MARK_SYMBOL_SQUARE, MS_FALSE); } else if (strcasecmp(pszSymbolName, "circle") == 0) { if (bFilled) nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_CIRCLE_FILLED, - MS_FALSE); + SLD_MARK_SYMBOL_CIRCLE_FILLED, MS_FALSE); else - nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_CIRCLE, - MS_FALSE); + nSymbolId = + msGetSymbolIndex(&map->symbolset, SLD_MARK_SYMBOL_CIRCLE, MS_FALSE); } else if (strcasecmp(pszSymbolName, "triangle") == 0) { if (bFilled) nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_TRIANGLE_FILLED, - MS_FALSE); + SLD_MARK_SYMBOL_TRIANGLE_FILLED, MS_FALSE); else - nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_TRIANGLE, - MS_FALSE); + nSymbolId = + msGetSymbolIndex(&map->symbolset, SLD_MARK_SYMBOL_TRIANGLE, MS_FALSE); } else if (strcasecmp(pszSymbolName, "star") == 0) { if (bFilled) - nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_STAR_FILLED, + nSymbolId = msGetSymbolIndex(&map->symbolset, SLD_MARK_SYMBOL_STAR_FILLED, MS_FALSE); else - nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_STAR, - MS_FALSE); + nSymbolId = + msGetSymbolIndex(&map->symbolset, SLD_MARK_SYMBOL_STAR, MS_FALSE); } else if (strcasecmp(pszSymbolName, "cross") == 0) { if (bFilled) nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_CROSS_FILLED, - MS_FALSE); + SLD_MARK_SYMBOL_CROSS_FILLED, MS_FALSE); else - nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_CROSS, - MS_FALSE); + nSymbolId = + msGetSymbolIndex(&map->symbolset, SLD_MARK_SYMBOL_CROSS, MS_FALSE); } else if (strcasecmp(pszSymbolName, "x") == 0) { if (bFilled) - nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_X_FILLED, - MS_FALSE); + nSymbolId = + msGetSymbolIndex(&map->symbolset, SLD_MARK_SYMBOL_X_FILLED, MS_FALSE); else - nSymbolId = msGetSymbolIndex(&map->symbolset, - SLD_MARK_SYMBOL_X, - MS_FALSE); + nSymbolId = + msGetSymbolIndex(&map->symbolset, SLD_MARK_SYMBOL_X, MS_FALSE); } else { - nSymbolId = msGetSymbolIndex(&map->symbolset, - pszSymbolName, - MS_FALSE); + nSymbolId = msGetSymbolIndex(&map->symbolset, pszSymbolName, MS_FALSE); } if (nSymbolId <= 0) { - if( (psSymbol = msGrowSymbolSet(&(map->symbolset))) == NULL) + if ((psSymbol = msGrowSymbolSet(&(map->symbolset))) == NULL) return 0; /* returns 0 for no symbol */ nSymbolId = map->symbolset.numsymbols; @@ -2280,7 +2207,6 @@ int msSLDGetMarkSymbol(mapObj *map, char *pszSymbolName, int bFilled) psSymbol->points[psSymbol->numpoints].y = 0; psSymbol->numpoints++; } - } return nSymbolId; @@ -2292,16 +2218,14 @@ int msSLDGetMarkSymbol(mapObj *map, char *pszSymbolName, int bFilled) /* Create a symbol entry for an inmap pixmap symbol. Returns */ /* the symbol id. */ /************************************************************************/ -int msSLDGetGraphicSymbol(mapObj *map, char *pszFileName, char* extGraphicName, - int nGap_ignored) -{ +int msSLDGetGraphicSymbol(mapObj *map, char *pszFileName, char *extGraphicName, + int nGap_ignored) { (void)nGap_ignored; int nSymbolId = 0; symbolObj *psSymbol = NULL; - if (map && pszFileName) { - if( (psSymbol = msGrowSymbolSet(&(map->symbolset))) == NULL) + if ((psSymbol = msGrowSymbolSet(&(map->symbolset))) == NULL) return 0; /* returns 0 for no symbol */ nSymbolId = map->symbolset.numsymbols; map->symbolset.numsymbols++; @@ -2315,7 +2239,6 @@ int msSLDGetGraphicSymbol(mapObj *map, char *pszFileName, char* extGraphicName, return nSymbolId; } - /************************************************************************/ /* msSLDParsePointSymbolizer */ /* */ @@ -2331,8 +2254,7 @@ int msSLDGetGraphicSymbol(mapObj *map, char *pszFileName, char* extGraphicName, /* */ /************************************************************************/ int msSLDParsePointSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, - int bNewClass, const char* pszUserStyleName) -{ + int bNewClass, const char *pszUserStyleName) { int nClassId = 0; int iStyle = 0; @@ -2340,14 +2262,14 @@ int msSLDParsePointSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, return MS_FAILURE; nClassId = getClassId(psLayer, bNewClass, pszUserStyleName); - if( nClassId < 0 ) + if (nClassId < 0) return MS_FAILURE; // Get uom if any, defaults to MS_PIXELS enum MS_UNITS sizeunits = MS_PIXELS; - if (msSLDParseUomAttribute(psRoot, &sizeunits) != MS_SUCCESS) - { - msSetError(MS_WMSERR, "Invalid uom attribute value.", "msSLDParsePolygonSymbolizer()"); + if (msSLDParseUomAttribute(psRoot, &sizeunits) != MS_SUCCESS) { + msSetError(MS_WMSERR, "Invalid uom attribute value.", + "msSLDParsePolygonSymbolizer()"); return MS_FAILURE; } @@ -2355,14 +2277,12 @@ int msSLDParsePointSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, msMaybeAllocateClassStyle(psLayer->class[nClassId], iStyle); psLayer->class[nClassId]->styles[iStyle]->sizeunits = sizeunits; - msSLDParseGraphicFillOrStroke(psRoot, NULL, - psLayer->class[nClassId]->styles[iStyle], - psLayer->map); + msSLDParseGraphicFillOrStroke( + psRoot, NULL, psLayer->class[nClassId] -> styles[iStyle], psLayer -> map); return MS_SUCCESS; } - /************************************************************************/ /* msSLDParseExternalGraphic */ /* */ @@ -2370,12 +2290,11 @@ int msSLDParsePointSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, /* by the URL and create a PIXMAP inmap symbol. Only GIF and */ /* PNG are supported. */ /************************************************************************/ -int msSLDParseExternalGraphic(CPLXMLNode *psExternalGraphic, - styleObj *psStyle, mapObj *map) -{ +int msSLDParseExternalGraphic(CPLXMLNode *psExternalGraphic, styleObj *psStyle, + mapObj *map) { char *pszFormat = NULL; - CPLXMLNode *psURL=NULL, *psFormat=NULL, *psTmp=NULL; - char *pszURL=NULL; + CPLXMLNode *psURL = NULL, *psFormat = NULL, *psTmp = NULL; + char *pszURL = NULL; if (!psExternalGraphic || !psStyle || !map) return MS_FAILURE; @@ -2385,32 +2304,31 @@ int msSLDParseExternalGraphic(CPLXMLNode *psExternalGraphic, pszFormat = psFormat->psChild->pszValue; /* supports GIF and PNG and SVG */ - if (pszFormat && - (strcasecmp(pszFormat, "GIF") == 0 || - strcasecmp(pszFormat, "image/gif") == 0 || - strcasecmp(pszFormat, "PNG") == 0 || - strcasecmp(pszFormat, "image/png") == 0 || - strcasecmp(pszFormat, "image/svg+xml") == 0)) { - - /* */ + if (pszFormat && (strcasecmp(pszFormat, "GIF") == 0 || + strcasecmp(pszFormat, "image/gif") == 0 || + strcasecmp(pszFormat, "PNG") == 0 || + strcasecmp(pszFormat, "image/png") == 0 || + strcasecmp(pszFormat, "image/svg+xml") == 0)) { + + /* + */ psURL = CPLGetXMLNode(psExternalGraphic, "OnlineResource"); if (psURL && psURL->psChild) { - psTmp = psURL->psChild; - while (psTmp != NULL && - psTmp->pszValue && + psTmp = psURL->psChild; + while (psTmp != NULL && psTmp->pszValue && strcasecmp(psTmp->pszValue, "xlink:href") != 0) { psTmp = psTmp->psNext; } if (psTmp && psTmp->psChild) { - pszURL = (char*)psTmp->psChild->pszValue; + pszURL = (char *)psTmp->psChild->pszValue; char *symbolurl = NULL; // Handle relative URL for ExternalGraphic - if (map->sldurl && !strstr(pszURL,"://")) - { + if (map->sldurl && !strstr(pszURL, "://")) { char *baseurl = NULL; char *relpath = NULL; - symbolurl = malloc(sizeof(char)*MS_MAXPATHLEN); + symbolurl = malloc(sizeof(char) * MS_MAXPATHLEN); if (pszURL[0] != '/') { // Symbol file is relative to SLD file // e.g. SLD : http://example.com/path/to/sld.xml @@ -2418,57 +2336,58 @@ int msSLDParseExternalGraphic(CPLXMLNode *psExternalGraphic, // lead to: http://example.com/path/to/assets/symbol.svg baseurl = msGetPath(map->sldurl); relpath = pszURL; - } - else - { + } else { // Symbol file is relative to the root of SLD server // e.g. SLD : http://example.com/path/to/sld.xml // and symbol: /path/to/assets/symbol.svg // lead to: http://example.com/path/to/assets/symbol.svg baseurl = msStrdup(map->sldurl); - relpath = pszURL+1; - char * sep = strstr(baseurl,"://"); + relpath = pszURL + 1; + char *sep = strstr(baseurl, "://"); if (sep) sep += 3; else sep = baseurl; - sep = strchr(sep,'/'); + sep = strchr(sep, '/'); if (!sep) sep = baseurl + strlen(baseurl); sep[1] = '\0'; } - msBuildPath(symbolurl,baseurl,relpath); + msBuildPath(symbolurl, baseurl, relpath); msFree(baseurl); - } - else - { + } else { // Absolute URL // e.g. symbol: http://example.com/path/to/assets/symbol.svg symbolurl = msStrdup(pszURL); } /* validate the ExternalGraphic parameter */ - if(msValidateParameter(symbolurl, msLookupHashTable(&(map->web.validation), "sld_external_graphic"), - NULL, NULL, NULL) != MS_SUCCESS) { - msSetError(MS_WEBERR, "SLD ExternalGraphic OnlineResource value fails to validate against sld_external_graphic VALIDATION", "mapserv()"); + if (msValidateParameter(symbolurl, + msLookupHashTable(&(map->web.validation), + "sld_external_graphic"), + NULL, NULL, NULL) != MS_SUCCESS) { + msSetError(MS_WEBERR, + "SLD ExternalGraphic OnlineResource value fails to " + "validate against sld_external_graphic VALIDATION", + "mapserv()"); msFree(symbolurl); return MS_FAILURE; } - - /*external symbols using http will be automaticallly downloaded. The file should be - saved in a temporary directory (msAddImageSymbol) #2305*/ - psStyle->symbol = msGetSymbolIndex(&map->symbolset, - symbolurl, - MS_TRUE); + /*external symbols using http will be automaticallly downloaded. The + file should be saved in a temporary directory (msAddImageSymbol) + #2305*/ + psStyle->symbol = msGetSymbolIndex(&map->symbolset, symbolurl, MS_TRUE); msFree(symbolurl); if (psStyle->symbol > 0 && psStyle->symbol < map->symbolset.numsymbols) - psStyle->symbolname = msStrdup(map->symbolset.symbol[psStyle->symbol]->name); + psStyle->symbolname = + msStrdup(map->symbolset.symbol[psStyle->symbol]->name); /* set the color parameter if not set. Does not make sense */ /* for pixmap but mapserver needs it. */ - if (psStyle->color.red == -1 || psStyle->color.green || psStyle->color.blue) { + if (psStyle->color.red == -1 || psStyle->color.green || + psStyle->color.blue) { psStyle->color.red = 0; psStyle->color.green = 0; psStyle->color.blue = 0; @@ -2480,7 +2399,6 @@ int msSLDParseExternalGraphic(CPLXMLNode *psExternalGraphic, return MS_SUCCESS; } - /************************************************************************/ /* msSLDParseTextSymbolizer */ /* */ @@ -2574,9 +2492,9 @@ int msSLDParseExternalGraphic(CPLXMLNode *psExternalGraphic, /* */ /************************************************************************/ int msSLDParseTextSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, - int bOtherSymboliser, const char* pszUserStyleName) -{ - int nStyleId=0, nClassId=0; + int bOtherSymboliser, + const char *pszUserStyleName) { + int nStyleId = 0, nClassId = 0; if (!psRoot || !psLayer) return MS_FAILURE; @@ -2586,26 +2504,23 @@ int msSLDParseTextSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, return MS_FAILURE; initClass(psLayer->class[psLayer->numclasses]); nClassId = psLayer->numclasses; - if( pszUserStyleName ) - psLayer->class[nClassId]->group = msStrdup(pszUserStyleName); + if (pszUserStyleName) + psLayer->class[nClassId]->group = msStrdup(pszUserStyleName); psLayer->numclasses++; msMaybeAllocateClassStyle(psLayer->class[nClassId], 0); nStyleId = 0; } else { nClassId = psLayer->numclasses - 1; - if (nClassId >= 0)/* should always be true */ - nStyleId = psLayer->class[nClassId]->numstyles -1; + if (nClassId >= 0) /* should always be true */ + nStyleId = psLayer->class[nClassId]->numstyles - 1; } if (nStyleId >= 0 && nClassId >= 0) /* should always be true */ - msSLDParseTextParams(psRoot, psLayer, - psLayer->class[nClassId]); + msSLDParseTextParams(psRoot, psLayer, psLayer->class[nClassId]); return MS_SUCCESS; } - - /************************************************************************/ /* msSLDParseRasterSymbolizer */ /* */ @@ -2645,7 +2560,8 @@ int msSLDParseTextSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, /* */ /* SLD 1.1 */ /* */ -/* */ +/* */ /* */ /* */ /* */ @@ -2671,7 +2587,8 @@ int msSLDParseTextSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, /* */ /* */ /* */ -/* */ +/* */ /* */ /* */ /* */ @@ -2683,7 +2600,8 @@ int msSLDParseTextSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, /* */ /* */ /* */ -/* */ +/* */ /* */ /* */ /* */ @@ -2699,21 +2617,20 @@ int msSLDParseTextSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, /* */ /************************************************************************/ int msSLDParseRasterSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, - const char* pszUserStyleName) -{ - CPLXMLNode *psColorMap = NULL, *psColorEntry = NULL, *psOpacity=NULL; - char *pszColor=NULL, *pszQuantity=NULL; - char *pszPreviousColor=NULL, *pszPreviousQuality=NULL; + const char *pszUserStyleName) { + CPLXMLNode *psColorMap = NULL, *psColorEntry = NULL, *psOpacity = NULL; + char *pszColor = NULL, *pszQuantity = NULL; + char *pszPreviousColor = NULL, *pszPreviousQuality = NULL; colorObj sColor; char szExpression[100]; double dfOpacity = 1.0; - char *pszLabel = NULL, *pszPreviousLabel = NULL; - char *pch = NULL, *pchPrevious=NULL; + char *pszLabel = NULL, *pszPreviousLabel = NULL; + char *pch = NULL, *pchPrevious = NULL; - CPLXMLNode *psNode=NULL, *psCategorize=NULL; + CPLXMLNode *psNode = NULL, *psCategorize = NULL; char *pszTmp = NULL; - int nValues=0, nThresholds=0; - int i,nMaxValues= 100, nMaxThreshold=100; + int nValues = 0, nThresholds = 0; + int i, nMaxValues = 100, nMaxThreshold = 100; if (!psRoot || !psLayer) return MS_FAILURE; @@ -2723,11 +2640,14 @@ int msSLDParseRasterSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, if (psOpacity->psChild && psOpacity->psChild->pszValue) dfOpacity = atof(psOpacity->psChild->pszValue); - /* values in sld goes from 0.0 (for transparent) to 1.0 (for full opacity); */ - if (dfOpacity >=0.0 && dfOpacity <=1.0) - msSetLayerOpacity(psLayer,(int)(dfOpacity * 100)); + /* values in sld goes from 0.0 (for transparent) to 1.0 (for full opacity); + */ + if (dfOpacity >= 0.0 && dfOpacity <= 1.0) + msSetLayerOpacity(psLayer, (int)(dfOpacity * 100)); else { - msSetError(MS_WMSERR, "Invalid opacity value. Values should be between 0.0 and 1.0", "msSLDParseRasterSymbolizer()"); + msSetError(MS_WMSERR, + "Invalid opacity value. Values should be between 0.0 and 1.0", + "msSLDParseRasterSymbolizer()"); return MS_FAILURE; } } @@ -2744,47 +2664,41 @@ int msSLDParseRasterSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, if (pszColor && pszQuantity) { if (pszPreviousColor && pszPreviousQuality) { - if (strlen(pszPreviousColor) == 7 && - pszPreviousColor[0] == '#' && + if (strlen(pszPreviousColor) == 7 && pszPreviousColor[0] == '#' && strlen(pszColor) == 7 && pszColor[0] == '#') { - sColor.red = msHexToInt(pszPreviousColor+1); - sColor.green= msHexToInt(pszPreviousColor+3); - sColor.blue = msHexToInt(pszPreviousColor+5); + sColor.red = msHexToInt(pszPreviousColor + 1); + sColor.green = msHexToInt(pszPreviousColor + 3); + sColor.blue = msHexToInt(pszPreviousColor + 5); /* pszQuantity and pszPreviousQuality may be integer or float */ - pchPrevious=strchr(pszPreviousQuality,'.'); - pch=strchr(pszQuantity,'.'); - if (pchPrevious==NULL && pch==NULL) { + pchPrevious = strchr(pszPreviousQuality, '.'); + pch = strchr(pszQuantity, '.'); + if (pchPrevious == NULL && pch == NULL) { snprintf(szExpression, sizeof(szExpression), "([pixel] >= %d AND [pixel] < %d)", - atoi(pszPreviousQuality), - atoi(pszQuantity)); - } else if (pchPrevious != NULL && pch==NULL) { + atoi(pszPreviousQuality), atoi(pszQuantity)); + } else if (pchPrevious != NULL && pch == NULL) { snprintf(szExpression, sizeof(szExpression), "([pixel] >= %f AND [pixel] < %d)", - atof(pszPreviousQuality), - atoi(pszQuantity)); + atof(pszPreviousQuality), atoi(pszQuantity)); } else if (pchPrevious == NULL && pch != NULL) { snprintf(szExpression, sizeof(szExpression), "([pixel] >= %d AND [pixel] < %f)", - atoi(pszPreviousQuality), - atof(pszQuantity)); + atoi(pszPreviousQuality), atof(pszQuantity)); } else { snprintf(szExpression, sizeof(szExpression), "([pixel] >= %f AND [pixel] < %f)", - atof(pszPreviousQuality), - atof(pszQuantity)); + atof(pszPreviousQuality), atof(pszQuantity)); } - if (msGrowLayerClasses(psLayer) == NULL) return MS_FAILURE; else { initClass(psLayer->class[psLayer->numclasses]); psLayer->numclasses++; - const int nClassId = psLayer->numclasses-1; - if( pszUserStyleName ) - psLayer->class[nClassId]->group = msStrdup(pszUserStyleName); + const int nClassId = psLayer->numclasses - 1; + if (pszUserStyleName) + psLayer->class[nClassId]->group = msStrdup(pszUserStyleName); /*set the class name using the label. If label not defined set it with the quantity*/ @@ -2795,52 +2709,46 @@ int msSLDParseRasterSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, msMaybeAllocateClassStyle(psLayer->class[nClassId], 0); - psLayer->class[nClassId]->styles[0]->color.red = - sColor.red; - psLayer->class[nClassId]->styles[0]->color.green = - sColor.green; - psLayer->class[nClassId]->styles[0]->color.blue = - sColor.blue; + psLayer->class[nClassId]->styles[0]->color.red = sColor.red; + psLayer->class[nClassId]->styles[0]->color.green = sColor.green; + psLayer->class[nClassId]->styles[0]->color.blue = sColor.blue; if (psLayer->classitem && strcasecmp(psLayer->classitem, "[pixel]") != 0) free(psLayer->classitem); psLayer->classitem = msStrdup("[pixel]"); - msLoadExpressionString(&psLayer->class[nClassId]->expression, + msLoadExpressionString(&psLayer->class[nClassId] -> expression, szExpression); - - } } else { - msSetError(MS_WMSERR, - "Invalid ColorMap Entry.", + msSetError(MS_WMSERR, "Invalid ColorMap Entry.", "msSLDParseRasterSymbolizer()"); return MS_FAILURE; } - } pszPreviousColor = pszColor; pszPreviousQuality = pszQuantity; pszPreviousLabel = pszLabel; - } psColorEntry = psColorEntry->psNext; } /* do the last Color Map Entry */ if (pszColor && pszQuantity) { if (strlen(pszColor) == 7 && pszColor[0] == '#') { - sColor.red = msHexToInt(pszColor+1); - sColor.green= msHexToInt(pszColor+3); - sColor.blue = msHexToInt(pszColor+5); + sColor.red = msHexToInt(pszColor + 1); + sColor.green = msHexToInt(pszColor + 3); + sColor.blue = msHexToInt(pszColor + 5); /* pszQuantity may be integer or float */ - pch=strchr(pszQuantity,'.'); - if (pch==NULL) { - snprintf(szExpression, sizeof(szExpression), "([pixel] = %d)", atoi(pszQuantity)); + pch = strchr(pszQuantity, '.'); + if (pch == NULL) { + snprintf(szExpression, sizeof(szExpression), "([pixel] = %d)", + atoi(pszQuantity)); } else { - snprintf(szExpression, sizeof(szExpression), "([pixel] = %f)", atof(pszQuantity)); + snprintf(szExpression, sizeof(szExpression), "([pixel] = %f)", + atof(pszQuantity)); } if (msGrowLayerClasses(psLayer) == NULL) @@ -2848,9 +2756,9 @@ int msSLDParseRasterSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, else { initClass(psLayer->class[psLayer->numclasses]); psLayer->numclasses++; - const int nClassId = psLayer->numclasses-1; - if( pszUserStyleName ) - psLayer->class[nClassId]->group = msStrdup(pszUserStyleName); + const int nClassId = psLayer->numclasses - 1; + if (pszUserStyleName) + psLayer->class[nClassId]->group = msStrdup(pszUserStyleName); msMaybeAllocateClassStyle(psLayer->class[nClassId], 0); if (pszLabel) @@ -2858,119 +2766,118 @@ int msSLDParseRasterSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, else psLayer->class[nClassId]->name = msStrdup(pszQuantity); psLayer->class[nClassId]->numstyles = 1; - psLayer->class[nClassId]->styles[0]->color.red = - sColor.red; - psLayer->class[nClassId]->styles[0]->color.green = - sColor.green; - psLayer->class[nClassId]->styles[0]->color.blue = - sColor.blue; + psLayer->class[nClassId]->styles[0]->color.red = sColor.red; + psLayer->class[nClassId]->styles[0]->color.green = sColor.green; + psLayer->class[nClassId]->styles[0]->color.blue = sColor.blue; if (psLayer->classitem && strcasecmp(psLayer->classitem, "[pixel]") != 0) free(psLayer->classitem); psLayer->classitem = msStrdup("[pixel]"); - msLoadExpressionString(&psLayer->class[nClassId]->expression, + msLoadExpressionString(&psLayer->class[nClassId] -> expression, szExpression); } } } } else if ((psCategorize = CPLGetXMLNode(psColorMap, "Categorize"))) { - char** papszValues = (char **)msSmallMalloc(sizeof(char*)*nMaxValues); - char** papszThresholds = (char **)msSmallMalloc(sizeof(char*)*nMaxThreshold); - psNode = CPLGetXMLNode(psCategorize, "Value"); - while (psNode && psNode->pszValue && - psNode->psChild && psNode->psChild->pszValue) + char **papszValues = (char **)msSmallMalloc(sizeof(char *) * nMaxValues); + char **papszThresholds = + (char **)msSmallMalloc(sizeof(char *) * nMaxThreshold); + psNode = CPLGetXMLNode(psCategorize, "Value"); + while (psNode && psNode->pszValue && psNode->psChild && + psNode->psChild->pszValue) { if (strcasecmp(psNode->pszValue, "Value") == 0) { - papszValues[nValues] = psNode->psChild->pszValue; + papszValues[nValues] = psNode->psChild->pszValue; nValues++; if (nValues == nMaxValues) { - nMaxValues +=100; - papszValues = (char **)msSmallRealloc(papszValues, sizeof(char*)*nMaxValues); + nMaxValues += 100; + papszValues = (char **)msSmallRealloc(papszValues, + sizeof(char *) * nMaxValues); } } else if (strcasecmp(psNode->pszValue, "Threshold") == 0) { - papszThresholds[nThresholds] = psNode->psChild->pszValue; + papszThresholds[nThresholds] = psNode->psChild->pszValue; nThresholds++; if (nValues == nMaxThreshold) { nMaxThreshold += 100; - papszThresholds = (char **)msSmallRealloc(papszThresholds, sizeof(char*)*nMaxThreshold); + papszThresholds = (char **)msSmallRealloc( + papszThresholds, sizeof(char *) * nMaxThreshold); } } psNode = psNode->psNext; } - if (nThresholds > 0 && nValues == nThresholds+1) { + if (nThresholds > 0 && nValues == nThresholds + 1) { /*free existing classes*/ - for(i=0; inumclasses; i++) { + for (i = 0; i < psLayer->numclasses; i++) { if (psLayer->class[i] != NULL) { - psLayer->class[i]->layer=NULL; - if ( freeClass(psLayer->class[i]) == MS_SUCCESS ) { + psLayer->class[i]->layer = NULL; + if (freeClass(psLayer->class[i]) == MS_SUCCESS) { msFree(psLayer->class[i]); - psLayer->class[i]=NULL; + psLayer->class[i] = NULL; } } } - psLayer->numclasses=0; - for (i=0; inumclasses = 0; + for (i = 0; i < nValues; i++) { pszTmp = (papszValues[i]); if (pszTmp && strlen(pszTmp) == 7 && pszTmp[0] == '#') { - sColor.red = msHexToInt(pszTmp+1); - sColor.green= msHexToInt(pszTmp+3); - sColor.blue = msHexToInt(pszTmp+5); + sColor.red = msHexToInt(pszTmp + 1); + sColor.green = msHexToInt(pszTmp + 3); + sColor.blue = msHexToInt(pszTmp + 5); if (i == 0) { - if (strchr(papszThresholds[i],'.')) - snprintf(szExpression, sizeof(szExpression), "([pixel] < %f)", atof(papszThresholds[i])); + if (strchr(papszThresholds[i], '.')) + snprintf(szExpression, sizeof(szExpression), "([pixel] < %f)", + atof(papszThresholds[i])); else - snprintf(szExpression, sizeof(szExpression), "([pixel] < %d)", atoi(papszThresholds[i])); + snprintf(szExpression, sizeof(szExpression), "([pixel] < %d)", + atoi(papszThresholds[i])); - } else if (i < nValues-1) { - if (strchr(papszThresholds[i],'.')) - snprintf(szExpression, sizeof(szExpression), + } else if (i < nValues - 1) { + if (strchr(papszThresholds[i], '.')) + snprintf(szExpression, sizeof(szExpression), "([pixel] >= %f AND [pixel] < %f)", - atof(papszThresholds[i-1]), + atof(papszThresholds[i - 1]), atof(papszThresholds[i])); else snprintf(szExpression, sizeof(szExpression), "([pixel] >= %d AND [pixel] < %d)", - atoi(papszThresholds[i-1]), + atoi(papszThresholds[i - 1]), atoi(papszThresholds[i])); } else { - if (strchr(papszThresholds[i-1],'.')) - snprintf(szExpression, sizeof(szExpression), "([pixel] >= %f)", atof(papszThresholds[i-1])); + if (strchr(papszThresholds[i - 1], '.')) + snprintf(szExpression, sizeof(szExpression), "([pixel] >= %f)", + atof(papszThresholds[i - 1])); else - snprintf(szExpression, sizeof(szExpression), "([pixel] >= %d)", atoi(papszThresholds[i-1])); + snprintf(szExpression, sizeof(szExpression), "([pixel] >= %d)", + atoi(papszThresholds[i - 1])); } if (msGrowLayerClasses(psLayer)) { initClass(psLayer->class[psLayer->numclasses]); psLayer->numclasses++; - const int nClassId = psLayer->numclasses-1; - if( pszUserStyleName ) + const int nClassId = psLayer->numclasses - 1; + if (pszUserStyleName) psLayer->class[nClassId]->group = msStrdup(pszUserStyleName); msMaybeAllocateClassStyle(psLayer->class[nClassId], 0); psLayer->class[nClassId]->numstyles = 1; - psLayer->class[nClassId]->styles[0]->color.red = - sColor.red; - psLayer->class[nClassId]->styles[0]->color.green = - sColor.green; - psLayer->class[nClassId]->styles[0]->color.blue = - sColor.blue; + psLayer->class[nClassId]->styles[0]->color.red = sColor.red; + psLayer->class[nClassId]->styles[0]->color.green = sColor.green; + psLayer->class[nClassId]->styles[0]->color.blue = sColor.blue; if (psLayer->classitem && strcasecmp(psLayer->classitem, "[pixel]") != 0) free(psLayer->classitem); psLayer->classitem = msStrdup("[pixel]"); - msLoadExpressionString(&psLayer->class[nClassId]->expression, + msLoadExpressionString(&psLayer->class[nClassId] -> expression, szExpression); } - } } } msFree(papszValues); msFree(papszThresholds); - } else { msSetError(MS_WMSERR, "Invalid SLD document. msSLDParseRaster", ""); return MS_FAILURE; @@ -2985,24 +2892,26 @@ int msSLDParseRasterSymbolizer(CPLXMLNode *psRoot, layerObj *psLayer, /* Parse text parameters like font, placement and color. */ /************************************************************************/ int msSLDParseTextParams(CPLXMLNode *psRoot, layerObj *psLayer, - classObj *psClass) -{ + classObj *psClass) { char szFontName[100]; - CPLXMLNode *psLabel=NULL, *psFont=NULL; + CPLXMLNode *psLabel = NULL, *psFont = NULL; CPLXMLNode *psCssParam = NULL; - char *pszName=NULL, *pszFontFamily=NULL, *pszFontStyle=NULL; - char *pszFontWeight=NULL; - CPLXMLNode *psLabelPlacement=NULL, *psPointPlacement=NULL, *psLinePlacement=NULL; - CPLXMLNode *psFill = NULL, *psHalo=NULL, *psHaloRadius=NULL, *psHaloFill=NULL; + char *pszName = NULL, *pszFontFamily = NULL, *pszFontStyle = NULL; + char *pszFontWeight = NULL; + CPLXMLNode *psLabelPlacement = NULL, *psPointPlacement = NULL, + *psLinePlacement = NULL; + CPLXMLNode *psFill = NULL, *psHalo = NULL, *psHaloRadius = NULL, + *psHaloFill = NULL; labelObj *psLabelObj = NULL; - szFontName[0]='\0'; + szFontName[0] = '\0'; if (!psRoot || !psClass || !psLayer) return MS_FAILURE; - if(psClass->numlabels == 0) { - if(msGrowClassLabels(psClass) == NULL) return(MS_FAILURE); + if (psClass->numlabels == 0) { + if (msGrowClassLabels(psClass) == NULL) + return (MS_FAILURE); initLabel(psClass->labels[0]); psClass->numlabels++; } @@ -3012,59 +2921,54 @@ int msSLDParseTextParams(CPLXMLNode *psRoot, layerObj *psLayer, modified Label Placement #2806*/ psLabelObj->anglemode = MS_AUTO; - /* label */ /* support literal expression and propertyname - - - + - + Bug 1857 */ psLabel = CPLGetXMLNode(psRoot, "Label"); - if (psLabel) - { - char * sep = ""; - msStringBuffer * classtext = msStringBufferAlloc(); + if (psLabel) { + char *sep = ""; + msStringBuffer *classtext = msStringBufferAlloc(); msStringBufferAppend(classtext, "("); - for (CPLXMLNode * psTmpNode = psLabel->psChild ; psTmpNode ; psTmpNode = psTmpNode->psNext) - { - if (psTmpNode->eType == CXT_Text && psTmpNode->pszValue) - { + for (CPLXMLNode *psTmpNode = psLabel->psChild; psTmpNode; + psTmpNode = psTmpNode->psNext) { + if (psTmpNode->eType == CXT_Text && psTmpNode->pszValue) { msStringBufferAppend(classtext, sep); msStringBufferAppend(classtext, "\""); msStringBufferAppend(classtext, psTmpNode->pszValue); msStringBufferAppend(classtext, "\""); sep = "+"; - } - else if (psTmpNode->eType == CXT_Element - && strcasecmp(psTmpNode->pszValue,"Literal") == 0 - && psTmpNode->psChild) - { + } else if (psTmpNode->eType == CXT_Element && + strcasecmp(psTmpNode->pszValue, "Literal") == 0 && + psTmpNode->psChild) { msStringBufferAppend(classtext, sep); msStringBufferAppend(classtext, "\""); msStringBufferAppend(classtext, psTmpNode->psChild->pszValue); msStringBufferAppend(classtext, "\""); sep = "+"; - } - else if (psTmpNode->eType == CXT_Element - && strcasecmp(psTmpNode->pszValue,"PropertyName") == 0 - && psTmpNode->psChild) - { + } else if (psTmpNode->eType == CXT_Element && + strcasecmp(psTmpNode->pszValue, "PropertyName") == 0 && + psTmpNode->psChild) { msStringBufferAppend(classtext, sep); msStringBufferAppend(classtext, "\"["); msStringBufferAppend(classtext, psTmpNode->psChild->pszValue); msStringBufferAppend(classtext, "]\""); sep = "+"; - } - else if (psTmpNode->eType == CXT_Element - && strcasecmp(psTmpNode->pszValue,"Function") == 0 - && psTmpNode->psChild) - { + } else if (psTmpNode->eType == CXT_Element && + strcasecmp(psTmpNode->pszValue, "Function") == 0 && + psTmpNode->psChild) { msStringBufferAppend(classtext, sep); msStringBufferAppend(classtext, "tostring("); labelObj tempExpressionCollector; initLabel(&tempExpressionCollector); - msSLDParseOgcExpression(psTmpNode,&tempExpressionCollector,MS_LABEL_BINDING_SIZE,MS_OBJ_LABEL); - msStringBufferAppend(classtext,tempExpressionCollector.exprBindings[MS_LABEL_BINDING_SIZE].string); + msSLDParseOgcExpression(psTmpNode, &tempExpressionCollector, + MS_LABEL_BINDING_SIZE, MS_OBJ_LABEL); + msStringBufferAppend( + classtext, + tempExpressionCollector.exprBindings[MS_LABEL_BINDING_SIZE].string); freeLabel(&tempExpressionCollector); msStringBufferAppend(classtext, ",\"%g\")"); @@ -3072,10 +2976,9 @@ int msSLDParseTextParams(CPLXMLNode *psRoot, layerObj *psLayer, } } msStringBufferAppend(classtext, ")"); - const char * expressionstring = msStringBufferGetString(classtext); - if (strlen(expressionstring) > 2) - { - msLoadExpressionString(&psClass->text, (char*)expressionstring); + const char *expressionstring = msStringBufferGetString(classtext); + if (strlen(expressionstring) > 2) { + msLoadExpressionString(&psClass->text, (char *)expressionstring); } msStringBufferFree(classtext); @@ -3083,39 +2986,38 @@ int msSLDParseTextParams(CPLXMLNode *psRoot, layerObj *psLayer, /* font */ psFont = CPLGetXMLNode(psRoot, "Font"); if (psFont) { - psCssParam = CPLGetXMLNode(psFont, "CssParameter"); + psCssParam = CPLGetXMLNode(psFont, "CssParameter"); /*sld 1.1 used SvgParameter*/ if (psCssParam == NULL) - psCssParam = CPLGetXMLNode(psFont, "SvgParameter"); + psCssParam = CPLGetXMLNode(psFont, "SvgParameter"); while (psCssParam && psCssParam->pszValue && (strcasecmp(psCssParam->pszValue, "CssParameter") == 0 || strcasecmp(psCssParam->pszValue, "SvgParameter") == 0)) { - pszName = (char*)CPLGetXMLValue(psCssParam, "name", NULL); + pszName = (char *)CPLGetXMLValue(psCssParam, "name", NULL); if (pszName) { if (strcasecmp(pszName, "font-family") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext && + if (psCssParam->psChild && psCssParam->psChild->psNext && psCssParam->psChild->psNext->pszValue) pszFontFamily = psCssParam->psChild->psNext->pszValue; } /* normal, italic, oblique */ else if (strcasecmp(pszName, "font-style") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext && + if (psCssParam->psChild && psCssParam->psChild->psNext && psCssParam->psChild->psNext->pszValue) pszFontStyle = psCssParam->psChild->psNext->pszValue; } /* normal or bold */ else if (strcasecmp(pszName, "font-weight") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext && + if (psCssParam->psChild && psCssParam->psChild->psNext && psCssParam->psChild->psNext->pszValue) pszFontWeight = psCssParam->psChild->psNext->pszValue; } /* default is 10 pix */ else if (strcasecmp(pszName, "font-size") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { - msSLDParseOgcExpression(psCssParam->psChild->psNext, - psLabelObj, MS_LABEL_BINDING_SIZE, MS_OBJ_LABEL); + if (psCssParam->psChild && psCssParam->psChild->psNext) { + msSLDParseOgcExpression(psCssParam->psChild->psNext, psLabelObj, + MS_LABEL_BINDING_SIZE, MS_OBJ_LABEL); } } } @@ -3128,10 +3030,8 @@ int msSLDParseTextParams(CPLXMLNode *psRoot, layerObj *psLayer, /* -------------------------------------------------------------------- */ psLabelPlacement = CPLGetXMLNode(psRoot, "LabelPlacement"); if (psLabelPlacement) { - psPointPlacement = CPLGetXMLNode(psLabelPlacement, - "PointPlacement"); - psLinePlacement = CPLGetXMLNode(psLabelPlacement, - "LinePlacement"); + psPointPlacement = CPLGetXMLNode(psLabelPlacement, "PointPlacement"); + psLinePlacement = CPLGetXMLNode(psLabelPlacement, "LinePlacement"); if (psPointPlacement) ParseTextPointPlacement(psPointPlacement, psClass); if (psLinePlacement) @@ -3156,7 +3056,8 @@ int msSLDParseTextParams(CPLXMLNode *psRoot, layerObj *psLayer, strlcat(szFontName, pszFontStyle, sizeof(szFontName)); } - if ((msLookupHashTable(&(psLayer->map->fontset.fonts), szFontName) !=NULL)) { + if ((msLookupHashTable(&(psLayer->map->fontset.fonts), szFontName) != + NULL)) { psLabelObj->font = msStrdup(szFontName); } } @@ -3166,63 +3067,60 @@ int msSLDParseTextParams(CPLXMLNode *psRoot, layerObj *psLayer, /* -------------------------------------------------------------------- */ psHalo = CPLGetXMLNode(psRoot, "Halo"); if (psHalo) { - psHaloRadius = CPLGetXMLNode(psHalo, "Radius"); - if (psHaloRadius && psHaloRadius->psChild && psHaloRadius->psChild->pszValue) + psHaloRadius = CPLGetXMLNode(psHalo, "Radius"); + if (psHaloRadius && psHaloRadius->psChild && + psHaloRadius->psChild->pszValue) psLabelObj->outlinewidth = atoi(psHaloRadius->psChild->pszValue); - psHaloFill = CPLGetXMLNode(psHalo, "Fill"); + psHaloFill = CPLGetXMLNode(psHalo, "Fill"); if (psHaloFill) { - psCssParam = CPLGetXMLNode(psHaloFill, "CssParameter"); + psCssParam = CPLGetXMLNode(psHaloFill, "CssParameter"); /*sld 1.1 used SvgParameter*/ if (psCssParam == NULL) - psCssParam = CPLGetXMLNode(psHaloFill, "SvgParameter"); + psCssParam = CPLGetXMLNode(psHaloFill, "SvgParameter"); while (psCssParam && psCssParam->pszValue && (strcasecmp(psCssParam->pszValue, "CssParameter") == 0 || strcasecmp(psCssParam->pszValue, "SvgParameter") == 0)) { - pszName = (char*)CPLGetXMLValue(psCssParam, "name", NULL); + pszName = (char *)CPLGetXMLValue(psCssParam, "name", NULL); if (pszName) { if (strcasecmp(pszName, "fill") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { - msSLDParseOgcExpression(psCssParam->psChild->psNext, psLabelObj, + if (psCssParam->psChild && psCssParam->psChild->psNext) { + msSLDParseOgcExpression( + psCssParam->psChild->psNext, psLabelObj, MS_LABEL_BINDING_OUTLINECOLOR, MS_OBJ_LABEL); } } } psCssParam = psCssParam->psNext; } - } - } /* -------------------------------------------------------------------- */ /* Parse the color */ /* -------------------------------------------------------------------- */ psFill = CPLGetXMLNode(psRoot, "Fill"); if (psFill) { - psCssParam = CPLGetXMLNode(psFill, "CssParameter"); + psCssParam = CPLGetXMLNode(psFill, "CssParameter"); /*sld 1.1 used SvgParameter*/ if (psCssParam == NULL) - psCssParam = CPLGetXMLNode(psFill, "SvgParameter"); + psCssParam = CPLGetXMLNode(psFill, "SvgParameter"); while (psCssParam && psCssParam->pszValue && (strcasecmp(psCssParam->pszValue, "CssParameter") == 0 || strcasecmp(psCssParam->pszValue, "SvgParameter") == 0)) { - pszName = (char*)CPLGetXMLValue(psCssParam, "name", NULL); + pszName = (char *)CPLGetXMLValue(psCssParam, "name", NULL); if (pszName) { if (strcasecmp(pszName, "fill") == 0) { - if(psCssParam->psChild && psCssParam->psChild->psNext) - { + if (psCssParam->psChild && psCssParam->psChild->psNext) { msSLDParseOgcExpression(psCssParam->psChild->psNext, psLabelObj, - MS_LABEL_BINDING_COLOR, MS_OBJ_LABEL); + MS_LABEL_BINDING_COLOR, MS_OBJ_LABEL); } } } psCssParam = psCssParam->psNext; } } - } } @@ -3234,17 +3132,17 @@ int msSLDParseTextParams(CPLXMLNode *psRoot, layerObj *psLayer, /* */ /* point placement node for the text symbolizer. */ /************************************************************************/ -int ParseTextPointPlacement(CPLXMLNode *psRoot, classObj *psClass) -{ +int ParseTextPointPlacement(CPLXMLNode *psRoot, classObj *psClass) { CPLXMLNode *psAnchor, *psAnchorX, *psAnchorY; CPLXMLNode *psDisplacement, *psDisplacementX, *psDisplacementY; - CPLXMLNode *psRotation=NULL; + CPLXMLNode *psRotation = NULL; labelObj *psLabelObj = NULL; if (!psRoot || !psClass) return MS_FAILURE; - if(psClass->numlabels == 0) { - if(msGrowClassLabels(psClass) == NULL) return(MS_FAILURE); + if (psClass->numlabels == 0) { + if (msGrowClassLabels(psClass) == NULL) + return (MS_FAILURE); initLabel(psClass->labels[0]); psClass->numlabels++; } @@ -3262,12 +3160,8 @@ int ParseTextPointPlacement(CPLXMLNode *psRoot, classObj *psClass) psAnchorX = CPLGetXMLNode(psAnchor, "AnchorPointX"); psAnchorY = CPLGetXMLNode(psAnchor, "AnchorPointY"); /* psCssParam->psChild->psNext->pszValue) */ - if (psAnchorX && - psAnchorX->psChild && - psAnchorX->psChild->pszValue && - psAnchorY && - psAnchorY->psChild && - psAnchorY->psChild->pszValue) { + if (psAnchorX && psAnchorX->psChild && psAnchorX->psChild->pszValue && + psAnchorY && psAnchorY->psChild && psAnchorY->psChild->pszValue) { const double dfAnchorX = atof(psAnchorX->psChild->pszValue); const double dfAnchorY = atof(psAnchorY->psChild->pszValue); @@ -3305,12 +3199,9 @@ int ParseTextPointPlacement(CPLXMLNode *psRoot, classObj *psClass) psDisplacementX = CPLGetXMLNode(psDisplacement, "DisplacementX"); psDisplacementY = CPLGetXMLNode(psDisplacement, "DisplacementY"); /* psCssParam->psChild->psNext->pszValue) */ - if (psDisplacementX && - psDisplacementX->psChild && - psDisplacementX->psChild->pszValue && - psDisplacementY && - psDisplacementY->psChild && - psDisplacementY->psChild->pszValue) { + if (psDisplacementX && psDisplacementX->psChild && + psDisplacementX->psChild->pszValue && psDisplacementY && + psDisplacementY->psChild && psDisplacementY->psChild->pszValue) { psLabelObj->offsetx = atoi(psDisplacementX->psChild->pszValue); psLabelObj->offsety = atoi(psDisplacementY->psChild->pszValue); } @@ -3320,10 +3211,9 @@ int ParseTextPointPlacement(CPLXMLNode *psRoot, classObj *psClass) /* parse rotation. */ /* -------------------------------------------------------------------- */ psRotation = CPLGetXMLNode(psRoot, "Rotation"); - if (psRotation && psRotation->psChild) - { + if (psRotation && psRotation->psChild) { msSLDParseOgcExpression(psRotation->psChild, psLabelObj, - MS_LABEL_BINDING_ANGLE, MS_OBJ_LABEL); + MS_LABEL_BINDING_ANGLE, MS_OBJ_LABEL); } return MS_SUCCESS; @@ -3334,16 +3224,16 @@ int ParseTextPointPlacement(CPLXMLNode *psRoot, classObj *psClass) /* */ /* Lineplacement node fro the text symbolizer. */ /************************************************************************/ -int ParseTextLinePlacement(CPLXMLNode *psRoot, classObj *psClass) -{ - CPLXMLNode *psOffset = NULL, *psAligned=NULL; +int ParseTextLinePlacement(CPLXMLNode *psRoot, classObj *psClass) { + CPLXMLNode *psOffset = NULL, *psAligned = NULL; labelObj *psLabelObj = NULL; if (!psRoot || !psClass) return MS_FAILURE; - if(psClass->numlabels == 0) { - if(msGrowClassLabels(psClass) == NULL) return(MS_FAILURE); + if (psClass->numlabels == 0) { + if (msGrowClassLabels(psClass) == NULL) + return (MS_FAILURE); initLabel(psClass->labels[0]); psClass->numlabels++; } @@ -3379,7 +3269,6 @@ int ParseTextLinePlacement(CPLXMLNode *psRoot, classObj *psClass) return MS_SUCCESS; } - /************************************************************************/ /* void msSLDSetColorObject(char *psHexColor, colorObj */ /* *psColor) */ @@ -3388,14 +3277,13 @@ int ParseTextLinePlacement(CPLXMLNode *psRoot, classObj *psClass) /* color string (format is : #aaff08) and set it in the color */ /* object. */ /************************************************************************/ -int msSLDSetColorObject(char *psHexColor, colorObj *psColor) -{ - if (psHexColor && psColor && strlen(psHexColor)== 7 && +int msSLDSetColorObject(char *psHexColor, colorObj *psColor) { + if (psHexColor && psColor && strlen(psHexColor) == 7 && psHexColor[0] == '#') { - psColor->red = msHexToInt(psHexColor+1); - psColor->green = msHexToInt(psHexColor+3); - psColor->blue= msHexToInt(psHexColor+5); + psColor->red = msHexToInt(psHexColor + 1); + psColor->green = msHexToInt(psHexColor + 3); + psColor->blue = msHexToInt(psHexColor + 5); } return MS_SUCCESS; @@ -3415,9 +3303,9 @@ int msSLDSetColorObject(char *psHexColor, colorObj *psColor) /* */ /* The caller should free the returned string. */ /************************************************************************/ -char *msSLDGenerateSLD(mapObj *map, int iLayer, const char *pszVersion) -{ -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) +char *msSLDGenerateSLD(mapObj *map, int iLayer, const char *pszVersion) { +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) char szTmp[500]; int i = 0; @@ -3429,24 +3317,42 @@ char *msSLDGenerateSLD(mapObj *map, int iLayer, const char *pszVersion) sld_version = msOWSParseVersionString(pszVersion); if (sld_version == OWS_VERSION_NOTSET || - (sld_version!= OWS_1_0_0 && sld_version!= OWS_1_1_0)) + (sld_version != OWS_1_0_0 && sld_version != OWS_1_1_0)) sld_version = OWS_1_0_0; if (map) { schemalocation = msEncodeHTMLEntities(msOWSGetSchemasLocation(map)); - if (sld_version == OWS_1_0_0) - snprintf(szTmp, sizeof(szTmp), "\n",schemalocation ); + if (sld_version == OWS_1_0_0) + snprintf(szTmp, sizeof(szTmp), + "\n", + schemalocation); else - snprintf(szTmp, sizeof(szTmp), "\n", schemalocation); + snprintf(szTmp, sizeof(szTmp), + "\n", + schemalocation); free(schemalocation); pszSLD = msStringConcatenate(pszSLD, szTmp); - if (iLayer < 0 || iLayer > map->numlayers -1) { - for (i=0; inumlayers; i++) { + if (iLayer < 0 || iLayer > map->numlayers - 1) { + for (i = 0; i < map->numlayers; i++) { pszTmp = msSLDGenerateSLDLayer(GET_LAYER(map, i), sld_version); if (pszTmp) { - pszSLD= msStringConcatenate(pszSLD, pszTmp); + pszSLD = msStringConcatenate(pszSLD, pszTmp); free(pszTmp); } } @@ -3471,27 +3377,25 @@ char *msSLDGenerateSLD(mapObj *map, int iLayer, const char *pszVersion) #endif } - - /************************************************************************/ /* msSLDGetGraphicSLD */ /* */ /* Get an SLD for a style containing a symbol (Mark or external). */ /************************************************************************/ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, - int bNeedMarkSybol, int nVersion) -{ -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) + int bNeedMarkSybol, int nVersion) { +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) - msStringBuffer * sldString = msStringBufferAlloc(); + msStringBuffer *sldString = msStringBufferAlloc(); int nSymbol = -1; symbolObj *psSymbol = NULL; char szTmp[512]; char szFormat[4]; int i = 0, nLength = 0; - int bColorAvailable=0; + int bColorAvailable = 0; int bGenerateDefaultSymbol = 0; - char *pszSymbolName= NULL; + char *pszSymbolName = NULL; char sNameSpace[10]; char sCssParam[30]; @@ -3510,17 +3414,17 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, if (psStyle->symbol > 0) nSymbol = psStyle->symbol; else if (psStyle->symbolname) - nSymbol = msGetSymbolIndex(&psLayer->map->symbolset, - psStyle->symbolname, MS_FALSE); + nSymbol = msGetSymbolIndex(&psLayer->map->symbolset, psStyle->symbolname, + MS_FALSE); bGenerateDefaultSymbol = 0; if (bNeedMarkSybol && - (nSymbol <=0 || nSymbol >= psLayer->map->symbolset.numsymbols)) + (nSymbol <= 0 || nSymbol >= psLayer->map->symbolset.numsymbols)) bGenerateDefaultSymbol = 1; if (nSymbol > 0 && nSymbol < psLayer->map->symbolset.numsymbols) { - psSymbol = psLayer->map->symbolset.symbol[nSymbol]; + psSymbol = psLayer->map->symbolset.symbol[nSymbol]; if (psSymbol->type == MS_SYMBOL_VECTOR || psSymbol->type == MS_SYMBOL_ELLIPSE) { /* Mark symbol */ @@ -3534,30 +3438,26 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, strcasecmp(psSymbol->name, "cross") == 0 || strcasecmp(psSymbol->name, "x") == 0) pszSymbolName = msStrdup(psSymbol->name); - else if (strncasecmp(psSymbol->name, - "sld_mark_symbol_square", 22) == 0) + else if (strncasecmp(psSymbol->name, "sld_mark_symbol_square", 22) == + 0) pszSymbolName = msStrdup("square"); - else if (strncasecmp(psSymbol->name, - "sld_mark_symbol_triangle", 24) == 0) + else if (strncasecmp(psSymbol->name, "sld_mark_symbol_triangle", + 24) == 0) pszSymbolName = msStrdup("triangle"); - else if (strncasecmp(psSymbol->name, - "sld_mark_symbol_circle", 22) == 0) + else if (strncasecmp(psSymbol->name, "sld_mark_symbol_circle", 22) == + 0) pszSymbolName = msStrdup("circle"); - else if (strncasecmp(psSymbol->name, - "sld_mark_symbol_star", 20) == 0) + else if (strncasecmp(psSymbol->name, "sld_mark_symbol_star", 20) == 0) pszSymbolName = msStrdup("star"); - else if (strncasecmp(psSymbol->name, - "sld_mark_symbol_cross", 21) == 0) + else if (strncasecmp(psSymbol->name, "sld_mark_symbol_cross", 21) == + 0) pszSymbolName = msStrdup("cross"); - else if (strncasecmp(psSymbol->name, - "sld_mark_symbol_x", 17) == 0) + else if (strncasecmp(psSymbol->name, "sld_mark_symbol_x", 17) == 0) pszSymbolName = msStrdup("X"); - - if (pszSymbolName) { - colorObj sTmpFillColor = { 128, 128, 128, 255 }; - colorObj sTmpStrokeColor = { 0, 0, 0, 255 }; + colorObj sTmpFillColor = {128, 128, 128, 255}; + colorObj sTmpStrokeColor = {0, 0, 0, 255}; int hasFillColor = 0; int hasStrokeColor = 0; @@ -3567,14 +3467,13 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, snprintf(szTmp, sizeof(szTmp), "<%sMark>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - snprintf(szTmp, sizeof(szTmp), "<%sWellKnownName>%s\n", - sNameSpace, pszSymbolName, sNameSpace); + snprintf(szTmp, sizeof(szTmp), + "<%sWellKnownName>%s\n", sNameSpace, + pszSymbolName, sNameSpace); msStringBufferAppend(sldString, szTmp); - if (psStyle->color.red != -1 && - psStyle->color.green != -1 && - psStyle->color.blue != -1) - { + if (psStyle->color.red != -1 && psStyle->color.green != -1 && + psStyle->color.blue != -1) { sTmpFillColor.red = psStyle->color.red; sTmpFillColor.green = psStyle->color.green; sTmpFillColor.blue = psStyle->color.blue; @@ -3583,25 +3482,20 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, } if (psStyle->outlinecolor.red != -1 && psStyle->outlinecolor.green != -1 && - psStyle->outlinecolor.blue != -1) - { + psStyle->outlinecolor.blue != -1) { sTmpStrokeColor.red = psStyle->outlinecolor.red; sTmpStrokeColor.green = psStyle->outlinecolor.green; sTmpStrokeColor.blue = psStyle->outlinecolor.blue; sTmpStrokeColor.alpha = psStyle->outlinecolor.alpha; hasStrokeColor = 1; // Make defaults implicit - if (sTmpStrokeColor.red == 0 && - sTmpStrokeColor.green == 0 && - sTmpStrokeColor.blue == 0 && - sTmpStrokeColor.alpha == 255 && - psStyle->width == 1) - { + if (sTmpStrokeColor.red == 0 && sTmpStrokeColor.green == 0 && + sTmpStrokeColor.blue == 0 && sTmpStrokeColor.alpha == 255 && + psStyle->width == 1) { hasStrokeColor = 0; } } - if (!hasFillColor && !hasStrokeColor) - { + if (!hasFillColor && !hasStrokeColor) { sTmpFillColor.red = 128; sTmpFillColor.green = 128; sTmpFillColor.blue = 128; @@ -3612,19 +3506,15 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, if (hasFillColor) { snprintf(szTmp, sizeof(szTmp), "<%sFill>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - snprintf(szTmp, sizeof(szTmp), "<%s name=\"fill\">#%02x%02x%02x\n", - sCssParam, - sTmpFillColor.red, - sTmpFillColor.green, - sTmpFillColor.blue, - sCssParam); + snprintf(szTmp, sizeof(szTmp), + "<%s name=\"fill\">#%02x%02x%02x\n", sCssParam, + sTmpFillColor.red, sTmpFillColor.green, + sTmpFillColor.blue, sCssParam); msStringBufferAppend(sldString, szTmp); - if (sTmpFillColor.alpha != 255 && sTmpFillColor.alpha != -1) - { - snprintf(szTmp, sizeof(szTmp), "<%s name=\"fill-opacity\">%.2f\n", - sCssParam, - (float)sTmpFillColor.alpha/255.0, - sCssParam); + if (sTmpFillColor.alpha != 255 && sTmpFillColor.alpha != -1) { + snprintf(szTmp, sizeof(szTmp), + "<%s name=\"fill-opacity\">%.2f\n", sCssParam, + (float)sTmpFillColor.alpha / 255.0, sCssParam); msStringBufferAppend(sldString, szTmp); } snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); @@ -3633,27 +3523,21 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, if (hasStrokeColor) { snprintf(szTmp, sizeof(szTmp), "<%sStroke>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - snprintf(szTmp, sizeof(szTmp), "<%s name=\"stroke\">#%02x%02x%02x\n", - sCssParam, - sTmpStrokeColor.red, - sTmpStrokeColor.green, - sTmpStrokeColor.blue, - sCssParam); + snprintf(szTmp, sizeof(szTmp), + "<%s name=\"stroke\">#%02x%02x%02x\n", sCssParam, + sTmpStrokeColor.red, sTmpStrokeColor.green, + sTmpStrokeColor.blue, sCssParam); msStringBufferAppend(sldString, szTmp); - if (psStyle->width > 0) - { - snprintf(szTmp, sizeof(szTmp), "<%s name=\"stroke-width\">%g\n", - sCssParam, - psStyle->width, - sCssParam); + if (psStyle->width > 0) { + snprintf(szTmp, sizeof(szTmp), + "<%s name=\"stroke-width\">%g\n", sCssParam, + psStyle->width, sCssParam); msStringBufferAppend(sldString, szTmp); } - if (sTmpStrokeColor.alpha != 255 && sTmpStrokeColor.alpha != -1) - { - snprintf(szTmp, sizeof(szTmp), "<%s name=\"stroke-opacity\">%.2f\n", - sCssParam, - (float)sTmpStrokeColor.alpha/255.0, - sCssParam); + if (sTmpStrokeColor.alpha != 255 && sTmpStrokeColor.alpha != -1) { + snprintf(szTmp, sizeof(szTmp), + "<%s name=\"stroke-opacity\">%.2f\n", sCssParam, + (float)sTmpStrokeColor.alpha / 255.0, sCssParam); msStringBufferAppend(sldString, szTmp); } snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); @@ -3665,33 +3549,33 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, if (psStyle->size > 0) { snprintf(szTmp, sizeof(szTmp), "<%sSize>%g\n", - sNameSpace, psStyle->size, sNameSpace); + sNameSpace, psStyle->size, sNameSpace); msStringBufferAppend(sldString, szTmp); } - if (fmod(psStyle->angle, 360)) - { + if (fmod(psStyle->angle, 360)) { snprintf(szTmp, sizeof(szTmp), "<%sRotation>%g\n", - sNameSpace, psStyle->angle, sNameSpace); + sNameSpace, psStyle->angle, sNameSpace); msStringBufferAppend(sldString, szTmp); } - // Style opacity is already reported to alpha channel of color and outlinecolor - // if (psStyle->opacity < 100) - // { - // snprintf(szTmp, sizeof(szTmp), "<%sOpacity>%g\n", - // sNameSpace, psStyle->opacity/100.0, sNameSpace); - // pszSLD = msStringConcatenate(pszSLD, szTmp); - // } - - if (psStyle->offsetx != 0 || psStyle->offsety != 0) - { + // Style opacity is already reported to alpha channel of color and + // outlinecolor if (psStyle->opacity < 100) + // { + // snprintf(szTmp, sizeof(szTmp), "<%sOpacity>%g\n", + // sNameSpace, psStyle->opacity/100.0, sNameSpace); + // pszSLD = msStringConcatenate(pszSLD, szTmp); + // } + + if (psStyle->offsetx != 0 || psStyle->offsety != 0) { snprintf(szTmp, sizeof(szTmp), "<%sDisplacement>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - snprintf(szTmp, sizeof(szTmp), "<%sDisplacementX>%g\n", - sNameSpace, psStyle->offsetx, sNameSpace); + snprintf(szTmp, sizeof(szTmp), + "<%sDisplacementX>%g\n", sNameSpace, + psStyle->offsetx, sNameSpace); msStringBufferAppend(sldString, szTmp); - snprintf(szTmp, sizeof(szTmp), "<%sDisplacementY>%g\n", - sNameSpace, psStyle->offsety, sNameSpace); + snprintf(szTmp, sizeof(szTmp), + "<%sDisplacementY>%g\n", sNameSpace, + psStyle->offsety, sNameSpace); msStringBufferAppend(sldString, szTmp); snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); msStringBufferAppend(sldString, szTmp); @@ -3704,71 +3588,76 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, free(pszSymbolName); } } else - bGenerateDefaultSymbol =1; - } else if (psSymbol->type == MS_SYMBOL_PIXMAP || psSymbol->type == MS_SYMBOL_SVG) { + bGenerateDefaultSymbol = 1; + } else if (psSymbol->type == MS_SYMBOL_PIXMAP || + psSymbol->type == MS_SYMBOL_SVG) { if (psSymbol->name) { - const char *pszURL = msLookupHashTable(&(psLayer->metadata), "WMS_SLD_SYMBOL_URL"); + const char *pszURL = + msLookupHashTable(&(psLayer->metadata), "WMS_SLD_SYMBOL_URL"); if (!pszURL) - pszURL = msLookupHashTable(&(psLayer->map->web.metadata), "WMS_SLD_SYMBOL_URL"); + pszURL = msLookupHashTable(&(psLayer->map->web.metadata), + "WMS_SLD_SYMBOL_URL"); if (pszURL) { snprintf(szTmp, sizeof(szTmp), "<%sGraphic>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - - snprintf(szTmp, sizeof(szTmp), "<%sExternalGraphic>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - snprintf(szTmp, sizeof(szTmp), "<%sOnlineResource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"%s%s\"/>\n", sNameSpace, - pszURL,psSymbol->imagepath); + snprintf(szTmp, sizeof(szTmp), + "<%sOnlineResource " + "xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "xlink:type=\"simple\" xlink:href=\"%s%s\"/>\n", + sNameSpace, pszURL, psSymbol->imagepath); msStringBufferAppend(sldString, szTmp); /* TODO : extract format from symbol */ szFormat[0] = '\0'; nLength = strlen(psSymbol->imagepath); if (nLength > 3) { - for (i=0; i<=2; i++) - szFormat[2-i] = psSymbol->imagepath[nLength-1-i]; + for (i = 0; i <= 2; i++) + szFormat[2 - i] = psSymbol->imagepath[nLength - 1 - i]; szFormat[3] = '\0'; } - if (strlen(szFormat) > 0 && - ((strcasecmp (szFormat, "GIF") == 0) || - (strcasecmp (szFormat, "PNG") == 0))) { - if (strcasecmp (szFormat, "GIF") == 0) - snprintf(szTmp, sizeof(szTmp), "<%sFormat>image/gif\n", - sNameSpace, sNameSpace); + if (strlen(szFormat) > 0 && ((strcasecmp(szFormat, "GIF") == 0) || + (strcasecmp(szFormat, "PNG") == 0))) { + if (strcasecmp(szFormat, "GIF") == 0) + snprintf(szTmp, sizeof(szTmp), + "<%sFormat>image/gif\n", sNameSpace, + sNameSpace); else - snprintf(szTmp, sizeof(szTmp), "<%sFormat>image/png\n", - sNameSpace, sNameSpace); + snprintf(szTmp, sizeof(szTmp), + "<%sFormat>image/png\n", sNameSpace, + sNameSpace); } else - snprintf(szTmp, sizeof(szTmp), "<%sFormat>%s\n", sNameSpace, - (psSymbol->type ==MS_SYMBOL_SVG)?"image/svg+xml":"image/gif",sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sFormat>%s\n", + sNameSpace, + (psSymbol->type == MS_SYMBOL_SVG) ? "image/svg+xml" + : "image/gif", + sNameSpace); msStringBufferAppend(sldString, szTmp); - snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "\n", + sNameSpace); msStringBufferAppend(sldString, szTmp); if (psStyle->size > 0) - snprintf(szTmp, sizeof(szTmp), "<%sSize>%g\n", sNameSpace, psStyle->size, - sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sSize>%g\n", + sNameSpace, psStyle->size, sNameSpace); msStringBufferAppend(sldString, szTmp); snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - } } - } } if (bGenerateDefaultSymbol) { /* generate a default square symbol */ snprintf(szTmp, sizeof(szTmp), "<%sGraphic>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - - snprintf(szTmp, sizeof(szTmp), "<%sMark>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); @@ -3777,17 +3666,13 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, msStringBufferAppend(sldString, szTmp); bColorAvailable = 0; - if (psStyle->color.red != -1 && - psStyle->color.green != -1 && + if (psStyle->color.red != -1 && psStyle->color.green != -1 && psStyle->color.blue != -1) { snprintf(szTmp, sizeof(szTmp), "<%sFill>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); snprintf(szTmp, sizeof(szTmp), "<%s name=\"fill\">#%02x%02x%02x\n", - sCssParam, - psStyle->color.red, - psStyle->color.green, - psStyle->color.blue, - sCssParam); + sCssParam, psStyle->color.red, psStyle->color.green, + psStyle->color.blue, sCssParam); msStringBufferAppend(sldString, szTmp); snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); msStringBufferAppend(sldString, szTmp); @@ -3798,12 +3683,10 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, psStyle->outlinecolor.blue != -1) { snprintf(szTmp, sizeof(szTmp), "<%sStroke>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - snprintf(szTmp, sizeof(szTmp), "<%s name=\"Stroke\">#%02x%02x%02x\n", - sCssParam, - psStyle->outlinecolor.red, - psStyle->outlinecolor.green, - psStyle->outlinecolor.blue, - sCssParam); + snprintf(szTmp, sizeof(szTmp), + "<%s name=\"Stroke\">#%02x%02x%02x\n", sCssParam, + psStyle->outlinecolor.red, psStyle->outlinecolor.green, + psStyle->outlinecolor.blue, sCssParam); msStringBufferAppend(sldString, szTmp); snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); msStringBufferAppend(sldString, szTmp); @@ -3813,9 +3696,8 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, /* default color */ snprintf(szTmp, sizeof(szTmp), "<%sFill>\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - snprintf(szTmp, sizeof(szTmp), - "<%s name=\"fill\">%s\n", - sCssParam, "#808080", sCssParam); + snprintf(szTmp, sizeof(szTmp), "<%s name=\"fill\">%s\n", sCssParam, + "#808080", sCssParam); msStringBufferAppend(sldString, szTmp); snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); msStringBufferAppend(sldString, szTmp); @@ -3828,13 +3710,12 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, snprintf(szTmp, sizeof(szTmp), "<%sSize>%g\n", sNameSpace, psStyle->size, sNameSpace); else - snprintf(szTmp, sizeof(szTmp), "<%sSize>%d\n", sNameSpace,1,sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sSize>%d\n", sNameSpace, 1, + sNameSpace); msStringBufferAppend(sldString, szTmp); snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); msStringBufferAppend(sldString, szTmp); - - } } @@ -3844,20 +3725,16 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer, return NULL; #endif - } - - - /************************************************************************/ /* msSLDGenerateLineSLD */ /* */ /* Generate SLD for a Line layer. */ /************************************************************************/ -char *msSLDGenerateLineSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) -{ -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) +char *msSLDGenerateLineSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) { +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) char *pszSLD = NULL; char szTmp[100]; @@ -3870,45 +3747,47 @@ char *msSLDGenerateLineSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) char sCssParam[30]; char sNameSpace[10]; - if ( msCheckParentPointer(psLayer->map,"map")==MS_FAILURE ) + if (msCheckParentPointer(psLayer->map, "map") == MS_FAILURE) return NULL; sCssParam[0] = '\0'; if (nVersion > OWS_1_0_0) - strcpy( sCssParam, "se:SvgParameter"); + strcpy(sCssParam, "se:SvgParameter"); else - strcpy( sCssParam, "CssParameter"); + strcpy(sCssParam, "CssParameter"); sNameSpace[0] = '\0'; if (nVersion > OWS_1_0_0) strcpy(sNameSpace, "se:"); - snprintf(szTmp, sizeof(szTmp), "<%sLineSymbolizer>\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sLineSymbolizer>\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); - snprintf(szTmp, sizeof(szTmp), "<%sStroke>\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sStroke>\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); pszGraphicSLD = msSLDGetGraphicSLD(psStyle, psLayer, 0, nVersion); if (pszGraphicSLD) { - snprintf(szTmp, sizeof(szTmp), "<%sGraphicStroke>\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sGraphicStroke>\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); pszSLD = msStringConcatenate(pszSLD, pszGraphicSLD); - if(nVersion >= OWS_1_1_0) { - if(psStyle->gap > 0) { - snprintf(szTmp, sizeof(szTmp), "<%sGap>%.2f\n", sNameSpace,psStyle->gap,sNameSpace); + if (nVersion >= OWS_1_1_0) { + if (psStyle->gap > 0) { + snprintf(szTmp, sizeof(szTmp), "<%sGap>%.2f\n", sNameSpace, + psStyle->gap, sNameSpace); } - if(psStyle->initialgap > 0) { - snprintf(szTmp, sizeof(szTmp), "<%sInitialGap>%.2f\n", sNameSpace,psStyle->initialgap,sNameSpace); + if (psStyle->initialgap > 0) { + snprintf(szTmp, sizeof(szTmp), "<%sInitialGap>%.2f\n", + sNameSpace, psStyle->initialgap, sNameSpace); } } - snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); @@ -3916,37 +3795,33 @@ char *msSLDGenerateLineSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) pszGraphicSLD = NULL; } - if (psStyle->color.red != -1 && - psStyle->color.green != -1 && + if (psStyle->color.red != -1 && psStyle->color.green != -1 && psStyle->color.blue != -1) - sprintf(szHexColor,"%02x%02x%02x",psStyle->color.red, - psStyle->color.green,psStyle->color.blue); + sprintf(szHexColor, "%02x%02x%02x", psStyle->color.red, + psStyle->color.green, psStyle->color.blue); else - sprintf(szHexColor,"%02x%02x%02x",psStyle->outlinecolor.red, - psStyle->outlinecolor.green,psStyle->outlinecolor.blue); + sprintf(szHexColor, "%02x%02x%02x", psStyle->outlinecolor.red, + psStyle->outlinecolor.green, psStyle->outlinecolor.blue); - snprintf(szTmp, sizeof(szTmp), - "<%s name=\"stroke\">#%s\n", - sCssParam, szHexColor, sCssParam); + snprintf(szTmp, sizeof(szTmp), "<%s name=\"stroke\">#%s\n", sCssParam, + szHexColor, sCssParam); pszSLD = msStringConcatenate(pszSLD, szTmp); - if(psStyle->color.alpha != 255 && psStyle->color.alpha!=-1) { - snprintf(szTmp, sizeof(szTmp), - "<%s name=\"stroke-opacity\">%.2f\n", - sCssParam, (float)psStyle->color.alpha/255.0, sCssParam); + if (psStyle->color.alpha != 255 && psStyle->color.alpha != -1) { + snprintf(szTmp, sizeof(szTmp), "<%s name=\"stroke-opacity\">%.2f\n", + sCssParam, (float)psStyle->color.alpha / 255.0, sCssParam); pszSLD = msStringConcatenate(pszSLD, szTmp); } - nSymbol = -1; if (psStyle->symbol >= 0) nSymbol = psStyle->symbol; else if (psStyle->symbolname) - nSymbol = msGetSymbolIndex(&psLayer->map->symbolset, - psStyle->symbolname, MS_FALSE); + nSymbol = msGetSymbolIndex(&psLayer->map->symbolset, psStyle->symbolname, + MS_FALSE); - if (nSymbol <0) + if (nSymbol < 0) dfSize = 1.0; else { if (psStyle->size > 0) @@ -3957,8 +3832,7 @@ char *msSLDGenerateLineSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) dfSize = 1; } - snprintf(szTmp, sizeof(szTmp), - "<%s name=\"stroke-width\">%.2f\n", + snprintf(szTmp, sizeof(szTmp), "<%s name=\"stroke-width\">%.2f\n", sCssParam, dfSize, sCssParam); pszSLD = msStringConcatenate(pszSLD, szTmp); @@ -3966,24 +3840,22 @@ char *msSLDGenerateLineSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) /* dash array */ /* -------------------------------------------------------------------- */ - if (psStyle->patternlength > 0) { - for (i=0; ipatternlength; i++) { + for (i = 0; i < psStyle->patternlength; i++) { snprintf(szTmp, sizeof(szTmp), "%.2f ", psStyle->pattern[i]); pszDashArray = msStringConcatenate(pszDashArray, szTmp); } - snprintf(szTmp, sizeof(szTmp), - "<%s name=\"stroke-dasharray\">%s\n", + snprintf(szTmp, sizeof(szTmp), "<%s name=\"stroke-dasharray\">%s\n", sCssParam, pszDashArray, sCssParam); pszSLD = msStringConcatenate(pszSLD, szTmp); msFree(pszDashArray); } - snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); - snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); @@ -3994,15 +3866,15 @@ char *msSLDGenerateLineSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) #endif } - /************************************************************************/ /* msSLDGeneratePolygonSLD */ /* */ /* Generate SLD for a Polygon layer. */ /************************************************************************/ -char *msSLDGeneratePolygonSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) -{ -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) +char *msSLDGeneratePolygonSLD(styleObj *psStyle, layerObj *psLayer, + int nVersion) { +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) char szTmp[100]; char *pszSLD = NULL; @@ -4022,26 +3894,26 @@ char *msSLDGeneratePolygonSLD(styleObj *psStyle, layerObj *psLayer, int nVersion if (nVersion > OWS_1_0_0) strcpy(sNameSpace, "se:"); - snprintf(szTmp, sizeof(szTmp), "<%sPolygonSymbolizer>\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sPolygonSymbolizer>\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); /* fill */ if (psStyle->color.red != -1 && psStyle->color.green != -1 && psStyle->color.blue != -1) { - snprintf(szTmp, sizeof(szTmp), "<%sFill>\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sFill>\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); pszGraphicSLD = msSLDGetGraphicSLD(psStyle, psLayer, 0, nVersion); if (pszGraphicSLD) { - snprintf(szTmp, sizeof(szTmp), "<%sGraphicFill>\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sGraphicFill>\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); pszSLD = msStringConcatenate(pszSLD, pszGraphicSLD); - snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); @@ -4049,46 +3921,40 @@ char *msSLDGeneratePolygonSLD(styleObj *psStyle, layerObj *psLayer, int nVersion pszGraphicSLD = NULL; } - sprintf(szHexColor,"%02x%02x%02x",psStyle->color.red, - psStyle->color.green,psStyle->color.blue); + sprintf(szHexColor, "%02x%02x%02x", psStyle->color.red, + psStyle->color.green, psStyle->color.blue); - snprintf(szTmp, sizeof(szTmp), - "<%s name=\"fill\">#%s\n", - sCssParam, szHexColor, sCssParam); + snprintf(szTmp, sizeof(szTmp), "<%s name=\"fill\">#%s\n", sCssParam, + szHexColor, sCssParam); pszSLD = msStringConcatenate(pszSLD, szTmp); - if(psStyle->color.alpha != 255 && psStyle->color.alpha!=-1) { - snprintf(szTmp, sizeof(szTmp), - "<%s name=\"fill-opacity\">%.2f\n", - sCssParam, (float)psStyle->color.alpha/255, sCssParam); + if (psStyle->color.alpha != 255 && psStyle->color.alpha != -1) { + snprintf(szTmp, sizeof(szTmp), "<%s name=\"fill-opacity\">%.2f\n", + sCssParam, (float)psStyle->color.alpha / 255, sCssParam); pszSLD = msStringConcatenate(pszSLD, szTmp); } - - snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); } /* stroke */ - if (psStyle->outlinecolor.red != -1 && - psStyle->outlinecolor.green != -1 && + if (psStyle->outlinecolor.red != -1 && psStyle->outlinecolor.green != -1 && psStyle->outlinecolor.blue != -1) { - snprintf(szTmp, sizeof(szTmp), "<%sStroke>\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sStroke>\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); - - /* If there is a symbol to be used for stroke, the color in the */ /* style should be set to -1. Else It won't apply here. */ if (psStyle->color.red == -1 && psStyle->color.green == -1 && psStyle->color.blue == -1) { pszGraphicSLD = msSLDGetGraphicSLD(psStyle, psLayer, 0, nVersion); if (pszGraphicSLD) { - snprintf(szTmp, sizeof(szTmp), "<%sGraphicFill>\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sGraphicFill>\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); pszSLD = msStringConcatenate(pszSLD, pszGraphicSLD); - snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); free(pszGraphicSLD); @@ -4096,13 +3962,11 @@ char *msSLDGeneratePolygonSLD(styleObj *psStyle, layerObj *psLayer, int nVersion } } - sprintf(szHexColor,"%02x%02x%02x",psStyle->outlinecolor.red, - psStyle->outlinecolor.green, - psStyle->outlinecolor.blue); + sprintf(szHexColor, "%02x%02x%02x", psStyle->outlinecolor.red, + psStyle->outlinecolor.green, psStyle->outlinecolor.blue); - snprintf(szTmp, sizeof(szTmp), - "<%s name=\"stroke\">#%s\n", - sCssParam, szHexColor, sCssParam); + snprintf(szTmp, sizeof(szTmp), "<%s name=\"stroke\">#%s\n", sCssParam, + szHexColor, sCssParam); pszSLD = msStringConcatenate(pszSLD, szTmp); dfSize = 1.0; @@ -4111,20 +3975,18 @@ char *msSLDGeneratePolygonSLD(styleObj *psStyle, layerObj *psLayer, int nVersion else if (psStyle->width > 0) dfSize = psStyle->width; - snprintf(szTmp, sizeof(szTmp), - "<%s name=\"stroke-width\">%.2f\n", - sCssParam,dfSize,sCssParam); + snprintf(szTmp, sizeof(szTmp), "<%s name=\"stroke-width\">%.2f\n", + sCssParam, dfSize, sCssParam); pszSLD = msStringConcatenate(pszSLD, szTmp); - if(psStyle->outlinecolor.alpha != 255 && psStyle->outlinecolor.alpha != -1) - { - snprintf(szTmp, sizeof(szTmp), - "<%s name=\"stroke-opacity\">%.2f\n", - sCssParam, psStyle->outlinecolor.alpha/255.0, sCssParam); + if (psStyle->outlinecolor.alpha != 255 && + psStyle->outlinecolor.alpha != -1) { + snprintf(szTmp, sizeof(szTmp), "<%s name=\"stroke-opacity\">%.2f\n", + sCssParam, psStyle->outlinecolor.alpha / 255.0, sCssParam); pszSLD = msStringConcatenate(pszSLD, szTmp); } - snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); } @@ -4143,9 +4005,10 @@ char *msSLDGeneratePolygonSLD(styleObj *psStyle, layerObj *psLayer, int nVersion /* */ /* Generate SLD for a Point layer. */ /************************************************************************/ -char *msSLDGeneratePointSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) -{ -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) +char *msSLDGeneratePointSLD(styleObj *psStyle, layerObj *psLayer, + int nVersion) { +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) char *pszSLD = NULL; char *pszGraphicSLD = NULL; char szTmp[100]; @@ -4155,7 +4018,7 @@ char *msSLDGeneratePointSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) if (nVersion > OWS_1_0_0) strcpy(sNameSpace, "se:"); - snprintf(szTmp, sizeof(szTmp), "<%sPointSymbolizer>\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "<%sPointSymbolizer>\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); pszGraphicSLD = msSLDGetGraphicSLD(psStyle, psLayer, 1, nVersion); @@ -4164,7 +4027,7 @@ char *msSLDGeneratePointSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) free(pszGraphicSLD); } - snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); + snprintf(szTmp, sizeof(szTmp), "\n", sNameSpace); pszSLD = msStringConcatenate(pszSLD, szTmp); return pszSLD; @@ -4175,17 +4038,15 @@ char *msSLDGeneratePointSLD(styleObj *psStyle, layerObj *psLayer, int nVersion) #endif } - - /************************************************************************/ /* msSLDGenerateTextSLD */ /* */ /* Generate a TextSymboliser SLD xml based on the class's label */ /* object. */ /************************************************************************/ -char *msSLDGenerateTextSLD(classObj *psClass, layerObj *psLayer, int nVersion) -{ -#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) +char *msSLDGenerateTextSLD(classObj *psClass, layerObj *psLayer, int nVersion) { +#if defined(USE_WMS_SVR) || defined(USE_WFS_SVR) || defined(USE_WCS_SVR) || \ + defined(USE_SOS_SVR) char *pszSLD = NULL; char szTmp[1000]; @@ -4209,41 +4070,32 @@ char *msSLDGenerateTextSLD(classObj *psClass, layerObj *psLayer, int nVersion) if (nVersion > OWS_1_0_0) strcpy(sNameSpace, "se:"); + if (!psLayer || !psClass) + return pszSLD; - if (!psLayer || !psClass) return pszSLD; - - for (lid=0 ; lid < psClass->numlabels ; lid++) - { - char * psLabelText; + for (lid = 0; lid < psClass->numlabels; lid++) { + char *psLabelText; expressionObj psLabelExpr; parseObj p; msInitExpression(&psLabelExpr); psLabelObj = psClass->labels[lid]; - if (psLabelObj->text.string) - { + if (psLabelObj->text.string) { psLabelExpr.string = msStrdup(psLabelObj->text.string); psLabelExpr.type = psLabelObj->text.type; - } - else if (psClass->text.string) - { + } else if (psClass->text.string) { psLabelExpr.string = msStrdup(psClass->text.string); psLabelExpr.type = psClass->text.type; - } - else if (psLayer->labelitem) - { + } else if (psLayer->labelitem) { psLabelExpr.string = msStrdup(psLayer->labelitem); psLabelExpr.type = MS_STRING; - } - else - { + } else { msFreeExpression(&psLabelExpr); continue; // Can't find text content for this