cvs: pear /PECL/xmgrace CREDITS EXPERIMENTAL Makefile.in README config.m4 php_xmgrace.h xmgrace.c /PECL/xmgrace/doc xmgrace.xml
/PECL/xmgrace/examples xmgrace.php

From: Date: Tue, 14 May 2002 00:42:59 +0000
Subject: cvs: pear /PECL/xmgrace CREDITS EXPERIMENTAL Makefile.in README config.m4 php_xmgrace.h xmgrace.c /PECL/xmgrace/doc xmgrace.xml
/PECL/xmgrace/examples xmgrace.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3810@lists.php.net to get a copy of this message
jmcastagnetto Mon May 13 20:42:59 2002 EDT Added files: /pear/PECL/xmgrace CREDITS EXPERIMENTAL Makefile.in README config.m4 php_xmgrace.h xmgrace.c /pear/PECL/xmgrace/doc xmgrace.xml /pear/PECL/xmgrace/examples xmgrace.php Log: Initial commit of xmgrace extension Works OK on Solaris 8 (Grace 5.1.3), dumps core from command line on RH Linux 6.1 (Grace 5.1.7)

Index: pear/PECL/xmgrace/Makefile.in +++ pear/PECL/xmgrace/Makefile.in # $Id: Makefile.in,v 1.1 2002/05/14 00:42:58 jmcastagnetto Exp $ LTLIBRARY_NAME = libxmgrace.la LTLIBRARY_SOURCES = xmgrace.c LTLIBRARY_SHARED_NAME = xmgrace.la LTLIBRARY_SHARED_LIBADD = $(XMGRACE_SHARED_LIBADD) include $(top_srcdir)/build/dynlib.mk Index: pear/PECL/xmgrace/config.m4 +++ pear/PECL/xmgrace/config.m4 dnl $Id: config.m4,v 1.1 2002/05/14 00:42:58 jmcastagnetto Exp $ dnl config.m4 for extension xmgrace PHP_ARG_WITH(xmgrace, xmgrace install dir, [ --with-xmgrace[=DIR] Include xmgrace support]) if test "$PHP_XMGRACE" != "no"; then SEARCH_PATH="/usr/local/grace /usr/local /usr" SEARCH_FOR="/include/grace_np.h" if test -r $PHP_XMGRACE/; then # path given as parameter XMGRACE_DIR=$PHP_XMGRACE else # search default path list AC_MSG_CHECKING([for xmgrace files in default path]) for i in $SEARCH_PATH ; do if test -r $i/$SEARCH_FOR; then XMGRACE_DIR=$i AC_MSG_RESULT(found in $i) fi done fi if test -z "$XMGRACE_DIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the xmgrace distribution]) fi dnl # --with-xmgrace -> add include path dnl PHP_ADD_INCLUDE($XMGRACE_DIR/include) dnl # --with-xmgrace -> chech for lib and symbol presence LIBNAME=grace_np LIBSYMBOL=GraceOpen PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, [ PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $XMGRACE_DIR/lib, XMGRACE_SHARED_LIBADD) AC_ADD_INCLUDE($XMGRACE_DIR/include) AC_DEFINE(HAVE_XMGRACELIB,1,[ ]) ],[ AC_MSG_ERROR([wrong xmgrace lib version or lib not found]) ],[ -L$XMGRACE_DIR/lib -lm -ldl -I$XMGRACE_DIR/include ]) PHP_EXTENSION(xmgrace, $ext_shared) PHP_SUBST(XMGRACE_SHARED_LIBADD) fi dnl TODO: learn more about m4 and fix the errors when doing phpize dnl aclocal: macro `AC_ADD_LIBPATH' defined in acinclude.m4 but never used dnl aclocal: macro `AC_ADD_LIBRARY' defined in acinclude.m4 but never used dnl aclocal: macro `AC_ADD_LIBRARY_WITH_PATH' defined in acinclude.m4 but never used dnl aclocal: macro `AC_ADD_INCLUDE' defined in acinclude.m4 but never used Index: pear/PECL/xmgrace/php_xmgrace.h +++ pear/PECL/xmgrace/php_xmgrace.h /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | +----------------------------------------------------------------------+ $Id: php_xmgrace.h,v 1.1 2002/05/14 00:42:58 jmcastagnetto Exp $ */ #ifndef PHP_XMGRACE_H #define PHP_XMGRACE_H extern zend_module_entry xmgrace_module_entry; #define phpext_xmgrace_ptr &xmgrace_module_entry #ifdef PHP_WIN32 #define PHP_XMGRACE_API __declspec(dllexport) #else #define PHP_XMGRACE_API #endif #ifdef ZTS #include "TSRM.h" #endif #include <grace_np.h> #define PHP_XMGRACE_VERSION "0.1" #define PHP_XMGRACE_EXE "/usr/local/bin/xmgrace" #define PHP_XMGRACE_BUFSIZE 2048 #define PHP_XMGRACE_HARDCOPY "-hardcopy" PHP_MINIT_FUNCTION(xmgrace); PHP_MSHUTDOWN_FUNCTION(xmgrace); PHP_RINIT_FUNCTION(xmgrace); PHP_RSHUTDOWN_FUNCTION(xmgrace); PHP_MINFO_FUNCTION(xmgrace); PHP_FUNCTION(xmgrace_open); PHP_FUNCTION(xmgrace_open_visual); PHP_FUNCTION(xmgrace_is_open); PHP_FUNCTION(xmgrace_close); PHP_FUNCTION(xmgrace_close_pipe); PHP_FUNCTION(xmgrace_flush); /* PHP_FUNCTION(xmgrace_printf); */ PHP_FUNCTION(xmgrace_command); /* ZEND_BEGIN_MODULE_GLOBALS(xmgrace) int global_value; char *global_string; ZEND_END_MODULE_GLOBALS(xmgrace) */ /* In every utility function you add that needs to use variables in php_xmgrace_globals, call TSRM_FETCH(); after declaring other variables used by that function, or better yet, pass in TSRMLS_CC after the last function argument and declare your utility function with TSRMLS_DC after the last declared argument. Always refer to the globals in your function as XMGRACE_G(variable). You are encouraged to rename these macros something shorter, see examples in any other php module directory. */ #ifdef ZTS #define XMGRACE_G(v) TSRMG(xmgrace_globals_id, zend_xmgrace_globals *, v) #else #define XMGRACE_G(v) (xmgrace_globals.v) #endif #endif /* PHP_XMGRACE_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: t * End: */ Index: pear/PECL/xmgrace/xmgrace.c +++ pear/PECL/xmgrace/xmgrace.c /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | +----------------------------------------------------------------------+ $Id: xmgrace.c,v 1.1 2002/05/14 00:42:58 jmcastagnetto Exp $ */ /* TODO: * - figure out the reason for coredumps at closing * Not sure about the usefulness of the following: * - implement the GraceOpenVA() function * - implement the GracePrintf() function */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_xmgrace.h" /* If you declare any globals in php_xmgrace.h uncomment this: ZEND_DECLARE_MODULE_GLOBALS(xmgrace) */ /* True global resources - no need for thread safety here */ static int le_xmgrace; /* {{{ xmgrace_functions[] * * Every user visible function must have an entry in xmgrace_functions[]. */ function_entry xmgrace_functions[] = { PHP_FE(xmgrace_open, NULL) PHP_FE(xmgrace_open_visual, NULL) /* PHP_FE(xmgrace_open, NULL) # not sure if needed? */ PHP_FE(xmgrace_is_open, NULL) PHP_FE(xmgrace_close, NULL) PHP_FE(xmgrace_close_pipe, NULL) PHP_FE(xmgrace_flush, NULL) /* PHP_FE(xmgrace_printf, NULL) # not sure if needed */ PHP_FE(xmgrace_command, NULL) {NULL, NULL, NULL} /* Must be the last line in xmgrace_functions[] */ }; /* }}} */ /* {{{ xmgrace_module_entry */ zend_module_entry xmgrace_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "xmgrace", xmgrace_functions, PHP_MINIT(xmgrace), PHP_MSHUTDOWN(xmgrace), NULL, NULL, PHP_MINFO(xmgrace), #if ZEND_MODULE_API_NO >= 20010901 PHP_XMGRACE_VERSION, #endif STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_XMGRACE ZEND_GET_MODULE(xmgrace) #endif /* {{{ PHP_INI */ /* Remove comments and fill if you need to have entries in php.ini PHP_INI_BEGIN() STD_PHP_INI_ENTRY("xmgrace.global_value", "42", PHP_INI_ALL, OnUpdateInt, global_value, zend_xmgrace_globals, xmgrace_globals) STD_PHP_INI_ENTRY("xmgrace.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_xmgrace_globals, xmgrace_globals) PHP_INI_END() */ /* }}} */ /* {{{ php_xmgrace_init_globals */ /* Uncomment this function if you have INI entries static void php_xmgrace_init_globals(zend_xmgrace_globals *xmgrace_globals) { xmgrace_globals->global_value = 0; xmgrace_globals->global_string = NULL; } */ /* }}} */ /* to handle errors in xmgrace extension */ void _php_xmgrace_error_handler(const char *msg) { php_error(E_ERROR, "Fatal error in module xmgrace: %s", msg); } /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(xmgrace) { /* If you have INI entries, uncomment these lines ZEND_INIT_MODULE_GLOBALS(xmgrace, php_xmgrace_init_globals, NULL); REGISTER_INI_ENTRIES(); */ GraceRegisterErrorFunction(_php_xmgrace_error_handler); return SUCCESS; } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(xmgrace) { /* uncomment this line if you have INI entries UNREGISTER_INI_ENTRIES(); */ return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(xmgrace) { php_info_print_table_start(); php_info_print_table_header(2, "xmgrace support", "enabled"); php_info_print_table_end(); /* Remove comments if you have entries in php.ini DISPLAY_INI_ENTRIES(); */ } /* }}} */ int _php_xmgrace_open_va(const char *type) { return GraceOpenVA(PHP_XMGRACE_EXE, PHP_XMGRACE_BUFSIZE, PHP_XMGRACE_HARDCOPY, NULL); } PHP_FUNCTION(xmgrace_open) { int argc = ZEND_NUM_ARGS(); long buffer; long retval; if (argc > 1) { WRONG_PARAM_COUNT; } if (zend_parse_parameters(argc TSRMLS_CC, "|l", &buffer) == FAILURE) { RETURN_FALSE; } if (argc == 0) { retval = GraceOpenVA(PHP_XMGRACE_EXE, PHP_XMGRACE_BUFSIZE, PHP_XMGRACE_HARDCOPY, NULL); } else { retval = GraceOpenVA(PHP_XMGRACE_EXE, (int) buffer, PHP_XMGRACE_HARDCOPY, NULL); } if (retval == -1) { RETURN_FALSE; } else { RETURN_TRUE; } } /* {{{ proto bool xmgrace_open_visual([int bufsize]) * Launches an xmgrace instance and opens a channel using bufsize * bytes for data buffering. If no paramater is passed a buffer * of 2048 bytes will be used. */ PHP_FUNCTION(xmgrace_open_visual) { int argc = ZEND_NUM_ARGS(); long buffer; long retval; if (argc > 1) { WRONG_PARAM_COUNT; } if (zend_parse_parameters(argc TSRMLS_CC, "|l", &buffer) == FAILURE) { RETURN_FALSE; } if (argc == 0) { retval = GraceOpen(PHP_XMGRACE_BUFSIZE); } else { retval = GraceOpen((int) buffer); } if (retval == -1) { RETURN_FALSE; } else { RETURN_TRUE; } } /* }}} */ /* {{{ proto bool xmgrace_is_open(void) * Returns true if a connection to xmgrace is open, false otherwise */ PHP_FUNCTION(xmgrace_is_open) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } if (GraceIsOpen()) { RETURN_TRUE; } else { RETURN_FALSE; } } /* }}} */ /* {{{ proto bool xmgrace_close(void) * Closes a connection to xmgrace and exits the xmgrace process. * Returns true on success, false otherwise */ PHP_FUNCTION(xmgrace_close) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } if (GraceClose() == -1) { RETURN_FALSE; } else { RETURN_TRUE; } } /* }}} */ /* {{{ proto bool xmgrace_close_pipe(void) * Closes a connection to xmgrace, leaving the xmgrace process running * Returns true on success, false otherwise */ PHP_FUNCTION(xmgrace_close_pipe) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } if (GraceClosePipe() == -1) { RETURN_FALSE; } else { RETURN_TRUE; } } /* }}} */ /* {{{ proto bool xmgrace_flush(void) * Flush all the data remaining in the buffer */ PHP_FUNCTION(xmgrace_flush) { if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } if (GraceFlush() == -1) { RETURN_FALSE; } else { RETURN_TRUE; } } /* }}} */ /* {{{ proto bool xmgrace_command(string cmd) * Sends formatted command to xmgrace. */ PHP_FUNCTION(xmgrace_command) { int argc = ZEND_NUM_ARGS(); char *cmd; int cmd_len; if (argc != 1) { WRONG_PARAM_COUNT; } if (zend_parse_parameters(argc TSRMLS_CC, "s", &cmd, &cmd_len) == FAILURE) { php_error(E_ERROR, "Fatal Error: cannot parse parameters"); } else { if (GraceCommand(cmd) == -1) { RETURN_FALSE; } else { RETURN_TRUE; } } } /* }}} */ /* TODO: implement the GracePrintf() function? */ /* * 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 */ Index: pear/PECL/xmgrace/doc/xmgrace.xml +++ pear/PECL/xmgrace/doc/xmgrace.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <reference id="ref.xmgrace"> <title> functions</title> <titleabbrev></titleabbrev> <partintro> &warn.experimental; <para> </para> </partintro> <refentry id="function.xmgrace-open-visual"> <refnamediv> <refname>xmgrace_open_visual</refname> <refpurpose>Launches an xmgrace instance and opens a channel using bufsize bytes for data buffering. If no paramater is passed a buffer of 2048 bytes will be used.</refpurpose> </refnamediv> <refsect1> <title>Description</title> <funcsynopsis> <funcprototype> <funcdef>bool <function>xmgrace_open_visual</function></funcdef> <paramdef>int <parameter><optional>bufsize</optional></parameter> </paramdef> </funcprototype> </funcsynopsis> &warn.experimental.func; <para> &warn.undocumented.func; </para> </refsect1> </refentry> <refentry id="function.xmgrace-open"> <refnamediv> <refname>xmgrace_open</refname> <refpurpose>creates a xmgrace instance and opens a channel using bufsize bytes for data buffering. If no paramater is passed a buffer of 2048 bytes will be used.</refpurpose> </refnamediv> <refsect1> <title>Description</title> <funcsynopsis> <funcprototype> <funcdef>bool <function>xmgrace_open</function></funcdef> <paramdef>int <parameter><optional>bufsize</optional></parameter> </paramdef> </funcprototype> </funcsynopsis> &warn.experimental.func; <para> &warn.undocumented.func; </para> </refsect1> </refentry> <refentry id="function.xmgrace-is-open"> <refnamediv> <refname>xmgrace_is_open</refname> <refpurpose>Returns true if a connection to xmgrace is open, false otherwise</refpurpose> </refnamediv> <refsect1> <title>Description</title> <funcsynopsis> <funcprototype> <funcdef>bool <function>xmgrace_is_open</function></funcdef> <void/> </funcprototype> </funcsynopsis> &warn.experimental.func; <para> &warn.undocumented.func; </para> </refsect1> </refentry> <refentry id="function.xmgrace-close"> <refnamediv> <refname>xmgrace_close</refname> <refpurpose>Closes a connection to xmgrace and exits the xmgrace process. Returns true on success, false otherwise.</refpurpose> </refnamediv> <refsect1> <title>Description</title> <funcsynopsis> <funcprototype> <funcdef>bool <function>xmgrace_close</function></funcdef> <void/> </funcprototype> </funcsynopsis> &warn.experimental.func; <para> &warn.undocumented.func; </para> </refsect1> </refentry> <refentry id="function.xmgrace-close-pipe"> <refnamediv> <refname>xmgrace_close_pipe</refname> <refpurpose>Closes a connection to xmgrace, leaving the xmgrace process running. Returns true on success, false otherwise.</refpurpose> </refnamediv> <refsect1> <title>Description</title> <funcsynopsis> <funcprototype> <funcdef>bool <function>xmgrace_close_pipe</function></funcdef> <void/> </funcprototype> </funcsynopsis> &warn.experimental.func; <para> &warn.undocumented.func; </para> </refsect1> </refentry> <refentry id="function.xmgrace-flush"> <refnamediv> <refname>xmgrace_flush</refname> <refpurpose>Flush all the data remaining in the buffer.</refpurpose> </refnamediv> <refsect1> <title>Description</title> <funcsynopsis> <funcprototype> <funcdef>bool <function>xmgrace_flush</function></funcdef> <void/> </funcprototype> </funcsynopsis> &warn.experimental.func; <para> &warn.undocumented.func; </para> </refsect1> </refentry> <refentry id="function.xmgrace-command"> <refnamediv> <refname>xmgrace_command</refname> <refpurpose>Sends formatted command to xmgrace.</refpurpose> </refnamediv> <refsect1> <title>Description</title> <funcsynopsis> <funcprototype> <funcdef>bool <function>xmgrace_command</function></funcdef> <paramdef>string <parameter>cmd</parameter></paramdef> </funcprototype> </funcsynopsis> &warn.experimental.func; <para> &warn.undocumented.func; </para> </refsect1> </refentry> </reference> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> Index: pear/PECL/xmgrace/examples/xmgrace.php +++ pear/PECL/xmgrace/examples/xmgrace.php <?php /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | +----------------------------------------------------------------------+ $Id: xmgrace.php,v 1.1 2002/05/14 00:42:59 jmcastagnetto Exp $ */ // To test the xmgrace extension // WARNING: it usually coredumps php $module = 'xmgrace'; if(!extension_loaded($module)) dl($module.'.so'); /* $functions = get_extension_funcs($module); echo "Functions available in the $module extension:\n"; foreach($functions as $func) echo $func."\n"; */ function exec_commands($commands) { foreach ($commands as $cmd) xmgrace_command($cmd); } $commands = array ( "world xmax 100", "world ymax 10000", "xaxis tick major 20", "xaxis tick minor 10", "yaxis tick major 2000", "yaxis tick minor 1000", "s0 on", "s0 symbol 1", "s0 symbol size 0.3", "s0 symbol fill pattern 1", "s1 on", "s1 symbol 2", "s1 symbol size 0.3", "s1 symbol fill pattern 1" ); echo "Lets generate a non-visual output first\n"; if (xmgrace_open()) { /* Send some initialization commands to Grace */ /* xmgrace_command("hardcopy device \"PNG\""); xmgrace_command("device \"PNG\" op \"interlaced:off\""); xmgrace_command("device \"PNG\" op \"transparent:off\""); xmgrace_command("device \"PNG\" op \"compression:9\""); xmgrace_command("print to \"sample.png\""); */ xmgrace_command("hardcopy device \"EPS\""); xmgrace_command("print to \"sample.eps\""); xmgrace_command("title font 3"); xmgrace_command("title size 2"); xmgrace_command("title \"Non-visual generation\""); xmgrace_command("subtitle \"Using experimental xmgrace module for PHP\""); xmgrace_command("timestamp on"); exec_commands($commands); /* generate some sample data */ for ($i = 1; $i <= 100 && xmgrace_is_open(); $i++) { xmgrace_command (sprintf("g0.s0 point %d, %d", $i, 100*$i)); xmgrace_command (sprintf("g0.s1 point %d, %d", $i, $i * $i)); } xmgrace_command("print"); xmgrace_close(); } echo "Now let's use a visual output\n"; if (xmgrace_open_visual()) { exec_commands($commands); xmgrace_command("title font 1"); xmgrace_command("title color 2"); xmgrace_command("title \"Visual generation\""); xmgrace_command("subtitle \"Using experimental xmgrace module for PHP\""); xmgrace_command("timestamp on"); /* generate some sample data */ for ($i = 1; $i <= 100 && xmgrace_is_open(); $i++) { xmgrace_command (sprintf("g0.s0 point %d, %d", $i, 100*$i)); xmgrace_command (sprintf("g0.s1 point %d, %d", $i, $i * $i)); /* Update the Grace display after every ten steps */ if ($i % 10 == 0) xmgrace_command ("redraw"); } xmgrace_command ("saveall \"sample.agr\""); xmgrace_close_pipe(); } ?>
« previous php.pear.cvs (#3810) next »