php-src/ext/gettext/gettext.c

159 lines
3.8 KiB
C
Raw Normal View History

1999-04-21 17:26:16 +00:00
/*
+----------------------------------------------------------------------+
1999-07-16 13:13:16 +00:00
| PHP version 4.0 |
1999-04-21 17:26:16 +00:00
+----------------------------------------------------------------------+
1999-07-16 13:13:16 +00:00
| Copyright (c) 1997, 1998, 1999 The PHP Group |
1999-04-21 17:26:16 +00:00
+----------------------------------------------------------------------+
1999-07-16 13:13:16 +00:00
| This source file is subject to version 2.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
1999-04-21 17:26:16 +00:00
+----------------------------------------------------------------------+
| Author: Alex Plotnick <alex@wgate.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include <stdio.h>
#include "php.h"
#include "php_gettext.h"
1999-04-21 17:26:16 +00:00
#if HAVE_LIBINTL
#include <libintl.h>
1999-12-17 21:50:07 +00:00
function_entry php_gettext_functions[] = {
1999-07-27 19:44:46 +00:00
PHP_FE(textdomain, NULL)
PHP_FE(gettext, NULL)
PHP_FALIAS(_, gettext, NULL)
PHP_FE(dgettext, NULL)
PHP_FE(dcgettext, NULL)
PHP_FE(bindtextdomain, NULL)
1999-04-21 17:26:16 +00:00
{NULL, NULL, NULL}
};
1999-12-17 21:50:07 +00:00
zend_module_entry php_gettext_module_entry = {
"gettext", php_gettext_functions, NULL, NULL, NULL, NULL, PHP_MINFO(gettext), STANDARD_MODULE_PROPERTIES
1999-04-21 17:26:16 +00:00
};
1999-07-27 19:44:46 +00:00
PHP_MINFO_FUNCTION(gettext)
1999-04-21 17:26:16 +00:00
{
php_printf("GNU gettext support active.");
1999-04-21 17:26:16 +00:00
}
PHP_FUNCTION(textdomain)
1999-04-21 17:26:16 +00:00
{
pval **domain;
1999-04-21 17:26:16 +00:00
char *domain_name, *retval;
char *val;
1999-04-21 17:26:16 +00:00
if (ARG_COUNT(ht) != 1 || getParametersEx(1, &domain) == FAILURE) {
1999-04-21 17:26:16 +00:00
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain);
1999-04-21 17:26:16 +00:00
val = (*domain)->value.str.val;
if (strcmp(val, "") && strcmp(val, "0")) {
domain_name = val;
1999-04-21 17:26:16 +00:00
} else {
domain_name = NULL;
}
retval = textdomain(domain_name);
RETURN_STRING(retval, 1);
}
PHP_FUNCTION(gettext)
1999-04-21 17:26:16 +00:00
{
pval **msgid;
1999-04-21 17:26:16 +00:00
char *msgstr;
if (ARG_COUNT(ht) != 1 || getParametersEx(1, &msgid) == FAILURE) {
1999-04-21 17:26:16 +00:00
WRONG_PARAM_COUNT;
}
convert_to_string_ex(msgid);
1999-04-21 17:26:16 +00:00
msgstr = gettext((*msgid)->value.str.val);
1999-04-21 17:26:16 +00:00
RETURN_STRING(msgstr, 1);
}
PHP_FUNCTION(dgettext)
1999-04-21 17:26:16 +00:00
{
pval **domain_name, **msgid;
1999-04-21 17:26:16 +00:00
char *msgstr;
if (ARG_COUNT(ht) != 2
|| getParametersEx(2, &domain_name, &msgid) == FAILURE)
1999-04-21 17:26:16 +00:00
{
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain_name);
convert_to_string_ex(msgid);
1999-04-21 17:26:16 +00:00
msgstr = dgettext((*domain_name)->value.str.val, (*msgid)->value.str.val);
1999-04-21 17:26:16 +00:00
RETURN_STRING(msgstr, 1);
}
PHP_FUNCTION(dcgettext)
1999-04-21 17:26:16 +00:00
{
pval **domain_name, **msgid, **category;
1999-04-21 17:26:16 +00:00
char *msgstr;
if (ARG_COUNT(ht) != 3
|| getParametersEx(3, &domain_name, &msgid, &category) == FAILURE)
1999-04-21 17:26:16 +00:00
{
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain_name);
convert_to_string_ex(msgid);
convert_to_long_ex(category);
1999-04-21 17:26:16 +00:00
msgstr = dcgettext((*domain_name)->value.str.val,
(*msgid)->value.str.val,
(*category)->value.lval);
1999-04-21 17:26:16 +00:00
RETURN_STRING(msgstr, 1);
}
PHP_FUNCTION(bindtextdomain)
1999-04-21 17:26:16 +00:00
{
pval **domain_name, **dir;
1999-04-21 17:26:16 +00:00
char *retval, *dir_name;
char *val;
1999-04-21 17:26:16 +00:00
if (ARG_COUNT(ht) != 2
|| getParametersEx(2, &domain_name, &dir) == FAILURE)
1999-04-21 17:26:16 +00:00
{
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain_name);
convert_to_string_ex(dir);
1999-04-21 17:26:16 +00:00
val = (*dir)->value.str.val;
if (strcmp(val, "") && strcmp(val, "0")) {
dir_name = val;
1999-04-21 17:26:16 +00:00
} else {
dir_name = NULL;
}
retval = bindtextdomain((*domain_name)->value.str.val, dir_name);
1999-04-21 17:26:16 +00:00
RETURN_STRING(retval, 1);
}
#endif /* HAVE_LIBINTL */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/