From 9d468a33c4e8894d40b42d3bda61ac2e7630491d Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Wed, 22 Nov 2000 01:00:44 +0000 Subject: [PATCH] an experimental extension providing the C ctype function family --- ext/ctype/Makefile.in | 8 + ext/ctype/config.m4 | 26 +++ ext/ctype/ctype.c | 385 +++++++++++++++++++++++++++++++++++++++ ext/ctype/ctype.xml | 245 +++++++++++++++++++++++++ ext/ctype/php_ctype.h | 94 ++++++++++ ext/ctype/tests/001.phpt | 41 +++++ ext/ctype/tests/002.phpt | 43 +++++ 7 files changed, 842 insertions(+) create mode 100644 ext/ctype/Makefile.in create mode 100644 ext/ctype/config.m4 create mode 100644 ext/ctype/ctype.c create mode 100644 ext/ctype/ctype.xml create mode 100644 ext/ctype/php_ctype.h create mode 100644 ext/ctype/tests/001.phpt create mode 100644 ext/ctype/tests/002.phpt diff --git a/ext/ctype/Makefile.in b/ext/ctype/Makefile.in new file mode 100644 index 0000000000..940398455b --- /dev/null +++ b/ext/ctype/Makefile.in @@ -0,0 +1,8 @@ +# $Id$ + +LTLIBRARY_NAME = libctype.la +LTLIBRARY_SOURCES = ctype.c +LTLIBRARY_SHARED_NAME = ctype.la +LTLIBRARY_SHARED_LIBADD = $(CTYPE_SHARED_LIBADD) + +include $(top_srcdir)/build/dynlib.mk diff --git a/ext/ctype/config.m4 b/ext/ctype/config.m4 new file mode 100644 index 0000000000..9bcdcdb2c6 --- /dev/null +++ b/ext/ctype/config.m4 @@ -0,0 +1,26 @@ +dnl $Id$ +dnl config.m4 for extension ctype +dnl don't forget to call PHP_EXTENSION(ctype) + +dnl Comments in this file start with the string 'dnl'. +dnl Remove where necessary. This file will not work +dnl without editing. + +dnl If your extension references something external, use with: + +dnl PHP_ARG_WITH(ctype, for ctype support, +dnl Make sure that the comment is aligned: +dnl [ --with-ctype Include ctype support]) + +dnl Otherwise use enable: + +PHP_ARG_ENABLE(ctype, whether to enable ctype support,[ --enable-ctype Enable ctype support]) + +if test "$PHP_CTYPE" != "no"; then + dnl If you will not be testing anything external, like existence of + dnl headers, libraries or functions in them, just uncomment the + dnl following line and you are ready to go. + AC_DEFINE(HAVE_CTYPE, 1, [ ]) + dnl Write more examples of tests here... + PHP_EXTENSION(ctype, $ext_shared) +fi diff --git a/ext/ctype/ctype.c b/ext/ctype/ctype.c new file mode 100644 index 0000000000..32e04eaed8 --- /dev/null +++ b/ext/ctype/ctype.c @@ -0,0 +1,385 @@ +/* + +----------------------------------------------------------------------+ + | PHP version 4.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997, 1998, 1999, 2000 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. | + +----------------------------------------------------------------------+ + | Authors: Hartmut Holzgraefe | + | | + +----------------------------------------------------------------------+ + */ + +#include "php.h" +#include "php_ini.h" +#include "php_ctype.h" +#include "SAPI.h" +#include "ext/standard/info.h" + +#include + +/* You should tweak config.m4 so this symbol (or some else suitable) + gets defined. +*/ +#if HAVE_CTYPE + +/* If you declare any globals in php_ctype.h uncomment this: +ZEND_DECLARE_MODULE_GLOBALS(ctype) +*/ + +/* True global resources - no need for thread safety here */ +static int le_ctype; + +/* Every user visible function must have an entry in ctype_functions[]. +*/ +function_entry ctype_functions[] = { + PHP_FE(confirm_ctype_compiled, NULL) /* For testing, remove later. */ + PHP_FE(isalnum, NULL) + PHP_FE(isalpha, NULL) + PHP_FE(iscntrl, NULL) + PHP_FE(isdigit, NULL) + PHP_FE(islower, NULL) + PHP_FE(isgraph, NULL) + PHP_FE(isprint, NULL) + PHP_FE(ispunct, NULL) + PHP_FE(isspace, NULL) + PHP_FE(isupper, NULL) + PHP_FE(isxdigit, NULL) + {NULL, NULL, NULL} /* Must be the last line in ctype_functions[] */ +}; + +zend_module_entry ctype_module_entry = { + "ctype", + ctype_functions, + PHP_MINIT(ctype), + PHP_MSHUTDOWN(ctype), + PHP_RINIT(ctype), /* Replace with NULL if there's nothing to do at request start */ + PHP_RSHUTDOWN(ctype), /* Replace with NULL if there's nothing to do at request end */ + PHP_MINFO(ctype), + STANDARD_MODULE_PROPERTIES +}; + +#ifdef COMPILE_DL_CTYPE +ZEND_GET_MODULE(ctype) +#endif + +/* Remove comments and fill if you need to have entries in php.ini +PHP_INI_BEGIN() +PHP_INI_END() +*/ + +#ifndef PHP_EXPERIMENTAL +#define PHP_EXPERIMENTAL(x,y) +#endif + + +PHP_MINIT_FUNCTION(ctype) +{ +/* Remove comments if you have entries in php.ini + REGISTER_INI_ENTRIES(); +*/ + + return SUCCESS; +} + +PHP_MSHUTDOWN_FUNCTION(ctype) +{ +/* Remove comments if you have entries in php.ini + UNREGISTER_INI_ENTRIES(); +*/ + return SUCCESS; +} + +/* Remove if there's nothing to do at request start */ +PHP_RINIT_FUNCTION(ctype) +{ + return SUCCESS; +} + +/* Remove if there's nothing to do at request end */ +PHP_RSHUTDOWN_FUNCTION(ctype) +{ + return SUCCESS; +} + +PHP_MINFO_FUNCTION(ctype) +{ + ELS_FETCH(); + SLS_FETCH(); + + php_info_print_table_start(); + php_info_print_table_row(2, "ctype functions", "enabled (experimental)"); + php_info_print_table_end(); + + /* Remove comments if you have entries in php.ini + DISPLAY_INI_ENTRIES(); + */ +} + +/* Remove the following function when you have succesfully modified config.m4 + so that your module can be compiled into PHP, it exists only for testing + purposes. */ + +/* Every user-visible function in PHP should document itself in the source */ +/* {{{ proto string confirm_ctype_compiled(string arg) + Return a string to confirm that the module is compiled in */ +PHP_FUNCTION(confirm_ctype_compiled) +{ + zval **arg; + int len; + char string[256]; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_string_ex(arg); + + len = sprintf(string, "Congratulations, you have successfully modified ext/ctype/config.m4, module %s is compiled into PHP", Z_STRVAL_PP(arg)); + RETURN_STRINGL(string, len, 1); +} +/* }}} */ +/* The previous line is meant for emacs, so it can correctly fold and unfold + functions in source code. See the corresponding marks just before function + definition, where the functions purpose is also documented. Please follow + this convention for the convenience of others editing your code. +*/ + +static int ctype(int (*iswhat)(int),zval **c) +{ + switch ((*c)->type) { + case IS_LONG: + return iswhat((*c)->value.lval); + case IS_STRING: + { + char *p; + int n,len; + convert_to_string_ex(c); + p=(*c)->value.str.val; + len = (*c)->value.str.len; + for(n=0;n + Character type functions + ctype + + + + These functions check whether a character or string + falls into a certain character class according to the i + current locale. + + + When called with an integer argument theese functions + behave exactly like their C counterparts. + + + When called with a string argument they will check + every character in the string and will only return + true if every character in the string matches the + requested criteria. + + + Passing anything else but a string or integer will + return false immediately. + + + + + + + isalnum + Check for alphanumeric character(s) + + + Description + + + bool isalnum + string c + + + + See also setlocale. + + + + + + + isalpha + + + + Description + + + bool isalpha + string c + + + + + + + + + + iscntrl + + + + Description + + + bool iscntrl + string c + + + + + + + + + + isdigit + + + + Description + + + bool isdigit + string c + + + + + + + + + + islower + + + + Description + + + bool islower + string c + + + + + + + + + + isgraph + + + + Description + + + bool isgraph + string c + + + + + + + + + + isprint + + + + Description + + + bool isprint + string c + + + + + + + + + + ispunct + + + + Description + + + bool ispunct + string c + + + + + + + + + + isspace + + + + Description + + + bool isspace + string c + + + + + + + + + + isupper + + + + Description + + + bool isupper + string c + + + + + + + + + + isxdigit + + + + Description + + + bool isxdigit + string c + + + + + + + + + + + diff --git a/ext/ctype/php_ctype.h b/ext/ctype/php_ctype.h new file mode 100644 index 0000000000..2702dd021d --- /dev/null +++ b/ext/ctype/php_ctype.h @@ -0,0 +1,94 @@ +/* + +----------------------------------------------------------------------+ + | PHP version 4.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997, 1998, 1999, 2000 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. | + +----------------------------------------------------------------------+ + | Authors: | + | | + +----------------------------------------------------------------------+ + */ + +#ifndef PHP_CTYPE_H +#define PHP_CTYPE_H + +/* You should tweak config.m4 so this symbol (or some else suitable) + gets defined. +*/ +#if HAVE_CTYPE + +extern zend_module_entry ctype_module_entry; +#define phpext_ctype_ptr &ctype_module_entry + +#ifdef PHP_WIN32 +#define PHP_CTYPE_API __declspec(dllexport) +#else +#define PHP_CTYPE_API +#endif + +PHP_MINIT_FUNCTION(ctype); +PHP_MSHUTDOWN_FUNCTION(ctype); +PHP_RINIT_FUNCTION(ctype); +PHP_RSHUTDOWN_FUNCTION(ctype); +PHP_MINFO_FUNCTION(ctype); + +PHP_FUNCTION(confirm_ctype_compiled); /* For testing, remove later. */ +PHP_FUNCTION(isalnum); +PHP_FUNCTION(isalpha); +PHP_FUNCTION(iscntrl); +PHP_FUNCTION(isdigit); +PHP_FUNCTION(islower); +PHP_FUNCTION(isgraph); +PHP_FUNCTION(isprint); +PHP_FUNCTION(ispunct); +PHP_FUNCTION(isspace); +PHP_FUNCTION(isupper); +PHP_FUNCTION(isxdigit); + +/* + Declare any global variables you may need between the BEGIN + and END macros here: + +ZEND_BEGIN_MODULE_GLOBALS(ctype) + int global_variable; +ZEND_END_MODULE_GLOBALS(ctype) +*/ + +/* In every function that needs to use variables in php_ctype_globals, + do call CTYPELS_FETCH(); after declaring other variables used by + that function, and always refer to them as CTYPEG(variable). + You are encouraged to rename these macros something shorter, see + examples in any other php module directory. +*/ + +#ifdef ZTS +#define CTYPEG(v) (ctype_globals->v) +#define CTYPELS_FETCH() php_ctype_globals *ctype_globals = ts_resource(ctype_globals_id) +#else +#define CTYPEG(v) (ctype_globals.v) +#define CTYPELS_FETCH() +#endif + +#else + +#define phpext_ctype_ptr NULL + +#endif + +#endif /* PHP_CTYPE_H */ + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/ext/ctype/tests/001.phpt b/ext/ctype/tests/001.phpt new file mode 100644 index 0000000000..53ae99b56a --- /dev/null +++ b/ext/ctype/tests/001.phpt @@ -0,0 +1,41 @@ +--TEST-- +ctype on integers +--SKIPIF-- + +--POST-- +--GET-- +--FILE-- + +--EXPECT-- +islower 26 +isupper 26 +isalpha 52 +isdigit 10 +isalnum 62 +iscntrl 33 +isgraph 94 +isprint 95 +ispunct 32 +isspace 6 +isxdigit 22 diff --git a/ext/ctype/tests/002.phpt b/ext/ctype/tests/002.phpt new file mode 100644 index 0000000000..e5a6062d11 --- /dev/null +++ b/ext/ctype/tests/002.phpt @@ -0,0 +1,43 @@ +--TEST-- +ctype on strings +--SKIPIF-- + +--POST-- +--GET-- +--FILE-- + +--EXPECT-- +islower 26 0 +isupper 26 0 +isalpha 52 0 +isdigit 10 0 +isalnum 62 0 +iscntrl 33 0 +isgraph 94 94 +isprint 95 95 +ispunct 32 0 +isspace 6 0 +isxdigit 22 0 -- 2.50.1