Skip to content

Commit

Permalink
use zval
Browse files Browse the repository at this point in the history
  • Loading branch information
duguying committed Nov 7, 2013
1 parent 8d7e290 commit 20c7e69
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 283 deletions.
30 changes: 14 additions & 16 deletions funs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@
#include <string.h>
#include <malloc.h>
#include "./pinyin.inc"
#include "hashtable.c"
#include "php.h"

#ifndef FUNS_C
#define FUNS_C
#define DE '|'
#define MAX_LEN 10000

void get_pinyin(char pinyin_char[8], int index){
void get_pinyin(char* pinyin_char, int index){
memset(pinyin_char, 0, sizeof(char)*8);
strncpy(pinyin_char, pinyin+index, 8);
strtok(pinyin_char,"|");
}

void pinyin_init(){

void pinyin_init(zval* dict){
int cn_count,pinyin_arr_count,pinyin_index;
int index[MAX_LEN];
char tmp[4];
char pinyin_char[8];
int i,j;

array_init(dict);

hash_table_init();
cn_count=strlen(cnchar)/3;
pinyin_arr_count=strlen(pinyin);
// printf("%d\n", cn_count);

//scan pinyin
pinyin_index=0;
Expand All @@ -36,24 +38,20 @@ void pinyin_init(){
pinyin_index++;
}
}

for(j=0;j<cn_count;j++){
strtok(pinyin+index[j]+1,"|");
}

for (i = 0; i < cn_count; i++)
{
memset(tmp, 0, sizeof(char)*4);
memset(tmp, 0, sizeof(char)*8);
strncpy(tmp, (cnchar+3*(i)), 3);
hash_table_insert(tmp, index[i]);

add_assoc_string(dict, tmp, (pinyin+index[i]+1), 0);
}

// char pinyin_char[8];
// HashNode *pNode = hash_table_lookup("胫");
// get_pinyin(pinyin_char, pNode->nValue+1);
// printf("lookup result:%s\n", pinyin_char);
// pNode = hash_table_lookup("一");
// get_pinyin(pinyin_char, pNode->nValue+1);
// printf("lookup result:%s\n", pinyin_char);
// pNode = hash_table_lookup("龠");
// get_pinyin(pinyin_char, pNode->nValue+1);
// printf("lookup result:%s\n", pinyin_char);
}

#endif
138 changes: 0 additions & 138 deletions hashtable.c

This file was deleted.

19 changes: 0 additions & 19 deletions php_pinyin.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,8 @@ PHP_RINIT_FUNCTION(pinyin);
PHP_RSHUTDOWN_FUNCTION(pinyin);
PHP_MINFO_FUNCTION(pinyin);

//PHP_FUNCTION(confirm_pinyin_compiled); /* For testing, remove later. */
PHP_FUNCTION(pinyin);
/*
Declare any global variables you may need between the BEGIN
and END macros here:

ZEND_BEGIN_MODULE_GLOBALS(pinyin)
long global_value;
char *global_string;
ZEND_END_MODULE_GLOBALS(pinyin)
*/

/* In every utility function you add that needs to use variables
in php_pinyin_globals, call TSRMLS_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 PINYIN_G(variable). You are
encouraged to rename these macros something shorter, see
examples in any other php module directory.
*/

#ifdef ZTS
#define PINYIN_G(v) TSRMG(pinyin_globals_id, zend_pinyin_globals *, v)
Expand Down
Loading

0 comments on commit 20c7e69

Please sign in to comment.