cvs: Zend / zend_compile.c zend_language_scanner.l zend_multibyte.c zend_multibyte.h

From: Date: Sat, 18 May 2002 15:17:29 +0000
Subject: cvs: Zend / zend_compile.c zend_language_scanner.l zend_multibyte.c zend_multibyte.h
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-128@lists.php.net to get a copy of this message
fujimoto Sat May 18 11:17:29 2002 EDT Modified files: /Zend zend_compile.c zend_language_scanner.l zend_multibyte.c zend_multibyte.h Log: fixed coding style.

Index: Zend/zend_compile.c diff -u Zend/zend_compile.c:1.228 Zend/zend_compile.c:1.229 --- Zend/zend_compile.c:1.228 Wed May 8 08:29:51 2002 +++ Zend/zend_compile.c Sat May 18 11:17:29 2002 @@ -117,8 +117,9 @@ zend_hash_destroy(&CG(filenames_table)); zend_llist_destroy(&CG(open_files)); #ifdef ZEND_MULTIBYTE - if (CG(script_encoding_list)) + if (CG(script_encoding_list)) { efree(CG(script_encoding_list)); + } #endif /* ZEND_MULTIBYTE */ } Index: Zend/zend_language_scanner.l diff -u Zend/zend_language_scanner.l:1.46 Zend/zend_language_scanner.l:1.47 --- Zend/zend_language_scanner.l:1.46 Wed May 8 08:29:51 2002 +++ Zend/zend_language_scanner.l Sat May 18 11:17:29 2002 @@ -256,8 +256,9 @@ /* Reset the scanner for scanning the new file */ SCNG(yy_in) = file_handle->handle.fp; #ifdef ZEND_MULTIBYTE - if (zend_read_file(TSRMLS_C) != 0) + if (zend_read_file(TSRMLS_C) != 0) { return FAILURE; + } /* force flex to use buffer only */ SCNG(yy_in) = NULL; @@ -266,26 +267,25 @@ zend_multibyte_set_filter(NULL TSRMLS_CC); - if (!SCNG(input_filter)) - { + if (!SCNG(input_filter)) { SCNG(current_code) = (char*)emalloc(SCNG(code_size)+1); - if (!SCNG(current_code)) + if (!SCNG(current_code)) { return FAILURE; + } memcpy(SCNG(current_code), SCNG(code), SCNG(code_size)+1); SCNG(current_code_size) = SCNG(code_size); - } - else - { - SCNG(input_filter)(&SCNG(current_code), &SCNG(current_code_size), - SCNG(code), SCNG(code_size) TSRMLS_CC); - if (!SCNG(current_code) || !SCNG(current_code_size)) + } else { + SCNG(input_filter)(&SCNG(current_code), &SCNG(current_code_size), SCNG(code), SCNG(code_size) TSRMLS_CC); + if (!SCNG(current_code) || !SCNG(current_code_size)) { return FAILURE; + } } /* we need two nulls so that ralloc... */ SCNG(current_code) = (char*)erealloc(SCNG(current_code), SCNG(current_code_size)+2); - if (!SCNG(current_code)) + if (!SCNG(current_code)) { return FAILURE; + } *(SCNG(current_code)+SCNG(current_code_size)) = (char)NULL; *(SCNG(current_code)+SCNG(current_code_size)+1) = (char)NULL; yy_scan_buffer(SCNG(current_code), SCNG(current_code_size)+2 TSRMLS_CC); @@ -350,10 +350,12 @@ } compilation_successful=1; #ifdef ZEND_MULTIBYTE - if (SCNG(code)) + if (SCNG(code)) { efree(SCNG(code)); - if (SCNG(current_code)) + } + if (SCNG(current_code)) { efree(SCNG(current_code)); + } #endif /* ZEND_MULTIBYTE */ } @@ -415,31 +417,31 @@ #ifdef ZEND_MULTIBYTE /* instead of zend_readfile() */ SCNG(code) = estrdup(str->value.str.val); - if (!SCNG(code)) + if (!SCNG(code)) { return FAILURE; + } SCNG(code_size) = str->value.str.len; zend_multibyte_set_filter(CG(internal_encoding) TSRMLS_CC); - if (!SCNG(input_filter)) - { + if (!SCNG(input_filter)) { SCNG(current_code) = (char*)emalloc(SCNG(code_size)+1); - if (!SCNG(current_code)) + if (!SCNG(current_code)) { return FAILURE; + } memcpy(SCNG(current_code), SCNG(code), SCNG(code_size)+1); SCNG(current_code_size) = SCNG(code_size); - } - else - { - SCNG(input_filter)(&SCNG(current_code), &SCNG(current_code_size), - SCNG(code), SCNG(code_size) TSRMLS_CC); - if (!SCNG(current_code) || !SCNG(current_code_size)) + } else { + SCNG(input_filter)(&SCNG(current_code), &SCNG(current_code_size), SCNG(code), SCNG(code_size) TSRMLS_CC); + if (!SCNG(current_code) || !SCNG(current_code_size)) { return FAILURE; + } } SCNG(current_code) = (char*)erealloc(SCNG(current_code), SCNG(current_code_size)+2); - if (!SCNG(current_code)) + if (!SCNG(current_code)) { return FAILURE; + } *(SCNG(current_code)+SCNG(current_code_size)) = (char)NULL; *(SCNG(current_code)+SCNG(current_code_size)+1) = (char)NULL; yy_scan_buffer(SCNG(current_code), SCNG(current_code_size)+2 TSRMLS_CC); @@ -486,10 +488,12 @@ BEGIN(ST_IN_SCRIPTING); compiler_result = zendparse(TSRMLS_C); #ifdef ZEND_MULTIBYTE - if (SCNG(code)) + if (SCNG(code)) { efree(SCNG(code)); - if (SCNG(current_code)) + } + if (SCNG(current_code)) { efree(SCNG(current_code)); + } #endif /* ZEND_MULTIBYTE */ if (compiler_result==1) { @@ -560,42 +564,36 @@ /* calculate current position */ offset = original_offset = yy_c_buf_p - b->yy_ch_buf; - if (old_input_filter && original_offset > 0) - { + if (old_input_filter && original_offset > 0) { /* we need to adjust offset ? (i've gotta improve this...) */ new_encoding = SCNG(script_encoding); SCNG(script_encoding) = old_encoding; - do - { + do { (old_input_filter)(&p, &length, SCNG(code), offset TSRMLS_CC); - if (!p) - { + if (!p) { SCNG(script_encoding) = new_encoding; return; } efree(p); - if (length > original_offset) + if (length > original_offset) { offset--; - else if (length < original_offset) + } else if (length < original_offset) { offset++; + } } while (original_offset != length); SCNG(script_encoding) = new_encoding; } /* convert and set */ - if (!SCNG(input_filter)) - { + if (!SCNG(input_filter)) { length = SCNG(code_size)-offset-1; p = SCNG(code)+offset+1; free_flag = 0; - } - else - { + } else { SCNG(input_filter)(&p, &length, SCNG(code)+offset+1, SCNG(code_size)-offset-1 TSRMLS_CC); free_flag = 1; } - if (original_offset+length+1 > (int)b->yy_buf_size) - { + if (original_offset+length+1 > (int)b->yy_buf_size) { b->yy_buf_size = original_offset+length+1; b->yy_ch_buf = (char*)erealloc(b->yy_ch_buf, b->yy_buf_size+2); SCNG(current_code) = b->yy_ch_buf; @@ -608,8 +606,9 @@ b->yy_ch_buf[SCNG(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; b->yy_ch_buf[SCNG(yy_n_chars)+1] = YY_END_OF_BUFFER_CHAR; - if (free_flag) + if (free_flag) { efree(p); + } } @@ -621,42 +620,32 @@ SCNG(code) = NULL; SCNG(code_size) = 0; - do - { -# ifdef __cplusplus - if (SCNG(yy_in)->eof() || SCNG(yy_in)->fail()) - break; - (void)SCNG(yy_in)->read(buf, 8192); - if (SCNG(yy_in)->bad()) - return -1; - n = SCNG(yy_in)->gcount(); -# else + do { n = fread(buf, 1, 8192, SCNG(yy_in)); -# endif - if (n) - { + if (n) { SCNG(code_size) += n; - if (SCNG(code)) - { - SCNG(code) = (char*)erealloc(SCNG(code), - SCNG(code_size)+1); - if (!SCNG(code)) + if (SCNG(code)) { + SCNG(code) = (char*)erealloc(SCNG(code), SCNG(code_size)+1); + if (!SCNG(code)) { return -1; - } - else - { + } + } else { SCNG(code) = (char*)emalloc(SCNG(code_size)+1); - if (!SCNG(code)) + if (!SCNG(code)) { return -1; + } } memcpy(SCNG(code)+SCNG(code_size)-n, buf, n); } } while(n); -#ifndef __cplusplus - if (ferror(SCNG(yy_in))) + if (ferror(SCNG(yy_in))) { return -1; -#endif + } + if (!SCNG(code)) { + SCNG(code) = emalloc(SCNG(code_size)+1); + } *(SCNG(code)+SCNG(code_size)) = (char)NULL; + return 0; } @@ -666,13 +655,11 @@ */ # define zend_copy_value(zendlval, yytext, yyleng) \ if (SCNG(output_filter)) { \ - SCNG(output_filter)(&(zendlval->value.str.val), &(zendlval->value.str.len), \ - yytext, yyleng TSRMLS_CC); \ + SCNG(output_filter)(&(zendlval->value.str.val), &(zendlval->value.str.len), yytext, yyleng TSRMLS_CC); \ } else { \ zendlval->value.str.val = (char *) estrndup(yytext, yyleng); \ zendlval->value.str.len = yyleng; \ } - #else /* ZEND_MULTIBYTE */ # define zend_copy_value(zendlval, yytext, yyleng) \ zendlval->value.str.val = (char *)estrndup(yytext, yyleng); \ @@ -1495,8 +1482,7 @@ *t = 0; #ifdef ZEND_MULTIBYTE - if (SCNG(output_filter)) - { + if (SCNG(output_filter)) { s = zendlval->value.str.val; SCNG(output_filter)(&(zendlval->value.str.val), &(zendlval->value.str.len), s, zendlval->value.str.len TSRMLS_CC); efree(s); Index: Zend/zend_multibyte.c diff -u Zend/zend_multibyte.c:1.2 Zend/zend_multibyte.c:1.3 --- Zend/zend_multibyte.c:1.2 Thu May 9 22:18:25 2002 +++ Zend/zend_multibyte.c Sat May 18 11:17:29 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_multibyte.c,v 1.2 2002/05/10 02:18:25 rasmus Exp $ */ +/* $Id: zend_multibyte.c,v 1.3 2002/05/18 15:17:29 fujimoto Exp $ */ #include "zend.h" #include "zend_compile.h" @@ -26,9 +26,6 @@ #ifdef ZEND_MULTIBYTE -/*-------------------------------------------------------------------------- - vars - --------------------------------------------------------------------------*/ const char *utf8_aliases[] = {"UTF8", NULL}; zend_encoding encoding_utf8 = { NULL, @@ -73,9 +70,7 @@ NULL }; -/*-------------------------------------------------------------------------- - protos - --------------------------------------------------------------------------*/ + static char* zend_multibyte_assemble_list(zend_encoding **encoding_list, int encoding_list_size); static int zend_multibyte_parse_encoding_list(const char *encoding_list, @@ -83,21 +78,19 @@ static inline char* zend_memnstr(char *haystack, char *needle, int needle_len, char *end); -/*-------------------------------------------------------------------------- - interfaces - --------------------------------------------------------------------------*/ + ZEND_API int zend_multibyte_set_script_encoding(char *encoding_list, int encoding_list_size TSRMLS_DC) { - if (CG(script_encoding_list)) - { + if (CG(script_encoding_list)) { efree(CG(script_encoding_list)); CG(script_encoding_list) = NULL; } CG(script_encoding_list_size) = 0; - if (!encoding_list) + if (!encoding_list) { return 0; + } zend_multibyte_parse_encoding_list(encoding_list, encoding_list_size, &(CG(script_encoding_list)), &(CG(script_encoding_list_size))); @@ -137,75 +130,76 @@ LANG_SCNG(internal_encoding) = NULL; /* decision making... */ - if (!onetime_encoding) - { - if (!CG(script_encoding_list) || !CG(script_encoding_list_size)) + if (!onetime_encoding) { + if (!CG(script_encoding_list) || !CG(script_encoding_list_size)) { script_encoding = NULL; - else if (CG(script_encoding_list_size) > 1 && CG(encoding_detector)) - { + } else if (CG(script_encoding_list_size) > 1 && CG(encoding_detector)) { /* we need to detect automatically */ list = zend_multibyte_assemble_list(CG(script_encoding_list), CG(script_encoding_list_size)); name = CG(encoding_detector)(LANG_SCNG(code), LANG_SCNG(code_size), list TSRMLS_CC); - if (list) + if (list) { efree(list); + } script_encoding = zend_multibyte_fetch_encoding(name); efree(name); - } - else + } else { script_encoding = *(CG(script_encoding_list)); - } - else + } + } else { script_encoding = onetime_encoding; + } - if (CG(encoding_converter)) + if (CG(encoding_converter)) { internal_encoding = CG(internal_encoding); - else + } else { internal_encoding = NULL; + } /* judge input/output filter */ LANG_SCNG(script_encoding) = script_encoding; LANG_SCNG(internal_encoding) = internal_encoding; - if (!script_encoding) + if (!script_encoding) { return 0; + } - if (!internal_encoding) - { - if (script_encoding->input_filter) + if (!internal_encoding) { + if (script_encoding->input_filter) { LANG_SCNG(input_filter) = script_encoding->input_filter; - if (script_encoding->output_filter) + } + if (script_encoding->output_filter) { LANG_SCNG(output_filter) = script_encoding->output_filter; + } return 0; } - if (script_encoding == internal_encoding) - { - if (script_encoding->compatible) + if (script_encoding == internal_encoding) { + if (script_encoding->compatible) { return 0; + } - if (script_encoding->input_filter) + if (script_encoding->input_filter) { LANG_SCNG(input_filter) = script_encoding->input_filter; - if (script_encoding->output_filter) + } + if (script_encoding->output_filter) { LANG_SCNG(output_filter) = script_encoding->output_filter; + } return 0; } - if (internal_encoding->compatible) - { + if (internal_encoding->compatible) { LANG_SCNG(input_filter) = zend_multibyte_encoding_filter; return 0; } - if (script_encoding->compatible) - { + if (script_encoding->compatible) { LANG_SCNG(output_filter) = zend_multibyte_encoding_filter; return 0; } /* no way! it's too hard... :( */ - if (script_encoding->input_filter && internal_encoding->output_filter) - { + if (script_encoding->input_filter && internal_encoding->output_filter) { LANG_SCNG(input_filter) = script_encoding->input_filter; LANG_SCNG(output_filter) = internal_encoding->output_filter; } @@ -219,27 +213,26 @@ int i, j; zend_encoding *encoding; - if (!encoding_name) + if (!encoding_name) { return NULL; + } - for (i = 0; (encoding = zend_encoding_table[i]) != NULL; i++) - { + for (i = 0; (encoding = zend_encoding_table[i]) != NULL; i++) { if (zend_binary_strcasecmp((char*)encoding->name, strlen(encoding->name), encoding_name, - strlen(encoding_name)) == 0) + strlen(encoding_name)) == 0) { return encoding; + } } - for (i = 0; (encoding = zend_encoding_table[i]) != NULL; i++) - { - if (encoding->aliases != NULL) - { - for (j = 0; (*encoding->aliases)[j] != NULL; j++) - { + for (i = 0; (encoding = zend_encoding_table[i]) != NULL; i++) { + if (encoding->aliases != NULL) { + for (j = 0; (*encoding->aliases)[j] != NULL; j++) { if (zend_binary_strcasecmp((char*)(*encoding->aliases)[j], strlen((*encoding->aliases)[j]), encoding_name, - strlen(encoding_name)) == 0) + strlen(encoding_name)) == 0) { return encoding; + } } } } @@ -253,32 +246,31 @@ { int oddlen; - if (!CG(encoding_converter)) + if (!CG(encoding_converter)) { return 0; + } - if (CG(multibyte_oddlen)) - { + if (CG(multibyte_oddlen)) { oddlen = CG(multibyte_oddlen)(from, from_length, LANG_SCNG(script_encoding)->name TSRMLS_CC); - if (oddlen > 0) + if (oddlen > 0) { from_length -= oddlen; + } } if (CG(encoding_converter)(to, to_length, from, from_length, LANG_SCNG(internal_encoding)->name, LANG_SCNG(script_encoding)->name - TSRMLS_CC) != 0) + TSRMLS_CC) != 0) { return 0; + } return from_length; } -/*-------------------------------------------------------------------------- - input/output filters - --------------------------------------------------------------------------*/ /* - * Shift_JIS + * Shift_JIS Input/Output Filter */ static const unsigned char table_sjis[] = { /* 0x80-0x9f,0xE0-0xEF */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -314,68 +306,62 @@ q = (unsigned char*)*buf; /* convert [SJIS -> EUC-JP] (for lex scan) -- some other better ways? */ - while (*p && (p-(unsigned char*)sjis) < sjis_length) - { - if (!(*p & 0x80)) - { + while (*p && (p-(unsigned char*)sjis) < sjis_length) { + if (!(*p & 0x80)) { *q++ = *p++; continue; } /* handling 8 bit code */ - if (table_sjis[*p] == 1) - { + if (table_sjis[*p] == 1) { /* 1 byte kana */ *q++ = 0x8e; *q++ = *p++; continue; } - if (!*(p+1)) - { + if (!*(p+1)) { *q++ = *p++; break; } - if (table_sjis[*p] == 2) - { + if (table_sjis[*p] == 2) { /* 2 byte kanji code */ c1 = *p++; - if (!*p || (p-(unsigned char*)sjis) >= sjis_length) + if (!*p || (p-(unsigned char*)sjis) >= sjis_length) { break; + } c2 = *p++; c1 -= (c1 <= 0x9f) ? 0x71 : 0xb1; c1 = (c1 << 1) + 1; - if (c2 >= 0x9e) - { + if (c2 >= 0x9e) { c2 -= 0x7e; c1++; - } - else if (c2 > 0x7f) + } else if (c2 > 0x7f) { c2 -= 0x20; - else + } else { c2 -= 0x1f; + } c1 |= 0x80; c2 |= 0x80; *q++ = c1; *q++ = c2; - } - /* - * for user defined chars (ATTENTION) - * - * THESE ARE NOT CODE FOR CONVERSION! :-P - * (using *ILLEGALLY* 3byte EUC-JP space) - * - * we cannot perfectly (== 1 to 1) convert these chars to EUC-JP. - * so, these code are for perfect RESTORING in sjis_output_filter() - */ - else - { + } else { + /* + * for user defined chars (ATTENTION) + * + * THESE ARE NOT CODE FOR CONVERSION! :-P + * (using *ILLEGALLY* 3byte EUC-JP space) + * + * we cannot perfectly (== 1 to 1) convert these chars to EUC-JP. + * so, these code are for perfect RESTORING in sjis_output_filter() + */ c1 = *p++; - if (!*p || (p-(unsigned char*)sjis) >= sjis_length) + if (!*p || (p-(unsigned char*)sjis) >= sjis_length) { break; + } c2 = *p++; *q++ = (char)0x8f; /* @@ -386,15 +372,14 @@ */ c1 -= (c1 > 0xf9) ? (0x79+0x71) : (0x0a+0xb1); c1 = (c1 << 1) + 1; - if (c2 >= 0x9e) - { + if (c2 >= 0x9e) { c2 -= 0x7e; c1++; - } - else if (c2 > 0x7f) + } else if (c2 > 0x7f) { c2 -= 0x20; - else + } else { c2 -= 0x1f; + } c1 |= 0x80; c2 |= 0x80; @@ -434,87 +419,87 @@ unsigned char c1, c2; char *p, *q; - if (!sjis || !sjis_length) + if (!sjis || !sjis_length) { return 0; + } /* always Shift_JIS <= EUC-JP */ *sjis = (char*)emalloc(length+1); - if (!sjis) + if (!sjis) { return 0; + } p = *sjis; q = buf; /* restore converted strings [EUC-JP -> Shift_JIS] */ - while (*q) - { - if (!(*q & 0x80)) - { + while (*q) { + if (!(*q & 0x80)) { *p++ = *q++; continue; } /* hankaku kana */ - if (*q == (char)0x8e) - { + if (*q == (char)0x8e) { q++; - if (*q) + if (*q) { *p++ = *q++; + } continue; } /* 2 byte kanji code */ - if (table_eucjp[(unsigned char)*q] == 2) - { + if (table_eucjp[(unsigned char)*q] == 2) { c1 = (*q++ & ~0x80) & 0xff; - if (*q) + if (*q) { c2 = (*q++ & ~0x80) & 0xff; - else - { + } else { q--; break; } c2 += (c1 & 0x01) ? 0x1f : 0x7d; - if (c2 >= 0x7f) + if (c2 >= 0x7f) { c2++; + } c1 = ((c1 - 0x21) >> 1) + 0x81; - if (c1 > 0x9f) + if (c1 > 0x9f) { c1 += 0x40; + } *p++ = c1; *p++ = c2; continue; } - if (*q == (char)0x8f) - { + if (*q == (char)0x8f) { q++; - if (*q) + if (*q) { c1 = (*q++ & ~0x80) & 0xff; - else - { + } else { q--; break; } - if (*q) + if (*q) { c2 = (*q++ & ~0x80) & 0xff; - else - { + } else { q -= 2; break; } c2 += (c1 & 0x01) ? 0x1f : 0x7d; - if (c2 >= 0x7f) + if (c2 >= 0x7f) { c2++; + } c1 = ((c1 - 0x21) >> 1) + 0x81; - if (c1 > 0x9f) + if (c1 > 0x9f) { c1 += 0x40; + } - if (c1 >= 0x81 && c1 <= 0x9f) + if (c1 >= 0x81 && c1 <= 0x9f) { c1 += 0x79; - else + } else { c1 += 0x0a; + } *p++ = c1; *p++ = c2; @@ -531,9 +516,6 @@ } -/*-------------------------------------------------------------------------- - static funcs - --------------------------------------------------------------------------*/ static char* zend_multibyte_assemble_list(zend_encoding **encoding_list, int encoding_list_size) { @@ -541,27 +523,25 @@ const char *name; char *list = NULL; - if (!encoding_list || !encoding_list_size) + if (!encoding_list || !encoding_list_size) { return NULL; + } - for (i = 0; i < encoding_list_size; i++) - { + for (i = 0; i < encoding_list_size; i++) { name = (*(encoding_list+i))->name; - if (name) - { + if (name) { list_size += strlen(name) + 1; - if (!list) - { + if (!list) { list = (char*)emalloc(list_size); - if (!list) + if (!list) { return NULL; + } *list = (char)NULL; - } - else - { + } else { list = (char*)erealloc(list, list_size); - if (!list) + if (!list) { return NULL; + } strcat(list, ","); } strcat(list, name); Index: Zend/zend_multibyte.h diff -u Zend/zend_multibyte.h:1.1 Zend/zend_multibyte.h:1.2 --- Zend/zend_multibyte.h:1.1 Wed May 8 08:29:51 2002 +++ Zend/zend_multibyte.h Sat May 18 11:17:29 2002 @@ -17,20 +17,13 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_multibyte.h,v 1.1 2002/05/08 12:29:51 hirokawa Exp $ */ +/* $Id: zend_multibyte.h,v 1.2 2002/05/18 15:17:29 fujimoto Exp $ */ #ifndef ZEND_MULTIBYTE_H #define ZEND_MULTIBYTE_H #ifdef ZEND_MULTIBYTE -/*------------------------------------------------------------------------- - defs - -------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------- - types - -------------------------------------------------------------------------*/ typedef int (*zend_multibyte_filter)(char **str, int *str_length, char *buf, int length TSRMLS_DC); @@ -53,9 +46,6 @@ } zend_encoding; -/*------------------------------------------------------------------------- - protos - -------------------------------------------------------------------------*/ BEGIN_EXTERN_C() ZEND_API int zend_multibyte_set_script_encoding(char *encoding_list, int encoding_list_size TSRMLS_DC);
« previous php.zend-engine.cvs (#128) next »