* \e$B8=:_!"\e(Bnkf \e$B$O\e(B SorceForge \e$B$K$F%a%s%F%J%s%9$,B3$1$i$l$F$$$^$9!#\e(B
* http://sourceforge.jp/projects/nkf/
***********************************************************************/
-/* $Id: nkf.c,v 1.141 2007/10/02 08:41:03 naruse Exp $ */
+/* $Id: nkf.c,v 1.142 2007/10/05 10:57:50 naruse Exp $ */
#define NKF_VERSION "2.0.8"
-#define NKF_RELEASE_DATE "2007-10-02"
+#define NKF_RELEASE_DATE "2007-10-05"
#define COPY_RIGHT \
"Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa),2000 S. Kono, COW\n" \
"Copyright (C) 2002-2007 Kono, Furukawa, Naruse, mastodon"
static void version(void);
#endif
static void options(unsigned char *c);
-#if defined(PERL_XS) || defined(WIN32DLL)
static void reinit(void);
-#endif
/* buffers */
#ifdef CHECK_OPTION
static int noout_f = FALSE;
static void no_putc(nkf_char c);
-static nkf_char debug_f = FALSE;
+static int debug_f = FALSE;
static void debug(const char *str);
static nkf_char (*iconv_for_check)(nkf_char c2,nkf_char c1,nkf_char c0) = 0;
#endif
for (argc--,argv++; (argc > 0) && **argv == '-'; argc--, argv++) {
cp = (unsigned char *)*argv;
options(cp);
+ if (guess_f) {
+#ifdef CHECK_OPTION
+ int debug_f_back = debug_f;
+#endif
+#ifdef EXEC_IO
+ int exec_f_back = exec_f;
+#endif
+#ifdef X0212_ENABLE
+ int x0212_f_back = x0212_f;
+#endif
+#ifdef X0212_ENABLE
+ int x0213_f_back = x0213_f;
+#endif
+ reinit();
+ guess_f = TRUE;
+ mime_f = FALSE;
+#ifdef CHECK_OPTION
+ debug_f = debug_f_back;
+#endif
+#ifdef EXEC_IO
+ exec_f = exec_f_back;
+#endif
+#ifdef X0212_ENABLE
+ x0212_f = x0212_f_back;
+#endif
+#ifdef X0213_ENABLE
+ x0213_f = x0213_f_back;
+#endif
+ }
#ifdef EXEC_IO
if (exec_f){
int fds[2], pid;
}
p = 0;
}
- if (p == 0) return;
+ if (p == 0) {
+ fprintf(stderr, "unknown long option: --%s\n", cp);
+ return;
+ }
while(*cp && *cp != SP && cp++);
if (long_option[i].alias[0]){
cp_back = cp;
input_f = UTF32_INPUT;
input_endian = ENDIAN_LITTLE;
#endif
+ } else {
+ fprintf(stderr, "unknown input encoding: %s\n", codeset);
}
continue;
}
output_endian = ENDIAN_LITTLE;
output_bom_f = TRUE;
#endif
+ } else {
+ fprintf(stderr, "unknown output encoding: %s\n", codeset);
}
continue;
}
nlmode_f = 0; cp++;
}
continue;
- case 'g':
#ifndef PERL_XS
+ case 'g':
guess_f = TRUE;
-#endif
continue;
+#endif
case SP:
/* module muliple options in a string are allowed for Perl moudle */
while(*cp && *cp++!='-');
continue;
default:
+ fprintf(stderr, "unknown option: -%c\n", *(cp-1));
/* bogus option but ignored */
continue;
}
#define SCORE_L2 (1) /* \e$BBh\e(B2\e$B?e=`4A;z\e(B */
#define SCORE_KANA (SCORE_L2 << 1) /* \e$B$$$o$f$kH>3Q%+%J\e(B */
#define SCORE_DEPEND (SCORE_KANA << 1) /* \e$B5!<o0MB8J8;z\e(B */
-#ifdef SHIFTJIS_CP932
-#define SCORE_CP932 (SCORE_DEPEND << 1) /* CP932 \e$B$K$h$kFI$_49$(\e(B */
+#define SCORE_CP932 (SCORE_DEPEND << 1) /* CP932 \e$B$K$h$kFI$_49$(\e(B (IBM extended characters) */
#define SCORE_NO_EXIST (SCORE_CP932 << 1) /* \e$BB8:_$7$J$$J8;z\e(B */
-#else
-#define SCORE_NO_EXIST (SCORE_DEPEND << 1) /* \e$BB8:_$7$J$$J8;z\e(B */
-#endif
#define SCORE_iMIME (SCORE_NO_EXIST << 1) /* MIME \e$B$K$h$k;XDj\e(B */
#define SCORE_ERROR (SCORE_iMIME << 1) /* \e$B%(%i!<\e(B */
static const char score_table_F0[] = {
SCORE_L2, SCORE_L2, SCORE_L2, SCORE_L2,
SCORE_L2, SCORE_DEPEND, SCORE_NO_EXIST, SCORE_NO_EXIST,
- SCORE_DEPEND, SCORE_DEPEND, SCORE_DEPEND, SCORE_DEPEND,
- SCORE_DEPEND, SCORE_NO_EXIST, SCORE_NO_EXIST, SCORE_ERROR,
+ SCORE_DEPEND, SCORE_DEPEND, SCORE_CP932, SCORE_CP932,
+ SCORE_CP932, SCORE_NO_EXIST, SCORE_NO_EXIST, SCORE_ERROR,
};
void set_code_score(struct input_code *ptr, nkf_char score)
ptr->stat = 1;
status_push_ch(ptr, c);
#ifdef SHIFTJIS_CP932
- }else if (cp51932_f
- && is_ibmext_in_sjis(c)){
+ }else if (is_ibmext_in_sjis(c)){
ptr->stat = 2;
status_push_ch(ptr, c);
#endif /* SHIFTJIS_CP932 */
#ifdef X0212_ENABLE
- }else if (x0212_f && 0xf0 <= c && c <= 0xfc){
+ }else if (0xf0 <= c && c <= 0xfc){
ptr->stat = 1;
status_push_ch(ptr, c);
#endif /* X0212_ENABLE */
break;
case 2:
#ifdef SHIFTJIS_CP932
- if ((0x40 <= c && c <= 0x7e) || (0x80 <= c && c <= 0xfc)){
- status_push_ch(ptr, c);
- if (s2e_conv(ptr->buf[0], ptr->buf[1], &ptr->buf[0], &ptr->buf[1]) == 0){
- set_code_score(ptr, SCORE_CP932);
- status_clear(ptr);
- break;
- }
- }
+ if ((0x40 <= c && c <= 0x7e) || (0x80 <= c && c <= 0xfc)) {
+ status_push_ch(ptr, c);
+ if (s2e_conv(ptr->buf[0], ptr->buf[1], &ptr->buf[0], &ptr->buf[1]) == 0) {
+ code_score(ptr);
+ status_clear(ptr);
+ break;
+ }
+ }
#endif /* SHIFTJIS_CP932 */
-#ifndef X0212_ENABLE
- status_disable(ptr);
-#endif
+ status_disable(ptr);
break;
}
}
if (input_codename && !*input_codename) {
printf("BINARY\n");
} else {
- printf("%s%s\n",
+ struct input_code *p = find_inputcode_byfunc(iconv);
+ printf("%s%s%s\n",
(input_codename ? input_codename : "ASCII"),
+ ((p->score & (SCORE_DEPEND|SCORE_CP932|SCORE_NO_EXIST)) ? "+" : ""),
input_nextline == CR ? " (CR)" :
input_nextline == LF ? " (LF)" :
input_nextline == CRLF ? " (CRLF)" :
}
-#if defined(PERL_XS) || defined(WIN32DLL)
void reinit(void)
{
{
reinitdll();
#endif /*WIN32DLL*/
}
-#endif
void no_connection(nkf_char c2, nkf_char c1)
{