pollita Mon Jan 21 06:08:04 2008 UTC
Modified files:
/php-src/ext/calendar calendar.c php_calendar.h
Log:
Make unicode ready
http://cvs.php.net/viewvc.cgi/php-src/ext/calendar/calendar.c?r1=1.54&r2=1.55&diff_format=u
Index: php-src/ext/calendar/calendar.c
diff -u php-src/ext/calendar/calendar.c:1.54
php-src/ext/calendar/calendar.c:1.55
--- php-src/ext/calendar/calendar.c:1.54 Mon Dec 31 07:12:07 2007
+++ php-src/ext/calendar/calendar.c Mon Jan 21 06:08:03 2008
@@ -18,7 +18,7 @@
| Wez Furlong <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: calendar.c,v 1.54 2007/12/31 07:12:07 sebastian Exp $ */
+/* $Id: calendar.c,v 1.55 2008/01/21 06:08:03 pollita Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -35,6 +35,8 @@
#include <stdio.h>
+ZEND_DECLARE_MODULE_GLOBALS(calendar);
+
/* {{{ arginfo */
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_unixtojd, 0, 0, 0)
@@ -169,6 +171,20 @@
{NULL, NULL, NULL}
};
+static PHP_GINIT_FUNCTION(calendar)
+{
+ if (zend_set_converter_encoding(&(calendar_globals->iso_8859_8_conv),
"iso-8859-8") == FAILURE) {
+ php_error(E_CORE_WARNING, "Unable to instatiate iso-8859-8
converter for calendar extension, will be unable to produce hebrew dates in
unicode mode");
+ calendar_globals = NULL;
+ }
+}
+
+static PHP_GSHUTDOWN_FUNCTION(calendar)
+{
+ if (calendar_globals->iso_8859_8_conv) {
+ ucnv_close(calendar_globals->iso_8859_8_conv);
+ }
+}
zend_module_entry calendar_module_entry = {
STANDARD_MODULE_HEADER,
@@ -180,7 +196,11 @@
NULL,
PHP_MINFO(calendar),
NO_VERSION_YET,
- STANDARD_MODULE_PROPERTIES,
+ PHP_MODULE_GLOBALS(calendar),
+ PHP_GINIT(calendar),
+ PHP_GSHUTDOWN(calendar),
+ NULL,
+ STANDARD_MODULE_PROPERTIES_EX,
};
#ifdef COMPILE_DL_CALENDAR
@@ -275,7 +295,7 @@
php_info_print_table_end();
}
-static void _php_cal_info(int cal, zval **ret)
+static void _php_cal_info(int cal, zval **ret TSRMLS_DC)
{
zval *months, *smonths;
int i;
@@ -290,23 +310,23 @@
array_init(smonths);
for (i = 1; i <= calendar->num_months; i++) {
- add_index_string(months, i, calendar->month_name_long[i], 1);
- add_index_string(smonths, i, calendar->month_name_short[i], 1);
+ add_index_ascii_string(months, i,
calendar->month_name_long[i], ZSTR_DUPLICATE);
+ add_index_ascii_string(smonths, i,
calendar->month_name_short[i], ZSTR_DUPLICATE);
}
- add_assoc_zval(*ret, "months", months);
- add_assoc_zval(*ret, "abbrevmonths", smonths);
- add_assoc_long(*ret, "maxdaysinmonth", calendar->max_days_in_month);
- add_assoc_string(*ret, "calname", calendar->name, 1);
- add_assoc_string(*ret, "calsymbol", calendar->symbol, 1);
+
+ add_ascii_assoc_zval(*ret, "months", months);
+ add_ascii_assoc_zval(*ret, "abbrevmonths", smonths);
+ add_ascii_assoc_long(*ret, "maxdaysinmonth",
calendar->max_days_in_month);
+ add_ascii_assoc_ascii_string(*ret, "calname", calendar->name, 1);
+ add_ascii_assoc_ascii_string(*ret, "calsymbol", calendar->symbol, 1);
}
-/* {{{ proto array cal_info([int calendar])
+/* {{{ proto array cal_info([int calendar]) U
Returns information about a particular calendar */
PHP_FUNCTION(cal_info)
{
long cal = -1;
-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &cal) ==
FAILURE) {
RETURN_FALSE;
@@ -320,7 +340,7 @@
for (i = 0; i < CAL_NUM_CALS; i++) {
MAKE_STD_ZVAL(val);
- _php_cal_info(i, &val);
+ _php_cal_info(i, &val TSRMLS_CC);
add_index_zval(return_value, i, val);
}
return;
@@ -332,12 +352,12 @@
RETURN_FALSE;
}
- _php_cal_info(cal, &return_value);
+ _php_cal_info(cal, &return_value TSRMLS_CC);
}
/* }}} */
-/* {{{ proto int cal_days_in_month(int calendar, int month, int year)
+/* {{{ proto int cal_days_in_month(int calendar, int month, int year) U
Returns the number of days in a month for a given year and calendar */
PHP_FUNCTION(cal_days_in_month)
{
@@ -366,7 +386,7 @@
sdn_next = calendar->to_jd(year, 1 + month, 1);
if (sdn_next == 0) {
-/* if invalid, try first month of the next year... */
+ /* if invalid, try first month of the next year... */
sdn_next = calendar->to_jd(year + 1, 1, 1);
}
@@ -374,7 +394,7 @@
}
/* }}} */
-/* {{{ proto int cal_to_jd(int calendar, int month, int day, int year)
+/* {{{ proto int cal_to_jd(int calendar, int month, int day, int year) U
Converts from a supported calendar to Julian Day Count */
PHP_FUNCTION(cal_to_jd)
{
@@ -393,7 +413,7 @@
}
/* }}} */
-/* {{{ proto array cal_from_jd(int jd, int calendar)
+/* {{{ proto array cal_from_jd(int jd, int calendar) U
Converts from Julian Day Count to a supported calendar and return extended
information */
PHP_FUNCTION(cal_from_jd)
{
@@ -423,18 +443,19 @@
add_assoc_long(return_value, "day", day);
add_assoc_long(return_value, "year", year);
-/* day of week */
+ /* day of week */
dow = DayOfWeek(jd);
- add_assoc_long(return_value, "dow", dow);
- add_assoc_string(return_value, "abbrevdayname", DayNameShort[dow], 1);
- add_assoc_string(return_value, "dayname", DayNameLong[dow], 1);
-/* month name */
- add_assoc_string(return_value, "abbrevmonth",
calendar->month_name_short[month], 1);
- add_assoc_string(return_value, "monthname",
calendar->month_name_long[month], 1);
+ add_ascii_assoc_long(return_value, "dow", dow);
+ add_ascii_assoc_ascii_string(return_value, "abbrevdayname",
DayNameShort[dow], 1);
+ add_ascii_assoc_ascii_string(return_value, "dayname",
DayNameLong[dow], 1);
+
+ /* month name */
+ add_ascii_assoc_ascii_string(return_value, "abbrevmonth",
calendar->month_name_short[month], 1);
+ add_ascii_assoc_ascii_string(return_value, "monthname",
calendar->month_name_long[month], 1);
}
/* }}} */
-/* {{{ proto string jdtogregorian(int juliandaycount)
+/* {{{ proto string jdtogregorian(int juliandaycount) U
Converts a julian day count to a gregorian calendar date */
PHP_FUNCTION(jdtogregorian)
{
@@ -449,11 +470,11 @@
SdnToGregorian(julday, &year, &month, &day);
snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);
- RETURN_STRING(date, 1);
+ RETURN_ASCII_STRING(date, ZSTR_DUPLICATE);
}
/* }}} */
-/* {{{ proto int gregoriantojd(int month, int day, int year)
+/* {{{ proto int gregoriantojd(int month, int day, int year) U
Converts a gregorian calendar date to julian day count */
PHP_FUNCTION(gregoriantojd)
{
@@ -467,7 +488,7 @@
}
/* }}} */
-/* {{{ proto string jdtojulian(int juliandaycount)
+/* {{{ proto string jdtojulian(int juliandaycount) U
Convert a julian day count to a julian calendar date */
PHP_FUNCTION(jdtojulian)
{
@@ -482,11 +503,11 @@
SdnToJulian(julday, &year, &month, &day);
snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);
- RETURN_STRING(date, 1);
+ RETURN_ASCII_STRING(date, ZSTR_DUPLICATE);
}
/* }}} */
-/* {{{ proto int juliantojd(int month, int day, int year)
+/* {{{ proto int juliantojd(int month, int day, int year) U
Converts a julian calendar date to julian day count */
PHP_FUNCTION(juliantojd)
{
@@ -595,7 +616,7 @@
}
/* }}} */
-/* {{{ proto string jdtojewish(int juliandaycount [, bool hebrew [, int fl]])
+/* {{{ proto string jdtojewish(int juliandaycount [, bool hebrew [, int fl]]) U
Converts a julian day count to a jewish calendar date */
PHP_FUNCTION(jdtojewish)
{
@@ -628,13 +649,16 @@
efree(yearp);
}
- RETURN_STRING(hebdate, 1);
-
+ if (UG(unicode) && CALENDAR_G(iso_8859_8_conv)) {
+ RETURN_U_STRING(CALENDAR_G(iso_8859_8_conv), hebdate,
ZSTR_DUPLICATE);
+ } else {
+ RETURN_STRING(hebdate, 1);
+ }
}
}
/* }}} */
-/* {{{ proto int jewishtojd(int month, int day, int year)
+/* {{{ proto int jewishtojd(int month, int day, int year) U
Converts a jewish calendar date to a julian day count */
PHP_FUNCTION(jewishtojd)
{
@@ -648,7 +672,7 @@
}
/* }}} */
-/* {{{ proto string jdtofrench(int juliandaycount)
+/* {{{ proto string jdtofrench(int juliandaycount) U
Converts a julian day count to a french republic calendar date */
PHP_FUNCTION(jdtofrench)
{
@@ -663,11 +687,11 @@
SdnToFrench(julday, &year, &month, &day);
snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);
- RETURN_STRING(date, 1);
+ RETURN_ASCII_STRING(date, ZSTR_DUPLICATE);
}
/* }}} */
-/* {{{ proto int frenchtojd(int month, int day, int year)
+/* {{{ proto int frenchtojd(int month, int day, int year) U
Converts a french republic calendar date to julian day count */
PHP_FUNCTION(frenchtojd)
{
@@ -681,7 +705,7 @@
}
/* }}} */
-/* {{{ proto mixed jddayofweek(int juliandaycount [, int mode])
+/* {{{ proto mixed jddayofweek(int juliandaycount [, int mode]) U
Returns name or number of day of week from julian day count */
PHP_FUNCTION(jddayofweek)
{
@@ -699,10 +723,10 @@
switch (mode) {
case CAL_DOW_SHORT:
- RETURN_STRING(daynamel, 1);
+ RETURN_ASCII_STRING(daynamel, ZSTR_DUPLICATE);
break;
case CAL_DOW_LONG:
- RETURN_STRING(daynames, 1);
+ RETURN_ASCII_STRING(daynames, ZSTR_DUPLICATE);
break;
case CAL_DOW_DAYNO:
default:
@@ -712,7 +736,7 @@
}
/* }}} */
-/* {{{ proto string jdmonthname(int juliandaycount, int mode)
+/* {{{ proto string jdmonthname(int juliandaycount, int mode) U
Returns name of month for julian day count */
PHP_FUNCTION(jdmonthname)
{
@@ -740,6 +764,11 @@
case CAL_MONTH_JEWISH: /* jewish month */
SdnToJewish(julday, &year, &month, &day);
monthname = JewishMonthName[month];
+ if (UG(unicode) && CALENDAR_G(iso_8859_8_conv)) {
+ RETURN_U_STRING(CALENDAR_G(iso_8859_8_conv), monthname,
ZSTR_DUPLICATE);
+ } else {
+ RETURN_STRING(monthname, 1);
+ }
break;
case CAL_MONTH_FRENCH: /* french month */
SdnToFrench(julday, &year, &month, &day);
@@ -752,7 +781,7 @@
break;
}
- RETURN_STRING(monthname, 1);
+ RETURN_ASCII_STRING(monthname, ZSTR_DUPLICATE);
}
/* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/calendar/php_calendar.h?r1=1.7&r2=1.8&diff_format=u
Index: php-src/ext/calendar/php_calendar.h
diff -u php-src/ext/calendar/php_calendar.h:1.7
php-src/ext/calendar/php_calendar.h:1.8
--- php-src/ext/calendar/php_calendar.h:1.7 Sun Jul 9 23:28:41 2006
+++ php-src/ext/calendar/php_calendar.h Mon Jan 21 06:08:03 2008
@@ -28,6 +28,17 @@
PHP_FUNCTION(cal_days_in_month);
PHP_FUNCTION(cal_info);
+#ifdef ZTS
+# include "TSRM.h"
+# define CALENDAR_G(v) TSRMG(calendar_globals_id, zend_calendar_globals *, v)
+#else
+# define CALENDAR_G(v) (calendar_globals.v)
+#endif
+
+ZEND_BEGIN_MODULE_GLOBALS(calendar)
+ UConverter *iso_8859_8_conv;
+ZEND_END_MODULE_GLOBALS(calendar)
+
#define phpext_calendar_ptr calendar_module_ptr
/*
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php