Return the bounding box needed by a string if rasterized */
PHP_FUNCTION(imagepsbbox)
{
- zval **str, **fnt, **sz, **sp, **wd, **ang;
- int i, space, add_width = 0, char_width, amount_kern;
+ zval *fnt;
+ long sz = 0, sp, wd;
+ char *str;
+ int i, space = 0, add_width = 0, char_width, amount_kern;
int cur_x, cur_y, dx, dy;
int x1, y1, x2, y2, x3, y3, x4, y4;
int *f_ind;
- int per_char = 0;
+ int str_len, per_char = 0;
+ int argc = ZEND_NUM_ARGS();
double angle, sin_a = 0, cos_a = 0;
BBox char_bbox, str_bbox = {0, 0, 0, 0};
- switch (ZEND_NUM_ARGS()) {
- case 3:
- if (zend_get_parameters_ex(3, &str, &fnt, &sz) == FAILURE) {
- RETURN_FALSE;
- }
- space = 0;
- break;
- case 6:
- if (zend_get_parameters_ex(6, &str, &fnt, &sz, &sp, &wd, &ang) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(sp);
- convert_to_long_ex(wd);
- convert_to_double_ex(ang);
- space = Z_LVAL_PP(sp);
- add_width = Z_LVAL_PP(wd);
- angle = Z_DVAL_PP(ang) * M_PI / 180;
- sin_a = sin(angle);
- cos_a = cos(angle);
- per_char = add_width || angle ? 1 : 0;
- break;
- default:
- ZEND_WRONG_PARAM_COUNT();
+ if (argc != 3 && argc != 6) {
+ ZEND_WRONG_PARAM_COUNT();
+ }
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "srl|lld", &str, &str_len, &fnt, &sz, &sp, &wd, &angle) == FAILURE) {
+ return;
+ }
+
+ if (argc == 6) {
+ space = sp;
+ add_width = wd;
+ angle = angle * M_PI / 180;
+ sin_a = sin(angle);
+ cos_a = cos(angle);
+ per_char = add_width || angle ? 1 : 0;
}
- ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font);
-
- convert_to_string_ex(str);
- convert_to_long_ex(sz);
+ ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
space += T1_GetCharWidth(*f_ind, ' ');
cur_x = cur_y = 0;
- for (i = 0; i < Z_STRLEN_PP(str); i++) {
- if (Z_STRVAL_PP(str)[i] == ' ') {
+ for (i = 0; i < str_len; i++) {
+ if (str[i] == ' ') {
char_bbox.llx = char_bbox.lly = char_bbox.ury = 0;
char_bbox.urx = char_width = space;
} else {
- char_bbox = T1_GetCharBBox(*f_ind, Z_STRVAL_PP(str)[i]);
- char_width = T1_GetCharWidth(*f_ind, Z_STRVAL_PP(str)[i]);
+ char_bbox = T1_GetCharBBox(*f_ind, str[i]);
+ char_width = T1_GetCharWidth(*f_ind, str[i]);
}
- amount_kern = i ? T1_GetKerning(*f_ind, Z_STRVAL_PP(str)[i - 1], Z_STRVAL_PP(str)[i]) : 0;
+ amount_kern = i ? T1_GetKerning(*f_ind, str[i - 1], str[i]) : 0;
/* Transfer character bounding box to right place */
x1 = new_x(char_bbox.llx, char_bbox.lly) + cur_x;
}
} else {
- str_bbox = T1_GetStringBBox(*f_ind, Z_STRVAL_PP(str), Z_STRLEN_PP(str), space, T1_KERNING);
+ str_bbox = T1_GetStringBBox(*f_ind, str, str_len, space, T1_KERNING);
}
if (T1_errno) {
if (stack->elements) {
for (i = 0; i < stack->top; i++) {
- if (((st_entry *)stack->elements[i])->data)
- {
+ if (((st_entry *)stack->elements[i])->data) {
zval_ptr_dtor(&((st_entry *)stack->elements[i])->data);
}
- if (((st_entry *)stack->elements[i])->varname)
+ if (((st_entry *)stack->elements[i])->varname) {
efree(((st_entry *)stack->elements[i])->varname);
+ }
efree(stack->elements[i]);
}
efree(stack->elements);
for (zend_hash_internal_pointer_reset(HASH_OF(obj));
zend_hash_get_current_data(HASH_OF(obj), (void**)&ent) == SUCCESS;
zend_hash_move_forward(HASH_OF(obj))) {
- if (*ent == obj)
+ if (*ent == obj) {
continue;
+ }
if (zend_hash_get_current_key_ex(HASH_OF(obj), &key, &key_len, &idx, 0, NULL) == HASH_KEY_IS_STRING) {
char *class_name, *prop_name;
HashTable *target_hash;
TSRMLS_FETCH();
- if (Z_TYPE_P(name_var) == IS_STRING)
- {
+ if (Z_TYPE_P(name_var) == IS_STRING) {
if (!EG(active_symbol_table)) {
zend_rebuild_symbol_table(TSRMLS_C);
}
Z_STRLEN_P(name_var)+1, (void**)&val) != FAILURE) {
php_wddx_serialize_var(packet, *val, Z_STRVAL_P(name_var), Z_STRLEN_P(name_var) TSRMLS_CC);
}
- }
- else if (Z_TYPE_P(name_var) == IS_ARRAY || Z_TYPE_P(name_var) == IS_OBJECT)
- {
+ } else if (Z_TYPE_P(name_var) == IS_ARRAY || Z_TYPE_P(name_var) == IS_OBJECT) {
target_hash = HASH_OF(name_var);
zend_hash_internal_pointer_reset(target_hash);
TSRMLS_FETCH();
/* OBJECTS_FIXME */
- if (stack->top == 0)
+ if (stack->top == 0) {
return;
+ }
if (!strcmp(name, EL_STRING) || !strcmp(name, EL_NUMBER) ||
!strcmp(name, EL_BOOLEAN) || !strcmp(name, EL_NULL) ||
zval_dtor(fname);
FREE_ZVAL(fname);
- if (retval)
+ if (retval) {
zval_ptr_dtor(&retval);
+ }
}
if (stack->top > 1) {
} else if (Z_TYPE_P(ent2->data) == IS_OBJECT) {
zend_class_entry *old_scope = EG(scope);
- EG(scope) = Z_OBJCE_P(ent2->data);
+ EG(scope) = Z_OBJCE_P(ent2->data);
Z_DELREF_P(ent1->data);
add_property_zval(ent2->data, ent1->varname, ent1->data);
EG(scope) = old_scope;
}
efree(ent1->varname);
} else {
- zend_hash_next_index_insert(target_hash,
- &ent1->data,
- sizeof(zval *), NULL);
+ zend_hash_next_index_insert(target_hash, &ent1->data, sizeof(zval *), NULL);
}
}
efree(ent1);
- } else
+ } else {
stack->done = 1;
+ }
} else if (!strcmp(name, EL_VAR) && stack->varname) {
efree(stack->varname);
} else if (!strcmp(name, EL_FIELD)) {
break;
case ST_BOOLEAN:
- if (!strcmp(s, "true"))
+ if (!strcmp(s, "true")) {
Z_LVAL_P(ent->data) = 1;
- else if (!strcmp(s, "false"))
+ } else if (!strcmp(s, "false")) {
Z_LVAL_P(ent->data) = 0;
- else {
+ } else {
stack->top--;
zval_ptr_dtor(&ent->data);
- if (ent->varname)
+ if (ent->varname) {
efree(ent->varname);
+ }
efree(ent);
}
break;
*return_value = *(ent->data);
zval_copy_ctor(return_value);
retval = SUCCESS;
- } else
+ } else {
retval = FAILURE;
+ }
wddx_stack_destroy(&stack);
{
int argc, i;
wddx_packet *packet;
- zval ***args;
-
- argc = ZEND_NUM_ARGS();
- if (argc < 1) {
- WRONG_PARAM_COUNT;
- }
+ zval ***args = NULL;
- /* Allocate arguments array and get the arguments, checking for errors. */
- args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
- if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
+ return;
}
packet = php_wddx_constructor();
}
/* }}} */
-/* {{{ proto int wddx_add_vars(int packet_id, mixed var_names [, mixed ...])
+/* {{{ proto int wddx_add_vars(resource packet_id, mixed var_names [, mixed ...])
Serializes given variables and adds them to packet given by packet_id */
PHP_FUNCTION(wddx_add_vars)
{
- int argc, i;
- zval ***args;
- zval **packet_id;
+ int num_args, i;
+ zval ***args = NULL;
+ zval *packet_id;
wddx_packet *packet = NULL;
- argc = ZEND_NUM_ARGS();
- if (argc < 2) {
- WRONG_PARAM_COUNT;
- }
-
- /* Allocate arguments array and get the arguments, checking for errors. */
- args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
- if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r+", &packet_id, &args, &num_args) == FAILURE) {
+ return;
}
-
- packet_id = args[0];
- packet = (wddx_packet *)zend_fetch_resource(packet_id TSRMLS_CC, -1, "WDDX packet ID", NULL, 1, le_wddx);
- if (!packet)
- {
+ ZEND_FETCH_RESOURCE(packet, wddx_packet *, &packet_id, -1, "WDDX packet ID", le_wddx);
+
+ if (!packet) {
efree(args);
RETURN_FALSE;
}
- for (i=1; i<argc; i++) {
- if (Z_TYPE_PP(args[i]) != IS_ARRAY && Z_TYPE_PP(args[i]) != IS_OBJECT)
+ for (i=1; i<num_args; i++) {
+ if (Z_TYPE_PP(args[i]) != IS_ARRAY && Z_TYPE_PP(args[i]) != IS_OBJECT) {
convert_to_string_ex(args[i]);
- php_wddx_add_var(packet, (*args[i]));
+ }
+ php_wddx_add_var(packet, *args[i]);
}
efree(args);
int payload_len;
php_stream *stream = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &packet) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &packet) == FAILURE) {
return;
+ }
if (Z_TYPE_P(packet) == IS_STRING) {
payload = Z_STRVAL_P(packet);
payload_len = Z_STRLEN_P(packet);
- }
- else if (Z_TYPE_P(packet) == IS_RESOURCE) {
+ } else if (Z_TYPE_P(packet) == IS_RESOURCE) {
php_stream_from_zval(stream, &packet);
if (stream) {
payload_len = php_stream_copy_to_mem(stream, (void **)&payload, PHP_STREAM_COPY_ALL, 0);
return;
}
- if (payload_len == 0)
+ if (payload_len == 0) {
return;
+ }
php_wddx_unserialize_ex(payload, payload_len, return_value);
- if (stream)
+ if (stream) {
pefree(payload, 0);
+ }
}
/* }}} */