├── EXPERIMENTAL ├── CREDITS ├── config.w32 ├── pinyin.h ├── .gitignore ├── tests └── 001.phpt ├── utf8vector.h ├── hz2py.php ├── README.md ├── pinyin.c ├── config.m4 ├── php_hz2py.h ├── utf8vector.c ├── hz2py.c └── LICENSE /EXPERIMENTAL: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | hz2py 2 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | // $Id$ 2 | // vim:ft=javascript 3 | 4 | // If your extension references something external, use ARG_WITH 5 | // ARG_WITH("hz2py", "for hz2py support", "no"); 6 | 7 | // Otherwise, use ARG_ENABLE 8 | // ARG_ENABLE("hz2py", "enable hz2py support", "no"); 9 | 10 | if (PHP_HZ2PY != "no") { 11 | EXTENSION("hz2py", "hz2py.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /pinyin.h: -------------------------------------------------------------------------------- 1 | #ifndef _PINYIN 2 | #define _PINYIN 3 | 4 | #include 5 | 6 | //判断unicode是否为汉字 7 | #define pinyin_ishanzi(uni) ((uni) > 19967 && (uni) < 40870) 8 | //是否为字母 9 | #define pinyin_isabc(uni) (((uni) > 64 && (uni) < 91) || ((uni) > 96 && (uni) < 123)) 10 | //转小写 11 | #define pinyin_lowercase(uni) (((uni > 64) && (uni) < 91)? (uni) + 32 : (uni)) 12 | 13 | int pinyin_get_tones_by_unicode(wchar_t uni, char **tones_out); 14 | int pinyin_get_pinyins_by_unicode(wchar_t uni, const char ***pinyins); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | *.lo 3 | *.la 4 | .libs 5 | acinclude.m4 6 | aclocal.m4 7 | autom4te.cache 8 | build 9 | config.guess 10 | config.h 11 | config.h.in 12 | config.log 13 | config.nice 14 | config.status 15 | config.sub 16 | configure 17 | configure.in 18 | include 19 | install-sh 20 | libtool 21 | ltmain.sh 22 | Makefile 23 | Makefile.fragments 24 | Makefile.global 25 | Makefile.objects 26 | missing 27 | mkinstalldirs 28 | modules 29 | run-tests.php 30 | tests/*/*.diff 31 | tests/*/*.out 32 | tests/*/*.php 33 | tests/*/*.exp 34 | tests/*/*.log 35 | tests/*/*.sh 36 | *.swp 37 | -------------------------------------------------------------------------------- /tests/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for hz2py presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 20 | --EXPECT-- 21 | hz2py extension is available 22 | -------------------------------------------------------------------------------- /utf8vector.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTF8VECTOR 2 | #define _UTF8VECTOR 3 | 4 | #include 5 | 6 | typedef struct _utf8vector *utf8vector; 7 | 8 | struct _utf8vector { 9 | const char *utf8_str; 10 | unsigned int length; 11 | unsigned int index; 12 | }; 13 | 14 | utf8vector utf8vector_create(const char *utf8, int string_length); 15 | void utf8vector_reset(utf8vector vector); 16 | wchar_t utf8vector_next_unichar_with_raw(utf8vector vector, const char **raw, int *raw_length); 17 | wchar_t utf8vector_next_unichar(utf8vector vector); 18 | int utf8vector_uni_count(utf8vector vector); 19 | void utf8vector_free(utf8vector vector); 20 | #endif 21 | -------------------------------------------------------------------------------- /hz2py.php: -------------------------------------------------------------------------------- 1 | "; 3 | 4 | if(!extension_loaded('hz2py')) { 5 | dl('hz2py.' . PHP_SHLIB_SUFFIX); 6 | } 7 | $module = 'hz2py'; 8 | $functions = get_extension_funcs($module); 9 | echo "Functions available in the test extension:$br\n"; 10 | foreach ($functions as $func) 11 | { 12 | echo $func."$br\n"; 13 | } 14 | 15 | $src = '一个重庆人,走在银行门前的人行道上.'; 16 | //$result; 17 | //$polyphone = array(); 18 | $ret = hz2py_jp($src, $result, $polyphone); 19 | 20 | var_dump($result); 21 | var_dump($polyphone); 22 | var_dump($ret); 23 | 24 | $ret = hz2py_qp($src, $result, $polyphone); 25 | 26 | var_dump($result); 27 | var_dump($polyphone); 28 | var_dump($ret); 29 | 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hz2py 2 | 汉字转拼音的 php 扩展,支持转全拼/简拼,多音字 3 | 4 | # 例子 5 | 6 | ```php 7 | $src = '一个重庆人,走在银行门前的人行道上.'; 8 | //$result; 9 | //$polyphone = array(); 10 | 11 | $ret = hz2py_jp($src, $result, $polyphone); 12 | var_dump($result); 13 | var_dump($polyphone); 14 | var_dump($ret); 15 | 16 | $ret = hz2py_qp($src, $result, $polyphone); 17 | var_dump($result); 18 | var_dump($polyphone); 19 | var_dump($ret); 20 | ``` 21 | 22 | 输出结果 23 | 24 | ```json 25 | string(18) "ygzqr,zzyhmqdrhds." 26 | array(2) { 27 | ["重"]=> 28 | array(2) { 29 | [0]=> 30 | string(1) "z" 31 | [1]=> 32 | string(1) "c" 33 | } 34 | ["行"]=> 35 | array(2) { 36 | [0]=> 37 | string(1) "h" 38 | [1]=> 39 | string(1) "x" 40 | } 41 | } 42 | int(0) 43 | string(55) "yigezhongqingren,zouzaiyinhangmenqiandirenhangdaoshang." 44 | array(3) { 45 | ["重"]=> 46 | array(2) { 47 | [0]=> 48 | string(5) "zhong" 49 | [1]=> 50 | string(5) "chong" 51 | } 52 | ["行"]=> 53 | array(2) { 54 | [0]=> 55 | string(4) "hang" 56 | [1]=> 57 | string(4) "xing" 58 | } 59 | ["的"]=> 60 | array(3) { 61 | [0]=> 62 | string(2) "di" 63 | [1]=> 64 | string(2) "di" 65 | [2]=> 66 | string(2) "de" 67 | } 68 | } 69 | int(0) 70 | ``` 71 | -------------------------------------------------------------------------------- /pinyin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 | * Author : emptyhua@gmail.com 4 | * Create : 2011.9.26 5 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "pinyin.h" 12 | #include "pinyin_data.h" 13 | 14 | int pinyin_get_tones_by_unicode(wchar_t uni, char **tones_out) 15 | { 16 | if (!pinyin_ishanzi(uni)) 17 | { 18 | *tones_out = NULL; 19 | return 0; 20 | } 21 | 22 | int count = pinyin_count[uni - 19968]; 23 | 24 | if (count == 0) 25 | { 26 | *tones_out = NULL; 27 | return 0; 28 | } 29 | 30 | char *tones = NULL; 31 | tones = strdup(pinyin_tones[uni - 19968]); 32 | 33 | *tones_out = tones; 34 | return count; 35 | 36 | } 37 | 38 | int pinyin_get_pinyins_by_unicode(wchar_t uni, const char ***pinyins_out) 39 | { 40 | if (!pinyin_ishanzi(uni)) 41 | { 42 | *pinyins_out = NULL; 43 | return 0; 44 | } 45 | 46 | 47 | int count = pinyin_count[uni - 19968]; 48 | 49 | if (count == 0) 50 | { 51 | *pinyins_out = NULL; 52 | return 0; 53 | } 54 | 55 | /* 56 | fprintf(stderr, "wchar_t uni: %u\n", uni); 57 | fprintf(stderr, "%s: count: %d\n", __func__, count); 58 | */ 59 | 60 | const char *indexs = pinyin_index[uni - 19968]; 61 | const char **pinyins = (const char **)malloc(sizeof(const char *) * count); 62 | int i = 0; 63 | for (i = 0; i < count; i++) 64 | { 65 | int start = i * 2; 66 | pinyins[i] = pinyin_all_pinyin[(unsigned char)indexs[start] + (unsigned char)indexs[start + 1]]; 67 | } 68 | 69 | *pinyins_out = pinyins; 70 | return count; 71 | } 72 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | dnl config.m4 for extension hz2py 3 | 4 | dnl Comments in this file start with the string 'dnl'. 5 | dnl Remove where necessary. This file will not work 6 | dnl without editing. 7 | 8 | dnl If your extension references something external, use with: 9 | 10 | dnl PHP_ARG_WITH(hz2py, for hz2py support, 11 | dnl Make sure that the comment is aligned: 12 | dnl [ --with-hz2py Include hz2py support]) 13 | 14 | dnl Otherwise use enable: 15 | 16 | PHP_ARG_ENABLE(hz2py, whether to enable hz2py support, 17 | [ --enable-hz2py Enable hz2py support]) 18 | 19 | if test "$PHP_HZ2PY" != "no"; then 20 | dnl Write more examples of tests here... 21 | 22 | dnl # --with-hz2py -> check with-path 23 | dnl SEARCH_PATH="/usr/local /usr" # you might want to change this 24 | dnl SEARCH_FOR="/include/hz2py.h" # you most likely want to change this 25 | dnl if test -r $PHP_HZ2PY/$SEARCH_FOR; then # path given as parameter 26 | dnl HZ2PY_DIR=$PHP_HZ2PY 27 | dnl else # search default path list 28 | dnl AC_MSG_CHECKING([for hz2py files in default path]) 29 | dnl for i in $SEARCH_PATH ; do 30 | dnl if test -r $i/$SEARCH_FOR; then 31 | dnl HZ2PY_DIR=$i 32 | dnl AC_MSG_RESULT(found in $i) 33 | dnl fi 34 | dnl done 35 | dnl fi 36 | dnl 37 | dnl if test -z "$HZ2PY_DIR"; then 38 | dnl AC_MSG_RESULT([not found]) 39 | dnl AC_MSG_ERROR([Please reinstall the hz2py distribution]) 40 | dnl fi 41 | 42 | dnl # --with-hz2py -> add include path 43 | dnl PHP_ADD_INCLUDE($HZ2PY_DIR/include) 44 | 45 | dnl # --with-hz2py -> check for lib and symbol presence 46 | dnl LIBNAME=hz2py # you may want to change this 47 | dnl LIBSYMBOL=hz2py # you most likely want to change this 48 | 49 | dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 50 | dnl [ 51 | dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $HZ2PY_DIR/$PHP_LIBDIR, HZ2PY_SHARED_LIBADD) 52 | dnl AC_DEFINE(HAVE_HZ2PYLIB,1,[ ]) 53 | dnl ],[ 54 | dnl AC_MSG_ERROR([wrong hz2py lib version or lib not found]) 55 | dnl ],[ 56 | dnl -L$HZ2PY_DIR/$PHP_LIBDIR -lm 57 | dnl ]) 58 | dnl 59 | dnl PHP_SUBST(HZ2PY_SHARED_LIBADD) 60 | 61 | PHP_NEW_EXTENSION(hz2py, hz2py.c utf8vector.c pinyin.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) 62 | fi 63 | -------------------------------------------------------------------------------- /php_hz2py.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2014 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifndef PHP_HZ2PY_H 22 | #define PHP_HZ2PY_H 23 | 24 | extern zend_module_entry hz2py_module_entry; 25 | #define phpext_hz2py_ptr &hz2py_module_entry 26 | 27 | #define PHP_HZ2PY_VERSION "0.1.0" /* Replace with version number for your extension */ 28 | 29 | #ifdef PHP_WIN32 30 | # define PHP_HZ2PY_API __declspec(dllexport) 31 | #elif defined(__GNUC__) && __GNUC__ >= 4 32 | # define PHP_HZ2PY_API __attribute__ ((visibility("default"))) 33 | #else 34 | # define PHP_HZ2PY_API 35 | #endif 36 | 37 | #ifdef ZTS 38 | #include "TSRM.h" 39 | #endif 40 | 41 | /* 42 | Declare any global variables you may need between the BEGIN 43 | and END macros here: 44 | 45 | ZEND_BEGIN_MODULE_GLOBALS(hz2py) 46 | zend_long global_value; 47 | char *global_string; 48 | ZEND_END_MODULE_GLOBALS(hz2py) 49 | */ 50 | 51 | /* Always refer to the globals in your function as HZ2PY_G(variable). 52 | You are encouraged to rename these macros something shorter, see 53 | examples in any other php module directory. 54 | */ 55 | 56 | #ifdef ZTS 57 | #define HZ2PY_G(v) ZEND_TSRMG(hz2py_globals_id, zend_hz2py_globals *, v) 58 | #ifdef COMPILE_DL_HZ2PY 59 | ZEND_TSRMLS_CACHE_EXTERN; 60 | #endif 61 | #else 62 | #define HZ2PY_G(v) (hz2py_globals.v) 63 | #endif 64 | 65 | #define HZ2PY_SUCCESS 0 66 | #define HZ2PY_ERROR -1 67 | #define HZ2PY_EMPTY 1 68 | 69 | #endif /* PHP_HZ2PY_H */ 70 | 71 | 72 | /* 73 | * Local variables: 74 | * tab-width: 4 75 | * c-basic-offset: 4 76 | * End: 77 | * vim600: noet sw=4 ts=4 fdm=marker 78 | * vim<600: noet sw=4 ts=4 79 | */ 80 | -------------------------------------------------------------------------------- /utf8vector.c: -------------------------------------------------------------------------------- 1 | /* 2 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 | * Author : emptyhua@gmail.com 4 | * Create : 2011.9.26 5 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "utf8vector.h" 14 | 15 | ///////////////////////////////////////////////////////////////////// 16 | //utf8vector 17 | //////////////////////////////////////////////////////////////////// 18 | 19 | utf8vector utf8vector_create(const char *utf8, int string_length) 20 | { 21 | utf8vector vector = (utf8vector)calloc(1, sizeof(struct _utf8vector)); 22 | vector->utf8_str = utf8; 23 | vector->length = string_length; 24 | vector->index = 0; 25 | return vector; 26 | } 27 | 28 | void utf8vector_reset(utf8vector vector) 29 | { 30 | vector->index = 0; 31 | } 32 | 33 | int utf8vector_uni_count(utf8vector vector) 34 | { 35 | int count = 0; 36 | while (utf8vector_next_unichar(vector) != '\0') 37 | count ++; 38 | utf8vector_reset(vector); 39 | return count; 40 | } 41 | 42 | #define utf8vector_check_eof(num) \ 43 | if (vector->length == -1) \ 44 | { \ 45 | int i = 0; \ 46 | for (i = 0;i < num; i ++) \ 47 | { \ 48 | if (utf[i] == '\0') return '\0'; \ 49 | } \ 50 | } \ 51 | else \ 52 | { \ 53 | if (vector->index + num > vector->length) return '\0'; \ 54 | } 55 | 56 | wchar_t utf8vector_next_unichar_with_raw(utf8vector vector, const char **raw, int *raw_length) 57 | { 58 | wchar_t uni; 59 | const char *utf = vector->utf8_str + vector->index; 60 | 61 | if (*utf >> 7 == 0) 62 | { 63 | utf8vector_check_eof(1); 64 | vector->index += 1; 65 | if (raw) 66 | { 67 | *raw = utf; 68 | *raw_length = 1; 69 | } 70 | return *utf; 71 | } 72 | //两个字节 73 | else if ( (*utf & 0xE0) == 0xC0 ) 74 | { 75 | utf8vector_check_eof(2); 76 | vector->index += 2; 77 | uni = ((utf[0] & 0x1F) << 6) 78 | | (utf[1] & 0x3F); 79 | vector->index += 2; 80 | if (raw) 81 | { 82 | *raw = utf; 83 | *raw_length = 2; 84 | } 85 | return uni; 86 | } 87 | //三个字节 88 | else if ( (*utf & 0xF0) == 0xE0 ) 89 | { 90 | utf8vector_check_eof(3); 91 | vector->index += 3; 92 | uni = (((utf[0] & 0x0F)) << 12) 93 | | (((utf[1] & 0x3F)) << 6) 94 | | (utf[2] & 0x3F); 95 | if (raw) 96 | { 97 | *raw = utf; 98 | *raw_length = 3; 99 | } 100 | 101 | return uni; 102 | } 103 | //四个字节 104 | else if ( (*utf & 0xF8) == 0xF0 ) 105 | { 106 | utf8vector_check_eof(4); 107 | vector->index += 4; 108 | uni = ((utf[0] & 0x07) << 18) 109 | |((utf[1] & 0x3f) << 12) 110 | |((utf[2] & 0x3f) << 6) 111 | |(utf[3] & 0x3f); 112 | 113 | if (raw) 114 | { 115 | *raw = utf; 116 | *raw_length = 4; 117 | } 118 | 119 | return uni; 120 | } 121 | //五个字节 122 | else if ( (*utf & 0xFC) == 0xF8 ) 123 | { 124 | utf8vector_check_eof(5); 125 | vector->index += 5; 126 | uni = ((utf[0] & 0x03) << 24) 127 | |((utf[1] & 0x3f) << 18) 128 | |((utf[2] & 0x3f) << 12) 129 | |((utf[3] & 0x3f) << 6) 130 | |(utf[4] & 0x3f); 131 | 132 | if (raw) 133 | { 134 | *raw = utf; 135 | *raw_length = 5; 136 | } 137 | 138 | return uni; 139 | } 140 | //六个字节 141 | else if ( (*utf & 0xFE) == 0xFC ) 142 | { 143 | utf8vector_check_eof(6); 144 | vector->index += 6; 145 | uni = ((utf[0] & 0x01) << 30) 146 | |((utf[1] & 0x3f) << 24) 147 | |((utf[2] & 0x3f) << 18) 148 | |((utf[3] & 0x3f) << 12) 149 | |((utf[4] & 0x3f) << 6) 150 | |(utf[5] & 0x3f); 151 | 152 | if (raw) 153 | { 154 | *raw = utf; 155 | *raw_length = 6; 156 | } 157 | 158 | return uni; 159 | } 160 | 161 | return 0; 162 | } 163 | 164 | wchar_t utf8vector_next_unichar(utf8vector vector) 165 | { 166 | return utf8vector_next_unichar_with_raw(vector, NULL, NULL); 167 | } 168 | 169 | void utf8vector_free(utf8vector vector) 170 | { 171 | free(vector); 172 | } 173 | 174 | #ifdef UTF8VECTOR_BIN 175 | int main(int argc, char *argv[]) 176 | { 177 | char read_buff[1024] = "XXXXXXXXXXXXXXXXXX"; 178 | #ifdef DEBUG 179 | wchar_t uni; 180 | utf8vector vector = utf8vector_create(read_buff, 1024); 181 | while ((uni = utf8vector_next_unichar(vector)) != '\0') 182 | printf("%d", uni); 183 | utf8vector_free(vector); 184 | #else 185 | while (1) 186 | { 187 | memset(read_buff, '\0', sizeof(char) * 1024); 188 | 189 | if (read(STDIN_FILENO, read_buff, 1024) <= 0) 190 | break; 191 | 192 | utf8vector vector = utf8vector_create(read_buff, 1024); 193 | wchar_t uni; 194 | while ((uni = utf8vector_next_unichar(vector)) != '\0') 195 | printf("%d ", uni); 196 | utf8vector_free(vector); 197 | } 198 | #endif 199 | return 0; 200 | } 201 | #endif 202 | -------------------------------------------------------------------------------- /hz2py.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2014 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #include "php.h" 26 | #include "php_ini.h" 27 | #include "ext/standard/info.h" 28 | #include "php_hz2py.h" 29 | 30 | #include "utf8vector.h" 31 | #include "pinyin.h" 32 | 33 | static void php_hz2py(const char *line, 34 | int line_length, 35 | int add_blank, 36 | int polyphone_support, /** 支持多音字 */ 37 | int first_letter_only, 38 | int convert_double_char, 39 | int show_tones, 40 | zval *result, 41 | zval *polyphone) 42 | { 43 | assert(NULL != line); 44 | assert(NULL != result); 45 | assert(NULL != polyphone); 46 | assert(line_length > 0); 47 | 48 | wchar_t uni_char; 49 | wchar_t last_uni_char = 0; 50 | const char *utf8; 51 | int utf8_length; 52 | size_t SNPRINTF_SIZE = line_length * 8 + 1; 53 | char *buf = emalloc(SNPRINTF_SIZE); 54 | char *p = buf; 55 | 56 | memset(buf, 0, SNPRINTF_SIZE); 57 | 58 | utf8vector line_vector = utf8vector_create(line, line_length); 59 | 60 | while ((uni_char = utf8vector_next_unichar_with_raw(line_vector, &utf8, &utf8_length)) != '\0') 61 | { 62 | char current[8]; 63 | int uc; 64 | for (uc = 0; uc < utf8_length && uc < 8; uc++) 65 | { 66 | current[uc] = utf8[uc]; 67 | } 68 | current[uc] = '\0'; 69 | //printf("%s\n", current); 70 | 71 | if (pinyin_ishanzi(uni_char)) 72 | { 73 | const char **pinyins = NULL; 74 | int print_count = 0; 75 | int count = pinyin_get_pinyins_by_unicode(uni_char, &pinyins); 76 | if (count == 0) 77 | { 78 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "%.*s", utf8_length, utf8); 79 | } 80 | else 81 | { 82 | char *tones = NULL; 83 | if (show_tones) 84 | pinyin_get_tones_by_unicode(uni_char, &tones); 85 | 86 | // add blank 87 | if (add_blank && last_uni_char != 0 && !pinyin_ishanzi(last_uni_char)) 88 | { 89 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), " "); 90 | } 91 | 92 | if (first_letter_only) 93 | { 94 | if (show_tones) 95 | { 96 | if (print_count > 0) 97 | { 98 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "|"); 99 | } 100 | 101 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "%c", pinyins[0][0]); 102 | print_count ++; 103 | } 104 | else 105 | { 106 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "%c", pinyins[0][0]); 107 | print_count++; 108 | } 109 | } 110 | else 111 | { 112 | if (show_tones) 113 | { 114 | if (print_count > 0) 115 | { 116 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "|"); 117 | } 118 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "%s", pinyins[0]); 119 | print_count ++; 120 | } 121 | else 122 | { 123 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "%s", pinyins[0]); 124 | print_count ++; 125 | } 126 | } 127 | 128 | if (show_tones) 129 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "%d", tones[0]); 130 | 131 | do { 132 | // 多音字逻辑 133 | if (count > 0) 134 | { 135 | int mi = 0; 136 | int has_flag = 0; 137 | 138 | if (first_letter_only) 139 | { 140 | char check = pinyins[0][0]; 141 | for (mi = 1; mi < count; mi++) 142 | { 143 | if (check != pinyins[mi][0]) 144 | { 145 | has_flag = 1; 146 | break; 147 | } 148 | } 149 | } 150 | else 151 | { 152 | char *check = (char *)pinyins[0]; 153 | for (mi = 1; mi < count; mi++) 154 | { 155 | if (0 != strcmp(pinyins[mi], check)) 156 | { 157 | has_flag = 1; 158 | break; 159 | } 160 | } 161 | } 162 | 163 | if (! has_flag) 164 | { 165 | break; 166 | } 167 | 168 | // 如果已经添加过,测跳过 169 | if (zend_hash_exists(Z_ARRVAL_P(polyphone), current, uc)) 170 | { 171 | break; 172 | } 173 | 174 | // 创建字数组 175 | zval *subarray; 176 | MAKE_STD_ZVAL(subarray); 177 | array_init(subarray); 178 | 179 | // 简拼 180 | if (first_letter_only) 181 | { 182 | char jp[2] = {0}; 183 | for (mi = 0; mi < count; mi++) 184 | { 185 | jp[0] = pinyins[mi][0]; 186 | add_index_string(subarray, mi, jp, 1); 187 | } 188 | } 189 | // 全拼 190 | else 191 | { 192 | for (mi = 0; mi < count; mi++) 193 | { 194 | add_index_string(subarray, mi, pinyins[mi], 1); 195 | } 196 | } 197 | 198 | add_assoc_zval(polyphone, current, subarray); 199 | } 200 | } while (0); 201 | 202 | if (add_blank) 203 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), " "); 204 | 205 | if (NULL != tones) 206 | { 207 | free(tones); 208 | } 209 | } 210 | if (NULL != pinyins) 211 | { 212 | free(pinyins); 213 | } 214 | } 215 | else 216 | { 217 | if (convert_double_char && uni_char > 65280 && uni_char < 65375) 218 | { 219 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "%c", uni_char - 65248); 220 | } 221 | else if (convert_double_char && uni_char == 12288) 222 | { 223 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "%c", 32); 224 | } 225 | else 226 | { 227 | p += snprintf(p, SNPRINTF_SIZE - (p - buf), "%.*s", utf8_length, utf8); 228 | } 229 | } 230 | last_uni_char = uni_char; 231 | } 232 | 233 | utf8vector_free(line_vector); 234 | 235 | ZVAL_STRINGL(result, buf, p - buf, 1); 236 | efree(buf); 237 | 238 | return; 239 | } 240 | 241 | 242 | 243 | /* If you declare any globals in php_hz2py.h uncomment this: 244 | ZEND_DECLARE_MODULE_GLOBALS(hz2py) 245 | */ 246 | 247 | /* True global resources - no need for thread safety here */ 248 | static int le_hz2py; 249 | 250 | /* {{{ PHP_INI 251 | */ 252 | /* Remove comments and fill if you need to have entries in php.ini 253 | PHP_INI_BEGIN() 254 | STD_PHP_INI_ENTRY("hz2py.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_hz2py_globals, hz2py_globals) 255 | STD_PHP_INI_ENTRY("hz2py.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_hz2py_globals, hz2py_globals) 256 | PHP_INI_END() 257 | */ 258 | /* }}} */ 259 | 260 | /* The previous line is meant for vim and emacs, so it can correctly fold and 261 | unfold functions in source code. See the corresponding marks just before 262 | function definition, where the functions purpose is also documented. Please 263 | follow this convention for the convenience of others editing your code. 264 | */ 265 | 266 | /** 包裹函数 */ 267 | PHP_FUNCTION(hz2py_jp) 268 | { 269 | char *src; 270 | size_t src_len = 0; 271 | 272 | zval *result; 273 | zval *polyphone; 274 | 275 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "szz", &src, &src_len, &result, &polyphone) == FAILURE) 276 | { 277 | RETVAL_LONG(HZ2PY_ERROR); 278 | goto END; 279 | } 280 | 281 | if (0 == src_len) 282 | { 283 | RETVAL_LONG(HZ2PY_EMPTY); 284 | goto END; 285 | } 286 | 287 | ZVAL_EMPTY_STRING(result); 288 | if (Z_TYPE_P(polyphone) != IS_ARRAY) 289 | { 290 | //php_printf("不是数组,需要初始化"); 291 | array_init(polyphone); 292 | } 293 | 294 | /** debug {{{ */ 295 | // 需要强制分离 296 | //ZVAL_STRINGL(result, "abc", 3, 1); 297 | //add_assoc_string(polyphone, "key", "value", 1); 298 | 299 | //char *str; 300 | //size_t len = spprintf(&str, 0, "%s", "为后续开发准备"); 301 | //ZVAL_STRINGL(result, str, len, 1); 302 | /** end of }}} */ 303 | php_hz2py(src, src_len, 0, 1, 1, 0, 0, result, polyphone); 304 | 305 | RETVAL_LONG(HZ2PY_SUCCESS); 306 | 307 | END: 308 | return; 309 | } 310 | 311 | PHP_FUNCTION(hz2py_qp) 312 | { 313 | char *src; 314 | size_t src_len = 0; 315 | 316 | zval *result; 317 | zval *polyphone; 318 | 319 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "szz", &src, &src_len, &result, &polyphone) == FAILURE) 320 | { 321 | RETVAL_LONG(HZ2PY_ERROR); 322 | goto END; 323 | } 324 | 325 | if (0 == src_len) 326 | { 327 | RETVAL_LONG(HZ2PY_EMPTY); 328 | goto END; 329 | } 330 | 331 | ZVAL_EMPTY_STRING(result); 332 | if (Z_TYPE_P(polyphone) != IS_ARRAY) 333 | { 334 | array_init(polyphone); 335 | } 336 | 337 | php_hz2py(src, src_len, 0, 1, 0, 0, 0, result, polyphone); 338 | 339 | RETVAL_LONG(HZ2PY_SUCCESS); 340 | 341 | END: 342 | 343 | return; 344 | } 345 | 346 | /* {{{ arginfo */ 347 | ZEND_BEGIN_ARG_INFO_EX(arginfo_hz2py_jp, 0, 0, 3) 348 | ZEND_ARG_INFO(0, src) 349 | ZEND_ARG_INFO(1, result) 350 | ZEND_ARG_INFO(1, polyphone) /* array */ 351 | ZEND_END_ARG_INFO() 352 | 353 | ZEND_BEGIN_ARG_INFO_EX(arginfo_hz2py_qp, 0, 0, 3) 354 | ZEND_ARG_INFO(0, src) 355 | ZEND_ARG_INFO(1, result) 356 | ZEND_ARG_INFO(1, polyphone) /* array */ 357 | ZEND_END_ARG_INFO() 358 | /* }}} */ 359 | 360 | /* {{{ php_hz2py_init_globals 361 | */ 362 | /* Uncomment this function if you have INI entries 363 | static void php_hz2py_init_globals(zend_hz2py_globals *hz2py_globals) 364 | { 365 | hz2py_globals->global_value = 0; 366 | hz2py_globals->global_string = NULL; 367 | } 368 | */ 369 | /* }}} */ 370 | 371 | /* {{{ PHP_MINIT_FUNCTION 372 | */ 373 | PHP_MINIT_FUNCTION(hz2py) 374 | { 375 | /* If you have INI entries, uncomment these lines 376 | REGISTER_INI_ENTRIES(); 377 | */ 378 | return SUCCESS; 379 | } 380 | /* }}} */ 381 | 382 | /* {{{ PHP_MSHUTDOWN_FUNCTION 383 | */ 384 | PHP_MSHUTDOWN_FUNCTION(hz2py) 385 | { 386 | /* uncomment this line if you have INI entries 387 | UNREGISTER_INI_ENTRIES(); 388 | */ 389 | return SUCCESS; 390 | } 391 | /* }}} */ 392 | 393 | /* Remove if there's nothing to do at request start */ 394 | /* {{{ PHP_RINIT_FUNCTION 395 | */ 396 | PHP_RINIT_FUNCTION(hz2py) 397 | { 398 | #if defined(COMPILE_DL_HZ2PY) && defined(ZTS) 399 | ZEND_TSRMLS_CACHE_UPDATE; 400 | #endif 401 | return SUCCESS; 402 | } 403 | /* }}} */ 404 | 405 | /* Remove if there's nothing to do at request end */ 406 | /* {{{ PHP_RSHUTDOWN_FUNCTION 407 | */ 408 | PHP_RSHUTDOWN_FUNCTION(hz2py) 409 | { 410 | return SUCCESS; 411 | } 412 | /* }}} */ 413 | 414 | /* {{{ PHP_MINFO_FUNCTION 415 | */ 416 | PHP_MINFO_FUNCTION(hz2py) 417 | { 418 | php_info_print_table_start(); 419 | //php_info_print_table_header(2, "hz2py support", "enabled"); 420 | php_info_print_table_row(2, "hz2py support", "enabled"); 421 | php_info_print_table_row(2, "Version", "0.0.1"); 422 | php_info_print_table_row(2, "Charset", "utf-8"); 423 | php_info_print_table_row(2, "Author", "hy0kl[email: hy0kle@gmail.com]"); 424 | php_info_print_table_end(); 425 | 426 | /* Remove comments if you have entries in php.ini 427 | DISPLAY_INI_ENTRIES(); 428 | */ 429 | } 430 | /* }}} */ 431 | 432 | /* {{{ hz2py_functions[] 433 | * 434 | * Every user visible function must have an entry in hz2py_functions[]. 435 | */ 436 | const zend_function_entry hz2py_functions[] = { 437 | PHP_FE(hz2py_jp, arginfo_hz2py_jp) 438 | PHP_FE(hz2py_qp, arginfo_hz2py_qp) 439 | PHP_FE_END /* Must be the last line in hz2py_functions[] */ 440 | }; 441 | /* }}} */ 442 | 443 | /* {{{ hz2py_module_entry 444 | */ 445 | zend_module_entry hz2py_module_entry = { 446 | STANDARD_MODULE_HEADER, 447 | "hz2py", 448 | hz2py_functions, 449 | PHP_MINIT(hz2py), 450 | PHP_MSHUTDOWN(hz2py), 451 | PHP_RINIT(hz2py), /* Replace with NULL if there's nothing to do at request start */ 452 | PHP_RSHUTDOWN(hz2py), /* Replace with NULL if there's nothing to do at request end */ 453 | PHP_MINFO(hz2py), 454 | PHP_HZ2PY_VERSION, 455 | STANDARD_MODULE_PROPERTIES 456 | }; 457 | /* }}} */ 458 | 459 | #ifdef COMPILE_DL_HZ2PY 460 | #ifdef ZTS 461 | ZEND_TSRMLS_CACHE_DEFINE; 462 | #endif 463 | ZEND_GET_MODULE(hz2py) 464 | #endif 465 | 466 | /* 467 | * Local variables: 468 | * tab-width: 4 469 | * c-basic-offset: 4 470 | * End: 471 | * vim600: noet sw=4 ts=4 fdm=marker 472 | * vim<600: noet sw=4 ts=4 473 | */ 474 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | --------------------------------------------------------------------------------