summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-27 08:55:31 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-27 08:55:31 +0000
commit4aa64b35fa75eb7fb2c953b557d950766386f17b (patch)
treef41a045430c4551542c334d860650e879fd5258d
parentb1e6c052cdbac72b3aeab3d6d06dc035d4a26985 (diff)
* ext/nkf/nkf.c: raise error when no output encoding is given.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--ext/nkf/nkf-utf8/config.h11
-rw-r--r--ext/nkf/nkf-utf8/nkf.c18
-rwxr-xr-xext/nkf/nkf-utf8/nkf.h12
4 files changed, 31 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 82869d96af..5bbd947571 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sun Jan 27 17:54:48 2008 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * ext/nkf/nkf.c: raise error when no output encoding is given.
+
Sun Jan 27 17:20:10 2008 Tanaka Akira <akr@fsij.org>
* string.c (rb_str_succ): don't increment/decrement codepoint.
diff --git a/ext/nkf/nkf-utf8/config.h b/ext/nkf/nkf-utf8/config.h
index 473be76a8e..50daa891fa 100644
--- a/ext/nkf/nkf-utf8/config.h
+++ b/ext/nkf/nkf-utf8/config.h
@@ -40,12 +40,13 @@
/*
* Select Default Output Encoding
*
- * If not defined, locale encoding is used.
*/
-/* #define DEFAULT_CODE_JIS */
-/* #define DEFAULT_CODE_SJIS */
-/* #define DEFAULT_CODE_EUC */
-/* #define DEFAULT_CODE_UTF8 */
+/* #define DEFAULT_CODE_JIS */
+/* #define DEFAULT_CODE_SJIS */
+/* #define DEFAULT_CODE_EUC */
+/* #define DEFAULT_CODE_UTF8 */
+/* #define DEFAULT_CODE_LOCALE */
#endif /* _CONFIG_H_ */
+
diff --git a/ext/nkf/nkf-utf8/nkf.c b/ext/nkf/nkf-utf8/nkf.c
index b51ece582c..9bf96fdb93 100644
--- a/ext/nkf/nkf-utf8/nkf.c
+++ b/ext/nkf/nkf-utf8/nkf.c
@@ -258,6 +258,8 @@ struct {
#define DEFAULT_ENCIDX EUC_JP
#elif defined(DEFAULT_CODE_UTF8)
#define DEFAULT_ENCIDX UTF_8
+#else
+#define DEFAULT_ENCIDX 0
#endif
@@ -714,7 +716,7 @@ static nkf_encoding *nkf_enc_find(const char *name)
nkf_enc_to_index(enc) == CP50221 ||\
nkf_enc_to_index(enc) == CP50222)
-#ifndef DEFAULT_ENCIDX
+#ifdef DEFAULT_CODE_LOCALE
static char* nkf_locale_charmap()
{
#ifdef HAVE_LANGINFO_H
@@ -735,16 +737,16 @@ static nkf_encoding* nkf_locale_encoding()
if (enc < 0) enc = 0;
return enc;
}
-#endif
+#endif /* DEFAULT_CODE_LOCALE */
static nkf_encoding* nkf_default_encoding()
{
-#ifdef DEFAULT_ENCIDX
- return nkf_enc_from_index(DEFAULT_ENCIDX);
-#else
+#ifdef DEFAULT_CODE_LOCALE
nkf_encoding *enc = nkf_locale_encoding();
if (enc <= 0) enc = nkf_enc_from_index(ISO_2022_JP);
return enc;
+#else
+ return nkf_enc_from_index(DEFAULT_ENCIDX);
#endif
}
@@ -837,11 +839,13 @@ void show_configuration(void)
);
fprintf(HELP_OUTPUT,
" Default output encoding: "
-#ifdef DEFAULT_ENCIDX
+#ifdef DEFAULT_CODE_LOCALE
"%s\n", nkf_enc_name(nkf_default_encoding())
-#else
+#elif DEFAULT_ENCIDX
"%s (%s)\n", nkf_locale_encoding() ? "LOCALE" : "DEFAULT",
nkf_enc_name(nkf_default_encoding())
+#else
+ "NONE"
#endif
);
fprintf(HELP_OUTPUT,
diff --git a/ext/nkf/nkf-utf8/nkf.h b/ext/nkf/nkf-utf8/nkf.h
index 30efd4b5dd..a27015416f 100755
--- a/ext/nkf/nkf-utf8/nkf.h
+++ b/ext/nkf/nkf-utf8/nkf.h
@@ -5,7 +5,6 @@
* $Id: nkf.h,v 1.2 2008/01/23 09:10:25 naruse Exp $
*/
-
#ifndef NKF_H
/* Wrapper of configurations */
@@ -144,10 +143,16 @@ void setbinmode(FILE *fp)
#endif
#endif
+#ifdef DEFAULT_CODE_LOCALE
+
#ifndef __WIN32__ /* not win32 is posix */
+#ifndef HAVE_LANGINFO_H
#define HAVE_LANGINFO_H
+#endif
+#ifndef HAVE_LOCALE_H
#define HAVE_LOCALE_H
#endif
+#endif
#ifdef HAVE_LANGINFO_H
#include <langinfo.h>
@@ -156,6 +161,8 @@ void setbinmode(FILE *fp)
#include <locale.h>
#endif
+#endif /* DEFAULT_CODE_LOCALE */
+
#define FALSE 0
#define TRUE 1
@@ -163,4 +170,5 @@ void setbinmode(FILE *fp)
#include "nkf32.h"
#endif
-#endif
+#endif /* NKF_H */
+