common.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. +----------------------------------------------------------------------+
  3. | XlsWriter Extension |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2017-2018 The Viest |
  6. +----------------------------------------------------------------------+
  7. | http://www.viest.me |
  8. +----------------------------------------------------------------------+
  9. | Author: viest <[email protected]> |
  10. +----------------------------------------------------------------------+
  11. */
  12. #include "xlswriter.h"
  13. /* {{{ */
  14. void xls_file_path(zend_string *file_name, zval *dir_path, zval *file_path)
  15. {
  16. zend_string *full_path, *zstr_path;
  17. zstr_path = zval_get_string(dir_path);
  18. if (Z_STRVAL_P(dir_path)[Z_STRLEN_P(dir_path)-1] == '/') {
  19. full_path = zend_string_extend(zstr_path, ZSTR_LEN(zstr_path) + ZSTR_LEN(file_name), 0);
  20. memcpy(ZSTR_VAL(full_path)+ZSTR_LEN(zstr_path), ZSTR_VAL(file_name), ZSTR_LEN(file_name)+1);
  21. } else {
  22. full_path = zend_string_extend(zstr_path, ZSTR_LEN(zstr_path) + ZSTR_LEN(file_name) + 1, 0);
  23. ZSTR_VAL(full_path)[ZSTR_LEN(zstr_path)] ='/';
  24. memcpy(ZSTR_VAL(full_path)+ZSTR_LEN(zstr_path)+1, ZSTR_VAL(file_name), ZSTR_LEN(file_name)+1);
  25. }
  26. ZVAL_STR(file_path, full_path);
  27. }
  28. /* }}} */
  29. /* {{{ */
  30. zend_string* str_pick_up(zend_string *left, const char *right, size_t len)
  31. {
  32. zend_string *full = NULL;
  33. size_t _left_length = ZSTR_LEN(left);
  34. size_t _extend_length = _left_length + len;
  35. full = zend_string_extend(left, _extend_length, 0);
  36. memcpy(ZSTR_VAL(full) + _left_length, right, len);
  37. ZSTR_VAL(full)[_extend_length] = '\0';
  38. return full;
  39. }
  40. /* }}} */
  41. /* {{{ */
  42. void call_object_method(zval *object, const char *function_name, uint32_t param_count, zval *params, zval *ret_val)
  43. {
  44. uint32_t index;
  45. zval z_f_name;
  46. ZVAL_STRINGL(&z_f_name, function_name, strlen(function_name));
  47. call_user_function(NULL, object, &z_f_name, ret_val, param_count, params);
  48. if (Z_ISUNDEF_P(ret_val)) {
  49. ZVAL_NULL(ret_val);
  50. }
  51. for (index = 0; index < param_count; index++) {
  52. zval_ptr_dtor(&params[index]);
  53. }
  54. zval_ptr_dtor(&z_f_name);
  55. }
  56. /* }}} */
  57. lxw_datetime timestamp_to_datetime(zend_long timestamp)
  58. {
  59. int yearLocal = php_idate('Y', timestamp, 0);
  60. int monthLocal = php_idate('m', timestamp, 0);
  61. int dayLocal = php_idate('d', timestamp, 0);
  62. int hourLocal = php_idate('H', timestamp, 0);
  63. int minuteLocal = php_idate('i', timestamp, 0);
  64. int secondLocal = php_idate('s', timestamp, 0);
  65. lxw_datetime datetime = {
  66. yearLocal, monthLocal, dayLocal, hourLocal, minuteLocal, secondLocal
  67. };
  68. return datetime;
  69. }