cvs: /php4/dl/calendar calendar.c sdncal.h
| From: | Evan Klinger | Date: | Tue, 08 Feb 2000 04:42:38 +0000 |
| Subject: | cvs: /php4/dl/calendar calendar.c sdncal.h | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-9930@lists.php.net to get a copy of this message | ||
evan Mon Feb 7 20:42:38 2000 EDT
Modified files:
/php4/dl/calendar calendar.c sdncal.h
Log:
@- Updated calendar dynamic library to work with PHP4. (Evan)
calendar.so now works with php4.
Index: php4/dl/calendar/calendar.c
diff -u php4/dl/calendar/calendar.c:1.3 php4/dl/calendar/calendar.c:1.4
--- php4/dl/calendar/calendar.c:1.3 Fri Dec 17 12:54:36 1999
+++ php4/dl/calendar/calendar.c Mon Feb 7 20:42:07 2000
@@ -13,16 +13,16 @@
*/
function_entry calendar_functions[] = {
- {"jdtogregorian", cal_jdtogreg, NULL},
- {"gregoriantojd", cal_gregtojd, NULL},
- {"jdtojulian", cal_jdtojul, NULL},
- {"juliantojd", cal_jultojd, NULL},
- {"jdtojewish", cal_jdtojewish, NULL},
- {"jewishtojd", cal_jewishtojd, NULL},
- {"jdtofrench", cal_jdtofrench, NULL},
- {"frenchtojd", cal_frenchtojd, NULL},
- {"jddayofweek", cal_jddayofweek, NULL},
- {"jdmonthname", cal_monthname, NULL},
+ PHP_FE(jdtogregorian, NULL)
+ PHP_FE(gregoriantojd, NULL)
+ PHP_FE(jdtojulian, NULL)
+ PHP_FE(juliantojd, NULL)
+ PHP_FE(jdtojewish, NULL)
+ PHP_FE(jewishtojd, NULL)
+ PHP_FE(jdtofrench, NULL)
+ PHP_FE(frenchtojd, NULL)
+ PHP_FE(jddayofweek, NULL)
+ PHP_FE(jdmonthname, NULL)
{NULL, NULL, NULL}
};
@@ -39,256 +39,232 @@
DLEXPORT zend_module_entry *get_module(void) { return &calendar_module_entry; }
#endif
-DLEXPORT void cal_jdtogreg(INTERNAL_FUNCTION_PARAMETERS)
+DLEXPORT PHP_FUNCTION(jdtogregorian)
{
- pval *julday;
+ pval **julday;
int year, month, day;
char date[10];
- if (getParameters(ht, 1, &julday) == SUCCESS) {
- convert_to_long(julday);
- SdnToGregorian(julday->value.lval, &year, &month, &day);
- sprintf(date, "%i/%i/%i", month, day, year);
-
- return_value->value.str.val = estrdup(date);
- return_value->value.str.len = strlen(date);
- return_value->type = IS_STRING;
- } else {
+ if (zend_get_parameters_ex(1, &julday) != SUCCESS) {
WRONG_PARAM_COUNT;
}
- return;
+
+ convert_to_long_ex(julday);
+ SdnToGregorian((*julday)->value.lval, &year, &month, &day);
+ sprintf(date, "%i/%i/%i", month, day, year);
+
+ RETURN_STRING(date,1);
}
-DLEXPORT void cal_gregtojd(INTERNAL_FUNCTION_PARAMETERS)
+DLEXPORT PHP_FUNCTION(gregoriantojd)
{
- pval *year, *month, *day;
+ pval **year, **month, **day;
int jdate;
- if (getParameters(ht, 3, &month, &day, &year) == SUCCESS) {
- convert_to_long(month);
- convert_to_long(day);
- convert_to_long(year);
-
- jdate = GregorianToSdn(year->value.lval, month->value.lval, day->value.lval);
-
- return_value->value.lval = jdate;
- return_value->type = IS_LONG;
- } else {
+ if (zend_get_parameters_ex(3, &month, &day, &year) != SUCCESS) {
WRONG_PARAM_COUNT;
}
+
+ convert_to_long_ex(month);
+ convert_to_long_ex(day);
+ convert_to_long_ex(year);
+
+ jdate = GregorianToSdn((*year)->value.lval, (*month)->value.lval,(*day)->value.lval);
+
+ RETURN_LONG(jdate);
}
-DLEXPORT void cal_jdtojul(INTERNAL_FUNCTION_PARAMETERS)
+DLEXPORT PHP_FUNCTION(jdtojulian)
{
- pval *julday;
+ pval **julday;
int year, month, day;
char date[10];
- if (getParameters(ht, 1, &julday) == SUCCESS) {
- convert_to_long(julday);
- SdnToJulian(julday->value.lval, &year, &month, &day);
- sprintf(date, "%i/%i/%i", month, day, year);
-
- return_value->value.str.val = estrdup(date);
- return_value->value.str.len = strlen(date);
- return_value->type = IS_STRING;
- } else {
+ if (zend_get_parameters_ex(1, &julday) != SUCCESS) {
WRONG_PARAM_COUNT;
}
- return;
+
+ convert_to_long_ex(julday);
+ SdnToJulian((*julday)->value.lval, &year, &month, &day);
+ sprintf(date, "%i/%i/%i", month, day, year);
+
+ RETURN_STRING(date,1);
}
-DLEXPORT void cal_jultojd(INTERNAL_FUNCTION_PARAMETERS)
+DLEXPORT PHP_FUNCTION(juliantojd)
{
- pval *year, *month, *day;
+ pval **year, **month, **day;
int jdate;
- if (getParameters(ht, 3, &month, &day, &year) == SUCCESS) {
- convert_to_long(month);
- convert_to_long(day);
- convert_to_long(year);
-
- jdate = JulianToSdn(year->value.lval, month->value.lval, day->value.lval);
-
- return_value->value.lval = jdate;
- return_value->type = IS_LONG;
- } else {
+ if (zend_get_parameters_ex(3, &month, &day, &year) != SUCCESS) {
WRONG_PARAM_COUNT;
}
+
+ convert_to_long_ex(month);
+ convert_to_long_ex(day);
+ convert_to_long_ex(year);
+
+ jdate = JulianToSdn((*year)->value.lval,(*month)->value.lval, (*day)->value.lval);
+
+ RETURN_LONG(jdate);
}
-DLEXPORT void cal_jdtojewish(INTERNAL_FUNCTION_PARAMETERS)
+DLEXPORT PHP_FUNCTION(jdtojewish)
{
- pval *julday;
+ pval **julday;
int year, month, day;
char date[10];
- if (getParameters(ht, 1, &julday) == SUCCESS) {
- convert_to_long(julday);
- SdnToJewish(julday->value.lval, &year, &month, &day);
- sprintf(date, "%i/%i/%i", month, day, year);
-
- return_value->value.str.val = estrdup(date);
- return_value->value.str.len = strlen(date);
- return_value->type = IS_STRING;
- } else {
+ if (zend_get_parameters_ex(1, &julday) != SUCCESS) {
WRONG_PARAM_COUNT;
}
- return;
+
+ convert_to_long_ex(julday);
+
+ SdnToJewish((*julday)->value.lval, &year, &month, &day);
+ sprintf(date, "%i/%i/%i", month, day, year);
+
+ RETURN_STRING(date,1);
}
-DLEXPORT void cal_jewishtojd(INTERNAL_FUNCTION_PARAMETERS)
+DLEXPORT PHP_FUNCTION(jewishtojd)
{
- pval *year, *month, *day;
+ pval **year, **month, **day;
int jdate;
- if (getParameters(ht, 3, &month, &day, &year) == SUCCESS) {
- convert_to_long(month);
- convert_to_long(day);
- convert_to_long(year);
-
- jdate = JewishToSdn(year->value.lval, month->value.lval, day->value.lval);
-
- return_value->value.lval = jdate;
- return_value->type = IS_LONG;
- } else {
+ if (zend_get_parameters_ex(3, &month, &day, &year) != SUCCESS) {
WRONG_PARAM_COUNT;
}
+
+ convert_to_long_ex(month);
+ convert_to_long_ex(day);
+ convert_to_long_ex(year);
+
+ jdate = JewishToSdn((*year)->value.lval,(*month)->value.lval, (*day)->value.lval);
+
+ RETURN_LONG(jdate);
}
-DLEXPORT void cal_jdtofrench(INTERNAL_FUNCTION_PARAMETERS)
+DLEXPORT PHP_FUNCTION(jdtofrench)
{
- pval *julday;
+ pval **julday;
int year, month, day;
char date[10];
- if (getParameters(ht, 1, &julday) == SUCCESS) {
- convert_to_long(julday);
- SdnToFrench(julday->value.lval, &year, &month, &day);
- sprintf(date, "%i/%i/%i", month, day, year);
-
- return_value->value.str.val = estrdup(date);
- return_value->value.str.len = strlen(date);
- return_value->type = IS_STRING;
- } else {
+ if (zend_get_parameters_ex(1, &julday) != SUCCESS) {
WRONG_PARAM_COUNT;
}
- return;
+
+ convert_to_long_ex(julday);
+
+ SdnToFrench((*julday)->value.lval, &year, &month, &day);
+ sprintf(date, "%i/%i/%i", month, day, year);
+
+ RETURN_STRING(date,1);
}
-DLEXPORT void cal_frenchtojd(INTERNAL_FUNCTION_PARAMETERS)
+DLEXPORT PHP_FUNCTION(frenchtojd)
{
- pval *year, *month, *day;
+ pval **year, **month, **day;
int jdate;
- if (getParameters(ht, 3, &month, &day, &year) == SUCCESS) {
- convert_to_long(month);
- convert_to_long(day);
- convert_to_long(year);
-
- jdate = FrenchToSdn(year->value.lval, month->value.lval, day->value.lval);
-
- return_value->value.lval = jdate;
- return_value->type = IS_LONG;
- } else {
+ if (zend_get_parameters_ex(3, &month, &day, &year) != SUCCESS) {
WRONG_PARAM_COUNT;
}
+
+ convert_to_long_ex(month);
+ convert_to_long_ex(day);
+ convert_to_long_ex(year);
+
+ jdate = FrenchToSdn((*year)->value.lval,(*month)->value.lval,(*day)->value.lval);
+
+ RETURN_LONG(jdate);
}
-DLEXPORT void cal_jddayofweek(INTERNAL_FUNCTION_PARAMETERS)
+DLEXPORT PHP_FUNCTION(jddayofweek)
{
- pval *julday, *mode;
+ pval **julday, **mode;
int day;
char *daynamel, *daynames;
- if (getParameters(ht, 2, &julday, &mode) == SUCCESS) {
- convert_to_long(julday);
- convert_to_long(mode);
-
- day = DayOfWeek(julday->value.lval);
- daynamel = DayNameLong[day];
- daynames = DayNameShort[day];
+ if (zend_get_parameters_ex(2, &julday, &mode) != SUCCESS) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long_ex(julday);
+ convert_to_long_ex(mode);
+
+ day = DayOfWeek((*julday)->value.lval);
+ daynamel = DayNameLong[day];
+ daynames = DayNameShort[day];
- switch (mode->value.lval) {
+ switch ((*mode)->value.lval) {
case 0L:
- return_value->value.lval = day;
- return_value->type = IS_LONG;
+ RETURN_LONG(day);
break;
case 1L:
- return_value->value.str.val = estrdup(daynamel);
- return_value->value.str.len = strlen(daynamel);
- return_value->type = IS_STRING;
+ RETURN_STRING(daynamel,1);
break;
case 2L:
- return_value->value.str.val = estrdup(daynames);
- return_value->value.str.len = strlen(daynames);
- return_value->type = IS_STRING;
+ RETURN_STRING(daynames,1);
break;
default:
- return_value->value.lval = day;
- return_value->type = IS_LONG;
+ RETURN_LONG(day);
break;
}
- } else {
- WRONG_PARAM_COUNT;
- }
- return;
}
-DLEXPORT void cal_monthname(INTERNAL_FUNCTION_PARAMETERS)
+DLEXPORT PHP_FUNCTION(jdmonthname)
{
- pval *julday, *mode;
+ pval **julday, **mode;
char *monthname = NULL;
int month, day, year;
- if (getParameters(ht, 2, &julday, &mode) == SUCCESS) {
- convert_to_long(julday);
- convert_to_long(mode);
+ if (zend_get_parameters_ex(2, &julday, &mode) != SUCCESS) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long_ex(julday);
+ convert_to_long_ex(mode);
- switch (mode->value.lval) {
+ switch((*mode)->value.lval) {
case 0L: /* gregorian or julian month */
- SdnToGregorian(julday->value.lval, &year, &month, &day);
+ SdnToGregorian((*julday)->value.lval,&year, &month, &day);
monthname = MonthNameShort[month];
break;
case 1L: /* gregorian or julian month */
- SdnToGregorian(julday->value.lval, &year, &month, &day);
+ SdnToGregorian((*julday)->value.lval,&year, &month, &day);
monthname = MonthNameLong[month];
break;
case 2L: /* gregorian or julian month */
- SdnToJulian(julday->value.lval, &year, &month, &day);
+ SdnToJulian((*julday)->value.lval, &year,&month, &day);
monthname = MonthNameShort[month];
break;
case 3L: /* gregorian or julian month */
- SdnToJulian(julday->value.lval, &year, &month, &day);
+ SdnToJulian((*julday)->value.lval, &year,&month, &day);
monthname = MonthNameLong[month];
break;
case 4L: /* jewish month */
- SdnToJewish(julday->value.lval, &year, &month, &day);
+ SdnToJewish((*julday)->value.lval, &year,&month, &day);
monthname = JewishMonthName[month];
break;
case 5L: /* french month */
- SdnToFrench(julday->value.lval, &year, &month, &day);
+ SdnToFrench((*julday)->value.lval, &year,&month, &day);
monthname = FrenchMonthName[month];
break;
default: /* default gregorian */
/* FIXME - need to set monthname to something here ?? */
break;
}
- return_value->value.str.val = estrdup(monthname);
- return_value->value.str.len = strlen(monthname);
- return_value->type = IS_STRING;
- return;
- } else {
- WRONG_PARAM_COUNT;
- }
- return;
+
+ RETURN_STRING(monthname,1);
}
Index: php4/dl/calendar/sdncal.h
diff -u php4/dl/calendar/sdncal.h:1.1 php4/dl/calendar/sdncal.h:1.2
--- php4/dl/calendar/sdncal.h:1.1 Wed Apr 7 14:02:57 1999
+++ php4/dl/calendar/sdncal.h Mon Feb 7 20:42:07 2000
@@ -69,16 +69,16 @@
/* Functions accessable to PHP */
-DLEXPORT void cal_jdtogreg(INTERNAL_FUNCTION_PARAMETERS);
-DLEXPORT void cal_gregtojd(INTERNAL_FUNCTION_PARAMETERS);
-DLEXPORT void cal_jdtojul(INTERNAL_FUNCTION_PARAMETERS);
-DLEXPORT void cal_jultojd(INTERNAL_FUNCTION_PARAMETERS);
-DLEXPORT void cal_jdtojewish(INTERNAL_FUNCTION_PARAMETERS);
-DLEXPORT void cal_jewishtojd(INTERNAL_FUNCTION_PARAMETERS);
-DLEXPORT void cal_jdtofrench(INTERNAL_FUNCTION_PARAMETERS);
-DLEXPORT void cal_frenchtojd(INTERNAL_FUNCTION_PARAMETERS);
-DLEXPORT void cal_jddayofweek(INTERNAL_FUNCTION_PARAMETERS);
-DLEXPORT void cal_monthname(INTERNAL_FUNCTION_PARAMETERS);
+DLEXPORT PHP_FUNCTION(jdtogregorian);
+DLEXPORT PHP_FUNCTION(gregoriantojd);
+DLEXPORT PHP_FUNCTION(jdtojulian);
+DLEXPORT PHP_FUNCTION(juliantojd);
+DLEXPORT PHP_FUNCTION(jdtojewish);
+DLEXPORT PHP_FUNCTION(jewishtojd);
+DLEXPORT PHP_FUNCTION(jdtofrench);
+DLEXPORT PHP_FUNCTION(frenchtojd);
+DLEXPORT PHP_FUNCTION(jddayofweek);
+DLEXPORT PHP_FUNCTION(jdmonthname);
/* These functions are internal to the dll */
/* Gregorian calendar conversions. */