/* -*- c-file-style: "ruby" -*- * Copyright (C) 2000 Yashi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ruby.h" #include VALUE mLocale; VALUE locale_set(self, category, locale) VALUE self, category, locale; { char *ret; ret = setlocale(NUM2INT(category), locale == Qnil ? "" : STR2CSTR(locale)); return ret == NULL ? Qnil : rb_str_new2(ret); } VALUE locale_get( self, category ) VALUE self, category; { char *ret; ret = setlocale(NUM2INT(category), NULL ); return ret == NULL ? Qnil : rb_str_new2(ret); } void Init_locale() { char *curr_locale; mLocale = rb_define_module("Locale"); if (!setlocale(LC_ALL, "")) { fprintf(stderr, "current locale is not supported by your C library\n"); fprintf(stderr, "locale set to C\n"); setlocale(LC_ALL, "C"); } rb_define_module_function(mLocale, "set", locale_set, 2); rb_define_module_function(mLocale, "get", locale_get, 1); rb_define_const(mLocale, "ALL", INT2FIX(LC_ALL)); rb_define_const(mLocale, "COLLATE", INT2FIX(LC_COLLATE)); rb_define_const(mLocale, "CTYPE", INT2FIX(LC_CTYPE)); rb_define_const(mLocale, "MESSAGES", INT2FIX(LC_MESSAGES)); rb_define_const(mLocale, "MONETARY", INT2FIX(LC_MONETARY)); rb_define_const(mLocale, "NUMERIC", INT2FIX(LC_NUMERIC)); rb_define_const(mLocale, "TIME", INT2FIX(LC_TIME)); }