diff options
author | Wez Furlong <wez@php.net> | 2002-11-26 14:52:00 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2002-11-26 14:52:00 +0000 |
commit | b1a543453772247692af05f018bd274f09ed3042 (patch) | |
tree | 63b1b9d21e7e57733c965ba214772d25f805acdb | |
parent | 579e3ca96b81ae148fd728b0f415d1d27b628655 (diff) | |
download | php-git-b1a543453772247692af05f018bd274f09ed3042.tar.gz |
Update to use new parameter parsing API.
Updates to Jewish/Hebrew calendar code.
Patch from Moshe Doron, amended by Tal Peer,
reviewed by me.
# Maybe Tal and/or Moshe could comment on whether this should
# also be commited to the 4_3 branch (it completes some earlier work
# started prior to the branch).
-rw-r--r-- | ext/calendar/calendar.c | 516 |
1 files changed, 248 insertions, 268 deletions
diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c index b0f65eeb88..abab7225d8 100644 --- a/ext/calendar/calendar.c +++ b/ext/calendar/calendar.c @@ -34,7 +34,7 @@ #include "sdncal.h" #include <stdio.h> - + function_entry calendar_functions[] = { PHP_FE(jdtogregorian, NULL) PHP_FE(gregoriantojd, NULL) @@ -48,10 +48,10 @@ function_entry calendar_functions[] = { PHP_FE(jdmonthname, NULL) PHP_FE(easter_date, NULL) PHP_FE(easter_days, NULL) - PHP_FE(unixtojd, NULL) - PHP_FE(jdtounix, NULL) - PHP_FE(cal_to_jd, NULL) - PHP_FE(cal_from_jd, NULL) + PHP_FE(unixtojd, NULL) + PHP_FE(jdtounix, NULL) + PHP_FE(cal_to_jd, NULL) + PHP_FE(cal_from_jd, NULL) PHP_FE(cal_days_in_month, NULL) PHP_FE(cal_info, NULL) {NULL, NULL, NULL} @@ -60,8 +60,8 @@ function_entry calendar_functions[] = { zend_module_entry calendar_module_entry = { STANDARD_MODULE_HEADER, - "calendar", - calendar_functions, + "calendar", + calendar_functions, PHP_MINIT(calendar), NULL, NULL, @@ -74,7 +74,6 @@ zend_module_entry calendar_module_entry = { #ifdef COMPILE_DL_CALENDAR ZEND_GET_MODULE(calendar) #endif - /* this order must match the conversion table below */ enum cal_name_type_t { CAL_GREGORIAN = 0, @@ -83,60 +82,73 @@ enum cal_name_type_t { CAL_FRENCH, CAL_NUM_CALS }; -typedef long int (*cal_to_jd_func_t)(int month, int day, int year); -typedef void (*cal_from_jd_func_t)(long int jd, int* year, int* month, int* day); -typedef char* (*cal_as_string_func_t)(int year, int month, int day); +typedef long int (*cal_to_jd_func_t) (int month, int day, int year); +typedef void (*cal_from_jd_func_t) (long int jd, int *year, int *month, int *day); +typedef char *(*cal_as_string_func_t) (int year, int month, int day); struct cal_entry_t { - char *name; - char *symbol; - cal_to_jd_func_t to_jd; - cal_from_jd_func_t from_jd; - int num_months; - int max_days_in_month; - char **month_name_short; - char **month_name_long; + char *name; + char *symbol; + cal_to_jd_func_t to_jd; + cal_from_jd_func_t from_jd; + int num_months; + int max_days_in_month; + char **month_name_short; + char **month_name_long; }; static struct cal_entry_t cal_conversion_table[CAL_NUM_CALS] = { - { "Gregorian", "CAL_GREGORIAN", GregorianToSdn, SdnToGregorian, 12, 31, MonthNameShort, MonthNameLong }, - { "Julian", "CAL_JULIAN", JulianToSdn, SdnToJulian, 12, 31, MonthNameShort, MonthNameLong }, - { "Jewish", "CAL_JEWISH", JewishToSdn, SdnToJewish, 13, 30, JewishMonthName, JewishMonthName }, - { "French", "CAL_FRENCH", FrenchToSdn, SdnToFrench, 13, 30, FrenchMonthName, FrenchMonthName } + {"Gregorian", "CAL_GREGORIAN", GregorianToSdn, SdnToGregorian, 12, 31, + MonthNameShort, MonthNameLong}, + {"Julian", "CAL_JULIAN", JulianToSdn, SdnToJulian, 12, 31, + MonthNameShort, MonthNameLong}, + {"Jewish", "CAL_JEWISH", JewishToSdn, SdnToJewish, 13, 30, + JewishMonthName, JewishMonthName}, + {"French", "CAL_FRENCH", FrenchToSdn, SdnToFrench, 13, 30, + FrenchMonthName, FrenchMonthName} }; /* For jddayofweek */ -enum { CAL_DOW_DAYNO, CAL_DOW_SHORT, CAL_DOW_LONG }; +enum { CAL_DOW_DAYNO, CAL_DOW_SHORT, CAL_DOW_LONG }; /* For jdmonthname */ -enum { CAL_MONTH_GREGORIAN_SHORT, CAL_MONTH_GREGORIAN_LONG, +enum { CAL_MONTH_GREGORIAN_SHORT, CAL_MONTH_GREGORIAN_LONG, CAL_MONTH_JULIAN_SHORT, CAL_MONTH_JULIAN_LONG, CAL_MONTH_JEWISH, - CAL_MONTH_FRENCH }; + CAL_MONTH_FRENCH +}; /* for heb_number_to_chars */ static char alef_bet[25] = "0אבגדהוזחטיכלמנסעפצקרשת"; - + +#define CAL_JEWISH_ADD_ALAFIM_GERESH 0x2 +#define CAL_JEWISH_ADD_ALAFIM 0x4 +#define CAL_JEWISH_ADD_GERESHAYIM 0x8 + PHP_MINIT_FUNCTION(calendar) { - REGISTER_LONG_CONSTANT("CAL_GREGORIAN", CAL_GREGORIAN, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_JULIAN", CAL_JULIAN, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_JEWISH", CAL_JEWISH, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_FRENCH", CAL_FRENCH, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_NUM_CALS", CAL_NUM_CALS, CONST_CS|CONST_PERSISTENT); - /* constants for jddayofweek */ - REGISTER_LONG_CONSTANT("CAL_DOW_DAYNO", CAL_DOW_DAYNO, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_DOW_SHORT", CAL_DOW_SHORT, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_DOW_LONG", CAL_DOW_LONG, CONST_CS|CONST_PERSISTENT); - /* constants for jdmonthname */ - REGISTER_LONG_CONSTANT("CAL_MONTH_GREGORIAN_SHORT", CAL_MONTH_GREGORIAN_SHORT, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_MONTH_GREGORIAN_LONG", CAL_MONTH_GREGORIAN_LONG, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_MONTH_JULIAN_SHORT", CAL_MONTH_JULIAN_SHORT, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_MONTH_JULIAN_LONG", CAL_MONTH_JULIAN_LONG, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_MONTH_JEWISH", CAL_MONTH_JEWISH, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_MONTH_FRENCH", CAL_MONTH_FRENCH, CONST_CS|CONST_PERSISTENT); - /* constants for easter calculation */ - REGISTER_LONG_CONSTANT("CAL_EASTER_DEFAULT", CAL_EASTER_DEFAULT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_EASTER_ROMAN", CAL_EASTER_ROMAN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_EASTER_ALWAYS_GREGORIAN", CAL_EASTER_ALWAYS_GREGORIAN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CAL_EASTER_ALWAYS_JULIAN", CAL_EASTER_ALWAYS_JULIAN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_GREGORIAN", CAL_GREGORIAN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_JULIAN", CAL_JULIAN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_JEWISH", CAL_JEWISH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_FRENCH", CAL_FRENCH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_NUM_CALS", CAL_NUM_CALS, CONST_CS | CONST_PERSISTENT); +/* constants for jddayofweek */ + REGISTER_LONG_CONSTANT("CAL_DOW_DAYNO", CAL_DOW_DAYNO, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_DOW_SHORT", CAL_DOW_SHORT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_DOW_LONG", CAL_DOW_LONG, CONST_CS | CONST_PERSISTENT); +/* constants for jdmonthname */ + REGISTER_LONG_CONSTANT("CAL_MONTH_GREGORIAN_SHORT", CAL_MONTH_GREGORIAN_SHORT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_MONTH_GREGORIAN_LONG", CAL_MONTH_GREGORIAN_LONG, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_MONTH_JULIAN_SHORT", CAL_MONTH_JULIAN_SHORT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_MONTH_JULIAN_LONG", CAL_MONTH_JULIAN_LONG, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_MONTH_JEWISH", CAL_MONTH_JEWISH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_MONTH_FRENCH", CAL_MONTH_FRENCH, CONST_CS | CONST_PERSISTENT); +/* constants for easter calculation */ + REGISTER_LONG_CONSTANT("CAL_EASTER_DEFAULT", CAL_EASTER_DEFAULT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_EASTER_ROMAN", CAL_EASTER_ROMAN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_EASTER_ALWAYS_GREGORIAN", CAL_EASTER_ALWAYS_GREGORIAN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_EASTER_ALWAYS_JULIAN", CAL_EASTER_ALWAYS_JULIAN, CONST_CS | CONST_PERSISTENT); +/* constants for Jewish date formatting */ + REGISTER_LONG_CONSTANT("CAL_JEWISH_ADD_ALAFIM_GERESH", CAL_JEWISH_ADD_ALAFIM_GERESH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_JEWISH_ADD_ALAFIM", CAL_JEWISH_ADD_ALAFIM, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CAL_JEWISH_ADD_GERESHAYIM", CAL_JEWISH_ADD_GERESHAYIM, CONST_CS | CONST_PERSISTENT); return SUCCESS; } @@ -151,29 +163,29 @@ PHP_MINFO_FUNCTION(calendar) Returns information about a particular calendar */ PHP_FUNCTION(cal_info) { - zval ** cal; - zval * months, *smonths; + long cal; + zval *months, *smonths; int i; - struct cal_entry_t * calendar; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &cal) != SUCCESS) { - WRONG_PARAM_COUNT; + struct cal_entry_t *calendar; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &cal) == FAILURE) { + RETURN_FALSE; } - convert_to_long_ex(cal); - if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) { - zend_error(E_WARNING, "%s(): invalid calendar ID %d", get_active_function_name(TSRMLS_C), Z_LVAL_PP(cal)); + + if (cal < 0 || cal >= CAL_NUM_CALS) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid calendar ID %d.", cal); RETURN_FALSE; } - calendar = &cal_conversion_table[Z_LVAL_PP(cal)]; + calendar = &cal_conversion_table[cal]; array_init(return_value); MAKE_STD_ZVAL(months); MAKE_STD_ZVAL(smonths); array_init(months); array_init(smonths); - - for (i=1; i<= calendar->num_months; i++) { + + 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); } @@ -182,7 +194,7 @@ PHP_FUNCTION(cal_info) add_assoc_long(return_value, "maxdaysinmonth", calendar->max_days_in_month); add_assoc_string(return_value, "calname", calendar->name, 1); add_assoc_string(return_value, "calsymbol", calendar->symbol, 1); - + } /* }}} */ @@ -190,34 +202,30 @@ PHP_FUNCTION(cal_info) Returns the number of days in a month for a given year and calendar */ PHP_FUNCTION(cal_days_in_month) { - zval ** cal, **month, **year; - struct cal_entry_t * calendar; + long cal, month, year; + struct cal_entry_t *calendar; long sdn_start, sdn_next; - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &cal, &month, &year) != SUCCESS) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(cal); - convert_to_long_ex(month); - convert_to_long_ex(year); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &cal, &month, &year) == FAILURE) { + RETURN_FALSE; + } - if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) { - zend_error(E_WARNING, "%s(): invalid calendar ID %d", get_active_function_name(TSRMLS_C), Z_LVAL_PP(cal)); + if (cal < 0 || cal >= CAL_NUM_CALS) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid calendar ID %d.", cal); RETURN_FALSE; } - calendar = &cal_conversion_table[Z_LVAL_PP(cal)]; - - sdn_start = calendar->to_jd(Z_LVAL_PP(year), Z_LVAL_PP(month), 1); - - sdn_next = calendar->to_jd(Z_LVAL_PP(year), 1 + Z_LVAL_PP(month), 1); + calendar = &cal_conversion_table[cal]; + + sdn_start = calendar->to_jd(year, month, 1); - if (sdn_next == 0) { - /* if invalid, try first month of the next year... */ - sdn_next = calendar->to_jd(Z_LVAL_PP(year) + 1, 1, 1); + sdn_next = calendar->to_jd(year, 1 + month, 1); + + if (sdn_next == 0) { +/* if invalid, try first month of the next year... */ + sdn_next = calendar->to_jd(year + 1, 1, 1); } - + RETURN_LONG(sdn_next - sdn_start); } /* }}} */ @@ -226,25 +234,18 @@ PHP_FUNCTION(cal_days_in_month) Converts from a supported calendar to Julian Day Count */ PHP_FUNCTION(cal_to_jd) { - zval ** cal, **month, **day, **year; - long jdate; + long cal, month, day, year, jdate; - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &cal, &month, &day, &year) != SUCCESS) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll", &cal, &month, &day, &year) != SUCCESS) { + RETURN_FALSE; } - convert_to_long_ex(cal); - convert_to_long_ex(month); - convert_to_long_ex(day); - convert_to_long_ex(year); - - if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) { - zend_error(E_WARNING, "%s(): invalid calendar ID %d", get_active_function_name(TSRMLS_C), Z_LVAL_PP(cal)); + if (cal < 0 || cal >= CAL_NUM_CALS) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid calendar ID %d.", cal); RETURN_FALSE; } - jdate = cal_conversion_table[Z_LVAL_PP(cal)].to_jd( - Z_LVAL_PP(year), Z_LVAL_PP(month), Z_LVAL_PP(day)); + jdate = cal_conversion_table[cal].to_jd(year, month, day); RETURN_LONG(jdate); } /* }}} */ @@ -253,42 +254,38 @@ PHP_FUNCTION(cal_to_jd) Converts from Julian Day Count to a supported calendar and return extended information */ PHP_FUNCTION(cal_from_jd) { - zval ** jd, ** cal; + long jd, cal; int month, day, year, dow; char date[16]; - struct cal_entry_t * calendar; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &jd, &cal) != SUCCESS) { - WRONG_PARAM_COUNT; + struct cal_entry_t *calendar; + + if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "ll", &jd, &cal) == FAILURE) { + RETURN_FALSE; } - convert_to_long_ex(jd); - convert_to_long_ex(cal); - if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) { - zend_error(E_WARNING, "%s(): invalid calendar ID %d", get_active_function_name(TSRMLS_C), Z_LVAL_PP(cal)); + if (cal < 0 || cal >= CAL_NUM_CALS) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid calendar ID %d", cal); RETURN_FALSE; } - calendar = &cal_conversion_table[Z_LVAL_PP(cal)]; + calendar = &cal_conversion_table[cal]; array_init(return_value); - calendar->from_jd( - Z_LVAL_PP(jd), - &year, &month, &day); + calendar->from_jd(jd, &year, &month, &day); sprintf(date, "%i/%i/%i", month, day, year); add_assoc_string(return_value, "date", date, 1); - + add_assoc_long(return_value, "month", month); add_assoc_long(return_value, "day", day); add_assoc_long(return_value, "year", year); - /* day of week */ - dow = DayOfWeek(Z_LVAL_PP(jd)); +/* 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 */ +/* 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); } @@ -298,16 +295,15 @@ PHP_FUNCTION(cal_from_jd) Converts a julian day count to a gregorian calendar date */ PHP_FUNCTION(jdtogregorian) { - pval **julday; + long julday; int year, month, day; char date[10]; - if (zend_get_parameters_ex(1, &julday) != SUCCESS) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &julday) == FAILURE) { + RETURN_FALSE; } - convert_to_long_ex(julday); - SdnToGregorian(Z_LVAL_PP(julday), &year, &month, &day); + SdnToGregorian(julday, &year, &month, &day); sprintf(date, "%i/%i/%i", month, day, year); RETURN_STRING(date, 1); @@ -318,18 +314,14 @@ PHP_FUNCTION(jdtogregorian) Converts a gregorian calendar date to julian day count */ PHP_FUNCTION(gregoriantojd) { - pval **year, **month, **day; + long year, month, day; int jdate; - if (zend_get_parameters_ex(3, &month, &day, &year) != SUCCESS) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &month, &day, &year) == FAILURE) { + RETURN_FALSE; } - - convert_to_long_ex(month); - convert_to_long_ex(day); - convert_to_long_ex(year); - jdate = GregorianToSdn(Z_LVAL_PP(year), Z_LVAL_PP(month), Z_LVAL_PP(day)); + jdate = GregorianToSdn(year, month, day); RETURN_LONG(jdate); } @@ -337,18 +329,17 @@ PHP_FUNCTION(gregoriantojd) /* {{{ proto string jdtojulian(int juliandaycount) Convert a julian day count to a julian calendar date */ -PHP_FUNCTION(jdtojulian) +PHP_FUNCTION(jdtojulian) { - pval **julday; + long julday; int year, month, day; char date[10]; - if (zend_get_parameters_ex(1, &julday) != SUCCESS) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &julday) == FAILURE) { + RETURN_FALSE; } - convert_to_long_ex(julday); - SdnToJulian(Z_LVAL_PP(julday), &year, &month, &day); + SdnToJulian(julday, &year, &month, &day); sprintf(date, "%i/%i/%i", month, day, year); RETURN_STRING(date, 1); @@ -359,129 +350,138 @@ PHP_FUNCTION(jdtojulian) Converts a julian calendar date to julian day count */ PHP_FUNCTION(juliantojd) { - pval **year, **month, **day; + long year, month, day; int jdate; - if (zend_get_parameters_ex(3, &month, &day, &year) != SUCCESS) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &month, &day, &year) == FAILURE) { + RETURN_FALSE; } - - convert_to_long_ex(month); - convert_to_long_ex(day); - convert_to_long_ex(year); - jdate = JulianToSdn(Z_LVAL_PP(year), Z_LVAL_PP(month), Z_LVAL_PP(day)); + jdate = JulianToSdn(year, month, day); RETURN_LONG(jdate); } /* }}} */ -/* - caution: the hebrew format product non unique result. - for example both: year '5' and year '5000' product 'ה'. - use the numeric one for calculations. +/* {{{ heb_number_to_chars*/ +/* +caution: the Hebrew format produces non unique result. +for example both: year '5' and year '5000' produce 'ה'. +use the numeric one for calculations. */ -static char* heb_number_to_chars(int n) +static char *heb_number_to_chars(int n, int fl) { - char *p, *old, *ret; - - p = emalloc(10); - old = p; + char *p, old[18], *ret, *endofalafim; - /* - prevents the option breaking the jewish beliefs, and some other - critical resources ;) - */ + p = endofalafim = old; +/* + prevents the option breaking the jewish beliefs, and some other + critical resources ;) + */ if (n > 9999 || n < 1) return NULL; - /* alafim case */ +/* alafim (thousands) case */ if (n / 1000) { *p = alef_bet[n / 1000]; p++; + + if (CAL_JEWISH_ADD_ALAFIM_GERESH & fl) { + *p = '\''; + p++; + } + if (CAL_JEWISH_ADD_ALAFIM & fl) { + strcpy(p, " אלפים "); + p += 7; + } + + endofalafim = p; n = n % 1000; } - /* taf-taf case */ +/* tav-tav (tav=400) case */ while (n >= 400) { *p = alef_bet[22]; p++; - n-=400; + n -= 400; } - /* meot case */ - if (n >= 100) { - *p = alef_bet[18+n/100]; +/* meot (hundreads) case */ + if (n >= 100) { + *p = alef_bet[18 + n / 100]; p++; n = n % 100; } - /* tet-vav tet-zain case */ +/* tet-vav & tet-zain case (special case for 15 and 16) */ if (n == 15 || n == 16) { *p = alef_bet[9]; p++; - *p = alef_bet[n-9]; + *p = alef_bet[n - 9]; p++; } else { - /* asarot case */ - if (n >= 10) { - *p = alef_bet[9+n/10]; +/* asarot (tens) case */ + if (n >= 10) { + *p = alef_bet[9 + n / 10]; p++; n = n % 10; } - /* yeihot case */ +/* yehidot (ones) case */ if (n > 0) { *p = alef_bet[n]; p++; } } + if (CAL_JEWISH_ADD_GERESHAYIM & fl) { + switch (p - endofalafim) { + case 0: + break; + case 1: + *p = '\''; + p++; + break; + default: + *(p) = *(p - 1); + *(p - 1) = '"'; + p++; + } + } + *p = '\0'; ret = emalloc((int) (p - old) + 1); strncpy(ret, old, (int) (p - old) + 1); return ret; } +/* }}} */ -/* {{{ proto string jdtojewish(int juliandaycount) +/* {{{ proto string jdtojewish(int juliandaycount [, int fl]) Converts a julian day count to a jewish calendar date */ -PHP_FUNCTION(jdtojewish) +PHP_FUNCTION(jdtojewish) { - long julday, fl; + long julday, fl = 0; int year, month, day; char date[10], hebdate[25]; - - if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(1 TSRMLS_CC,"l", &julday) != SUCCESS) { - RETURN_FALSE; - } - fl=0; - } else if (ZEND_NUM_ARGS() == 2) { - if (zend_parse_parameters(2 TSRMLS_CC,"ll", &julday, &fl) != SUCCESS) { - RETURN_FALSE; - } - } else { - WRONG_PARAM_COUNT; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &julday, &fl) == FAILURE) { + RETURN_FALSE; } - - + SdnToJewish(julday, &year, &month, &day); - if(!fl) { + if (!fl) { sprintf(date, "%i/%i/%i", month, day, year); RETURN_STRING(date, 1); } else { if (year <= 0 || year > 9999) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Out of range year."); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Year out of range (0-9999)."); RETURN_FALSE; } - - sprintf(hebdate, "%s %s %s", \ - heb_number_to_chars(day), \ - JewishMonthHebName[month], \ - heb_number_to_chars(year)); - + + sprintf(hebdate, "%s %s %s", heb_number_to_chars(day, fl), JewishMonthHebName[month], heb_number_to_chars(year, fl)); + RETURN_STRING(hebdate, 1); - + } } /* }}} */ @@ -490,18 +490,14 @@ PHP_FUNCTION(jdtojewish) Converts a jewish calendar date to a julian day count */ PHP_FUNCTION(jewishtojd) { - pval **year, **month, **day; + long year, month, day; int jdate; - if (zend_get_parameters_ex(3, &month, &day, &year) != SUCCESS) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &month, &day, &year) == FAILURE) { + RETURN_FALSE; } - convert_to_long_ex(month); - convert_to_long_ex(day); - convert_to_long_ex(year); - - jdate = JewishToSdn(Z_LVAL_PP(year), Z_LVAL_PP(month), Z_LVAL_PP(day)); + jdate = JewishToSdn(year, month, day); RETURN_LONG(jdate); } @@ -511,17 +507,15 @@ PHP_FUNCTION(jewishtojd) Converts a julian day count to a french republic calendar date */ PHP_FUNCTION(jdtofrench) { - pval **julday; + long julday; int year, month, day; char date[10]; - if (zend_get_parameters_ex(1, &julday) != SUCCESS) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &julday) == FAILURE) { + RETURN_FALSE; } - convert_to_long_ex(julday); - - SdnToFrench(Z_LVAL_PP(julday), &year, &month, &day); + SdnToFrench(julday, &year, &month, &day); sprintf(date, "%i/%i/%i", month, day, year); RETURN_STRING(date, 1); @@ -532,18 +526,14 @@ PHP_FUNCTION(jdtofrench) Converts a french republic calendar date to julian day count */ PHP_FUNCTION(frenchtojd) { - pval **year, **month, **day; + long year, month, day; int jdate; - if (zend_get_parameters_ex(3, &month, &day, &year) != SUCCESS) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &month, &day, &year) == FAILURE) { + RETURN_FALSE; } - - convert_to_long_ex(month); - convert_to_long_ex(day); - convert_to_long_ex(year); - jdate = FrenchToSdn(Z_LVAL_PP(year), Z_LVAL_PP(month), Z_LVAL_PP(day)); + jdate = FrenchToSdn(year, month, day); RETURN_LONG(jdate); } @@ -553,37 +543,30 @@ PHP_FUNCTION(frenchtojd) Returns name or number of day of week from julian day count */ PHP_FUNCTION(jddayofweek) { - pval *julday, *mode; + long julday, mode = CAL_DOW_DAYNO; int day; char *daynamel, *daynames; - int myargc=ZEND_NUM_ARGS(), mymode=0; - - if ((myargc < 1) || (myargc > 2) || (zend_get_parameters(ht, myargc, &julday, &mode) != SUCCESS)) { - WRONG_PARAM_COUNT; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &julday, &mode) == FAILURE) { + RETURN_FALSE; } - - convert_to_long(julday); - if(myargc==2) { - convert_to_long(mode); - mymode = Z_LVAL_P(mode); - } - - day = DayOfWeek(Z_LVAL_P(julday)); + + day = DayOfWeek(julday); daynamel = DayNameLong[day]; daynames = DayNameShort[day]; - switch (mymode) { - case CAL_DOW_SHORT: - RETURN_STRING(daynamel, 1); - break; - case CAL_DOW_LONG: - RETURN_STRING(daynames, 1); - break; - case CAL_DOW_DAYNO: - default: - RETURN_LONG(day); - break; - } + switch (mode) { + case CAL_DOW_SHORT: + RETURN_STRING(daynamel, 1); + break; + case CAL_DOW_LONG: + RETURN_STRING(daynames, 1); + break; + case CAL_DOW_DAYNO: + default: + RETURN_LONG(day); + break; + } } /* }}} */ @@ -591,43 +574,40 @@ PHP_FUNCTION(jddayofweek) Returns name of month for julian day count */ PHP_FUNCTION(jdmonthname) { - pval **julday, **mode; + long julday, mode; char *monthname = NULL; int month, day, year; - if (zend_get_parameters_ex(2, &julday, &mode) != SUCCESS) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &julday, &mode) == FAILURE) { + RETURN_FALSE; } - convert_to_long_ex(julday); - convert_to_long_ex(mode); - - switch(Z_LVAL_PP(mode)) { - case CAL_MONTH_GREGORIAN_LONG: /* gregorian or julian month */ - SdnToGregorian(Z_LVAL_PP(julday), &year, &month, &day); - monthname = MonthNameLong[month]; - break; - case CAL_MONTH_JULIAN_SHORT: /* gregorian or julian month */ - SdnToJulian(Z_LVAL_PP(julday), &year, &month, &day); - monthname = MonthNameShort[month]; - break; - case CAL_MONTH_JULIAN_LONG: /* gregorian or julian month */ - SdnToJulian(Z_LVAL_PP(julday), &year, &month, &day); - monthname = MonthNameLong[month]; - break; - case CAL_MONTH_JEWISH: /* jewish month */ - SdnToJewish(Z_LVAL_PP(julday), &year, &month, &day); - monthname = JewishMonthName[month]; - break; - case CAL_MONTH_FRENCH: /* french month */ - SdnToFrench(Z_LVAL_PP(julday), &year, &month, &day); - monthname = FrenchMonthName[month]; - break; - default: /* default gregorian */ - case CAL_MONTH_GREGORIAN_SHORT: /* gregorian or julian month */ - SdnToGregorian(Z_LVAL_PP(julday), &year, &month, &day); - monthname = MonthNameShort[month]; - break; + switch (mode) { + case CAL_MONTH_GREGORIAN_LONG: /* gregorian or julian month */ + SdnToGregorian(julday, &year, &month, &day); + monthname = MonthNameLong[month]; + break; + case CAL_MONTH_JULIAN_SHORT: /* gregorian or julian month */ + SdnToJulian(julday, &year, &month, &day); + monthname = MonthNameShort[month]; + break; + case CAL_MONTH_JULIAN_LONG: /* gregorian or julian month */ + SdnToJulian(julday, &year, &month, &day); + monthname = MonthNameLong[month]; + break; + case CAL_MONTH_JEWISH: /* jewish month */ + SdnToJewish(julday, &year, &month, &day); + monthname = JewishMonthName[month]; + break; + case CAL_MONTH_FRENCH: /* french month */ + SdnToFrench(julday, &year, &month, &day); + monthname = FrenchMonthName[month]; + break; + default: /* default gregorian */ + case CAL_MONTH_GREGORIAN_SHORT: /* gregorian or julian month */ + SdnToGregorian(julday, &year, &month, &day); + monthname = MonthNameShort[month]; + break; } RETURN_STRING(monthname, 1); |