cvs: pecl /shp .cvsignore CREDITS EXPERIMENTAL README config.m4 php_shp.h shp.c shp.php /shp/tests 001.phpt

From: Date: Sun, 10 Apr 2005 17:24:23 +0000
Subject: cvs: pecl /shp .cvsignore CREDITS EXPERIMENTAL README config.m4 php_shp.h shp.c shp.php /shp/tests 001.phpt
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-2958@lists.php.net to get a copy of this message
andrey Sun Apr 10 13:24:23 2005 EDT Added files: /pecl/shp .cvsignore CREDITS EXPERIMENTAL README config.m4 php_shp.h shp.c shp.php /pecl/shp/tests 001.phpt Log: libshape wrapper. libshape is a library for accessing ESRI shape files used in GIS systems.

http://cvs.php.net/co.php/pecl/shp/.cvsignore?r=1.1&p=1 Index: pecl/shp/.cvsignore +++ pecl/shp/.cvsignore #*# *.dsw *.la *.lo *.ncb *.o *.opt *.plg *.tgz *~..#*..deps..libs Debug Debug_TS Makefile Makefile.fragments Makefile.global Makefile.objects Release Release_TS Release_TSDbg Release_TS_inline Release_inline acinclude.m4 aclocal.m4 autom4te.cache build config.cache config.guess config.h config.h.in config.log config.nice config.status config.sub configure configure.in conftest conftest.c include install-sh libtool ltmain.sh missing mkinstalldirs modules scan_makefile_in.awk *.gcda *.gcno http://cvs.php.net/co.php/pecl/shp/config.m4?r=1.1&p=1 Index: pecl/shp/config.m4 +++ pecl/shp/config.m4 PHP_ARG_WITH(shp, for shp support, [ --with-shp Include shp support]) if test "$PHP_SHP" != "no"; then # --with-shp -> check with-path SEARCH_PATH="/usr/local /usr" # you might want to change this SEARCH_FOR="/include/libshp/shapefil.h" # you most likely want to change this if test -r $PHP_SHP/$SEARCH_FOR; then # path given as parameter SHP_DIR=$PHP_SHP else # search default path list AC_MSG_CHECKING([for shp files in default path]) for i in $SEARCH_PATH ; do if test -r $i/$SEARCH_FOR; then SHP_DIR=$i AC_MSG_RESULT(found in $i) fi done fi if test -z "$SHP_DIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the shp distribution]) fi # --with-shp -> add include path PHP_ADD_INCLUDE($SHP_DIR/include) # --with-shp -> check for lib and symbol presence LIBNAME=shp # you may want to change this LIBSYMBOL=SHPOpen # you most likely want to change this PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, [ PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $SHP_DIR/lib, SHP_SHARED_LIBADD) AC_DEFINE(HAVE_SHPLIB,1,[ ]) ],[ AC_MSG_ERROR([wrong shp lib version or lib not found]) ],[ -L$SHP_DIR/lib -lm -ldl ]) PHP_SUBST(SHP_SHARED_LIBADD) PHP_NEW_EXTENSION(shp, shp.c, $ext_shared) fi http://cvs.php.net/co.php/pecl/shp/php_shp.h?r=1.1&p=1 Index: pecl/shp/php_shp.h +++ pecl/shp/php_shp.h /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2004 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+ */ /* $Id: php_shp.h,v 1.1 2005/04/10 17:24:23 andrey Exp $ */ #ifndef PHP_SHP_H #define PHP_SHP_H #include "libshp/shapefil.h" extern zend_module_entry shp_module_entry; #define phpext_shp_ptr &shp_module_entry #ifdef PHP_WIN32 #define PHP_SHP_API __declspec(dllexport) #else #define PHP_SHP_API #endif #ifdef ZTS #include "TSRM.h" #endif PHP_MINIT_FUNCTION(shp); PHP_MSHUTDOWN_FUNCTION(shp); PHP_RINIT_FUNCTION(shp); PHP_RSHUTDOWN_FUNCTION(shp); PHP_MINFO_FUNCTION(shp); /* Declare any global variables you may need between the BEGIN and END macros here: ZEND_BEGIN_MODULE_GLOBALS(shp) long global_value; char *global_string; ZEND_END_MODULE_GLOBALS(shp) */ #ifdef ZTS #define SHP_G(v) TSRMG(shp_globals_id, zend_shp_globals *, v) #else #define SHP_G(v) (shp_globals.v) #endif #endif /* PHP_SHP_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ http://cvs.php.net/co.php/pecl/shp/shp.c?r=1.1&p=1 Index: pecl/shp/shp.c +++ pecl/shp/shp.c /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2004 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Andrey Hristov | +----------------------------------------------------------------------+ */ /* $Id: shp.c,v 1.1 2005/04/10 17:24:23 andrey Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_shp.h" #define SHPHANDLE_RES_NAME "SHP Handle" #define SHPOBJECT_RES_NAME "SHP Object" /* If you declare any globals in php_shp.h uncomment this: ZEND_DECLARE_MODULE_GLOBALS(shp) */ /* True global resources - no need for thread safety here */ static int le_shphandle; static int le_shpobject; #ifdef COMPILE_DL_SHP ZEND_GET_MODULE(shp) #endif /* {{{ PHP_INI */ /* Remove comments and fill if you need to have entries in php.ini PHP_INI_BEGIN() STD_PHP_INI_ENTRY("shp.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_shp_globals, shp_globals) STD_PHP_INI_ENTRY("shp.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_shp_globals, shp_globals) PHP_INI_END() */ /* }}} */ /* {{{ php_shp_init_globals */ /* Uncomment this function if you have INI entries static void php_shp_init_globals(zend_shp_globals *shp_globals) { shp_globals->global_value = 0; shp_globals->global_string = NULL; } */ /* }}} */ /* {{{ _close_shp_handle */ static void _close_shp_handle(zend_rsrc_list_entry *rsrc TSRMLS_DC) { SHPClose((SHPHandle) rsrc->ptr); } /* }}} */ /* {{{ _close_shp_object */ static void _close_shp_object(zend_rsrc_list_entry *rsrc TSRMLS_DC) { SHPDestroyObject((SHPObject *) rsrc->ptr); } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(shp) { php_info_print_table_start(); php_info_print_table_header(2, "shapelib support", "enabled"); php_info_print_table_end(); } /* }}} */ /* shp_open - implemented shp_get_info - NOT implemented shp_read_object - implemented shp_close - implemented shp_create - implemented shp_create_simple_object - NOT implemented shp_create_object - NOT implemented shp_compute_extents - NOT implemented shp_write_object - implemented shp_destroy_object - implemented shp_rewind_object - implemented */ /* {{{ proto string shp_open(string filename, string access) Opens a SHP handle */ PHP_FUNCTION(shp_open) { char *name = NULL, *acc = NULL; int name_len, acc_len; SHPHandle shph; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &acc, &acc_len) == FAILURE) { RETURN_FALSE; } shph = SHPOpen(name, acc); if (!shph) { RETURN_NULL(); } ZEND_REGISTER_RESOURCE(return_value, shph, le_shphandle); } /* }}} */ /* {{{ proto string shp_create(string filename, string access) Creates a SHP handle */ PHP_FUNCTION(shp_create) { char *name = NULL; int name_len, shape_type; SHPHandle shph; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &name, &name_len, &shape_type) == FAILURE) { RETURN_FALSE; } switch (shape_type) { case SHPT_POINT: case SHPT_ARC: case SHPT_POLYGON: case SHPT_MULTIPOINT: break; default: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported type %ld", shape_type); } shph = SHPCreate(name, shape_type); if (!shph) { RETURN_NULL(); } ZEND_REGISTER_RESOURCE(return_value, shph, le_shphandle); } /* }}} */ /* {{{ proto string shp_close(resource shp) Close a SHP handle */ PHP_FUNCTION(shp_close) { zval *res; SHPHandle shph; int c_id = -1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } if (!res) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got NULL for res"); RETURN_FALSE; } ZEND_FETCH_RESOURCE(shph, SHPHandle, &res, c_id, SHPHANDLE_RES_NAME, le_shphandle); if (!shph) { RETURN_FALSE; } zend_list_delete(Z_LVAL_P(res)); ZVAL_NULL(res); RETURN_TRUE; } /* }}} */ /* {{{ proto string shp_read_object(resource shp, int ord) Reads an object from a handle. The numbering starts from 0 */ PHP_FUNCTION(shp_read_object) { zval *res; SHPHandle shph; SHPObject *shp_obj; int c_id = -1, ord; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &ord) == FAILURE) { RETURN_FALSE; } if (!res) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got NULL for res"); RETURN_FALSE; } ZEND_FETCH_RESOURCE(shph, SHPHandle, &res, c_id, SHPHANDLE_RES_NAME, le_shphandle); if (!shph) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got NULL from the resource"); RETURN_FALSE; } shp_obj = SHPReadObject(shph, ord); if (!shp_obj) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Reading of object %ld failed", ord); RETURN_NULL(); } ZEND_REGISTER_RESOURCE(return_value, shp_obj, le_shpobject); } /* }}} */ /* {{{ proto string shp_destroy_object(resource shp_object) This function should be used to deallocate the resources associated with a SHPObject when it is no longer needed, including those created with shp_create_simple_object(), shp_create_object() and returned from shp_read_object(). */ PHP_FUNCTION(shp_destroy_object) { zval *res; SHPObject *shp_obj; int c_id = -1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { RETURN_FALSE; } if (!res) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got NULL for res"); RETURN_FALSE; } ZEND_FETCH_RESOURCE(shp_obj, SHPObject *, &res, c_id, SHPOBJECT_RES_NAME, le_shpobject); if (!shp_obj) { RETURN_FALSE; } zend_list_delete(Z_LVAL_P(res)); ZVAL_NULL(res); RETURN_TRUE; } /* }}} */ /* {{{ proto string shp_rewind_object(resource shp_handle, resource shp_object) This function will reverse any rings necessary in order to enforce the shapefile restrictions on the required order of inner and outer rings in the Shapefile specification. It returns TRUE if a change is made and FALSE if no change is made. Only polygon objects will be affected though any object may be passed. */ PHP_FUNCTION(shp_rewind_object) { zval *res_handle = NULL, *res_obj = NULL; SHPObject *shp_obj; SHPHandle shph; int c_id = -1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &res_handle, &res_obj) == FAILURE) { RETURN_FALSE; } if (!res_handle || !res_obj) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got NULL for res_handle or res_obj"); RETURN_FALSE; } ZEND_FETCH_RESOURCE(shph, SHPHandle, &res_handle, c_id, SHPHANDLE_RES_NAME, le_shphandle); ZEND_FETCH_RESOURCE(shp_obj, SHPObject *, &res_obj, c_id, SHPOBJECT_RES_NAME, le_shpobject); if (!shp_obj) { RETURN_FALSE; } RETURN_BOOL(SHPRewindObject(shph, shp_obj)); } /* }}} */ /* {{{ proto string shp_write_object(resource shp_handle, resource shp_object) The shp_write_object() call is used to write a single structure, or entity to the shapefile. See the definition of the SHPObject structure for detailed information on fields of a SHPObject. The return value is the entity number of the written shape. */ PHP_FUNCTION(shp_write_object) { zval *res_handle = NULL, *res_obj = NULL; SHPObject *shp_obj; SHPHandle shph; int c_id = -1, entity_n; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlr", &res_handle, &entity_n, &res_obj) == FAILURE) { RETURN_FALSE; } if (!res_handle || !res_obj) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got NULL for res_handle or res_obj"); RETURN_FALSE; } ZEND_FETCH_RESOURCE(shph, SHPHandle, &res_handle, c_id, SHPHANDLE_RES_NAME, le_shphandle); ZEND_FETCH_RESOURCE(shp_obj, SHPObject *, &res_obj, c_id, SHPOBJECT_RES_NAME, le_shpobject); RETURN_LONG(SHPWriteObject(shph, entity_n, shp_obj)); } /* }}} */ /* {{{ shp_functions[] * * Every user visible function must have an entry in shp_functions[]. */ function_entry shp_functions[] = { PHP_FE(shp_open, NULL) PHP_FE(shp_close, NULL) PHP_FE(shp_create, NULL) PHP_FE(shp_read_object, NULL) PHP_FE(shp_destroy_object, NULL) PHP_FE(shp_rewind_object, NULL) PHP_FE(shp_write_object, NULL) {NULL, NULL, NULL} /* Must be the last line in shp_functions[] */ }; /* }}} */ /* {{{ shp_module_entry */ zend_module_entry shp_module_entry = { STANDARD_MODULE_HEADER, "shp", shp_functions, PHP_MINIT(shp), PHP_MSHUTDOWN(shp), NULL, NULL, PHP_MINFO(shp), "0.1", STANDARD_MODULE_PROPERTIES }; /* }}} */ /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(shp) { /* If you have INI entries, uncomment these lines ZEND_INIT_MODULE_GLOBALS(shp, php_shp_init_globals, NULL); REGISTER_INI_ENTRIES(); */ le_shphandle = zend_register_list_destructors_ex(_close_shp_handle, NULL, SHPHANDLE_RES_NAME, module_number); le_shpobject = zend_register_list_destructors_ex(_close_shp_object, NULL, SHPOBJECT_RES_NAME, module_number); REGISTER_LONG_CONSTANT("SHPT_NULL", SHPT_NULL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_POINT", SHPT_POINT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_ARC", SHPT_ARC, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_POLYGON", SHPT_MULTIPOINT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_MULTIPOINT", SHPT_MULTIPOINT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_POINTZ", SHPT_POINTZ, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_ARCZ", SHPT_ARCZ, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_POLYGONZ", SHPT_POLYGONZ, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_MULTIPOINTZ", SHPT_MULTIPOINTZ, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_POINTM", SHPT_POINTM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_ARCM", SHPT_ARCM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_POLYGONM", SHPT_POLYGONM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_MULTIPOINTM", SHPT_MULTIPOINTM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPT_MULTIPATCH", SHPT_MULTIPATCH, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPP_TRISTRIP", SHPP_TRISTRIP, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPP_TRIFAN", SHPP_TRIFAN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPP_OUTERRING", SHPP_OUTERRING, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPP_INNERRING", SHPP_INNERRING, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPP_FIRSTRING", SHPP_FIRSTRING, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SHPP_RING", SHPP_RING, CONST_CS | CONST_PERSISTENT); return SUCCESS; } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(shp) { /* uncomment this line if you have INI entries UNREGISTER_INI_ENTRIES(); */ return SUCCESS; } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ http://cvs.php.net/co.php/pecl/shp/shp.php?r=1.1&p=1 Index: pecl/shp/shp.php +++ pecl/shp/shp.php <? if(!extension_loaded('shp')) { dl('shp.' . PHP_SHLIB_SUFFIX); } $module = 'shp'; $functions = get_extension_funcs($module); echo "Functions available in the test extension:<br>\n"; foreach($functions as $func) { echo $func."<br>\n"; } echo "<br>\n"; $function = 'confirm_' . $module . '_compiled'; if (extension_loaded($module)) { $str = $function($module); } else { $str = "Module $module is not compiled into PHP"; } echo "$str\n"; ?> http://cvs.php.net/co.php/pecl/shp/tests/001.phpt?r=1.1&p=1 Index: pecl/shp/tests/001.phpt +++ pecl/shp/tests/001.phpt --TEST-- Check for shp presence --FILE-- <?php //--SKIPIF-- //< ?php if (!extension_loaded("shp") || !dl('build/shp.so')) print "skip"; ? > dl('/home/andrey/dev/5_1/php-src/ext/shp/modules/shp.so'); error_reporting(E_ALL); echo "Opening a file with rb+: "; $shph = shp_open("/tmp/lakes.shp", "rb"); var_dump($shph); echo "Closing a file: "; $res = shp_close($shph); var_dump($res); echo "Creating a file: "; $shph = shp_create("/tmp/temp.shp", SHPT_POINT); var_dump($shph); echo "Opening again for reading: "; $shph = shp_open("/tmp/lakes.shp", "rb"); var_dump($shph); echo "Reading object 0: "; $shp_obj = shp_read_object($shph, 0); var_dump($shp_obj); echo "Destroying object 0: "; $res = shp_destroy_object($shp_obj); var_dump($res); echo "Reading object 999999: "; $shp_obj2 = shp_read_object($shph, 999999); var_dump($shp_obj2); echo "Extracting object 2 and rewinding: "; $shp_obj = shp_read_object($shph, 2); var_dump($shp_obj); $res = shp_rewind_object($shph, $shp_obj); var_dump($res); echo "Now writing at the end (should generate an error because read only mode): "; $res = shp_write_object($shph, -1, $shp_obj); var_dump($res); shp_close($shph); exec('cp /tmp/lakes.shp /tmp/lakes_for_update.shp'); exec('cp /tmp/lakes.shx /tmp/lakes_for_update.shx'); echo "Opening again for r/w: "; $shph = shp_open("/tmp/lakes_for_update.shp", "rb+"); var_dump($shph); echo "Extracting object 2: "; $shp_obj = shp_read_object($shph, 2); var_dump($shp_obj); echo "Now writing at the end (no error): "; $res = shp_write_object($shph, -1, $shp_obj); var_dump($res); echo "Now closing the file: "; $res = shp_close($shph); var_dump($res); unlink('/tmp/lakes_for_update.shp'); unlink('/tmp/lakes_for_update.shx'); echo "\n-END-\n"; ?> --EXPECTF-- Strict Standards: dl() is deprecated - use extension=%s.so in your php.ini in %s on line %d Opening a file with rb+: resource(%d) of type (SHP Handle) Closing a file: bool(true) Creating a file: resource(%d) of type (SHP Handle) Opening again for reading: resource(%d) of type (SHP Handle) Reading object 0: resource(%d) of type (SHP Object) Destroying object 0: bool(true) Reading object 999999: Warning: shp_read_object(): Reading of object 999999 failed in %s on line %d NULL Extracting object 2 and rewinding: resource(%d) of type (SHP Object) bool(false) Now writing at the end (should generate an error because read only mode): Error in fseek() or fwrite(). int(-1) Opening again for r/w: resource(%d) of type (SHP Handle) Extracting object 2: resource(%d) of type (SHP Object) Now writing at the end (no error): int(3) Now closing the file: bool(true) -END-
« previous php.pecl.cvs (#2958) next »