mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
localeinit.c: split
* localeinit.c (rb_locale_charmap, Init_enc_set_filesystem_encoding): move from encoding.c. * miniinit.c (rb_locale_charmap, Init_enc_set_filesystem_encoding): define miniruby specific functions only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3048637571
commit
5f2080048e
7 changed files with 114 additions and 64 deletions
|
@ -1,3 +1,11 @@
|
|||
Mon Jul 15 02:47:09 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* localeinit.c (rb_locale_charmap, Init_enc_set_filesystem_encoding):
|
||||
move from encoding.c.
|
||||
|
||||
* miniinit.c (rb_locale_charmap, Init_enc_set_filesystem_encoding):
|
||||
define miniruby specific functions only.
|
||||
|
||||
Mon Jul 15 02:32:58 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* encoding.c (rb_enc_init): no longer needs NO_PRESERVED_ENCODING.
|
||||
|
|
13
common.mk
13
common.mk
|
@ -33,7 +33,7 @@ MAINOBJ = $(NORMALMAINOBJ)
|
|||
EXTOBJS =
|
||||
DLDOBJS = $(DMYEXT)
|
||||
EXTSOLIBS =
|
||||
MINIOBJS = $(ARCHMINIOBJS) dmyencoding.$(OBJEXT) dmyloadpath.$(OBJEXT) miniprelude.$(OBJEXT)
|
||||
MINIOBJS = $(ARCHMINIOBJS) miniinit.$(OBJEXT) miniprelude.$(OBJEXT)
|
||||
ENC_MK = enc.mk
|
||||
|
||||
COMMONOBJS = array.$(OBJEXT) \
|
||||
|
@ -43,6 +43,7 @@ COMMONOBJS = array.$(OBJEXT) \
|
|||
complex.$(OBJEXT) \
|
||||
dir.$(OBJEXT) \
|
||||
dln_find.$(OBJEXT) \
|
||||
encoding.$(OBJEXT) \
|
||||
enum.$(OBJEXT) \
|
||||
enumerator.$(OBJEXT) \
|
||||
error.$(OBJEXT) \
|
||||
|
@ -99,7 +100,7 @@ COMMONOBJS = array.$(OBJEXT) \
|
|||
$(MISSING)
|
||||
|
||||
EXPORTOBJS = $(DLNOBJ) \
|
||||
encoding.$(OBJEXT) \
|
||||
localeinit.$(OBJEXT) \
|
||||
loadpath.$(OBJEXT) \
|
||||
$(COMMONOBJS)
|
||||
|
||||
|
@ -659,9 +660,6 @@ dln.$(OBJEXT): {$(VPATH)}dln.c {$(VPATH)}dln.h $(RUBY_H_INCLUDES)
|
|||
dln_find.$(OBJEXT): {$(VPATH)}dln_find.c {$(VPATH)}dln.h $(RUBY_H_INCLUDES)
|
||||
dmydln.$(OBJEXT): {$(VPATH)}dmydln.c $(RUBY_H_INCLUDES)
|
||||
dmyext.$(OBJEXT): {$(VPATH)}dmyext.c
|
||||
dmyencoding.$(OBJEXT): {$(VPATH)}dmyencoding.c $(RUBY_H_INCLUDES) \
|
||||
{$(VPATH)}regenc.h {$(VPATH)}util.h $(ENCODING_H_INCLUDES) \
|
||||
{$(VPATH)}encoding.c {$(VPATH)}internal.h
|
||||
encoding.$(OBJEXT): {$(VPATH)}encoding.c $(RUBY_H_INCLUDES) \
|
||||
$(ENCODING_H_INCLUDES) {$(VPATH)}regenc.h {$(VPATH)}util.h \
|
||||
{$(VPATH)}internal.h
|
||||
|
@ -777,7 +775,10 @@ version.$(OBJEXT): {$(VPATH)}version.c $(RUBY_H_INCLUDES) \
|
|||
loadpath.$(OBJEXT): {$(VPATH)}loadpath.c $(RUBY_H_INCLUDES) \
|
||||
$(srcdir)/include/ruby/version.h $(srcdir)/version.h {$(VPATH)}config.h \
|
||||
verconf.h
|
||||
dmyloadpath.$(OBJEXT): {$(VPATH)}dmyloadpath.c
|
||||
localeinit.$(OBJEXT): {$(VPATH)}localeinit.c $(RUBY_H_INCLUDES) \
|
||||
$(ENCODING_H_INCLUDES) {$(VPATH)}internal.h
|
||||
miniinit.$(OBJEXT): {$(VPATH)}miniinit.c $(RUBY_H_INCLUDES) \
|
||||
$(ENCODING_H_INCLUDES)
|
||||
|
||||
compile.$(OBJEXT): {$(VPATH)}compile.c {$(VPATH)}iseq.h \
|
||||
$(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) {$(VPATH)}insns.inc \
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
#define NO_LOCALE_CHARMAP 1
|
||||
#include "encoding.c"
|
|
@ -1,2 +0,0 @@
|
|||
const char ruby_exec_prefix[] = "";
|
||||
const char ruby_initial_load_paths[] = "";
|
58
encoding.c
58
encoding.c
|
@ -14,14 +14,6 @@
|
|||
#include "internal.h"
|
||||
#include "regenc.h"
|
||||
#include <ctype.h>
|
||||
#ifndef NO_LOCALE_CHARMAP
|
||||
#ifdef __CYGWIN__
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
#endif
|
||||
#include "ruby/util.h"
|
||||
|
||||
#undef rb_ascii8bit_encindex
|
||||
|
@ -1269,25 +1261,6 @@ rb_locale_encoding(void)
|
|||
return rb_enc_from_index(rb_locale_encindex());
|
||||
}
|
||||
|
||||
static int
|
||||
enc_set_filesystem_encoding(void)
|
||||
{
|
||||
int idx;
|
||||
#if defined NO_LOCALE_CHARMAP
|
||||
idx = rb_enc_to_index(rb_default_external_encoding());
|
||||
#elif defined _WIN32 || defined __CYGWIN__
|
||||
char cp[sizeof(int) * 8 / 3 + 4];
|
||||
snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP());
|
||||
idx = rb_enc_find_index(cp);
|
||||
if (idx < 0) idx = ENCINDEX_ASCII;
|
||||
#else
|
||||
idx = rb_enc_to_index(rb_default_external_encoding());
|
||||
#endif
|
||||
|
||||
enc_alias_internal("filesystem", idx);
|
||||
return idx;
|
||||
}
|
||||
|
||||
int
|
||||
rb_filesystem_encindex(void)
|
||||
{
|
||||
|
@ -1310,6 +1283,8 @@ struct default_encoding {
|
|||
|
||||
static struct default_encoding default_external = {0};
|
||||
|
||||
extern int Init_enc_set_filesystem_encoding(void);
|
||||
|
||||
static int
|
||||
enc_set_default_encoding(struct default_encoding *def, VALUE encoding, const char *name)
|
||||
{
|
||||
|
@ -1332,7 +1307,7 @@ enc_set_default_encoding(struct default_encoding *def, VALUE encoding, const cha
|
|||
}
|
||||
|
||||
if (def == &default_external)
|
||||
enc_set_filesystem_encoding();
|
||||
enc_alias_internal("filesystem", Init_enc_set_filesystem_encoding());
|
||||
|
||||
return overridden;
|
||||
}
|
||||
|
@ -1529,32 +1504,7 @@ set_default_internal(VALUE klass, VALUE encoding)
|
|||
*
|
||||
*/
|
||||
VALUE
|
||||
rb_locale_charmap(VALUE klass)
|
||||
{
|
||||
#if defined NO_LOCALE_CHARMAP
|
||||
return rb_usascii_str_new2("ASCII-8BIT");
|
||||
#elif defined _WIN32 || defined __CYGWIN__
|
||||
const char *codeset = 0;
|
||||
char cp[sizeof(int) * 3 + 4];
|
||||
# ifdef __CYGWIN__
|
||||
const char *nl_langinfo_codeset(void);
|
||||
codeset = nl_langinfo_codeset();
|
||||
# endif
|
||||
if (!codeset) {
|
||||
UINT codepage = GetConsoleCP();
|
||||
if (!codepage) codepage = GetACP();
|
||||
snprintf(cp, sizeof(cp), "CP%d", codepage);
|
||||
codeset = cp;
|
||||
}
|
||||
return rb_usascii_str_new2(codeset);
|
||||
#elif defined HAVE_LANGINFO_H
|
||||
char *codeset;
|
||||
codeset = nl_langinfo(CODESET);
|
||||
return rb_usascii_str_new2(codeset);
|
||||
#else
|
||||
return Qnil;
|
||||
#endif
|
||||
}
|
||||
rb_locale_charmap(VALUE klass);
|
||||
|
||||
static void
|
||||
set_encoding_const(const char *name, rb_encoding *enc)
|
||||
|
|
65
localeinit.c
Normal file
65
localeinit.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
/**********************************************************************
|
||||
|
||||
localeinit.c -
|
||||
|
||||
$Author$
|
||||
created at: Thu Jul 11 22:09:57 JST 2013
|
||||
|
||||
Copyright (C) 2013 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#include "ruby/ruby.h"
|
||||
#include "ruby/encoding.h"
|
||||
#include "internal.h"
|
||||
#ifdef __CYGWIN__
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
|
||||
VALUE
|
||||
rb_locale_charmap(VALUE klass)
|
||||
{
|
||||
#if defined NO_LOCALE_CHARMAP
|
||||
# error NO_LOCALE_CHARMAP defined
|
||||
#elif defined _WIN32 || defined __CYGWIN__
|
||||
const char *codeset = 0;
|
||||
char cp[sizeof(int) * 3 + 4];
|
||||
# ifdef __CYGWIN__
|
||||
const char *nl_langinfo_codeset(void);
|
||||
codeset = nl_langinfo_codeset();
|
||||
# endif
|
||||
if (!codeset) {
|
||||
UINT codepage = GetConsoleCP();
|
||||
if (!codepage) codepage = GetACP();
|
||||
snprintf(cp, sizeof(cp), "CP%d", codepage);
|
||||
codeset = cp;
|
||||
}
|
||||
return rb_usascii_str_new2(codeset);
|
||||
#elif defined HAVE_LANGINFO_H
|
||||
char *codeset;
|
||||
codeset = nl_langinfo(CODESET);
|
||||
return rb_usascii_str_new2(codeset);
|
||||
#else
|
||||
return Qnil;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
Init_enc_set_filesystem_encoding(void)
|
||||
{
|
||||
int idx;
|
||||
#if defined NO_LOCALE_CHARMAP
|
||||
# error NO_LOCALE_CHARMAP defined
|
||||
#elif defined _WIN32 || defined __CYGWIN__
|
||||
char cp[sizeof(int) * 8 / 3 + 4];
|
||||
snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP());
|
||||
idx = rb_enc_find_index(cp);
|
||||
if (idx < 0) idx = ENCINDEX_ASCII;
|
||||
#else
|
||||
idx = rb_enc_to_index(rb_default_external_encoding());
|
||||
#endif
|
||||
return idx;
|
||||
}
|
30
miniinit.c
Normal file
30
miniinit.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/**********************************************************************
|
||||
|
||||
miniinit.c -
|
||||
|
||||
$Author$
|
||||
created at: Thu Jul 11 22:09:57 JST 2013
|
||||
|
||||
Copyright (C) 2013 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#include "ruby/ruby.h"
|
||||
#include "ruby/encoding.h"
|
||||
|
||||
/* loadpath.c */
|
||||
const char ruby_exec_prefix[] = "";
|
||||
const char ruby_initial_load_paths[] = "";
|
||||
|
||||
/* localeinit.c */
|
||||
VALUE
|
||||
rb_locale_charmap(VALUE klass)
|
||||
{
|
||||
return rb_usascii_str_new2("ASCII-8BIT");
|
||||
}
|
||||
|
||||
int
|
||||
Init_enc_set_filesystem_encoding(void)
|
||||
{
|
||||
return rb_enc_to_index(rb_default_external_encoding());
|
||||
}
|
Loading…
Reference in a new issue