nkf 0.2.0-java → 0.3.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{LICENSE.txt → BSDL} +3 -3
- data/COPYING +56 -0
- data/Gemfile +13 -3
- data/LEGAL +26 -0
- data/Rakefile +19 -0
- data/ext/nkf/nkf-utf8/nkf.c +1228 -1054
- data/ext/nkf/nkf.c +102 -54
- data/lib/nkf.jar +0 -0
- data/nkf.gemspec +2 -1
- data/sig/kconv.rbs +166 -0
- data/sig/nkf.rbs +404 -0
- metadata +9 -11
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/test.yml +0 -29
- data/bin/console +0 -14
- data/bin/setup +0 -8
data/ext/nkf/nkf-utf8/nkf.c
CHANGED
|
@@ -132,31 +132,33 @@ enum nkf_encodings {
|
|
|
132
132
|
JIS_X_0213_1 = 0x1233 /* Q */
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
static nkf_char
|
|
138
|
-
static nkf_char
|
|
139
|
-
static nkf_char
|
|
140
|
-
static
|
|
141
|
-
static
|
|
142
|
-
static void
|
|
143
|
-
static void
|
|
144
|
-
static void
|
|
145
|
-
static void
|
|
135
|
+
typedef struct nkf_state_t nkf_state_t;
|
|
136
|
+
|
|
137
|
+
static nkf_char s_iconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0);
|
|
138
|
+
static nkf_char e_iconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0);
|
|
139
|
+
static nkf_char w_iconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0);
|
|
140
|
+
static nkf_char w_iconv16(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0);
|
|
141
|
+
static nkf_char w_iconv32(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0);
|
|
142
|
+
static void j_oconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1);
|
|
143
|
+
static void s_oconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1);
|
|
144
|
+
static void e_oconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1);
|
|
145
|
+
static void w_oconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1);
|
|
146
|
+
static void w_oconv16(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1);
|
|
147
|
+
static void w_oconv32(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1);
|
|
146
148
|
|
|
147
149
|
typedef const struct {
|
|
148
150
|
const char *name;
|
|
149
|
-
nkf_char (*
|
|
150
|
-
void (*
|
|
151
|
+
nkf_char (*iconv_func)(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0);
|
|
152
|
+
void (*oconv_func)(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1);
|
|
151
153
|
} nkf_native_encoding;
|
|
152
154
|
|
|
153
|
-
nkf_native_encoding NkfEncodingASCII = { "ASCII", e_iconv, e_oconv };
|
|
154
|
-
nkf_native_encoding NkfEncodingISO_2022_JP = { "ISO-2022-JP", e_iconv, j_oconv };
|
|
155
|
-
nkf_native_encoding NkfEncodingShift_JIS = { "Shift_JIS", s_iconv, s_oconv };
|
|
156
|
-
nkf_native_encoding NkfEncodingEUC_JP = { "EUC-JP", e_iconv, e_oconv };
|
|
157
|
-
nkf_native_encoding NkfEncodingUTF_8 = { "UTF-8", w_iconv, w_oconv };
|
|
158
|
-
nkf_native_encoding NkfEncodingUTF_16 = { "UTF-16", w_iconv16, w_oconv16 };
|
|
159
|
-
nkf_native_encoding NkfEncodingUTF_32 = { "UTF-32", w_iconv32, w_oconv32 };
|
|
155
|
+
static nkf_native_encoding NkfEncodingASCII = { "ASCII", e_iconv, e_oconv };
|
|
156
|
+
static nkf_native_encoding NkfEncodingISO_2022_JP = { "ISO-2022-JP", e_iconv, j_oconv };
|
|
157
|
+
static nkf_native_encoding NkfEncodingShift_JIS = { "Shift_JIS", s_iconv, s_oconv };
|
|
158
|
+
static nkf_native_encoding NkfEncodingEUC_JP = { "EUC-JP", e_iconv, e_oconv };
|
|
159
|
+
static nkf_native_encoding NkfEncodingUTF_8 = { "UTF-8", w_iconv, w_oconv };
|
|
160
|
+
static nkf_native_encoding NkfEncodingUTF_16 = { "UTF-16", w_iconv16, w_oconv16 };
|
|
161
|
+
static nkf_native_encoding NkfEncodingUTF_32 = { "UTF-32", w_iconv32, w_oconv32 };
|
|
160
162
|
|
|
161
163
|
typedef const struct {
|
|
162
164
|
int id;
|
|
@@ -164,7 +166,7 @@ typedef const struct {
|
|
|
164
166
|
nkf_native_encoding *base_encoding;
|
|
165
167
|
} nkf_encoding;
|
|
166
168
|
|
|
167
|
-
nkf_encoding nkf_encoding_table[] = {
|
|
169
|
+
static nkf_encoding nkf_encoding_table[] = {
|
|
168
170
|
{ASCII, "US-ASCII", &NkfEncodingASCII},
|
|
169
171
|
{ISO_8859_1, "ISO-8859-1", &NkfEncodingASCII},
|
|
170
172
|
{ISO_2022_JP, "ISO-2022-JP", &NkfEncodingISO_2022_JP},
|
|
@@ -328,14 +330,334 @@ struct input_code{
|
|
|
328
330
|
nkf_char score;
|
|
329
331
|
nkf_char index;
|
|
330
332
|
nkf_char buf[3];
|
|
331
|
-
void (*status_func)(struct input_code *, nkf_char);
|
|
332
|
-
nkf_char (*iconv_func)(nkf_char c2, nkf_char c1, nkf_char c0);
|
|
333
|
+
void (*status_func)(nkf_state_t *nkf_state, struct input_code *, nkf_char);
|
|
334
|
+
nkf_char (*iconv_func)(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0);
|
|
333
335
|
int _file_stat;
|
|
334
336
|
};
|
|
335
337
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
338
|
+
#ifdef UTF8_INPUT_ENABLE
|
|
339
|
+
#define INPUT_CODE_LIST_SIZE 6
|
|
340
|
+
#else
|
|
341
|
+
#define INPUT_CODE_LIST_SIZE 3
|
|
342
|
+
#endif
|
|
343
|
+
|
|
344
|
+
#define MIME_BUF_SIZE (1024) /* 2^n ring buffer */
|
|
345
|
+
#define MIME_BUF_MASK (MIME_BUF_SIZE-1)
|
|
346
|
+
#define MIMEOUT_BUF_LENGTH 74
|
|
347
|
+
|
|
348
|
+
typedef struct nkf_buf_t nkf_buf_t;
|
|
349
|
+
|
|
350
|
+
typedef struct {
|
|
351
|
+
unsigned char buf[MIME_BUF_SIZE];
|
|
352
|
+
unsigned int top;
|
|
353
|
+
unsigned int last; /* decoded */
|
|
354
|
+
unsigned int input; /* undecoded */
|
|
355
|
+
} mime_input_state_t;
|
|
356
|
+
|
|
357
|
+
typedef struct {
|
|
358
|
+
unsigned char buf[MIMEOUT_BUF_LENGTH+1];
|
|
359
|
+
int count;
|
|
360
|
+
} mimeout_state_t;
|
|
361
|
+
|
|
362
|
+
struct nkf_state_t {
|
|
363
|
+
const char *input_codename /* = NULL */; /* NULL: unestablished, "": BINARY */
|
|
364
|
+
nkf_encoding *input_encoding /* = NULL */;
|
|
365
|
+
nkf_encoding *output_encoding /* = NULL */;
|
|
366
|
+
#if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
|
|
367
|
+
int ms_ucs_map_f /* = UCS_MAP_ASCII */;
|
|
368
|
+
#endif
|
|
369
|
+
#ifdef UTF8_INPUT_ENABLE
|
|
370
|
+
/* no NEC special, NEC-selected IBM extended and IBM extended characters */
|
|
371
|
+
int no_cp932ext_f /* = FALSE */;
|
|
372
|
+
#endif
|
|
373
|
+
/* ignore ZERO WIDTH NO-BREAK SPACE */
|
|
374
|
+
int no_best_fit_chars_f /* = FALSE */;
|
|
375
|
+
int input_endian /* = ENDIAN_BIG */;
|
|
376
|
+
int input_bom_f /* = FALSE */;
|
|
377
|
+
nkf_char unicode_subchar /* = '?' */; /* the regular substitution character */
|
|
378
|
+
void (*encode_fallback)(nkf_state_t *nkf_state, nkf_char c) /* = NULL*/;
|
|
379
|
+
#ifdef UTF8_OUTPUT_ENABLE
|
|
380
|
+
int output_bom_f /* = FALSE */;
|
|
381
|
+
int output_endian /* = ENDIAN_BIG */;
|
|
382
|
+
#endif
|
|
383
|
+
|
|
384
|
+
/* buffers */
|
|
385
|
+
|
|
386
|
+
#if !defined(PERL_XS) && !defined(WIN32DLL)
|
|
387
|
+
unsigned char stdibuf[IOBUF_SIZE];
|
|
388
|
+
unsigned char stdobuf[IOBUF_SIZE];
|
|
389
|
+
#endif
|
|
390
|
+
|
|
391
|
+
/* flags */
|
|
392
|
+
int unbuf_f /* = FALSE */;
|
|
393
|
+
int estab_f /* = FALSE */;
|
|
394
|
+
int nop_f /* = FALSE */;
|
|
395
|
+
int binmode_f /* = TRUE */; /* binary mode */
|
|
396
|
+
int rot_f /* = FALSE */; /* rot14/43 mode */
|
|
397
|
+
int hira_f /* = FALSE */; /* hira/kata henkan */
|
|
398
|
+
int alpha_f /* = FALSE */; /* convert JIx0208 alphbet to ASCII */
|
|
399
|
+
int mime_f /* = MIME_DECODE_DEFAULT */; /* convert MIME B base64 or Q */
|
|
400
|
+
int mime_decode_f /* = FALSE */; /* mime decode is explicitly on */
|
|
401
|
+
int mimebuf_f /* = FALSE */; /* MIME buffered input */
|
|
402
|
+
int broken_f /* = FALSE */; /* convert ESC-less broken JIS */
|
|
403
|
+
int iso8859_f /* = FALSE */; /* ISO8859 through */
|
|
404
|
+
int mimeout_f /* = FALSE */; /* base64 mode */
|
|
405
|
+
int x0201_f /* = NKF_UNSPECIFIED */; /* convert JIS X 0201 */
|
|
406
|
+
int iso2022jp_f /* = FALSE */; /* replace non ISO-2022-JP with GETA */
|
|
407
|
+
|
|
408
|
+
#ifdef UNICODE_NORMALIZATION
|
|
409
|
+
int nfc_f /* = FALSE */;
|
|
410
|
+
nkf_char (*i_nfc_getc)(nkf_state_t *nkf_state, FILE *) /* = std_getc */; /* input of ugetc */
|
|
411
|
+
nkf_char (*i_nfc_ungetc)(nkf_state_t *nkf_state, nkf_char c ,FILE *f) /* = std_ungetc */;
|
|
412
|
+
#endif
|
|
413
|
+
|
|
414
|
+
#ifdef INPUT_OPTION
|
|
415
|
+
int cap_f /* = FALSE */;
|
|
416
|
+
nkf_char (*i_cgetc)(nkf_state_t *nkf_state, FILE *) /* = std_getc */; /* input of cgetc */
|
|
417
|
+
nkf_char (*i_cungetc)(nkf_state_t *nkf_state, nkf_char c ,FILE *f) /* = std_ungetc */;
|
|
418
|
+
|
|
419
|
+
int url_f /* = FALSE */;
|
|
420
|
+
nkf_char (*i_ugetc)(nkf_state_t *nkf_state, FILE *) /* = std_getc */; /* input of ugetc */
|
|
421
|
+
nkf_char (*i_uungetc)(nkf_state_t *nkf_state, nkf_char c ,FILE *f) /* = std_ungetc */;
|
|
422
|
+
#endif
|
|
423
|
+
|
|
424
|
+
#ifdef NUMCHAR_OPTION
|
|
425
|
+
int numchar_f /* = FALSE */;
|
|
426
|
+
nkf_char (*i_ngetc)(nkf_state_t *nkf_state, FILE *) /* = std_getc */; /* input of ugetc */
|
|
427
|
+
nkf_char (*i_nungetc)(nkf_state_t *nkf_state, nkf_char c ,FILE *f) /* = std_ungetc */;
|
|
428
|
+
#endif
|
|
429
|
+
|
|
430
|
+
#ifdef CHECK_OPTION
|
|
431
|
+
int noout_f /* = FALSE */;
|
|
432
|
+
int debug_f /* = FALSE */;
|
|
433
|
+
nkf_char (*iconv_for_check)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1,nkf_char c0) /* = 0 */;
|
|
434
|
+
#endif
|
|
435
|
+
|
|
436
|
+
int guess_f /* = 0 */; /* 0: OFF, 1: ON, 2: VERBOSE */
|
|
437
|
+
|
|
438
|
+
#ifdef EXEC_IO
|
|
439
|
+
int exec_f /* = 0 */;
|
|
440
|
+
#endif
|
|
441
|
+
|
|
442
|
+
#ifdef SHIFTJIS_CP932
|
|
443
|
+
/* invert IBM extended characters to others */
|
|
444
|
+
int cp51932_f /* = FALSE */;
|
|
445
|
+
|
|
446
|
+
/* invert NEC-selected IBM extended characters to IBM extended characters */
|
|
447
|
+
int cp932inv_f /* = TRUE */;
|
|
448
|
+
#endif /* SHIFTJIS_CP932 */
|
|
449
|
+
|
|
450
|
+
int x0212_f /* = FALSE */;
|
|
451
|
+
int x0213_f /* = FALSE */;
|
|
452
|
+
|
|
453
|
+
unsigned char prefix_table[256];
|
|
454
|
+
|
|
455
|
+
int mimeout_mode /* = 0 */; /* 0, -1, 'Q', 'B', 1, 2 */
|
|
456
|
+
int base64_count /* = 0 */;
|
|
457
|
+
|
|
458
|
+
int f_line /* = 0 */; /* chars in line */
|
|
459
|
+
int f_prev /* = 0 */;
|
|
460
|
+
int fold_preserve_f /* = FALSE */; /* preserve new lines */
|
|
461
|
+
int fold_f /* = FALSE */;
|
|
462
|
+
int fold_len /* = 0 */;
|
|
463
|
+
|
|
464
|
+
unsigned char kanji_intro /* = DEFAULT_J */;
|
|
465
|
+
unsigned char ascii_intro /* = DEFAULT_R */;
|
|
466
|
+
int fold_margin /* = FOLD_MARGIN */;
|
|
467
|
+
|
|
468
|
+
nkf_char (*iconv_func)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1,nkf_char c0) /* = no_connection2 */;
|
|
469
|
+
void (*oconv_func)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1) /* = no_connection */;
|
|
470
|
+
|
|
471
|
+
void (*o_zconv)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1) /* = no_connection */;
|
|
472
|
+
void (*o_fconv)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1) /* = no_connection */;
|
|
473
|
+
void (*o_eol_conv)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1) /* = no_connection */;
|
|
474
|
+
void (*o_rot_conv)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1) /* = no_connection */;
|
|
475
|
+
void (*o_hira_conv)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1) /* = no_connection */;
|
|
476
|
+
void (*o_base64conv)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1) /* = no_connection */;
|
|
477
|
+
void (*o_iso2022jp_check_conv)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1) /* = no_connection */;
|
|
478
|
+
|
|
479
|
+
void (*o_putc)(nkf_state_t *nkf_state, nkf_char c) /* = std_putc */;
|
|
480
|
+
|
|
481
|
+
nkf_char (*i_getc)(nkf_state_t *nkf_state, FILE *f) /* = std_getc */;
|
|
482
|
+
nkf_char (*i_ungetc)(nkf_state_t *nkf_state, nkf_char c,FILE *f) /* = std_ungetc */;
|
|
483
|
+
|
|
484
|
+
nkf_char (*i_bgetc)(nkf_state_t *nkf_state, FILE *) /* = std_getc */;
|
|
485
|
+
nkf_char (*i_bungetc)(nkf_state_t *nkf_state, nkf_char c ,FILE *f) /* = std_ungetc */;
|
|
486
|
+
|
|
487
|
+
void (*o_mputc)(nkf_state_t *nkf_state, nkf_char c) /* = std_putc */;
|
|
488
|
+
|
|
489
|
+
nkf_char (*i_mgetc)(nkf_state_t *nkf_state, FILE *) /* = std_getc */;
|
|
490
|
+
nkf_char (*i_mungetc)(nkf_state_t *nkf_state, nkf_char c ,FILE *f) /* = std_ungetc */;
|
|
491
|
+
|
|
492
|
+
nkf_char (*i_mgetc_buf)(nkf_state_t *nkf_state, FILE *) /* = std_getc */;
|
|
493
|
+
nkf_char (*i_mungetc_buf)(nkf_state_t *nkf_state, nkf_char c,FILE *f) /* = std_ungetc */;
|
|
494
|
+
|
|
495
|
+
int output_mode /* = ASCII */;
|
|
496
|
+
int input_mode /* = ASCII */;
|
|
497
|
+
int mime_decode_mode /* = FALSE */;
|
|
498
|
+
|
|
499
|
+
int option_mode /* = 0 */;
|
|
500
|
+
int file_out_f /* = FALSE */;
|
|
501
|
+
#ifdef OVERWRITE
|
|
502
|
+
int overwrite_f /* = FALSE */;
|
|
503
|
+
int preserve_time_f /* = FALSE */;
|
|
504
|
+
int backup_f /* = FALSE */;
|
|
505
|
+
char *backup_suffix /* = "" */;
|
|
506
|
+
#endif
|
|
507
|
+
|
|
508
|
+
int eolmode_f /* = 0 */;
|
|
509
|
+
int input_eol /* = 0 */;
|
|
510
|
+
nkf_char prev_cr /* = 0 */;
|
|
511
|
+
#ifdef EASYWIN /*Easy Win */
|
|
512
|
+
int end_check;
|
|
513
|
+
#endif /*Easy Win */
|
|
514
|
+
|
|
515
|
+
nkf_buf_t *std_gc_buf;
|
|
516
|
+
nkf_char broken_state;
|
|
517
|
+
nkf_buf_t *broken_buf;
|
|
518
|
+
nkf_char base64_state;
|
|
519
|
+
nkf_buf_t *nfc_buf;
|
|
520
|
+
|
|
521
|
+
nkf_char hold_buf[HOLD_SIZE*2];
|
|
522
|
+
int hold_count;
|
|
523
|
+
|
|
524
|
+
nkf_char z_prev2;
|
|
525
|
+
nkf_char z_prev1;
|
|
526
|
+
|
|
527
|
+
mime_input_state_t mime_input_state;
|
|
528
|
+
nkf_char (*mime_iconv_back)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1,nkf_char c0);
|
|
529
|
+
mimeout_state_t mimeout_state;
|
|
530
|
+
|
|
531
|
+
struct input_code input_code_list[INPUT_CODE_LIST_SIZE];
|
|
532
|
+
void *callback_arg;
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
#define input_codename nkf_state->input_codename
|
|
536
|
+
#define input_encoding nkf_state->input_encoding
|
|
537
|
+
#define output_encoding nkf_state->output_encoding
|
|
538
|
+
#if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
|
|
539
|
+
#define ms_ucs_map_f nkf_state->ms_ucs_map_f
|
|
540
|
+
#endif
|
|
541
|
+
#ifdef UTF8_INPUT_ENABLE
|
|
542
|
+
#define no_cp932ext_f nkf_state->no_cp932ext_f
|
|
543
|
+
#define no_best_fit_chars_f nkf_state->no_best_fit_chars_f
|
|
544
|
+
#define input_endian nkf_state->input_endian
|
|
545
|
+
#define input_bom_f nkf_state->input_bom_f
|
|
546
|
+
#define unicode_subchar nkf_state->unicode_subchar
|
|
547
|
+
#define encode_fallback nkf_state->encode_fallback
|
|
548
|
+
#endif
|
|
549
|
+
#ifdef UTF8_OUTPUT_ENABLE
|
|
550
|
+
#define output_bom_f nkf_state->output_bom_f
|
|
551
|
+
#define output_endian nkf_state->output_endian
|
|
552
|
+
#endif
|
|
553
|
+
#if !defined(PERL_XS) && !defined(WIN32DLL)
|
|
554
|
+
#define stdibuf nkf_state->stdibuf
|
|
555
|
+
#define stdobuf nkf_state->stdobuf
|
|
556
|
+
#endif
|
|
557
|
+
#define unbuf_f nkf_state->unbuf_f
|
|
558
|
+
#define estab_f nkf_state->estab_f
|
|
559
|
+
#define nop_f nkf_state->nop_f
|
|
560
|
+
#define binmode_f nkf_state->binmode_f
|
|
561
|
+
#define rot_f nkf_state->rot_f
|
|
562
|
+
#define hira_f nkf_state->hira_f
|
|
563
|
+
#define alpha_f nkf_state->alpha_f
|
|
564
|
+
#define mime_f nkf_state->mime_f
|
|
565
|
+
#define mime_decode_f nkf_state->mime_decode_f
|
|
566
|
+
#define mimebuf_f nkf_state->mimebuf_f
|
|
567
|
+
#define broken_f nkf_state->broken_f
|
|
568
|
+
#define iso8859_f nkf_state->iso8859_f
|
|
569
|
+
#define mimeout_f nkf_state->mimeout_f
|
|
570
|
+
#define x0201_f nkf_state->x0201_f
|
|
571
|
+
#define iso2022jp_f nkf_state->iso2022jp_f
|
|
572
|
+
#ifdef UNICODE_NORMALIZATION
|
|
573
|
+
#define nfc_f nkf_state->nfc_f
|
|
574
|
+
#define i_nfc_getc nkf_state->i_nfc_getc
|
|
575
|
+
#define i_nfc_ungetc nkf_state->i_nfc_ungetc
|
|
576
|
+
#endif
|
|
577
|
+
#ifdef INPUT_OPTION
|
|
578
|
+
#define cap_f nkf_state->cap_f
|
|
579
|
+
#define i_cgetc nkf_state->i_cgetc
|
|
580
|
+
#define i_cungetc nkf_state->i_cungetc
|
|
581
|
+
#define url_f nkf_state->url_f
|
|
582
|
+
#define i_ugetc nkf_state->i_ugetc
|
|
583
|
+
#define i_uungetc nkf_state->i_uungetc
|
|
584
|
+
#endif
|
|
585
|
+
#ifdef NUMCHAR_OPTION
|
|
586
|
+
#define numchar_f nkf_state->numchar_f
|
|
587
|
+
#define i_ngetc nkf_state->i_ngetc
|
|
588
|
+
#define i_nungetc nkf_state->i_nungetc
|
|
589
|
+
#endif
|
|
590
|
+
#ifdef CHECK_OPTION
|
|
591
|
+
#define noout_f nkf_state->noout_f
|
|
592
|
+
#define debug_f nkf_state->debug_f
|
|
593
|
+
#define iconv_for_check nkf_state->iconv_for_check
|
|
594
|
+
#endif
|
|
595
|
+
#define guess_f nkf_state->guess_f
|
|
596
|
+
#ifdef EXEC_IO
|
|
597
|
+
#define exec_f nkf_state->exec_f
|
|
598
|
+
#endif
|
|
599
|
+
#ifdef SHIFTJIS_CP932
|
|
600
|
+
#define cp51932_f nkf_state->cp51932_f
|
|
601
|
+
#define cp932inv_f nkf_state->cp932inv_f
|
|
602
|
+
#endif
|
|
603
|
+
#define x0212_f nkf_state->x0212_f
|
|
604
|
+
#define x0213_f nkf_state->x0213_f
|
|
605
|
+
#define prefix_table nkf_state->prefix_table
|
|
606
|
+
#define mimeout_mode nkf_state->mimeout_mode
|
|
607
|
+
#define base64_count nkf_state->base64_count
|
|
608
|
+
#define f_line nkf_state->f_line
|
|
609
|
+
#define f_prev nkf_state->f_prev
|
|
610
|
+
#define fold_preserve_f nkf_state->fold_preserve_f
|
|
611
|
+
#define fold_f nkf_state->fold_f
|
|
612
|
+
#define fold_len nkf_state->fold_len
|
|
613
|
+
#define kanji_intro nkf_state->kanji_intro
|
|
614
|
+
#define ascii_intro nkf_state->ascii_intro
|
|
615
|
+
#define fold_margin nkf_state->fold_margin
|
|
616
|
+
#define iconv nkf_state->iconv_func
|
|
617
|
+
#define oconv nkf_state->oconv_func
|
|
618
|
+
#define o_zconv nkf_state->o_zconv
|
|
619
|
+
#define o_fconv nkf_state->o_fconv
|
|
620
|
+
#define o_eol_conv nkf_state->o_eol_conv
|
|
621
|
+
#define o_rot_conv nkf_state->o_rot_conv
|
|
622
|
+
#define o_hira_conv nkf_state->o_hira_conv
|
|
623
|
+
#define o_base64conv nkf_state->o_base64conv
|
|
624
|
+
#define o_iso2022jp_check_conv nkf_state->o_iso2022jp_check_conv
|
|
625
|
+
#define o_putc nkf_state->o_putc
|
|
626
|
+
#define i_getc nkf_state->i_getc
|
|
627
|
+
#define i_ungetc nkf_state->i_ungetc
|
|
628
|
+
#define i_bgetc nkf_state->i_bgetc
|
|
629
|
+
#define i_bungetc nkf_state->i_bungetc
|
|
630
|
+
#define o_mputc nkf_state->o_mputc
|
|
631
|
+
#define i_mgetc nkf_state->i_mgetc
|
|
632
|
+
#define i_mungetc nkf_state->i_mungetc
|
|
633
|
+
#define i_mgetc_buf nkf_state->i_mgetc_buf
|
|
634
|
+
#define i_mungetc_buf nkf_state->i_mungetc_buf
|
|
635
|
+
#define output_mode nkf_state->output_mode
|
|
636
|
+
#define input_mode nkf_state->input_mode
|
|
637
|
+
#define mime_decode_mode nkf_state->mime_decode_mode
|
|
638
|
+
#define option_mode nkf_state->option_mode
|
|
639
|
+
#define file_out_f nkf_state->file_out_f
|
|
640
|
+
#ifdef OVERWRITE
|
|
641
|
+
#define overwrite_f nkf_state->overwrite_f
|
|
642
|
+
#define preserve_time_f nkf_state->preserve_time_f
|
|
643
|
+
#define backup_f nkf_state->backup_f
|
|
644
|
+
#define backup_suffix nkf_state->backup_suffix
|
|
645
|
+
#endif
|
|
646
|
+
#define eolmode_f nkf_state->eolmode_f
|
|
647
|
+
#define input_eol nkf_state->input_eol
|
|
648
|
+
#define prev_cr nkf_state->prev_cr
|
|
649
|
+
#ifdef EASYWIN /*Easy Win */
|
|
650
|
+
#define end_check nkf_state->end_check
|
|
651
|
+
#endif /*Easy Win */
|
|
652
|
+
#define hold_buf nkf_state->hold_buf
|
|
653
|
+
#define hold_count nkf_state->hold_count
|
|
654
|
+
#define z_prev2 nkf_state->z_prev2
|
|
655
|
+
#define z_prev1 nkf_state->z_prev1
|
|
656
|
+
#define mime_input_state nkf_state->mime_input_state
|
|
657
|
+
#define mime_iconv_back nkf_state->mime_iconv_back
|
|
658
|
+
#define mimeout_state nkf_state->mimeout_state
|
|
659
|
+
#define base64_state nkf_state->base64_state
|
|
660
|
+
#define input_code_list nkf_state->input_code_list
|
|
339
661
|
|
|
340
662
|
#if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
|
|
341
663
|
/* UCS Mapping
|
|
@@ -348,76 +670,24 @@ static nkf_encoding *output_encoding = NULL;
|
|
|
348
670
|
#define UCS_MAP_MS 1
|
|
349
671
|
#define UCS_MAP_CP932 2
|
|
350
672
|
#define UCS_MAP_CP10001 3
|
|
351
|
-
static int ms_ucs_map_f = UCS_MAP_ASCII;
|
|
352
673
|
#endif
|
|
353
674
|
#ifdef UTF8_INPUT_ENABLE
|
|
354
|
-
|
|
355
|
-
static int no_cp932ext_f = FALSE;
|
|
356
|
-
/* ignore ZERO WIDTH NO-BREAK SPACE */
|
|
357
|
-
static int no_best_fit_chars_f = FALSE;
|
|
358
|
-
static int input_endian = ENDIAN_BIG;
|
|
359
|
-
static int input_bom_f = FALSE;
|
|
360
|
-
static nkf_char unicode_subchar = '?'; /* the regular substitution character */
|
|
361
|
-
static void (*encode_fallback)(nkf_char c) = NULL;
|
|
362
|
-
static void w_status(struct input_code *, nkf_char);
|
|
675
|
+
static void w_status(nkf_state_t *nkf_state, struct input_code *, nkf_char);
|
|
363
676
|
#endif
|
|
364
|
-
#ifdef UTF8_OUTPUT_ENABLE
|
|
365
|
-
static int output_bom_f = FALSE;
|
|
366
|
-
static int output_endian = ENDIAN_BIG;
|
|
367
|
-
#endif
|
|
368
|
-
|
|
369
|
-
static void std_putc(nkf_char c);
|
|
370
|
-
static nkf_char std_getc(FILE *f);
|
|
371
|
-
static nkf_char std_ungetc(nkf_char c,FILE *f);
|
|
372
677
|
|
|
373
|
-
static
|
|
374
|
-
static nkf_char
|
|
678
|
+
static void std_putc(nkf_state_t *nkf_state, nkf_char c);
|
|
679
|
+
static nkf_char std_getc(nkf_state_t *nkf_state, FILE *f);
|
|
680
|
+
static nkf_char std_ungetc(nkf_state_t *nkf_state, nkf_char c,FILE *f);
|
|
375
681
|
|
|
376
|
-
static nkf_char
|
|
682
|
+
static nkf_char broken_getc(nkf_state_t *nkf_state, FILE *f);
|
|
683
|
+
static nkf_char broken_ungetc(nkf_state_t *nkf_state, nkf_char c,FILE *f);
|
|
377
684
|
|
|
378
|
-
static
|
|
685
|
+
static nkf_char mime_getc(nkf_state_t *nkf_state, FILE *f);
|
|
379
686
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
#if !defined(PERL_XS) && !defined(WIN32DLL)
|
|
383
|
-
static unsigned char stdibuf[IOBUF_SIZE];
|
|
384
|
-
static unsigned char stdobuf[IOBUF_SIZE];
|
|
385
|
-
#endif
|
|
687
|
+
static void mime_putc(nkf_state_t *nkf_state, nkf_char c);
|
|
386
688
|
|
|
387
689
|
#define NKF_UNSPECIFIED (-TRUE)
|
|
388
690
|
|
|
389
|
-
/* flags */
|
|
390
|
-
static int unbuf_f = FALSE;
|
|
391
|
-
static int estab_f = FALSE;
|
|
392
|
-
static int nop_f = FALSE;
|
|
393
|
-
static int binmode_f = TRUE; /* binary mode */
|
|
394
|
-
static int rot_f = FALSE; /* rot14/43 mode */
|
|
395
|
-
static int hira_f = FALSE; /* hira/kata henkan */
|
|
396
|
-
static int alpha_f = FALSE; /* convert JIx0208 alphbet to ASCII */
|
|
397
|
-
static int mime_f = MIME_DECODE_DEFAULT; /* convert MIME B base64 or Q */
|
|
398
|
-
static int mime_decode_f = FALSE; /* mime decode is explicitly on */
|
|
399
|
-
static int mimebuf_f = FALSE; /* MIME buffered input */
|
|
400
|
-
static int broken_f = FALSE; /* convert ESC-less broken JIS */
|
|
401
|
-
static int iso8859_f = FALSE; /* ISO8859 through */
|
|
402
|
-
static int mimeout_f = FALSE; /* base64 mode */
|
|
403
|
-
static int x0201_f = NKF_UNSPECIFIED; /* convert JIS X 0201 */
|
|
404
|
-
static int iso2022jp_f = FALSE; /* replace non ISO-2022-JP with GETA */
|
|
405
|
-
|
|
406
|
-
#ifdef UNICODE_NORMALIZATION
|
|
407
|
-
static int nfc_f = FALSE;
|
|
408
|
-
static nkf_char (*i_nfc_getc)(FILE *) = std_getc; /* input of ugetc */
|
|
409
|
-
static nkf_char (*i_nfc_ungetc)(nkf_char c ,FILE *f) = std_ungetc;
|
|
410
|
-
#endif
|
|
411
|
-
|
|
412
|
-
#ifdef INPUT_OPTION
|
|
413
|
-
static int cap_f = FALSE;
|
|
414
|
-
static nkf_char (*i_cgetc)(FILE *) = std_getc; /* input of cgetc */
|
|
415
|
-
static nkf_char (*i_cungetc)(nkf_char c ,FILE *f) = std_ungetc;
|
|
416
|
-
|
|
417
|
-
static int url_f = FALSE;
|
|
418
|
-
static nkf_char (*i_ugetc)(FILE *) = std_getc; /* input of ugetc */
|
|
419
|
-
static nkf_char (*i_uungetc)(nkf_char c ,FILE *f) = std_ungetc;
|
|
420
|
-
#endif
|
|
421
691
|
|
|
422
692
|
#define PREFIX_EUCG3 NKF_INT32_C(0x8F00)
|
|
423
693
|
#define CLASS_MASK NKF_INT32_C(0xFF000000)
|
|
@@ -433,46 +703,20 @@ static nkf_char (*i_uungetc)(nkf_char c ,FILE *f) = std_ungetc;
|
|
|
433
703
|
|
|
434
704
|
#define UTF16_TO_UTF32(lead, trail) (((lead) << 10) + (trail) - NKF_INT32_C(0x35FDC00))
|
|
435
705
|
|
|
436
|
-
|
|
437
|
-
static
|
|
438
|
-
static
|
|
439
|
-
static nkf_char (*i_nungetc)(nkf_char c ,FILE *f) = std_ungetc;
|
|
440
|
-
#endif
|
|
441
|
-
|
|
442
|
-
#ifdef CHECK_OPTION
|
|
443
|
-
static int noout_f = FALSE;
|
|
444
|
-
static void no_putc(nkf_char c);
|
|
445
|
-
static int debug_f = FALSE;
|
|
446
|
-
static void debug(const char *str);
|
|
447
|
-
static nkf_char (*iconv_for_check)(nkf_char c2,nkf_char c1,nkf_char c0) = 0;
|
|
448
|
-
#endif
|
|
706
|
+
static void no_putc(nkf_state_t *nkf_state, nkf_char c);
|
|
707
|
+
static void debug(nkf_state_t *nkf_state, const char *str);
|
|
708
|
+
static void reinit(nkf_state_t *nkf_state);
|
|
449
709
|
|
|
450
|
-
static
|
|
451
|
-
static void set_input_codename(const char *codename);
|
|
452
|
-
|
|
453
|
-
#ifdef EXEC_IO
|
|
454
|
-
static int exec_f = 0;
|
|
455
|
-
#endif
|
|
710
|
+
static void set_input_codename(nkf_state_t *nkf_state, const char *codename);
|
|
456
711
|
|
|
457
712
|
#ifdef SHIFTJIS_CP932
|
|
458
|
-
/* invert IBM extended characters to others */
|
|
459
|
-
static int cp51932_f = FALSE;
|
|
460
|
-
|
|
461
|
-
/* invert NEC-selected IBM extended characters to IBM extended characters */
|
|
462
|
-
static int cp932inv_f = TRUE;
|
|
463
|
-
|
|
464
713
|
/* static nkf_char cp932_conv(nkf_char c2, nkf_char c1); */
|
|
465
714
|
#endif /* SHIFTJIS_CP932 */
|
|
466
715
|
|
|
467
|
-
static
|
|
468
|
-
static
|
|
716
|
+
static void e_status(nkf_state_t *nkf_state, struct input_code *, nkf_char);
|
|
717
|
+
static void s_status(nkf_state_t *nkf_state, struct input_code *, nkf_char);
|
|
469
718
|
|
|
470
|
-
static
|
|
471
|
-
|
|
472
|
-
static void e_status(struct input_code *, nkf_char);
|
|
473
|
-
static void s_status(struct input_code *, nkf_char);
|
|
474
|
-
|
|
475
|
-
struct input_code input_code_list[] = {
|
|
719
|
+
static const struct input_code input_code_list_template[INPUT_CODE_LIST_SIZE] = {
|
|
476
720
|
{"EUC-JP", 0, 0, 0, {0, 0, 0}, e_status, e_iconv, 0},
|
|
477
721
|
{"Shift_JIS", 0, 0, 0, {0, 0, 0}, s_status, s_iconv, 0},
|
|
478
722
|
#ifdef UTF8_INPUT_ENABLE
|
|
@@ -483,33 +727,21 @@ struct input_code input_code_list[] = {
|
|
|
483
727
|
{NULL, 0, 0, 0, {0, 0, 0}, NULL, NULL, 0}
|
|
484
728
|
};
|
|
485
729
|
|
|
486
|
-
static int mimeout_mode = 0; /* 0, -1, 'Q', 'B', 1, 2 */
|
|
487
|
-
static int base64_count = 0;
|
|
488
|
-
|
|
489
730
|
/* X0208 -> ASCII converter */
|
|
490
731
|
|
|
491
732
|
/* fold parameter */
|
|
492
|
-
static int f_line = 0; /* chars in line */
|
|
493
|
-
static int f_prev = 0;
|
|
494
|
-
static int fold_preserve_f = FALSE; /* preserve new lines */
|
|
495
|
-
static int fold_f = FALSE;
|
|
496
|
-
static int fold_len = 0;
|
|
497
733
|
|
|
498
734
|
/* options */
|
|
499
|
-
static unsigned char kanji_intro = DEFAULT_J;
|
|
500
|
-
static unsigned char ascii_intro = DEFAULT_R;
|
|
501
735
|
|
|
502
736
|
/* Folding */
|
|
503
737
|
|
|
504
738
|
#define FOLD_MARGIN 10
|
|
505
739
|
#define DEFAULT_FOLD 60
|
|
506
740
|
|
|
507
|
-
static int fold_margin = FOLD_MARGIN;
|
|
508
|
-
|
|
509
741
|
/* process default */
|
|
510
742
|
|
|
511
743
|
static nkf_char
|
|
512
|
-
no_connection2(ARG_UNUSED nkf_char c2, ARG_UNUSED nkf_char c1, ARG_UNUSED nkf_char c0)
|
|
744
|
+
no_connection2(nkf_state_t *nkf_state, ARG_UNUSED nkf_char c2, ARG_UNUSED nkf_char c1, ARG_UNUSED nkf_char c0)
|
|
513
745
|
{
|
|
514
746
|
fprintf(stderr,"nkf internal module connection failure.\n");
|
|
515
747
|
exit(EXIT_FAILURE);
|
|
@@ -517,45 +749,15 @@ no_connection2(ARG_UNUSED nkf_char c2, ARG_UNUSED nkf_char c1, ARG_UNUSED nkf_ch
|
|
|
517
749
|
}
|
|
518
750
|
|
|
519
751
|
static void
|
|
520
|
-
no_connection(nkf_char c2, nkf_char c1)
|
|
752
|
+
no_connection(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
521
753
|
{
|
|
522
|
-
no_connection2(c2,c1,0);
|
|
754
|
+
no_connection2(nkf_state, c2,c1,0);
|
|
523
755
|
}
|
|
524
756
|
|
|
525
|
-
static nkf_char (*iconv)(nkf_char c2,nkf_char c1,nkf_char c0) = no_connection2;
|
|
526
|
-
static void (*oconv)(nkf_char c2,nkf_char c1) = no_connection;
|
|
527
|
-
|
|
528
|
-
static void (*o_zconv)(nkf_char c2,nkf_char c1) = no_connection;
|
|
529
|
-
static void (*o_fconv)(nkf_char c2,nkf_char c1) = no_connection;
|
|
530
|
-
static void (*o_eol_conv)(nkf_char c2,nkf_char c1) = no_connection;
|
|
531
|
-
static void (*o_rot_conv)(nkf_char c2,nkf_char c1) = no_connection;
|
|
532
|
-
static void (*o_hira_conv)(nkf_char c2,nkf_char c1) = no_connection;
|
|
533
|
-
static void (*o_base64conv)(nkf_char c2,nkf_char c1) = no_connection;
|
|
534
|
-
static void (*o_iso2022jp_check_conv)(nkf_char c2,nkf_char c1) = no_connection;
|
|
535
|
-
|
|
536
757
|
/* static redirections */
|
|
537
|
-
|
|
538
|
-
static void (*o_putc)(nkf_char c) = std_putc;
|
|
539
|
-
|
|
540
|
-
static nkf_char (*i_getc)(FILE *f) = std_getc; /* general input */
|
|
541
|
-
static nkf_char (*i_ungetc)(nkf_char c,FILE *f) =std_ungetc;
|
|
542
|
-
|
|
543
|
-
static nkf_char (*i_bgetc)(FILE *) = std_getc; /* input of mgetc */
|
|
544
|
-
static nkf_char (*i_bungetc)(nkf_char c ,FILE *f) = std_ungetc;
|
|
545
|
-
|
|
546
|
-
static void (*o_mputc)(nkf_char c) = std_putc ; /* output of mputc */
|
|
547
|
-
|
|
548
|
-
static nkf_char (*i_mgetc)(FILE *) = std_getc; /* input of mgetc */
|
|
549
|
-
static nkf_char (*i_mungetc)(nkf_char c ,FILE *f) = std_ungetc;
|
|
550
|
-
|
|
551
758
|
/* for strict mime */
|
|
552
|
-
static nkf_char (*i_mgetc_buf)(FILE *) = std_getc; /* input of mgetc_buf */
|
|
553
|
-
static nkf_char (*i_mungetc_buf)(nkf_char c,FILE *f) = std_ungetc;
|
|
554
759
|
|
|
555
760
|
/* Global states */
|
|
556
|
-
static int output_mode = ASCII; /* output kanji mode */
|
|
557
|
-
static int input_mode = ASCII; /* input kanji mode */
|
|
558
|
-
static int mime_decode_mode = FALSE; /* MIME mode B base64, Q hex */
|
|
559
761
|
|
|
560
762
|
/* X0201 / X0208 conversion tables */
|
|
561
763
|
|
|
@@ -665,20 +867,10 @@ static const unsigned char fv[] = {
|
|
|
665
867
|
|
|
666
868
|
|
|
667
869
|
|
|
668
|
-
static int option_mode = 0;
|
|
669
|
-
static int file_out_f = FALSE;
|
|
670
870
|
#ifdef OVERWRITE
|
|
671
|
-
static int overwrite_f = FALSE;
|
|
672
|
-
static int preserve_time_f = FALSE;
|
|
673
|
-
static int backup_f = FALSE;
|
|
674
|
-
static char *backup_suffix = "";
|
|
675
871
|
#endif
|
|
676
872
|
|
|
677
|
-
static int eolmode_f = 0; /* CR, LF, CRLF */
|
|
678
|
-
static int input_eol = 0; /* 0: unestablished, EOF: MIXED */
|
|
679
|
-
static nkf_char prev_cr = 0; /* CR or 0 */
|
|
680
873
|
#ifdef EASYWIN /*Easy Win */
|
|
681
|
-
static int end_check;
|
|
682
874
|
#endif /*Easy Win */
|
|
683
875
|
|
|
684
876
|
static void *
|
|
@@ -758,8 +950,8 @@ nkf_enc_find(const char *name)
|
|
|
758
950
|
#define nkf_enc_name(enc) (enc)->name
|
|
759
951
|
#define nkf_enc_to_index(enc) (enc)->id
|
|
760
952
|
#define nkf_enc_to_base_encoding(enc) (enc)->base_encoding
|
|
761
|
-
#define nkf_enc_to_iconv(enc) nkf_enc_to_base_encoding(enc)->
|
|
762
|
-
#define nkf_enc_to_oconv(enc) nkf_enc_to_base_encoding(enc)->
|
|
953
|
+
#define nkf_enc_to_iconv(enc) nkf_enc_to_base_encoding(enc)->iconv_func
|
|
954
|
+
#define nkf_enc_to_oconv(enc) nkf_enc_to_base_encoding(enc)->oconv_func
|
|
763
955
|
#define nkf_enc_asciicompat(enc) (\
|
|
764
956
|
nkf_enc_to_base_encoding(enc) == &NkfEncodingASCII ||\
|
|
765
957
|
nkf_enc_to_base_encoding(enc) == &NkfEncodingISO_2022_JP)
|
|
@@ -831,11 +1023,11 @@ nkf_default_encoding(void)
|
|
|
831
1023
|
return enc;
|
|
832
1024
|
}
|
|
833
1025
|
|
|
834
|
-
|
|
1026
|
+
struct nkf_buf_t {
|
|
835
1027
|
long capa;
|
|
836
1028
|
long len;
|
|
837
1029
|
nkf_char *ptr;
|
|
838
|
-
}
|
|
1030
|
+
};
|
|
839
1031
|
|
|
840
1032
|
static nkf_buf_t *
|
|
841
1033
|
nkf_buf_new(int length)
|
|
@@ -847,14 +1039,13 @@ nkf_buf_new(int length)
|
|
|
847
1039
|
return buf;
|
|
848
1040
|
}
|
|
849
1041
|
|
|
850
|
-
#if 0
|
|
851
1042
|
static void
|
|
852
1043
|
nkf_buf_dispose(nkf_buf_t *buf)
|
|
853
1044
|
{
|
|
1045
|
+
if (!buf) return;
|
|
854
1046
|
nkf_xfree(buf->ptr);
|
|
855
1047
|
nkf_xfree(buf);
|
|
856
1048
|
}
|
|
857
|
-
#endif
|
|
858
1049
|
|
|
859
1050
|
#define nkf_buf_length(buf) ((buf)->len)
|
|
860
1051
|
#define nkf_buf_empty_p(buf) ((buf)->len == 0)
|
|
@@ -1053,14 +1244,14 @@ get_backup_filename(const char *suffix, const char *filename)
|
|
|
1053
1244
|
|
|
1054
1245
|
#ifdef UTF8_INPUT_ENABLE
|
|
1055
1246
|
static void
|
|
1056
|
-
nkf_each_char_to_hex(void (*f)(nkf_char c2,nkf_char c1), nkf_char c)
|
|
1247
|
+
nkf_each_char_to_hex(nkf_state_t *nkf_state, void (*f)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1), nkf_char c)
|
|
1057
1248
|
{
|
|
1058
1249
|
int shift = 20;
|
|
1059
1250
|
c &= VALUE_MASK;
|
|
1060
1251
|
while(shift >= 0){
|
|
1061
1252
|
if(c >= NKF_INT32_C(1)<<shift){
|
|
1062
1253
|
while(shift >= 0){
|
|
1063
|
-
(*f)(0, bin2hex(c>>shift));
|
|
1254
|
+
(*f)(nkf_state, 0, bin2hex(c>>shift));
|
|
1064
1255
|
shift -= 4;
|
|
1065
1256
|
}
|
|
1066
1257
|
}else{
|
|
@@ -1071,85 +1262,85 @@ nkf_each_char_to_hex(void (*f)(nkf_char c2,nkf_char c1), nkf_char c)
|
|
|
1071
1262
|
}
|
|
1072
1263
|
|
|
1073
1264
|
static void
|
|
1074
|
-
encode_fallback_html(nkf_char c)
|
|
1265
|
+
encode_fallback_html(nkf_state_t *nkf_state, nkf_char c)
|
|
1075
1266
|
{
|
|
1076
|
-
(*oconv)(0, '&');
|
|
1077
|
-
(*oconv)(0, '#');
|
|
1267
|
+
(*oconv)(nkf_state, 0, '&');
|
|
1268
|
+
(*oconv)(nkf_state, 0, '#');
|
|
1078
1269
|
c &= VALUE_MASK;
|
|
1079
1270
|
if(c >= NKF_INT32_C(1000000))
|
|
1080
|
-
(*oconv)(0, 0x30+(c/NKF_INT32_C(1000000))%10);
|
|
1271
|
+
(*oconv)(nkf_state, 0, 0x30+(c/NKF_INT32_C(1000000))%10);
|
|
1081
1272
|
if(c >= NKF_INT32_C(100000))
|
|
1082
|
-
(*oconv)(0, 0x30+(c/NKF_INT32_C(100000) )%10);
|
|
1273
|
+
(*oconv)(nkf_state, 0, 0x30+(c/NKF_INT32_C(100000) )%10);
|
|
1083
1274
|
if(c >= 10000)
|
|
1084
|
-
(*oconv)(0, 0x30+(c/10000 )%10);
|
|
1275
|
+
(*oconv)(nkf_state, 0, 0x30+(c/10000 )%10);
|
|
1085
1276
|
if(c >= 1000)
|
|
1086
|
-
(*oconv)(0, 0x30+(c/1000 )%10);
|
|
1277
|
+
(*oconv)(nkf_state, 0, 0x30+(c/1000 )%10);
|
|
1087
1278
|
if(c >= 100)
|
|
1088
|
-
(*oconv)(0, 0x30+(c/100 )%10);
|
|
1279
|
+
(*oconv)(nkf_state, 0, 0x30+(c/100 )%10);
|
|
1089
1280
|
if(c >= 10)
|
|
1090
|
-
(*oconv)(0, 0x30+(c/10 )%10);
|
|
1281
|
+
(*oconv)(nkf_state, 0, 0x30+(c/10 )%10);
|
|
1091
1282
|
if(c >= 0)
|
|
1092
|
-
(*oconv)(0, 0x30+ c %10);
|
|
1093
|
-
(*oconv)(0, ';');
|
|
1283
|
+
(*oconv)(nkf_state, 0, 0x30+ c %10);
|
|
1284
|
+
(*oconv)(nkf_state, 0, ';');
|
|
1094
1285
|
return;
|
|
1095
1286
|
}
|
|
1096
1287
|
|
|
1097
1288
|
static void
|
|
1098
|
-
encode_fallback_xml(nkf_char c)
|
|
1289
|
+
encode_fallback_xml(nkf_state_t *nkf_state, nkf_char c)
|
|
1099
1290
|
{
|
|
1100
|
-
(*oconv)(0, '&');
|
|
1101
|
-
(*oconv)(0, '#');
|
|
1102
|
-
(*oconv)(0, 'x');
|
|
1103
|
-
nkf_each_char_to_hex(oconv, c);
|
|
1104
|
-
(*oconv)(0, ';');
|
|
1291
|
+
(*oconv)(nkf_state, 0, '&');
|
|
1292
|
+
(*oconv)(nkf_state, 0, '#');
|
|
1293
|
+
(*oconv)(nkf_state, 0, 'x');
|
|
1294
|
+
nkf_each_char_to_hex(nkf_state, oconv, c);
|
|
1295
|
+
(*oconv)(nkf_state, 0, ';');
|
|
1105
1296
|
return;
|
|
1106
1297
|
}
|
|
1107
1298
|
|
|
1108
1299
|
static void
|
|
1109
|
-
encode_fallback_java(nkf_char c)
|
|
1300
|
+
encode_fallback_java(nkf_state_t *nkf_state, nkf_char c)
|
|
1110
1301
|
{
|
|
1111
|
-
(*oconv)(0, '\\');
|
|
1302
|
+
(*oconv)(nkf_state, 0, '\\');
|
|
1112
1303
|
c &= VALUE_MASK;
|
|
1113
1304
|
if(!nkf_char_unicode_bmp_p(c)){
|
|
1114
1305
|
int high = (c >> 10) + NKF_INT32_C(0xD7C0); /* high surrogate */
|
|
1115
1306
|
int low = (c & 0x3FF) + NKF_INT32_C(0xDC00); /* low surrogate */
|
|
1116
|
-
(*oconv)(0, 'u');
|
|
1117
|
-
(*oconv)(0, bin2hex(high>>12));
|
|
1118
|
-
(*oconv)(0, bin2hex(high>> 8));
|
|
1119
|
-
(*oconv)(0, bin2hex(high>> 4));
|
|
1120
|
-
(*oconv)(0, bin2hex(high ));
|
|
1121
|
-
(*oconv)(0, '\\');
|
|
1122
|
-
(*oconv)(0, 'u');
|
|
1123
|
-
(*oconv)(0, bin2hex(low>>12));
|
|
1124
|
-
(*oconv)(0, bin2hex(low>> 8));
|
|
1125
|
-
(*oconv)(0, bin2hex(low>> 4));
|
|
1126
|
-
(*oconv)(0, bin2hex(low ));
|
|
1307
|
+
(*oconv)(nkf_state, 0, 'u');
|
|
1308
|
+
(*oconv)(nkf_state, 0, bin2hex(high>>12));
|
|
1309
|
+
(*oconv)(nkf_state, 0, bin2hex(high>> 8));
|
|
1310
|
+
(*oconv)(nkf_state, 0, bin2hex(high>> 4));
|
|
1311
|
+
(*oconv)(nkf_state, 0, bin2hex(high ));
|
|
1312
|
+
(*oconv)(nkf_state, 0, '\\');
|
|
1313
|
+
(*oconv)(nkf_state, 0, 'u');
|
|
1314
|
+
(*oconv)(nkf_state, 0, bin2hex(low>>12));
|
|
1315
|
+
(*oconv)(nkf_state, 0, bin2hex(low>> 8));
|
|
1316
|
+
(*oconv)(nkf_state, 0, bin2hex(low>> 4));
|
|
1317
|
+
(*oconv)(nkf_state, 0, bin2hex(low ));
|
|
1127
1318
|
}else{
|
|
1128
|
-
(*oconv)(0, 'u');
|
|
1129
|
-
(*oconv)(0, bin2hex(c>>12));
|
|
1130
|
-
(*oconv)(0, bin2hex(c>> 8));
|
|
1131
|
-
(*oconv)(0, bin2hex(c>> 4));
|
|
1132
|
-
(*oconv)(0, bin2hex(c ));
|
|
1319
|
+
(*oconv)(nkf_state, 0, 'u');
|
|
1320
|
+
(*oconv)(nkf_state, 0, bin2hex(c>>12));
|
|
1321
|
+
(*oconv)(nkf_state, 0, bin2hex(c>> 8));
|
|
1322
|
+
(*oconv)(nkf_state, 0, bin2hex(c>> 4));
|
|
1323
|
+
(*oconv)(nkf_state, 0, bin2hex(c ));
|
|
1133
1324
|
}
|
|
1134
1325
|
return;
|
|
1135
1326
|
}
|
|
1136
1327
|
|
|
1137
1328
|
static void
|
|
1138
|
-
encode_fallback_perl(nkf_char c)
|
|
1329
|
+
encode_fallback_perl(nkf_state_t *nkf_state, nkf_char c)
|
|
1139
1330
|
{
|
|
1140
|
-
(*oconv)(0, '\\');
|
|
1141
|
-
(*oconv)(0, 'x');
|
|
1142
|
-
(*oconv)(0, '{');
|
|
1143
|
-
nkf_each_char_to_hex(oconv, c);
|
|
1144
|
-
(*oconv)(0, '}');
|
|
1331
|
+
(*oconv)(nkf_state, 0, '\\');
|
|
1332
|
+
(*oconv)(nkf_state, 0, 'x');
|
|
1333
|
+
(*oconv)(nkf_state, 0, '{');
|
|
1334
|
+
nkf_each_char_to_hex(nkf_state, oconv, c);
|
|
1335
|
+
(*oconv)(nkf_state, 0, '}');
|
|
1145
1336
|
return;
|
|
1146
1337
|
}
|
|
1147
1338
|
|
|
1148
1339
|
static void
|
|
1149
|
-
encode_fallback_subchar(nkf_char c)
|
|
1340
|
+
encode_fallback_subchar(nkf_state_t *nkf_state, nkf_char c)
|
|
1150
1341
|
{
|
|
1151
1342
|
c = unicode_subchar;
|
|
1152
|
-
(*oconv)((c>>8)&0xFF, c&0xFF);
|
|
1343
|
+
(*oconv)(nkf_state, (c>>8)&0xFF, c&0xFF);
|
|
1153
1344
|
return;
|
|
1154
1345
|
}
|
|
1155
1346
|
#endif
|
|
@@ -1235,7 +1426,7 @@ static const struct {
|
|
|
1235
1426
|
};
|
|
1236
1427
|
|
|
1237
1428
|
static void
|
|
1238
|
-
set_input_encoding(nkf_encoding *enc)
|
|
1429
|
+
set_input_encoding(nkf_state_t *nkf_state, nkf_encoding *enc)
|
|
1239
1430
|
{
|
|
1240
1431
|
switch (nkf_enc_to_index(enc)) {
|
|
1241
1432
|
case ISO_8859_1:
|
|
@@ -1358,7 +1549,7 @@ set_input_encoding(nkf_encoding *enc)
|
|
|
1358
1549
|
}
|
|
1359
1550
|
|
|
1360
1551
|
static void
|
|
1361
|
-
set_output_encoding(nkf_encoding *enc)
|
|
1552
|
+
set_output_encoding(nkf_state_t *nkf_state, nkf_encoding *enc)
|
|
1362
1553
|
{
|
|
1363
1554
|
switch (nkf_enc_to_index(enc)) {
|
|
1364
1555
|
case CP50220:
|
|
@@ -1499,7 +1690,7 @@ set_output_encoding(nkf_encoding *enc)
|
|
|
1499
1690
|
}
|
|
1500
1691
|
|
|
1501
1692
|
static struct input_code*
|
|
1502
|
-
find_inputcode_byfunc(nkf_char (*iconv_func)(nkf_char c2,nkf_char c1,nkf_char c0))
|
|
1693
|
+
find_inputcode_byfunc(nkf_state_t *nkf_state, nkf_char (*iconv_func)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1,nkf_char c0))
|
|
1503
1694
|
{
|
|
1504
1695
|
if (iconv_func){
|
|
1505
1696
|
struct input_code *p = input_code_list;
|
|
@@ -1514,7 +1705,7 @@ find_inputcode_byfunc(nkf_char (*iconv_func)(nkf_char c2,nkf_char c1,nkf_char c0
|
|
|
1514
1705
|
}
|
|
1515
1706
|
|
|
1516
1707
|
static void
|
|
1517
|
-
set_iconv(nkf_char f, nkf_char (*iconv_func)(nkf_char c2,nkf_char c1,nkf_char c0))
|
|
1708
|
+
set_iconv(nkf_state_t *nkf_state, nkf_char f, nkf_char (*iconv_func)(nkf_state_t *nkf_state, nkf_char c2,nkf_char c1,nkf_char c0))
|
|
1518
1709
|
{
|
|
1519
1710
|
#ifdef INPUT_CODE_FIX
|
|
1520
1711
|
if (f || !input_encoding)
|
|
@@ -1532,10 +1723,10 @@ set_iconv(nkf_char f, nkf_char (*iconv_func)(nkf_char c2,nkf_char c1,nkf_char c0
|
|
|
1532
1723
|
}
|
|
1533
1724
|
#ifdef CHECK_OPTION
|
|
1534
1725
|
if (estab_f && iconv_for_check != iconv){
|
|
1535
|
-
struct input_code *p = find_inputcode_byfunc(iconv);
|
|
1726
|
+
struct input_code *p = find_inputcode_byfunc(nkf_state, iconv);
|
|
1536
1727
|
if (p){
|
|
1537
|
-
set_input_codename(p->name);
|
|
1538
|
-
debug(p->name);
|
|
1728
|
+
set_input_codename(nkf_state, p->name);
|
|
1729
|
+
debug(nkf_state, p->name);
|
|
1539
1730
|
}
|
|
1540
1731
|
iconv_for_check = iconv;
|
|
1541
1732
|
}
|
|
@@ -1588,7 +1779,7 @@ is_x0213_2_in_x0212(nkf_char c1)
|
|
|
1588
1779
|
}
|
|
1589
1780
|
|
|
1590
1781
|
static nkf_char
|
|
1591
|
-
e2s_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
|
|
1782
|
+
e2s_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
|
|
1592
1783
|
{
|
|
1593
1784
|
nkf_char ndx;
|
|
1594
1785
|
if (is_eucg3(c2)){
|
|
@@ -1631,7 +1822,7 @@ e2s_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
|
|
|
1631
1822
|
}
|
|
1632
1823
|
|
|
1633
1824
|
static nkf_char
|
|
1634
|
-
s2e_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
|
|
1825
|
+
s2e_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
|
|
1635
1826
|
{
|
|
1636
1827
|
#if defined(SHIFTJIS_CP932) || defined(X0212_ENABLE)
|
|
1637
1828
|
nkf_char val;
|
|
@@ -1773,7 +1964,7 @@ nkf_utf8_to_unicode(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
|
1773
1964
|
|
|
1774
1965
|
#ifdef UTF8_INPUT_ENABLE
|
|
1775
1966
|
static int
|
|
1776
|
-
unicode_to_jis_common2(nkf_char c1, nkf_char c0,
|
|
1967
|
+
unicode_to_jis_common2(nkf_state_t *nkf_state, nkf_char c1, nkf_char c0,
|
|
1777
1968
|
const unsigned short *const *pp, nkf_char psize,
|
|
1778
1969
|
nkf_char *p2, nkf_char *p1)
|
|
1779
1970
|
{
|
|
@@ -1810,7 +2001,7 @@ unicode_to_jis_common2(nkf_char c1, nkf_char c0,
|
|
|
1810
2001
|
}
|
|
1811
2002
|
|
|
1812
2003
|
static int
|
|
1813
|
-
unicode_to_jis_common(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_char *p1)
|
|
2004
|
+
unicode_to_jis_common(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_char *p1)
|
|
1814
2005
|
{
|
|
1815
2006
|
const unsigned short *const *pp;
|
|
1816
2007
|
const unsigned short *const *const *ppp;
|
|
@@ -1884,7 +2075,7 @@ unicode_to_jis_common(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_c
|
|
|
1884
2075
|
ms_ucs_map_f == UCS_MAP_CP10001 ? utf8_to_euc_2bytes_mac :
|
|
1885
2076
|
x0213_f ? utf8_to_euc_2bytes_x0213 :
|
|
1886
2077
|
utf8_to_euc_2bytes;
|
|
1887
|
-
ret = unicode_to_jis_common2(c2, c1, pp, sizeof_utf8_to_euc_2bytes, p2, p1);
|
|
2078
|
+
ret = unicode_to_jis_common2(nkf_state, c2, c1, pp, sizeof_utf8_to_euc_2bytes, p2, p1);
|
|
1888
2079
|
}else if(c0 < 0xF0){
|
|
1889
2080
|
if(no_best_fit_chars_f){
|
|
1890
2081
|
if(ms_ucs_map_f == UCS_MAP_CP932){
|
|
@@ -1952,7 +2143,7 @@ unicode_to_jis_common(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_c
|
|
|
1952
2143
|
ms_ucs_map_f == UCS_MAP_CP10001 ? utf8_to_euc_3bytes_mac :
|
|
1953
2144
|
x0213_f ? utf8_to_euc_3bytes_x0213 :
|
|
1954
2145
|
utf8_to_euc_3bytes;
|
|
1955
|
-
ret = unicode_to_jis_common2(c1, c0, ppp[c2 - 0xE0], sizeof_utf8_to_euc_C2, p2, p1);
|
|
2146
|
+
ret = unicode_to_jis_common2(nkf_state, c1, c0, ppp[c2 - 0xE0], sizeof_utf8_to_euc_C2, p2, p1);
|
|
1956
2147
|
}else return -1;
|
|
1957
2148
|
#ifdef SHIFTJIS_CP932
|
|
1958
2149
|
if (!ret&& is_eucg3(*p2)) {
|
|
@@ -1961,8 +2152,8 @@ unicode_to_jis_common(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_c
|
|
|
1961
2152
|
}
|
|
1962
2153
|
else {
|
|
1963
2154
|
nkf_char s2, s1;
|
|
1964
|
-
if (e2s_conv(*p2, *p1, &s2, &s1) == 0) {
|
|
1965
|
-
s2e_conv(s2, s1, p2, p1);
|
|
2155
|
+
if (e2s_conv(nkf_state, *p2, *p1, &s2, &s1) == 0) {
|
|
2156
|
+
s2e_conv(nkf_state, s2, s1, p2, p1);
|
|
1966
2157
|
}else{
|
|
1967
2158
|
ret = 1;
|
|
1968
2159
|
}
|
|
@@ -1983,7 +2174,7 @@ unicode_to_jis_common(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_c
|
|
|
1983
2174
|
} while (0)
|
|
1984
2175
|
|
|
1985
2176
|
static nkf_char
|
|
1986
|
-
e2w_conv(nkf_char c2, nkf_char c1)
|
|
2177
|
+
e2w_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
1987
2178
|
{
|
|
1988
2179
|
const unsigned short *p;
|
|
1989
2180
|
|
|
@@ -2044,7 +2235,7 @@ e2w_conv(nkf_char c2, nkf_char c1)
|
|
|
2044
2235
|
}
|
|
2045
2236
|
|
|
2046
2237
|
static nkf_char
|
|
2047
|
-
e2w_combining(nkf_char comb, nkf_char c2, nkf_char c1)
|
|
2238
|
+
e2w_combining(nkf_state_t *nkf_state, nkf_char comb, nkf_char c2, nkf_char c1)
|
|
2048
2239
|
{
|
|
2049
2240
|
nkf_char euc;
|
|
2050
2241
|
int i;
|
|
@@ -2062,7 +2253,7 @@ e2w_combining(nkf_char comb, nkf_char c2, nkf_char c1)
|
|
|
2062
2253
|
#endif
|
|
2063
2254
|
|
|
2064
2255
|
static nkf_char
|
|
2065
|
-
w2e_conv(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_char *p1)
|
|
2256
|
+
w2e_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_char *p1)
|
|
2066
2257
|
{
|
|
2067
2258
|
nkf_char ret = 0;
|
|
2068
2259
|
|
|
@@ -2070,7 +2261,7 @@ w2e_conv(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_char *p1)
|
|
|
2070
2261
|
*p2 = 0;
|
|
2071
2262
|
*p1 = c2;
|
|
2072
2263
|
}else if (0xc0 <= c2 && c2 <= 0xef) {
|
|
2073
|
-
ret = unicode_to_jis_common(c2, c1, c0, p2, p1);
|
|
2264
|
+
ret = unicode_to_jis_common(nkf_state, c2, c1, c0, p2, p1);
|
|
2074
2265
|
#ifdef NUMCHAR_OPTION
|
|
2075
2266
|
if (ret > 0){
|
|
2076
2267
|
if (p2) *p2 = 0;
|
|
@@ -2084,7 +2275,7 @@ w2e_conv(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_char *p1)
|
|
|
2084
2275
|
|
|
2085
2276
|
#ifdef UTF8_INPUT_ENABLE
|
|
2086
2277
|
static nkf_char
|
|
2087
|
-
w16e_conv(nkf_char val, nkf_char *p2, nkf_char *p1)
|
|
2278
|
+
w16e_conv(nkf_state_t *nkf_state, nkf_char val, nkf_char *p2, nkf_char *p1)
|
|
2088
2279
|
{
|
|
2089
2280
|
nkf_char c1, c2, c3, c4;
|
|
2090
2281
|
nkf_char ret = 0;
|
|
@@ -2095,7 +2286,7 @@ w16e_conv(nkf_char val, nkf_char *p2, nkf_char *p1)
|
|
|
2095
2286
|
}
|
|
2096
2287
|
else if (nkf_char_unicode_bmp_p(val)){
|
|
2097
2288
|
nkf_unicode_to_utf8(val, &c1, &c2, &c3, &c4);
|
|
2098
|
-
ret = unicode_to_jis_common(c1, c2, c3, p2, p1);
|
|
2289
|
+
ret = unicode_to_jis_common(nkf_state, c1, c2, c3, p2, p1);
|
|
2099
2290
|
if (ret > 0){
|
|
2100
2291
|
*p2 = 0;
|
|
2101
2292
|
*p1 = nkf_char_unicode_new(val);
|
|
@@ -2130,7 +2321,7 @@ w16e_conv(nkf_char val, nkf_char *p2, nkf_char *p1)
|
|
|
2130
2321
|
#endif
|
|
2131
2322
|
|
|
2132
2323
|
static nkf_char
|
|
2133
|
-
e_iconv(nkf_char c2, nkf_char c1, nkf_char c0)
|
|
2324
|
+
e_iconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0)
|
|
2134
2325
|
{
|
|
2135
2326
|
if (c2 == JIS_X_0201_1976_K || c2 == SS2){
|
|
2136
2327
|
if (iso2022jp_f && !x0201_f) {
|
|
@@ -2154,8 +2345,8 @@ e_iconv(nkf_char c2, nkf_char c1, nkf_char c0)
|
|
|
2154
2345
|
#ifdef SHIFTJIS_CP932
|
|
2155
2346
|
if (cp51932_f){
|
|
2156
2347
|
nkf_char s2, s1;
|
|
2157
|
-
if (e2s_conv(c2, c1, &s2, &s1) == 0){
|
|
2158
|
-
s2e_conv(s2, s1, &c2, &c1);
|
|
2348
|
+
if (e2s_conv(nkf_state, c2, c1, &s2, &s1) == 0){
|
|
2349
|
+
s2e_conv(nkf_state, s2, s1, &c2, &c1);
|
|
2159
2350
|
if (c2 < 0x100){
|
|
2160
2351
|
c1 &= 0x7f;
|
|
2161
2352
|
c2 &= 0x7f;
|
|
@@ -2178,8 +2369,8 @@ e_iconv(nkf_char c2, nkf_char c1, nkf_char c0)
|
|
|
2178
2369
|
#ifdef SHIFTJIS_CP932
|
|
2179
2370
|
if (cp51932_f && 0x79 <= c2 && c2 <= 0x7c){
|
|
2180
2371
|
nkf_char s2, s1;
|
|
2181
|
-
if (e2s_conv(c2, c1, &s2, &s1) == 0){
|
|
2182
|
-
s2e_conv(s2, s1, &c2, &c1);
|
|
2372
|
+
if (e2s_conv(nkf_state, c2, c1, &s2, &s1) == 0){
|
|
2373
|
+
s2e_conv(nkf_state, s2, s1, &c2, &c1);
|
|
2183
2374
|
if (c2 < 0x100){
|
|
2184
2375
|
c1 &= 0x7f;
|
|
2185
2376
|
c2 &= 0x7f;
|
|
@@ -2189,12 +2380,12 @@ e_iconv(nkf_char c2, nkf_char c1, nkf_char c0)
|
|
|
2189
2380
|
#endif /* SHIFTJIS_CP932 */
|
|
2190
2381
|
}
|
|
2191
2382
|
}
|
|
2192
|
-
(*oconv)(c2, c1);
|
|
2383
|
+
(*oconv)(nkf_state, c2, c1);
|
|
2193
2384
|
return 0;
|
|
2194
2385
|
}
|
|
2195
2386
|
|
|
2196
2387
|
static nkf_char
|
|
2197
|
-
s_iconv(ARG_UNUSED nkf_char c2, nkf_char c1, ARG_UNUSED nkf_char c0)
|
|
2388
|
+
s_iconv(nkf_state_t *nkf_state, ARG_UNUSED nkf_char c2, nkf_char c1, ARG_UNUSED nkf_char c0)
|
|
2198
2389
|
{
|
|
2199
2390
|
if (c2 == JIS_X_0201_1976_K || (0xA1 <= c2 && c2 <= 0xDF)) {
|
|
2200
2391
|
if (iso2022jp_f && !x0201_f) {
|
|
@@ -2210,10 +2401,10 @@ s_iconv(ARG_UNUSED nkf_char c2, nkf_char c1, ARG_UNUSED nkf_char c0)
|
|
|
2210
2401
|
c1 = nkf_char_unicode_new((c2 - 0xF0) * 188 + (c1 - 0x40 - (0x7E < c1)) + 0xE000);
|
|
2211
2402
|
c2 = 0;
|
|
2212
2403
|
} else {
|
|
2213
|
-
nkf_char ret = s2e_conv(c2, c1, &c2, &c1);
|
|
2404
|
+
nkf_char ret = s2e_conv(nkf_state, c2, c1, &c2, &c1);
|
|
2214
2405
|
if (ret) return ret;
|
|
2215
2406
|
}
|
|
2216
|
-
(*oconv)(c2, c1);
|
|
2407
|
+
(*oconv)(nkf_state, c2, c1);
|
|
2217
2408
|
return 0;
|
|
2218
2409
|
}
|
|
2219
2410
|
|
|
@@ -2242,7 +2433,7 @@ x0213_combining_p(nkf_char wc)
|
|
|
2242
2433
|
}
|
|
2243
2434
|
|
|
2244
2435
|
static nkf_char
|
|
2245
|
-
w_iconv(nkf_char c1, nkf_char c2, nkf_char c3)
|
|
2436
|
+
w_iconv(nkf_state_t *nkf_state, nkf_char c1, nkf_char c2, nkf_char c3)
|
|
2246
2437
|
{
|
|
2247
2438
|
nkf_char ret = 0, c4 = 0;
|
|
2248
2439
|
static const char w_iconv_utf8_1st_byte[] =
|
|
@@ -2310,21 +2501,21 @@ w_iconv(nkf_char c1, nkf_char c2, nkf_char c3)
|
|
|
2310
2501
|
} else {
|
|
2311
2502
|
if (x0213_f && x0213_wait_combining_p(nkf_utf8_to_unicode(c1, c2, c3, c4)))
|
|
2312
2503
|
return -3;
|
|
2313
|
-
ret = w2e_conv(c1, c2, c3, &c1, &c2);
|
|
2504
|
+
ret = w2e_conv(nkf_state, c1, c2, c3, &c1, &c2);
|
|
2314
2505
|
}
|
|
2315
2506
|
if (ret == 0){
|
|
2316
|
-
(*oconv)(c1, c2);
|
|
2507
|
+
(*oconv)(nkf_state, c1, c2);
|
|
2317
2508
|
}
|
|
2318
2509
|
return ret;
|
|
2319
2510
|
}
|
|
2320
2511
|
|
|
2321
2512
|
static nkf_char
|
|
2322
|
-
w_iconv_nocombine(nkf_char c1, nkf_char c2, nkf_char c3)
|
|
2513
|
+
w_iconv_nocombine(nkf_state_t *nkf_state, nkf_char c1, nkf_char c2, nkf_char c3)
|
|
2323
2514
|
{
|
|
2324
|
-
/* continue from the line below 'return -3;' in w_iconv
|
|
2325
|
-
nkf_char ret = w2e_conv(c1, c2, c3, &c1, &c2);
|
|
2515
|
+
/* continue from the line below 'return -3;' in w_iconv */
|
|
2516
|
+
nkf_char ret = w2e_conv(nkf_state, c1, c2, c3, &c1, &c2);
|
|
2326
2517
|
if (ret == 0){
|
|
2327
|
-
(*oconv)(c1, c2);
|
|
2518
|
+
(*oconv)(nkf_state, c1, c2);
|
|
2328
2519
|
}
|
|
2329
2520
|
return ret;
|
|
2330
2521
|
}
|
|
@@ -2333,7 +2524,7 @@ w_iconv_nocombine(nkf_char c1, nkf_char c2, nkf_char c3)
|
|
|
2333
2524
|
#define NKF_ICONV_WAIT_COMBINING_CHAR -14
|
|
2334
2525
|
#define NKF_ICONV_NOT_COMBINED -15
|
|
2335
2526
|
static size_t
|
|
2336
|
-
unicode_iconv(nkf_char wc, int nocombine)
|
|
2527
|
+
unicode_iconv(nkf_state_t *nkf_state, nkf_char wc, int nocombine)
|
|
2337
2528
|
{
|
|
2338
2529
|
nkf_char c1, c2;
|
|
2339
2530
|
int ret = 0;
|
|
@@ -2347,7 +2538,7 @@ unicode_iconv(nkf_char wc, int nocombine)
|
|
|
2347
2538
|
}else if (wc < 0xFFFF) {
|
|
2348
2539
|
if (!nocombine && x0213_f && x0213_wait_combining_p(wc))
|
|
2349
2540
|
return NKF_ICONV_WAIT_COMBINING_CHAR;
|
|
2350
|
-
ret = w16e_conv(wc, &c2, &c1);
|
|
2541
|
+
ret = w16e_conv(nkf_state, wc, &c2, &c1);
|
|
2351
2542
|
if (ret) return ret;
|
|
2352
2543
|
}else if (wc < 0x10FFFF) {
|
|
2353
2544
|
c2 = 0;
|
|
@@ -2355,12 +2546,12 @@ unicode_iconv(nkf_char wc, int nocombine)
|
|
|
2355
2546
|
} else {
|
|
2356
2547
|
return NKF_ICONV_INVALID_CODE_RANGE;
|
|
2357
2548
|
}
|
|
2358
|
-
(*oconv)(c2, c1);
|
|
2549
|
+
(*oconv)(nkf_state, c2, c1);
|
|
2359
2550
|
return 0;
|
|
2360
2551
|
}
|
|
2361
2552
|
|
|
2362
2553
|
static nkf_char
|
|
2363
|
-
unicode_iconv_combine(nkf_char wc, nkf_char wc2)
|
|
2554
|
+
unicode_iconv_combine(nkf_state_t *nkf_state, nkf_char wc, nkf_char wc2)
|
|
2364
2555
|
{
|
|
2365
2556
|
nkf_char c1, c2;
|
|
2366
2557
|
int i;
|
|
@@ -2378,7 +2569,7 @@ unicode_iconv_combine(nkf_char wc, nkf_char wc2)
|
|
|
2378
2569
|
x0213_combining_table[i][2] == wc2) {
|
|
2379
2570
|
c2 = x0213_combining_table[i][0] >> 8;
|
|
2380
2571
|
c1 = x0213_combining_table[i][0] & 0x7f;
|
|
2381
|
-
(*oconv)(c2, c1);
|
|
2572
|
+
(*oconv)(nkf_state, c2, c1);
|
|
2382
2573
|
return 0;
|
|
2383
2574
|
}
|
|
2384
2575
|
}
|
|
@@ -2391,25 +2582,25 @@ unicode_iconv_combine(nkf_char wc, nkf_char wc2)
|
|
|
2391
2582
|
}
|
|
2392
2583
|
|
|
2393
2584
|
static nkf_char
|
|
2394
|
-
w_iconv_combine(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4, nkf_char c5, nkf_char c6)
|
|
2585
|
+
w_iconv_combine(nkf_state_t *nkf_state, nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4, nkf_char c5, nkf_char c6)
|
|
2395
2586
|
{
|
|
2396
2587
|
nkf_char wc, wc2;
|
|
2397
2588
|
wc = nkf_utf8_to_unicode(c1, c2, c3, 0);
|
|
2398
2589
|
wc2 = nkf_utf8_to_unicode(c4, c5, c6, 0);
|
|
2399
2590
|
if (wc2 < 0)
|
|
2400
2591
|
return wc2;
|
|
2401
|
-
return unicode_iconv_combine(wc, wc2);
|
|
2592
|
+
return unicode_iconv_combine(nkf_state, wc, wc2);
|
|
2402
2593
|
}
|
|
2403
2594
|
|
|
2404
2595
|
#define NKF_ICONV_NEED_ONE_MORE_BYTE (size_t)-1
|
|
2405
2596
|
#define NKF_ICONV_NEED_TWO_MORE_BYTES (size_t)-2
|
|
2406
2597
|
static size_t
|
|
2407
|
-
nkf_iconv_utf_16(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
2598
|
+
nkf_iconv_utf_16(nkf_state_t *nkf_state, nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
2408
2599
|
{
|
|
2409
2600
|
nkf_char wc;
|
|
2410
2601
|
|
|
2411
2602
|
if (c1 == EOF) {
|
|
2412
|
-
(*oconv)(EOF, 0);
|
|
2603
|
+
(*oconv)(nkf_state, EOF, 0);
|
|
2413
2604
|
return 0;
|
|
2414
2605
|
}
|
|
2415
2606
|
|
|
@@ -2431,11 +2622,11 @@ nkf_iconv_utf_16(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
|
2431
2622
|
}
|
|
2432
2623
|
}
|
|
2433
2624
|
|
|
2434
|
-
return (*unicode_iconv)(wc, FALSE);
|
|
2625
|
+
return (*unicode_iconv)(nkf_state, wc, FALSE);
|
|
2435
2626
|
}
|
|
2436
2627
|
|
|
2437
2628
|
static size_t
|
|
2438
|
-
nkf_iconv_utf_16_combine(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
2629
|
+
nkf_iconv_utf_16_combine(nkf_state_t *nkf_state, nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
2439
2630
|
{
|
|
2440
2631
|
nkf_char wc, wc2;
|
|
2441
2632
|
|
|
@@ -2455,36 +2646,36 @@ nkf_iconv_utf_16_combine(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
|
2455
2646
|
}
|
|
2456
2647
|
}
|
|
2457
2648
|
|
|
2458
|
-
return unicode_iconv_combine(wc, wc2);
|
|
2649
|
+
return unicode_iconv_combine(nkf_state, wc, wc2);
|
|
2459
2650
|
}
|
|
2460
2651
|
|
|
2461
2652
|
static size_t
|
|
2462
|
-
nkf_iconv_utf_16_nocombine(nkf_char c1, nkf_char c2)
|
|
2653
|
+
nkf_iconv_utf_16_nocombine(nkf_state_t *nkf_state, nkf_char c1, nkf_char c2)
|
|
2463
2654
|
{
|
|
2464
2655
|
nkf_char wc;
|
|
2465
2656
|
if (input_endian == ENDIAN_BIG)
|
|
2466
2657
|
wc = c1 << 8 | c2;
|
|
2467
2658
|
else
|
|
2468
2659
|
wc = c2 << 8 | c1;
|
|
2469
|
-
return (*unicode_iconv)(wc, TRUE);
|
|
2660
|
+
return (*unicode_iconv)(nkf_state, wc, TRUE);
|
|
2470
2661
|
}
|
|
2471
2662
|
|
|
2472
2663
|
static nkf_char
|
|
2473
|
-
w_iconv16(nkf_char c2, nkf_char c1, ARG_UNUSED nkf_char c0)
|
|
2664
|
+
w_iconv16(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, ARG_UNUSED nkf_char c0)
|
|
2474
2665
|
{
|
|
2475
|
-
(*oconv)(c2, c1);
|
|
2666
|
+
(*oconv)(nkf_state, c2, c1);
|
|
2476
2667
|
return 16; /* different from w_iconv32 */
|
|
2477
2668
|
}
|
|
2478
2669
|
|
|
2479
2670
|
static nkf_char
|
|
2480
|
-
w_iconv32(nkf_char c2, nkf_char c1, ARG_UNUSED nkf_char c0)
|
|
2671
|
+
w_iconv32(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, ARG_UNUSED nkf_char c0)
|
|
2481
2672
|
{
|
|
2482
|
-
(*oconv)(c2, c1);
|
|
2673
|
+
(*oconv)(nkf_state, c2, c1);
|
|
2483
2674
|
return 32; /* different from w_iconv16 */
|
|
2484
2675
|
}
|
|
2485
2676
|
|
|
2486
2677
|
static nkf_char
|
|
2487
|
-
utf32_to_nkf_char(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
2678
|
+
utf32_to_nkf_char(nkf_state_t *nkf_state, nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
2488
2679
|
{
|
|
2489
2680
|
nkf_char wc;
|
|
2490
2681
|
|
|
@@ -2508,105 +2699,105 @@ utf32_to_nkf_char(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
|
2508
2699
|
}
|
|
2509
2700
|
|
|
2510
2701
|
static size_t
|
|
2511
|
-
nkf_iconv_utf_32(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
2702
|
+
nkf_iconv_utf_32(nkf_state_t *nkf_state, nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
2512
2703
|
{
|
|
2513
2704
|
nkf_char wc;
|
|
2514
2705
|
|
|
2515
2706
|
if (c1 == EOF) {
|
|
2516
|
-
(*oconv)(EOF, 0);
|
|
2707
|
+
(*oconv)(nkf_state, EOF, 0);
|
|
2517
2708
|
return 0;
|
|
2518
2709
|
}
|
|
2519
2710
|
|
|
2520
|
-
wc = utf32_to_nkf_char(c1, c2, c3, c4);
|
|
2711
|
+
wc = utf32_to_nkf_char(nkf_state, c1, c2, c3, c4);
|
|
2521
2712
|
if (wc < 0)
|
|
2522
2713
|
return wc;
|
|
2523
2714
|
|
|
2524
|
-
return (*unicode_iconv)(wc, FALSE);
|
|
2715
|
+
return (*unicode_iconv)(nkf_state, wc, FALSE);
|
|
2525
2716
|
}
|
|
2526
2717
|
|
|
2527
2718
|
static nkf_char
|
|
2528
|
-
nkf_iconv_utf_32_combine(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4, nkf_char c5, nkf_char c6, nkf_char c7, nkf_char c8)
|
|
2719
|
+
nkf_iconv_utf_32_combine(nkf_state_t *nkf_state, nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4, nkf_char c5, nkf_char c6, nkf_char c7, nkf_char c8)
|
|
2529
2720
|
{
|
|
2530
2721
|
nkf_char wc, wc2;
|
|
2531
2722
|
|
|
2532
|
-
wc = utf32_to_nkf_char(c1, c2, c3, c4);
|
|
2723
|
+
wc = utf32_to_nkf_char(nkf_state, c1, c2, c3, c4);
|
|
2533
2724
|
if (wc < 0)
|
|
2534
2725
|
return wc;
|
|
2535
|
-
wc2 = utf32_to_nkf_char(c5, c6, c7, c8);
|
|
2726
|
+
wc2 = utf32_to_nkf_char(nkf_state, c5, c6, c7, c8);
|
|
2536
2727
|
if (wc2 < 0)
|
|
2537
2728
|
return wc2;
|
|
2538
2729
|
|
|
2539
|
-
return unicode_iconv_combine(wc, wc2);
|
|
2730
|
+
return unicode_iconv_combine(nkf_state, wc, wc2);
|
|
2540
2731
|
}
|
|
2541
2732
|
|
|
2542
2733
|
static size_t
|
|
2543
|
-
nkf_iconv_utf_32_nocombine(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
2734
|
+
nkf_iconv_utf_32_nocombine(nkf_state_t *nkf_state, nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
|
|
2544
2735
|
{
|
|
2545
2736
|
nkf_char wc;
|
|
2546
2737
|
|
|
2547
|
-
wc = utf32_to_nkf_char(c1, c2, c3, c4);
|
|
2548
|
-
return (*unicode_iconv)(wc, TRUE);
|
|
2738
|
+
wc = utf32_to_nkf_char(nkf_state, c1, c2, c3, c4);
|
|
2739
|
+
return (*unicode_iconv)(nkf_state, wc, TRUE);
|
|
2549
2740
|
}
|
|
2550
2741
|
#endif
|
|
2551
2742
|
|
|
2552
2743
|
#define output_ascii_escape_sequence(mode) do { \
|
|
2553
2744
|
if (output_mode != ASCII && output_mode != ISO_8859_1) { \
|
|
2554
|
-
(*o_putc)(ESC); \
|
|
2555
|
-
(*o_putc)('('); \
|
|
2556
|
-
(*o_putc)(ascii_intro); \
|
|
2745
|
+
(*o_putc)(nkf_state, ESC); \
|
|
2746
|
+
(*o_putc)(nkf_state, '('); \
|
|
2747
|
+
(*o_putc)(nkf_state, ascii_intro); \
|
|
2557
2748
|
output_mode = mode; \
|
|
2558
2749
|
} \
|
|
2559
2750
|
} while (0)
|
|
2560
2751
|
|
|
2561
2752
|
static void
|
|
2562
|
-
output_escape_sequence(int mode)
|
|
2753
|
+
output_escape_sequence(nkf_state_t *nkf_state, int mode)
|
|
2563
2754
|
{
|
|
2564
2755
|
if (output_mode == mode)
|
|
2565
2756
|
return;
|
|
2566
2757
|
switch(mode) {
|
|
2567
2758
|
case ISO_8859_1:
|
|
2568
|
-
(*o_putc)(ESC);
|
|
2569
|
-
(*o_putc)('.');
|
|
2570
|
-
(*o_putc)('A');
|
|
2759
|
+
(*o_putc)(nkf_state, ESC);
|
|
2760
|
+
(*o_putc)(nkf_state, '.');
|
|
2761
|
+
(*o_putc)(nkf_state, 'A');
|
|
2571
2762
|
break;
|
|
2572
2763
|
case JIS_X_0201_1976_K:
|
|
2573
|
-
(*o_putc)(ESC);
|
|
2574
|
-
(*o_putc)('(');
|
|
2575
|
-
(*o_putc)('I');
|
|
2764
|
+
(*o_putc)(nkf_state, ESC);
|
|
2765
|
+
(*o_putc)(nkf_state, '(');
|
|
2766
|
+
(*o_putc)(nkf_state, 'I');
|
|
2576
2767
|
break;
|
|
2577
2768
|
case JIS_X_0208:
|
|
2578
|
-
(*o_putc)(ESC);
|
|
2579
|
-
(*o_putc)('$');
|
|
2580
|
-
(*o_putc)(kanji_intro);
|
|
2769
|
+
(*o_putc)(nkf_state, ESC);
|
|
2770
|
+
(*o_putc)(nkf_state, '$');
|
|
2771
|
+
(*o_putc)(nkf_state, kanji_intro);
|
|
2581
2772
|
break;
|
|
2582
2773
|
case JIS_X_0212:
|
|
2583
|
-
(*o_putc)(ESC);
|
|
2584
|
-
(*o_putc)('$');
|
|
2585
|
-
(*o_putc)('(');
|
|
2586
|
-
(*o_putc)('D');
|
|
2774
|
+
(*o_putc)(nkf_state, ESC);
|
|
2775
|
+
(*o_putc)(nkf_state, '$');
|
|
2776
|
+
(*o_putc)(nkf_state, '(');
|
|
2777
|
+
(*o_putc)(nkf_state, 'D');
|
|
2587
2778
|
break;
|
|
2588
2779
|
case JIS_X_0213_1:
|
|
2589
|
-
(*o_putc)(ESC);
|
|
2590
|
-
(*o_putc)('$');
|
|
2591
|
-
(*o_putc)('(');
|
|
2592
|
-
(*o_putc)('Q');
|
|
2780
|
+
(*o_putc)(nkf_state, ESC);
|
|
2781
|
+
(*o_putc)(nkf_state, '$');
|
|
2782
|
+
(*o_putc)(nkf_state, '(');
|
|
2783
|
+
(*o_putc)(nkf_state, 'Q');
|
|
2593
2784
|
break;
|
|
2594
2785
|
case JIS_X_0213_2:
|
|
2595
|
-
(*o_putc)(ESC);
|
|
2596
|
-
(*o_putc)('$');
|
|
2597
|
-
(*o_putc)('(');
|
|
2598
|
-
(*o_putc)('P');
|
|
2786
|
+
(*o_putc)(nkf_state, ESC);
|
|
2787
|
+
(*o_putc)(nkf_state, '$');
|
|
2788
|
+
(*o_putc)(nkf_state, '(');
|
|
2789
|
+
(*o_putc)(nkf_state, 'P');
|
|
2599
2790
|
break;
|
|
2600
2791
|
}
|
|
2601
2792
|
output_mode = mode;
|
|
2602
2793
|
}
|
|
2603
2794
|
|
|
2604
2795
|
static void
|
|
2605
|
-
j_oconv(nkf_char c2, nkf_char c1)
|
|
2796
|
+
j_oconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
2606
2797
|
{
|
|
2607
2798
|
#ifdef NUMCHAR_OPTION
|
|
2608
2799
|
if (c2 == 0 && nkf_char_unicode_p(c1)){
|
|
2609
|
-
w16e_conv(c1, &c2, &c1);
|
|
2800
|
+
w16e_conv(nkf_state, c1, &c2, &c1);
|
|
2610
2801
|
if (c2 == 0 && nkf_char_unicode_p(c1)){
|
|
2611
2802
|
c2 = c1 & VALUE_MASK;
|
|
2612
2803
|
if (ms_ucs_map_f && 0xE000 <= c2 && c2 <= 0xE757) {
|
|
@@ -2615,7 +2806,7 @@ j_oconv(nkf_char c2, nkf_char c1)
|
|
|
2615
2806
|
c2 = 0x7F + c1 / 94;
|
|
2616
2807
|
c1 = 0x21 + c1 % 94;
|
|
2617
2808
|
} else {
|
|
2618
|
-
if (encode_fallback) (*encode_fallback)(c1);
|
|
2809
|
+
if (encode_fallback) (*encode_fallback)(nkf_state, c1);
|
|
2619
2810
|
return;
|
|
2620
2811
|
}
|
|
2621
2812
|
}
|
|
@@ -2623,40 +2814,40 @@ j_oconv(nkf_char c2, nkf_char c1)
|
|
|
2623
2814
|
#endif
|
|
2624
2815
|
if (c2 == 0) {
|
|
2625
2816
|
output_ascii_escape_sequence(ASCII);
|
|
2626
|
-
(*o_putc)(c1);
|
|
2817
|
+
(*o_putc)(nkf_state, c1);
|
|
2627
2818
|
}
|
|
2628
2819
|
else if (c2 == EOF) {
|
|
2629
2820
|
output_ascii_escape_sequence(ASCII);
|
|
2630
|
-
(*o_putc)(EOF);
|
|
2821
|
+
(*o_putc)(nkf_state, EOF);
|
|
2631
2822
|
}
|
|
2632
2823
|
else if (c2 == ISO_8859_1) {
|
|
2633
2824
|
output_ascii_escape_sequence(ISO_8859_1);
|
|
2634
|
-
(*o_putc)(c1|0x80);
|
|
2825
|
+
(*o_putc)(nkf_state, c1|0x80);
|
|
2635
2826
|
}
|
|
2636
2827
|
else if (c2 == JIS_X_0201_1976_K) {
|
|
2637
|
-
output_escape_sequence(JIS_X_0201_1976_K);
|
|
2638
|
-
(*o_putc)(c1);
|
|
2828
|
+
output_escape_sequence(nkf_state, JIS_X_0201_1976_K);
|
|
2829
|
+
(*o_putc)(nkf_state, c1);
|
|
2639
2830
|
#ifdef X0212_ENABLE
|
|
2640
2831
|
} else if (is_eucg3(c2)){
|
|
2641
|
-
output_escape_sequence(x0213_f ? JIS_X_0213_2 : JIS_X_0212);
|
|
2642
|
-
(*o_putc)(c2 & 0x7f);
|
|
2643
|
-
(*o_putc)(c1);
|
|
2832
|
+
output_escape_sequence(nkf_state, x0213_f ? JIS_X_0213_2 : JIS_X_0212);
|
|
2833
|
+
(*o_putc)(nkf_state, c2 & 0x7f);
|
|
2834
|
+
(*o_putc)(nkf_state, c1);
|
|
2644
2835
|
#endif
|
|
2645
2836
|
} else {
|
|
2646
2837
|
if(ms_ucs_map_f
|
|
2647
2838
|
? c2<0x20 || 0x92<c2 || c1<0x20 || 0x7e<c1
|
|
2648
2839
|
: c2<0x20 || 0x7e<c2 || c1<0x20 || 0x7e<c1) return;
|
|
2649
|
-
output_escape_sequence(x0213_f ? JIS_X_0213_1 : JIS_X_0208);
|
|
2650
|
-
(*o_putc)(c2);
|
|
2651
|
-
(*o_putc)(c1);
|
|
2840
|
+
output_escape_sequence(nkf_state, x0213_f ? JIS_X_0213_1 : JIS_X_0208);
|
|
2841
|
+
(*o_putc)(nkf_state, c2);
|
|
2842
|
+
(*o_putc)(nkf_state, c1);
|
|
2652
2843
|
}
|
|
2653
2844
|
}
|
|
2654
2845
|
|
|
2655
2846
|
static void
|
|
2656
|
-
e_oconv(nkf_char c2, nkf_char c1)
|
|
2847
|
+
e_oconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
2657
2848
|
{
|
|
2658
2849
|
if (c2 == 0 && nkf_char_unicode_p(c1)){
|
|
2659
|
-
w16e_conv(c1, &c2, &c1);
|
|
2850
|
+
w16e_conv(nkf_state, c1, &c2, &c1);
|
|
2660
2851
|
if (c2 == 0 && nkf_char_unicode_p(c1)){
|
|
2661
2852
|
c2 = c1 & VALUE_MASK;
|
|
2662
2853
|
if (x0212_f && 0xE000 <= c2 && c2 <= 0xE757) {
|
|
@@ -2666,74 +2857,74 @@ e_oconv(nkf_char c2, nkf_char c1)
|
|
|
2666
2857
|
c2 += c2 < 10 ? 0x75 : 0x8FEB;
|
|
2667
2858
|
c1 = 0x21 + c1 % 94;
|
|
2668
2859
|
if (is_eucg3(c2)){
|
|
2669
|
-
(*o_putc)(0x8f);
|
|
2670
|
-
(*o_putc)((c2 & 0x7f) | 0x080);
|
|
2671
|
-
(*o_putc)(c1 | 0x080);
|
|
2860
|
+
(*o_putc)(nkf_state, 0x8f);
|
|
2861
|
+
(*o_putc)(nkf_state, (c2 & 0x7f) | 0x080);
|
|
2862
|
+
(*o_putc)(nkf_state, c1 | 0x080);
|
|
2672
2863
|
}else{
|
|
2673
|
-
(*o_putc)((c2 & 0x7f) | 0x080);
|
|
2674
|
-
(*o_putc)(c1 | 0x080);
|
|
2864
|
+
(*o_putc)(nkf_state, (c2 & 0x7f) | 0x080);
|
|
2865
|
+
(*o_putc)(nkf_state, c1 | 0x080);
|
|
2675
2866
|
}
|
|
2676
2867
|
return;
|
|
2677
2868
|
} else {
|
|
2678
|
-
if (encode_fallback) (*encode_fallback)(c1);
|
|
2869
|
+
if (encode_fallback) (*encode_fallback)(nkf_state, c1);
|
|
2679
2870
|
return;
|
|
2680
2871
|
}
|
|
2681
2872
|
}
|
|
2682
2873
|
}
|
|
2683
2874
|
|
|
2684
2875
|
if (c2 == EOF) {
|
|
2685
|
-
(*o_putc)(EOF);
|
|
2876
|
+
(*o_putc)(nkf_state, EOF);
|
|
2686
2877
|
} else if (c2 == 0) {
|
|
2687
2878
|
output_mode = ASCII;
|
|
2688
|
-
(*o_putc)(c1);
|
|
2879
|
+
(*o_putc)(nkf_state, c1);
|
|
2689
2880
|
} else if (c2 == JIS_X_0201_1976_K) {
|
|
2690
2881
|
output_mode = EUC_JP;
|
|
2691
|
-
(*o_putc)(SS2); (*o_putc)(c1|0x80);
|
|
2882
|
+
(*o_putc)(nkf_state, SS2); (*o_putc)(nkf_state, c1|0x80);
|
|
2692
2883
|
} else if (c2 == ISO_8859_1) {
|
|
2693
2884
|
output_mode = ISO_8859_1;
|
|
2694
|
-
(*o_putc)(c1 | 0x080);
|
|
2885
|
+
(*o_putc)(nkf_state, c1 | 0x080);
|
|
2695
2886
|
#ifdef X0212_ENABLE
|
|
2696
2887
|
} else if (is_eucg3(c2)){
|
|
2697
2888
|
output_mode = EUC_JP;
|
|
2698
2889
|
#ifdef SHIFTJIS_CP932
|
|
2699
2890
|
if (!cp932inv_f){
|
|
2700
2891
|
nkf_char s2, s1;
|
|
2701
|
-
if (e2s_conv(c2, c1, &s2, &s1) == 0){
|
|
2702
|
-
s2e_conv(s2, s1, &c2, &c1);
|
|
2892
|
+
if (e2s_conv(nkf_state, c2, c1, &s2, &s1) == 0){
|
|
2893
|
+
s2e_conv(nkf_state, s2, s1, &c2, &c1);
|
|
2703
2894
|
}
|
|
2704
2895
|
}
|
|
2705
2896
|
#endif
|
|
2706
2897
|
if (c2 == 0) {
|
|
2707
2898
|
output_mode = ASCII;
|
|
2708
|
-
(*o_putc)(c1);
|
|
2899
|
+
(*o_putc)(nkf_state, c1);
|
|
2709
2900
|
}else if (is_eucg3(c2)){
|
|
2710
2901
|
if (x0212_f){
|
|
2711
|
-
(*o_putc)(0x8f);
|
|
2712
|
-
(*o_putc)((c2 & 0x7f) | 0x080);
|
|
2713
|
-
(*o_putc)(c1 | 0x080);
|
|
2902
|
+
(*o_putc)(nkf_state, 0x8f);
|
|
2903
|
+
(*o_putc)(nkf_state, (c2 & 0x7f) | 0x080);
|
|
2904
|
+
(*o_putc)(nkf_state, c1 | 0x080);
|
|
2714
2905
|
}
|
|
2715
2906
|
}else{
|
|
2716
|
-
(*o_putc)((c2 & 0x7f) | 0x080);
|
|
2717
|
-
(*o_putc)(c1 | 0x080);
|
|
2907
|
+
(*o_putc)(nkf_state, (c2 & 0x7f) | 0x080);
|
|
2908
|
+
(*o_putc)(nkf_state, c1 | 0x080);
|
|
2718
2909
|
}
|
|
2719
2910
|
#endif
|
|
2720
2911
|
} else {
|
|
2721
2912
|
if (!nkf_isgraph(c1) || !nkf_isgraph(c2)) {
|
|
2722
|
-
set_iconv(FALSE, 0);
|
|
2913
|
+
set_iconv(nkf_state, FALSE, 0);
|
|
2723
2914
|
return; /* too late to rescue this char */
|
|
2724
2915
|
}
|
|
2725
2916
|
output_mode = EUC_JP;
|
|
2726
|
-
(*o_putc)(c2 | 0x080);
|
|
2727
|
-
(*o_putc)(c1 | 0x080);
|
|
2917
|
+
(*o_putc)(nkf_state, c2 | 0x080);
|
|
2918
|
+
(*o_putc)(nkf_state, c1 | 0x080);
|
|
2728
2919
|
}
|
|
2729
2920
|
}
|
|
2730
2921
|
|
|
2731
2922
|
static void
|
|
2732
|
-
s_oconv(nkf_char c2, nkf_char c1)
|
|
2923
|
+
s_oconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
2733
2924
|
{
|
|
2734
2925
|
#ifdef NUMCHAR_OPTION
|
|
2735
2926
|
if (c2 == 0 && nkf_char_unicode_p(c1)){
|
|
2736
|
-
w16e_conv(c1, &c2, &c1);
|
|
2927
|
+
w16e_conv(nkf_state, c1, &c2, &c1);
|
|
2737
2928
|
if (c2 == 0 && nkf_char_unicode_p(c1)){
|
|
2738
2929
|
c2 = c1 & VALUE_MASK;
|
|
2739
2930
|
if (!x0213_f && 0xE000 <= c2 && c2 <= 0xE757) {
|
|
@@ -2742,43 +2933,43 @@ s_oconv(nkf_char c2, nkf_char c1)
|
|
|
2742
2933
|
c2 = c1 / 188 + (cp932inv_f ? 0xF0 : 0xEB);
|
|
2743
2934
|
c1 = c1 % 188;
|
|
2744
2935
|
c1 += 0x40 + (c1 > 0x3e);
|
|
2745
|
-
(*o_putc)(c2);
|
|
2746
|
-
(*o_putc)(c1);
|
|
2936
|
+
(*o_putc)(nkf_state, c2);
|
|
2937
|
+
(*o_putc)(nkf_state, c1);
|
|
2747
2938
|
return;
|
|
2748
2939
|
} else {
|
|
2749
|
-
if(encode_fallback)(*encode_fallback)(c1);
|
|
2940
|
+
if(encode_fallback)(*encode_fallback)(nkf_state, c1);
|
|
2750
2941
|
return;
|
|
2751
2942
|
}
|
|
2752
2943
|
}
|
|
2753
2944
|
}
|
|
2754
2945
|
#endif
|
|
2755
2946
|
if (c2 == EOF) {
|
|
2756
|
-
(*o_putc)(EOF);
|
|
2947
|
+
(*o_putc)(nkf_state, EOF);
|
|
2757
2948
|
return;
|
|
2758
2949
|
} else if (c2 == 0) {
|
|
2759
2950
|
output_mode = ASCII;
|
|
2760
|
-
(*o_putc)(c1);
|
|
2951
|
+
(*o_putc)(nkf_state, c1);
|
|
2761
2952
|
} else if (c2 == JIS_X_0201_1976_K) {
|
|
2762
2953
|
output_mode = SHIFT_JIS;
|
|
2763
|
-
(*o_putc)(c1|0x80);
|
|
2954
|
+
(*o_putc)(nkf_state, c1|0x80);
|
|
2764
2955
|
} else if (c2 == ISO_8859_1) {
|
|
2765
2956
|
output_mode = ISO_8859_1;
|
|
2766
|
-
(*o_putc)(c1 | 0x080);
|
|
2957
|
+
(*o_putc)(nkf_state, c1 | 0x080);
|
|
2767
2958
|
#ifdef X0212_ENABLE
|
|
2768
2959
|
} else if (is_eucg3(c2)){
|
|
2769
2960
|
output_mode = SHIFT_JIS;
|
|
2770
|
-
if (e2s_conv(c2, c1, &c2, &c1) == 0){
|
|
2771
|
-
(*o_putc)(c2);
|
|
2772
|
-
(*o_putc)(c1);
|
|
2961
|
+
if (e2s_conv(nkf_state, c2, c1, &c2, &c1) == 0){
|
|
2962
|
+
(*o_putc)(nkf_state, c2);
|
|
2963
|
+
(*o_putc)(nkf_state, c1);
|
|
2773
2964
|
}
|
|
2774
2965
|
#endif
|
|
2775
2966
|
} else {
|
|
2776
2967
|
if (!nkf_isprint(c1) || !nkf_isprint(c2)) {
|
|
2777
|
-
set_iconv(FALSE, 0);
|
|
2968
|
+
set_iconv(nkf_state, FALSE, 0);
|
|
2778
2969
|
return; /* too late to rescue this char */
|
|
2779
2970
|
}
|
|
2780
2971
|
output_mode = SHIFT_JIS;
|
|
2781
|
-
e2s_conv(c2, c1, &c2, &c1);
|
|
2972
|
+
e2s_conv(nkf_state, c2, c1, &c2, &c1);
|
|
2782
2973
|
|
|
2783
2974
|
#ifdef SHIFTJIS_CP932
|
|
2784
2975
|
if (cp932inv_f
|
|
@@ -2791,38 +2982,38 @@ s_oconv(nkf_char c2, nkf_char c1)
|
|
|
2791
2982
|
}
|
|
2792
2983
|
#endif /* SHIFTJIS_CP932 */
|
|
2793
2984
|
|
|
2794
|
-
(*o_putc)(c2);
|
|
2985
|
+
(*o_putc)(nkf_state, c2);
|
|
2795
2986
|
if (prefix_table[(unsigned char)c1]){
|
|
2796
|
-
(*o_putc)(prefix_table[(unsigned char)c1]);
|
|
2987
|
+
(*o_putc)(nkf_state, prefix_table[(unsigned char)c1]);
|
|
2797
2988
|
}
|
|
2798
|
-
(*o_putc)(c1);
|
|
2989
|
+
(*o_putc)(nkf_state, c1);
|
|
2799
2990
|
}
|
|
2800
2991
|
}
|
|
2801
2992
|
|
|
2802
2993
|
#ifdef UTF8_OUTPUT_ENABLE
|
|
2803
2994
|
#define OUTPUT_UTF8(val) do { \
|
|
2804
2995
|
nkf_unicode_to_utf8(val, &c1, &c2, &c3, &c4); \
|
|
2805
|
-
(*o_putc)(c1); \
|
|
2806
|
-
if (c2) (*o_putc)(c2); \
|
|
2807
|
-
if (c3) (*o_putc)(c3); \
|
|
2808
|
-
if (c4) (*o_putc)(c4); \
|
|
2996
|
+
(*o_putc)(nkf_state, c1); \
|
|
2997
|
+
if (c2) (*o_putc)(nkf_state, c2); \
|
|
2998
|
+
if (c3) (*o_putc)(nkf_state, c3); \
|
|
2999
|
+
if (c4) (*o_putc)(nkf_state, c4); \
|
|
2809
3000
|
} while (0)
|
|
2810
3001
|
|
|
2811
3002
|
static void
|
|
2812
|
-
w_oconv(nkf_char c2, nkf_char c1)
|
|
3003
|
+
w_oconv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
2813
3004
|
{
|
|
2814
3005
|
nkf_char c3, c4;
|
|
2815
3006
|
nkf_char val, val2;
|
|
2816
3007
|
|
|
2817
3008
|
if (output_bom_f) {
|
|
2818
3009
|
output_bom_f = FALSE;
|
|
2819
|
-
(*o_putc)('\357');
|
|
2820
|
-
(*o_putc)('\273');
|
|
2821
|
-
(*o_putc)('\277');
|
|
3010
|
+
(*o_putc)(nkf_state, '\357');
|
|
3011
|
+
(*o_putc)(nkf_state, '\273');
|
|
3012
|
+
(*o_putc)(nkf_state, '\277');
|
|
2822
3013
|
}
|
|
2823
3014
|
|
|
2824
3015
|
if (c2 == EOF) {
|
|
2825
|
-
(*o_putc)(EOF);
|
|
3016
|
+
(*o_putc)(nkf_state, EOF);
|
|
2826
3017
|
return;
|
|
2827
3018
|
}
|
|
2828
3019
|
|
|
@@ -2833,11 +3024,11 @@ w_oconv(nkf_char c2, nkf_char c1)
|
|
|
2833
3024
|
}
|
|
2834
3025
|
|
|
2835
3026
|
if (c2 == 0) {
|
|
2836
|
-
(*o_putc)(c1);
|
|
3027
|
+
(*o_putc)(nkf_state, c1);
|
|
2837
3028
|
} else {
|
|
2838
|
-
val = e2w_conv(c2, c1);
|
|
3029
|
+
val = e2w_conv(nkf_state, c2, c1);
|
|
2839
3030
|
if (val){
|
|
2840
|
-
val2 = e2w_combining(val, c2, c1);
|
|
3031
|
+
val2 = e2w_combining(nkf_state, val, c2, c1);
|
|
2841
3032
|
if (val2)
|
|
2842
3033
|
OUTPUT_UTF8(val2);
|
|
2843
3034
|
OUTPUT_UTF8(val);
|
|
@@ -2847,11 +3038,11 @@ w_oconv(nkf_char c2, nkf_char c1)
|
|
|
2847
3038
|
|
|
2848
3039
|
#define OUTPUT_UTF16_BYTES(c1, c2) do { \
|
|
2849
3040
|
if (output_endian == ENDIAN_LITTLE){ \
|
|
2850
|
-
(*o_putc)(c1); \
|
|
2851
|
-
(*o_putc)(c2); \
|
|
3041
|
+
(*o_putc)(nkf_state, c1); \
|
|
3042
|
+
(*o_putc)(nkf_state, c2); \
|
|
2852
3043
|
}else{ \
|
|
2853
|
-
(*o_putc)(c2); \
|
|
2854
|
-
(*o_putc)(c1); \
|
|
3044
|
+
(*o_putc)(nkf_state, c2); \
|
|
3045
|
+
(*o_putc)(nkf_state, c1); \
|
|
2855
3046
|
} \
|
|
2856
3047
|
} while (0)
|
|
2857
3048
|
|
|
@@ -2872,7 +3063,7 @@ w_oconv(nkf_char c2, nkf_char c1)
|
|
|
2872
3063
|
} while (0)
|
|
2873
3064
|
|
|
2874
3065
|
static void
|
|
2875
|
-
w_oconv16(nkf_char c2, nkf_char c1)
|
|
3066
|
+
w_oconv16(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
2876
3067
|
{
|
|
2877
3068
|
if (output_bom_f) {
|
|
2878
3069
|
output_bom_f = FALSE;
|
|
@@ -2880,7 +3071,7 @@ w_oconv16(nkf_char c2, nkf_char c1)
|
|
|
2880
3071
|
}
|
|
2881
3072
|
|
|
2882
3073
|
if (c2 == EOF) {
|
|
2883
|
-
(*o_putc)(EOF);
|
|
3074
|
+
(*o_putc)(nkf_state, EOF);
|
|
2884
3075
|
return;
|
|
2885
3076
|
}
|
|
2886
3077
|
|
|
@@ -2888,9 +3079,9 @@ w_oconv16(nkf_char c2, nkf_char c1)
|
|
|
2888
3079
|
OUTPUT_UTF16(c1);
|
|
2889
3080
|
} else if (c2) {
|
|
2890
3081
|
nkf_char val, val2;
|
|
2891
|
-
val = e2w_conv(c2, c1);
|
|
3082
|
+
val = e2w_conv(nkf_state, c2, c1);
|
|
2892
3083
|
if (!val) return;
|
|
2893
|
-
val2 = e2w_combining(val, c2, c1);
|
|
3084
|
+
val2 = e2w_combining(nkf_state, val, c2, c1);
|
|
2894
3085
|
if (val2)
|
|
2895
3086
|
OUTPUT_UTF16(val2);
|
|
2896
3087
|
OUTPUT_UTF16(val);
|
|
@@ -2901,38 +3092,38 @@ w_oconv16(nkf_char c2, nkf_char c1)
|
|
|
2901
3092
|
|
|
2902
3093
|
#define OUTPUT_UTF32(c) do { \
|
|
2903
3094
|
if (output_endian == ENDIAN_LITTLE){ \
|
|
2904
|
-
(*o_putc)(
|
|
2905
|
-
(*o_putc)(((c) >> 8) & 0xFF); \
|
|
2906
|
-
(*o_putc)(((c) >> 16) & 0xFF); \
|
|
2907
|
-
(*o_putc)(0); \
|
|
3095
|
+
(*o_putc)(nkf_state, (c) & 0xFF); \
|
|
3096
|
+
(*o_putc)(nkf_state, ((c) >> 8) & 0xFF); \
|
|
3097
|
+
(*o_putc)(nkf_state, ((c) >> 16) & 0xFF); \
|
|
3098
|
+
(*o_putc)(nkf_state, 0); \
|
|
2908
3099
|
}else{ \
|
|
2909
|
-
(*o_putc)(0); \
|
|
2910
|
-
(*o_putc)(((c) >> 16) & 0xFF); \
|
|
2911
|
-
(*o_putc)(((c) >> 8) & 0xFF); \
|
|
2912
|
-
(*o_putc)(
|
|
3100
|
+
(*o_putc)(nkf_state, 0); \
|
|
3101
|
+
(*o_putc)(nkf_state, ((c) >> 16) & 0xFF); \
|
|
3102
|
+
(*o_putc)(nkf_state, ((c) >> 8) & 0xFF); \
|
|
3103
|
+
(*o_putc)(nkf_state, (c) & 0xFF); \
|
|
2913
3104
|
} \
|
|
2914
3105
|
} while (0)
|
|
2915
3106
|
|
|
2916
3107
|
static void
|
|
2917
|
-
w_oconv32(nkf_char c2, nkf_char c1)
|
|
3108
|
+
w_oconv32(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
2918
3109
|
{
|
|
2919
3110
|
if (output_bom_f) {
|
|
2920
3111
|
output_bom_f = FALSE;
|
|
2921
3112
|
if (output_endian == ENDIAN_LITTLE){
|
|
2922
|
-
(*o_putc)(0xFF);
|
|
2923
|
-
(*o_putc)(0xFE);
|
|
2924
|
-
(*o_putc)(0);
|
|
2925
|
-
(*o_putc)(0);
|
|
3113
|
+
(*o_putc)(nkf_state, 0xFF);
|
|
3114
|
+
(*o_putc)(nkf_state, 0xFE);
|
|
3115
|
+
(*o_putc)(nkf_state, 0);
|
|
3116
|
+
(*o_putc)(nkf_state, 0);
|
|
2926
3117
|
}else{
|
|
2927
|
-
(*o_putc)(0);
|
|
2928
|
-
(*o_putc)(0);
|
|
2929
|
-
(*o_putc)(0xFE);
|
|
2930
|
-
(*o_putc)(0xFF);
|
|
3118
|
+
(*o_putc)(nkf_state, 0);
|
|
3119
|
+
(*o_putc)(nkf_state, 0);
|
|
3120
|
+
(*o_putc)(nkf_state, 0xFE);
|
|
3121
|
+
(*o_putc)(nkf_state, 0xFF);
|
|
2931
3122
|
}
|
|
2932
3123
|
}
|
|
2933
3124
|
|
|
2934
3125
|
if (c2 == EOF) {
|
|
2935
|
-
(*o_putc)(EOF);
|
|
3126
|
+
(*o_putc)(nkf_state, EOF);
|
|
2936
3127
|
return;
|
|
2937
3128
|
}
|
|
2938
3129
|
|
|
@@ -2942,9 +3133,9 @@ w_oconv32(nkf_char c2, nkf_char c1)
|
|
|
2942
3133
|
c1 &= VALUE_MASK;
|
|
2943
3134
|
} else if (c2) {
|
|
2944
3135
|
nkf_char val, val2;
|
|
2945
|
-
val = e2w_conv(c2, c1);
|
|
3136
|
+
val = e2w_conv(nkf_state, c2, c1);
|
|
2946
3137
|
if (!val) return;
|
|
2947
|
-
val2 = e2w_combining(val, c2, c1);
|
|
3138
|
+
val2 = e2w_combining(nkf_state, val, c2, c1);
|
|
2948
3139
|
if (val2)
|
|
2949
3140
|
OUTPUT_UTF32(val2);
|
|
2950
3141
|
c1 = val;
|
|
@@ -3001,7 +3192,7 @@ static const nkf_char score_table_8FF0[] = {
|
|
|
3001
3192
|
};
|
|
3002
3193
|
|
|
3003
3194
|
static void
|
|
3004
|
-
set_code_score(struct input_code *ptr, nkf_char score)
|
|
3195
|
+
set_code_score(nkf_state_t *nkf_state, struct input_code *ptr, nkf_char score)
|
|
3005
3196
|
{
|
|
3006
3197
|
if (ptr){
|
|
3007
3198
|
ptr->score |= score;
|
|
@@ -3009,7 +3200,7 @@ set_code_score(struct input_code *ptr, nkf_char score)
|
|
|
3009
3200
|
}
|
|
3010
3201
|
|
|
3011
3202
|
static void
|
|
3012
|
-
clr_code_score(struct input_code *ptr, nkf_char score)
|
|
3203
|
+
clr_code_score(nkf_state_t *nkf_state, struct input_code *ptr, nkf_char score)
|
|
3013
3204
|
{
|
|
3014
3205
|
if (ptr){
|
|
3015
3206
|
ptr->score &= ~score;
|
|
@@ -3017,87 +3208,87 @@ clr_code_score(struct input_code *ptr, nkf_char score)
|
|
|
3017
3208
|
}
|
|
3018
3209
|
|
|
3019
3210
|
static void
|
|
3020
|
-
code_score(struct input_code *ptr)
|
|
3211
|
+
code_score(nkf_state_t *nkf_state, struct input_code *ptr)
|
|
3021
3212
|
{
|
|
3022
3213
|
nkf_char c2 = ptr->buf[0];
|
|
3023
3214
|
nkf_char c1 = ptr->buf[1];
|
|
3024
3215
|
if (c2 < 0){
|
|
3025
|
-
set_code_score(ptr, SCORE_ERROR);
|
|
3216
|
+
set_code_score(nkf_state, ptr, SCORE_ERROR);
|
|
3026
3217
|
}else if (c2 == SS2){
|
|
3027
|
-
set_code_score(ptr, SCORE_KANA);
|
|
3218
|
+
set_code_score(nkf_state, ptr, SCORE_KANA);
|
|
3028
3219
|
}else if (c2 == 0x8f){
|
|
3029
3220
|
if ((c1 & 0x70) == 0x20){
|
|
3030
|
-
set_code_score(ptr, score_table_8FA0[c1 & 0x0f]);
|
|
3221
|
+
set_code_score(nkf_state, ptr, score_table_8FA0[c1 & 0x0f]);
|
|
3031
3222
|
}else if ((c1 & 0x70) == 0x60){
|
|
3032
|
-
set_code_score(ptr, score_table_8FE0[c1 & 0x0f]);
|
|
3223
|
+
set_code_score(nkf_state, ptr, score_table_8FE0[c1 & 0x0f]);
|
|
3033
3224
|
}else if ((c1 & 0x70) == 0x70){
|
|
3034
|
-
set_code_score(ptr, score_table_8FF0[c1 & 0x0f]);
|
|
3225
|
+
set_code_score(nkf_state, ptr, score_table_8FF0[c1 & 0x0f]);
|
|
3035
3226
|
}else{
|
|
3036
|
-
set_code_score(ptr, SCORE_X0212);
|
|
3227
|
+
set_code_score(nkf_state, ptr, SCORE_X0212);
|
|
3037
3228
|
}
|
|
3038
3229
|
#ifdef UTF8_OUTPUT_ENABLE
|
|
3039
|
-
}else if (!e2w_conv(c2, c1)){
|
|
3040
|
-
set_code_score(ptr, SCORE_NO_EXIST);
|
|
3230
|
+
}else if (!e2w_conv(nkf_state, c2, c1)){
|
|
3231
|
+
set_code_score(nkf_state, ptr, SCORE_NO_EXIST);
|
|
3041
3232
|
#endif
|
|
3042
3233
|
}else if ((c2 & 0x70) == 0x20){
|
|
3043
|
-
set_code_score(ptr, score_table_A0[c2 & 0x0f]);
|
|
3234
|
+
set_code_score(nkf_state, ptr, score_table_A0[c2 & 0x0f]);
|
|
3044
3235
|
}else if ((c2 & 0x70) == 0x70){
|
|
3045
|
-
set_code_score(ptr, score_table_F0[c2 & 0x0f]);
|
|
3236
|
+
set_code_score(nkf_state, ptr, score_table_F0[c2 & 0x0f]);
|
|
3046
3237
|
}else if ((c2 & 0x70) >= 0x50){
|
|
3047
|
-
set_code_score(ptr, SCORE_L2);
|
|
3238
|
+
set_code_score(nkf_state, ptr, SCORE_L2);
|
|
3048
3239
|
}
|
|
3049
3240
|
}
|
|
3050
3241
|
|
|
3051
3242
|
static void
|
|
3052
|
-
status_disable(struct input_code *ptr)
|
|
3243
|
+
status_disable(nkf_state_t *nkf_state, struct input_code *ptr)
|
|
3053
3244
|
{
|
|
3054
3245
|
ptr->stat = -1;
|
|
3055
3246
|
ptr->buf[0] = -1;
|
|
3056
|
-
code_score(ptr);
|
|
3057
|
-
if (iconv == ptr->iconv_func) set_iconv(FALSE, 0);
|
|
3247
|
+
code_score(nkf_state, ptr);
|
|
3248
|
+
if (iconv == ptr->iconv_func) set_iconv(nkf_state, FALSE, 0);
|
|
3058
3249
|
}
|
|
3059
3250
|
|
|
3060
3251
|
static void
|
|
3061
|
-
status_push_ch(struct input_code *ptr, nkf_char c)
|
|
3252
|
+
status_push_ch(nkf_state_t *nkf_state, struct input_code *ptr, nkf_char c)
|
|
3062
3253
|
{
|
|
3063
3254
|
ptr->buf[ptr->index++] = c;
|
|
3064
3255
|
}
|
|
3065
3256
|
|
|
3066
3257
|
static void
|
|
3067
|
-
status_clear(struct input_code *ptr)
|
|
3258
|
+
status_clear(nkf_state_t *nkf_state, struct input_code *ptr)
|
|
3068
3259
|
{
|
|
3069
3260
|
ptr->stat = 0;
|
|
3070
3261
|
ptr->index = 0;
|
|
3071
3262
|
}
|
|
3072
3263
|
|
|
3073
3264
|
static void
|
|
3074
|
-
status_reset(struct input_code *ptr)
|
|
3265
|
+
status_reset(nkf_state_t *nkf_state, struct input_code *ptr)
|
|
3075
3266
|
{
|
|
3076
|
-
status_clear(ptr);
|
|
3267
|
+
status_clear(nkf_state, ptr);
|
|
3077
3268
|
ptr->score = SCORE_INIT;
|
|
3078
3269
|
}
|
|
3079
3270
|
|
|
3080
3271
|
static void
|
|
3081
|
-
status_reinit(struct input_code *ptr)
|
|
3272
|
+
status_reinit(nkf_state_t *nkf_state, struct input_code *ptr)
|
|
3082
3273
|
{
|
|
3083
|
-
status_reset(ptr);
|
|
3274
|
+
status_reset(nkf_state, ptr);
|
|
3084
3275
|
ptr->_file_stat = 0;
|
|
3085
3276
|
}
|
|
3086
3277
|
|
|
3087
3278
|
static void
|
|
3088
|
-
status_check(struct input_code *ptr, nkf_char c)
|
|
3279
|
+
status_check(nkf_state_t *nkf_state, struct input_code *ptr, nkf_char c)
|
|
3089
3280
|
{
|
|
3090
3281
|
if (c <= DEL && estab_f){
|
|
3091
|
-
status_reset(ptr);
|
|
3282
|
+
status_reset(nkf_state, ptr);
|
|
3092
3283
|
}
|
|
3093
3284
|
}
|
|
3094
3285
|
|
|
3095
3286
|
static void
|
|
3096
|
-
s_status(struct input_code *ptr, nkf_char c)
|
|
3287
|
+
s_status(nkf_state_t *nkf_state, struct input_code *ptr, nkf_char c)
|
|
3097
3288
|
{
|
|
3098
3289
|
switch(ptr->stat){
|
|
3099
3290
|
case -1:
|
|
3100
|
-
status_check(ptr, c);
|
|
3291
|
+
status_check(nkf_state, ptr, c);
|
|
3101
3292
|
break;
|
|
3102
3293
|
case 0:
|
|
3103
3294
|
if (c <= DEL){
|
|
@@ -3105,72 +3296,72 @@ s_status(struct input_code *ptr, nkf_char c)
|
|
|
3105
3296
|
}else if (nkf_char_unicode_p(c)){
|
|
3106
3297
|
break;
|
|
3107
3298
|
}else if (0xa1 <= c && c <= 0xdf){
|
|
3108
|
-
status_push_ch(ptr, SS2);
|
|
3109
|
-
status_push_ch(ptr, c);
|
|
3110
|
-
code_score(ptr);
|
|
3111
|
-
status_clear(ptr);
|
|
3299
|
+
status_push_ch(nkf_state, ptr, SS2);
|
|
3300
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3301
|
+
code_score(nkf_state, ptr);
|
|
3302
|
+
status_clear(nkf_state, ptr);
|
|
3112
3303
|
}else if ((0x81 <= c && c < 0xa0) || (0xe0 <= c && c <= 0xea)){
|
|
3113
3304
|
ptr->stat = 1;
|
|
3114
|
-
status_push_ch(ptr, c);
|
|
3305
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3115
3306
|
}else if (0xed <= c && c <= 0xee){
|
|
3116
3307
|
ptr->stat = 3;
|
|
3117
|
-
status_push_ch(ptr, c);
|
|
3308
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3118
3309
|
#ifdef SHIFTJIS_CP932
|
|
3119
3310
|
}else if (is_ibmext_in_sjis(c)){
|
|
3120
3311
|
ptr->stat = 2;
|
|
3121
|
-
status_push_ch(ptr, c);
|
|
3312
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3122
3313
|
#endif /* SHIFTJIS_CP932 */
|
|
3123
3314
|
#ifdef X0212_ENABLE
|
|
3124
3315
|
}else if (0xf0 <= c && c <= 0xfc){
|
|
3125
3316
|
ptr->stat = 1;
|
|
3126
|
-
status_push_ch(ptr, c);
|
|
3317
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3127
3318
|
#endif /* X0212_ENABLE */
|
|
3128
3319
|
}else{
|
|
3129
|
-
status_disable(ptr);
|
|
3320
|
+
status_disable(nkf_state, ptr);
|
|
3130
3321
|
}
|
|
3131
3322
|
break;
|
|
3132
3323
|
case 1:
|
|
3133
3324
|
if ((0x40 <= c && c <= 0x7e) || (0x80 <= c && c <= 0xfc)){
|
|
3134
|
-
status_push_ch(ptr, c);
|
|
3135
|
-
s2e_conv(ptr->buf[0], ptr->buf[1], &ptr->buf[0], &ptr->buf[1]);
|
|
3136
|
-
code_score(ptr);
|
|
3137
|
-
status_clear(ptr);
|
|
3325
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3326
|
+
s2e_conv(nkf_state, ptr->buf[0], ptr->buf[1], &ptr->buf[0], &ptr->buf[1]);
|
|
3327
|
+
code_score(nkf_state, ptr);
|
|
3328
|
+
status_clear(nkf_state, ptr);
|
|
3138
3329
|
}else{
|
|
3139
|
-
status_disable(ptr);
|
|
3330
|
+
status_disable(nkf_state, ptr);
|
|
3140
3331
|
}
|
|
3141
3332
|
break;
|
|
3142
3333
|
case 2:
|
|
3143
3334
|
#ifdef SHIFTJIS_CP932
|
|
3144
3335
|
if ((0x40 <= c && c <= 0x7e) || (0x80 <= c && c <= 0xfc)) {
|
|
3145
|
-
status_push_ch(ptr, c);
|
|
3146
|
-
if (s2e_conv(ptr->buf[0], ptr->buf[1], &ptr->buf[0], &ptr->buf[1]) == 0) {
|
|
3147
|
-
set_code_score(ptr, SCORE_CP932);
|
|
3148
|
-
status_clear(ptr);
|
|
3336
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3337
|
+
if (s2e_conv(nkf_state, ptr->buf[0], ptr->buf[1], &ptr->buf[0], &ptr->buf[1]) == 0) {
|
|
3338
|
+
set_code_score(nkf_state, ptr, SCORE_CP932);
|
|
3339
|
+
status_clear(nkf_state, ptr);
|
|
3149
3340
|
break;
|
|
3150
3341
|
}
|
|
3151
3342
|
}
|
|
3152
3343
|
#endif /* SHIFTJIS_CP932 */
|
|
3153
|
-
status_disable(ptr);
|
|
3344
|
+
status_disable(nkf_state, ptr);
|
|
3154
3345
|
break;
|
|
3155
3346
|
case 3:
|
|
3156
3347
|
if ((0x40 <= c && c <= 0x7e) || (0x80 <= c && c <= 0xfc)){
|
|
3157
|
-
status_push_ch(ptr, c);
|
|
3158
|
-
s2e_conv(ptr->buf[0], ptr->buf[1], &ptr->buf[0], &ptr->buf[1]);
|
|
3159
|
-
set_code_score(ptr, SCORE_CP932);
|
|
3160
|
-
status_clear(ptr);
|
|
3348
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3349
|
+
s2e_conv(nkf_state, ptr->buf[0], ptr->buf[1], &ptr->buf[0], &ptr->buf[1]);
|
|
3350
|
+
set_code_score(nkf_state, ptr, SCORE_CP932);
|
|
3351
|
+
status_clear(nkf_state, ptr);
|
|
3161
3352
|
}else{
|
|
3162
|
-
status_disable(ptr);
|
|
3353
|
+
status_disable(nkf_state, ptr);
|
|
3163
3354
|
}
|
|
3164
3355
|
break;
|
|
3165
3356
|
}
|
|
3166
3357
|
}
|
|
3167
3358
|
|
|
3168
3359
|
static void
|
|
3169
|
-
e_status(struct input_code *ptr, nkf_char c)
|
|
3360
|
+
e_status(nkf_state_t *nkf_state, struct input_code *ptr, nkf_char c)
|
|
3170
3361
|
{
|
|
3171
3362
|
switch (ptr->stat){
|
|
3172
3363
|
case -1:
|
|
3173
|
-
status_check(ptr, c);
|
|
3364
|
+
status_check(nkf_state, ptr, c);
|
|
3174
3365
|
break;
|
|
3175
3366
|
case 0:
|
|
3176
3367
|
if (c <= DEL){
|
|
@@ -3179,32 +3370,32 @@ e_status(struct input_code *ptr, nkf_char c)
|
|
|
3179
3370
|
break;
|
|
3180
3371
|
}else if (SS2 == c || (0xa1 <= c && c <= 0xfe)){
|
|
3181
3372
|
ptr->stat = 1;
|
|
3182
|
-
status_push_ch(ptr, c);
|
|
3373
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3183
3374
|
#ifdef X0212_ENABLE
|
|
3184
3375
|
}else if (0x8f == c){
|
|
3185
3376
|
ptr->stat = 2;
|
|
3186
|
-
status_push_ch(ptr, c);
|
|
3377
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3187
3378
|
#endif /* X0212_ENABLE */
|
|
3188
3379
|
}else{
|
|
3189
|
-
status_disable(ptr);
|
|
3380
|
+
status_disable(nkf_state, ptr);
|
|
3190
3381
|
}
|
|
3191
3382
|
break;
|
|
3192
3383
|
case 1:
|
|
3193
3384
|
if (0xa1 <= c && c <= 0xfe){
|
|
3194
|
-
status_push_ch(ptr, c);
|
|
3195
|
-
code_score(ptr);
|
|
3196
|
-
status_clear(ptr);
|
|
3385
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3386
|
+
code_score(nkf_state, ptr);
|
|
3387
|
+
status_clear(nkf_state, ptr);
|
|
3197
3388
|
}else{
|
|
3198
|
-
status_disable(ptr);
|
|
3389
|
+
status_disable(nkf_state, ptr);
|
|
3199
3390
|
}
|
|
3200
3391
|
break;
|
|
3201
3392
|
#ifdef X0212_ENABLE
|
|
3202
3393
|
case 2:
|
|
3203
3394
|
if (0xa1 <= c && c <= 0xfe){
|
|
3204
3395
|
ptr->stat = 1;
|
|
3205
|
-
status_push_ch(ptr, c);
|
|
3396
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3206
3397
|
}else{
|
|
3207
|
-
status_disable(ptr);
|
|
3398
|
+
status_disable(nkf_state, ptr);
|
|
3208
3399
|
}
|
|
3209
3400
|
#endif /* X0212_ENABLE */
|
|
3210
3401
|
}
|
|
@@ -3212,11 +3403,11 @@ e_status(struct input_code *ptr, nkf_char c)
|
|
|
3212
3403
|
|
|
3213
3404
|
#ifdef UTF8_INPUT_ENABLE
|
|
3214
3405
|
static void
|
|
3215
|
-
w_status(struct input_code *ptr, nkf_char c)
|
|
3406
|
+
w_status(nkf_state_t *nkf_state, struct input_code *ptr, nkf_char c)
|
|
3216
3407
|
{
|
|
3217
3408
|
switch (ptr->stat){
|
|
3218
3409
|
case -1:
|
|
3219
|
-
status_check(ptr, c);
|
|
3410
|
+
status_check(nkf_state, ptr, c);
|
|
3220
3411
|
break;
|
|
3221
3412
|
case 0:
|
|
3222
3413
|
if (c <= DEL){
|
|
@@ -3225,44 +3416,44 @@ w_status(struct input_code *ptr, nkf_char c)
|
|
|
3225
3416
|
break;
|
|
3226
3417
|
}else if (0xc0 <= c && c <= 0xdf){
|
|
3227
3418
|
ptr->stat = 1;
|
|
3228
|
-
status_push_ch(ptr, c);
|
|
3419
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3229
3420
|
}else if (0xe0 <= c && c <= 0xef){
|
|
3230
3421
|
ptr->stat = 2;
|
|
3231
|
-
status_push_ch(ptr, c);
|
|
3422
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3232
3423
|
}else if (0xf0 <= c && c <= 0xf4){
|
|
3233
3424
|
ptr->stat = 3;
|
|
3234
|
-
status_push_ch(ptr, c);
|
|
3425
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3235
3426
|
}else{
|
|
3236
|
-
status_disable(ptr);
|
|
3427
|
+
status_disable(nkf_state, ptr);
|
|
3237
3428
|
}
|
|
3238
3429
|
break;
|
|
3239
3430
|
case 1:
|
|
3240
3431
|
case 2:
|
|
3241
3432
|
if (0x80 <= c && c <= 0xbf){
|
|
3242
|
-
status_push_ch(ptr, c);
|
|
3433
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3243
3434
|
if (ptr->index > ptr->stat){
|
|
3244
3435
|
int bom = (ptr->buf[0] == 0xef && ptr->buf[1] == 0xbb
|
|
3245
3436
|
&& ptr->buf[2] == 0xbf);
|
|
3246
|
-
w2e_conv(ptr->buf[0], ptr->buf[1], ptr->buf[2],
|
|
3437
|
+
w2e_conv(nkf_state, ptr->buf[0], ptr->buf[1], ptr->buf[2],
|
|
3247
3438
|
&ptr->buf[0], &ptr->buf[1]);
|
|
3248
3439
|
if (!bom){
|
|
3249
|
-
code_score(ptr);
|
|
3440
|
+
code_score(nkf_state, ptr);
|
|
3250
3441
|
}
|
|
3251
|
-
status_clear(ptr);
|
|
3442
|
+
status_clear(nkf_state, ptr);
|
|
3252
3443
|
}
|
|
3253
3444
|
}else{
|
|
3254
|
-
status_disable(ptr);
|
|
3445
|
+
status_disable(nkf_state, ptr);
|
|
3255
3446
|
}
|
|
3256
3447
|
break;
|
|
3257
3448
|
case 3:
|
|
3258
3449
|
if (0x80 <= c && c <= 0xbf){
|
|
3259
3450
|
if (ptr->index < ptr->stat){
|
|
3260
|
-
status_push_ch(ptr, c);
|
|
3451
|
+
status_push_ch(nkf_state, ptr, c);
|
|
3261
3452
|
} else {
|
|
3262
|
-
status_clear(ptr);
|
|
3453
|
+
status_clear(nkf_state, ptr);
|
|
3263
3454
|
}
|
|
3264
3455
|
}else{
|
|
3265
|
-
status_disable(ptr);
|
|
3456
|
+
status_disable(nkf_state, ptr);
|
|
3266
3457
|
}
|
|
3267
3458
|
break;
|
|
3268
3459
|
}
|
|
@@ -3270,7 +3461,7 @@ w_status(struct input_code *ptr, nkf_char c)
|
|
|
3270
3461
|
#endif
|
|
3271
3462
|
|
|
3272
3463
|
static void
|
|
3273
|
-
code_status(nkf_char c)
|
|
3464
|
+
code_status(nkf_state_t *nkf_state, nkf_char c)
|
|
3274
3465
|
{
|
|
3275
3466
|
int action_flag = 1;
|
|
3276
3467
|
struct input_code *result = 0;
|
|
@@ -3282,7 +3473,7 @@ code_status(nkf_char c)
|
|
|
3282
3473
|
}
|
|
3283
3474
|
if (!p->status_func)
|
|
3284
3475
|
continue;
|
|
3285
|
-
(p->status_func)(p, c);
|
|
3476
|
+
(p->status_func)(nkf_state, p, c);
|
|
3286
3477
|
if (p->stat > 0){
|
|
3287
3478
|
action_flag = 0;
|
|
3288
3479
|
}else if(p->stat == 0){
|
|
@@ -3297,50 +3488,46 @@ code_status(nkf_char c)
|
|
|
3297
3488
|
|
|
3298
3489
|
if (action_flag){
|
|
3299
3490
|
if (result && !estab_f){
|
|
3300
|
-
set_iconv(TRUE, result->iconv_func);
|
|
3491
|
+
set_iconv(nkf_state, TRUE, result->iconv_func);
|
|
3301
3492
|
}else if (c <= DEL){
|
|
3302
3493
|
struct input_code *ptr = input_code_list;
|
|
3303
3494
|
while (ptr->name){
|
|
3304
|
-
status_reset(ptr);
|
|
3495
|
+
status_reset(nkf_state, ptr);
|
|
3305
3496
|
++ptr;
|
|
3306
3497
|
}
|
|
3307
3498
|
}
|
|
3308
3499
|
}
|
|
3309
3500
|
}
|
|
3310
3501
|
|
|
3311
|
-
typedef struct {
|
|
3312
|
-
nkf_buf_t *std_gc_buf;
|
|
3313
|
-
nkf_char broken_state;
|
|
3314
|
-
nkf_buf_t *broken_buf;
|
|
3315
|
-
nkf_char mimeout_state;
|
|
3316
|
-
nkf_buf_t *nfc_buf;
|
|
3317
|
-
} nkf_state_t;
|
|
3318
|
-
|
|
3319
|
-
static nkf_state_t *nkf_state = NULL;
|
|
3320
|
-
|
|
3321
3502
|
#define STD_GC_BUFSIZE (256)
|
|
3322
3503
|
|
|
3323
3504
|
static void
|
|
3324
|
-
nkf_state_init(
|
|
3505
|
+
nkf_state_init(nkf_state_t *nkf_state)
|
|
3325
3506
|
{
|
|
3326
|
-
if (nkf_state) {
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
nkf_buf_clear(nkf_state->nfc_buf);
|
|
3330
|
-
}
|
|
3331
|
-
else {
|
|
3332
|
-
nkf_state = nkf_xmalloc(sizeof(nkf_state_t));
|
|
3507
|
+
if (!nkf_state->std_gc_buf) {
|
|
3508
|
+
memset(nkf_state, 0, sizeof(nkf_state_t));
|
|
3509
|
+
memcpy(input_code_list, input_code_list_template, sizeof(input_code_list));
|
|
3333
3510
|
nkf_state->std_gc_buf = nkf_buf_new(STD_GC_BUFSIZE);
|
|
3334
3511
|
nkf_state->broken_buf = nkf_buf_new(3);
|
|
3335
3512
|
nkf_state->nfc_buf = nkf_buf_new(9);
|
|
3336
3513
|
}
|
|
3337
|
-
nkf_state
|
|
3338
|
-
|
|
3514
|
+
reinit(nkf_state);
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
static void
|
|
3518
|
+
nkf_state_dispose(nkf_state_t *nkf_state)
|
|
3519
|
+
{
|
|
3520
|
+
nkf_buf_dispose(nkf_state->std_gc_buf);
|
|
3521
|
+
nkf_buf_dispose(nkf_state->broken_buf);
|
|
3522
|
+
nkf_buf_dispose(nkf_state->nfc_buf);
|
|
3523
|
+
nkf_state->std_gc_buf = NULL;
|
|
3524
|
+
nkf_state->broken_buf = NULL;
|
|
3525
|
+
nkf_state->nfc_buf = NULL;
|
|
3339
3526
|
}
|
|
3340
3527
|
|
|
3341
3528
|
#ifndef WIN32DLL
|
|
3342
3529
|
static nkf_char
|
|
3343
|
-
std_getc(FILE *f)
|
|
3530
|
+
std_getc(nkf_state_t *nkf_state, FILE *f)
|
|
3344
3531
|
{
|
|
3345
3532
|
if (!nkf_buf_empty_p(nkf_state->std_gc_buf)){
|
|
3346
3533
|
return nkf_buf_pop(nkf_state->std_gc_buf);
|
|
@@ -3350,7 +3537,7 @@ std_getc(FILE *f)
|
|
|
3350
3537
|
#endif /*WIN32DLL*/
|
|
3351
3538
|
|
|
3352
3539
|
static nkf_char
|
|
3353
|
-
std_ungetc(nkf_char c, ARG_UNUSED FILE *f)
|
|
3540
|
+
std_ungetc(nkf_state_t *nkf_state, nkf_char c, ARG_UNUSED FILE *f)
|
|
3354
3541
|
{
|
|
3355
3542
|
nkf_buf_push(nkf_state->std_gc_buf, c);
|
|
3356
3543
|
return c;
|
|
@@ -3358,17 +3545,15 @@ std_ungetc(nkf_char c, ARG_UNUSED FILE *f)
|
|
|
3358
3545
|
|
|
3359
3546
|
#ifndef WIN32DLL
|
|
3360
3547
|
static void
|
|
3361
|
-
std_putc(nkf_char c)
|
|
3548
|
+
std_putc(nkf_state_t *nkf_state, nkf_char c)
|
|
3362
3549
|
{
|
|
3363
3550
|
if(c!=EOF)
|
|
3364
3551
|
putchar(c);
|
|
3365
3552
|
}
|
|
3366
3553
|
#endif /*WIN32DLL*/
|
|
3367
3554
|
|
|
3368
|
-
static nkf_char hold_buf[HOLD_SIZE*2];
|
|
3369
|
-
static int hold_count = 0;
|
|
3370
3555
|
static nkf_char
|
|
3371
|
-
push_hold_buf(nkf_char c2)
|
|
3556
|
+
push_hold_buf(nkf_state_t *nkf_state, nkf_char c2)
|
|
3372
3557
|
{
|
|
3373
3558
|
if (hold_count >= HOLD_SIZE*2)
|
|
3374
3559
|
return (EOF);
|
|
@@ -3377,7 +3562,7 @@ push_hold_buf(nkf_char c2)
|
|
|
3377
3562
|
}
|
|
3378
3563
|
|
|
3379
3564
|
static int
|
|
3380
|
-
h_conv(FILE *f, nkf_char c1, nkf_char c2)
|
|
3565
|
+
h_conv(nkf_state_t *nkf_state, FILE *f, nkf_char c1, nkf_char c2)
|
|
3381
3566
|
{
|
|
3382
3567
|
int ret;
|
|
3383
3568
|
int hold_index;
|
|
@@ -3389,16 +3574,16 @@ h_conv(FILE *f, nkf_char c1, nkf_char c2)
|
|
|
3389
3574
|
/** and it must be after 2 byte 8bit code */
|
|
3390
3575
|
|
|
3391
3576
|
hold_count = 0;
|
|
3392
|
-
push_hold_buf(c1);
|
|
3393
|
-
push_hold_buf(c2);
|
|
3577
|
+
push_hold_buf(nkf_state, c1);
|
|
3578
|
+
push_hold_buf(nkf_state, c2);
|
|
3394
3579
|
|
|
3395
|
-
while ((c2 = (*i_getc)(f)) != EOF) {
|
|
3580
|
+
while ((c2 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
3396
3581
|
if (c2 == ESC){
|
|
3397
|
-
(*i_ungetc)(c2,f);
|
|
3582
|
+
(*i_ungetc)(nkf_state, c2,f);
|
|
3398
3583
|
break;
|
|
3399
3584
|
}
|
|
3400
|
-
code_status(c2);
|
|
3401
|
-
if (push_hold_buf(c2) == EOF || estab_f) {
|
|
3585
|
+
code_status(nkf_state, c2);
|
|
3586
|
+
if (push_hold_buf(nkf_state, c2) == EOF || estab_f) {
|
|
3402
3587
|
break;
|
|
3403
3588
|
}
|
|
3404
3589
|
}
|
|
@@ -3407,7 +3592,7 @@ h_conv(FILE *f, nkf_char c1, nkf_char c2)
|
|
|
3407
3592
|
struct input_code *p = input_code_list;
|
|
3408
3593
|
struct input_code *result = p;
|
|
3409
3594
|
if (c2 == EOF) {
|
|
3410
|
-
code_status(c2);
|
|
3595
|
+
code_status(nkf_state, c2);
|
|
3411
3596
|
}
|
|
3412
3597
|
while (p->name) {
|
|
3413
3598
|
if (p->status_func && p->score < result->score) {
|
|
@@ -3415,7 +3600,7 @@ h_conv(FILE *f, nkf_char c1, nkf_char c2)
|
|
|
3415
3600
|
}
|
|
3416
3601
|
p++;
|
|
3417
3602
|
}
|
|
3418
|
-
set_iconv(TRUE, result->iconv_func);
|
|
3603
|
+
set_iconv(nkf_state, TRUE, result->iconv_func);
|
|
3419
3604
|
}
|
|
3420
3605
|
|
|
3421
3606
|
|
|
@@ -3433,14 +3618,14 @@ h_conv(FILE *f, nkf_char c1, nkf_char c2)
|
|
|
3433
3618
|
while (hold_index < hold_count){
|
|
3434
3619
|
c1 = hold_buf[hold_index++];
|
|
3435
3620
|
if (nkf_char_unicode_p(c1)) {
|
|
3436
|
-
(*oconv)(0, c1);
|
|
3621
|
+
(*oconv)(nkf_state, 0, c1);
|
|
3437
3622
|
continue;
|
|
3438
3623
|
}
|
|
3439
3624
|
else if (c1 <= DEL){
|
|
3440
|
-
(*iconv)(0, c1, 0);
|
|
3625
|
+
(*iconv)(nkf_state, 0, c1, 0);
|
|
3441
3626
|
continue;
|
|
3442
3627
|
}else if (iconv == s_iconv && 0xa1 <= c1 && c1 <= 0xdf){
|
|
3443
|
-
(*iconv)(JIS_X_0201_1976_K, c1, 0);
|
|
3628
|
+
(*iconv)(nkf_state, JIS_X_0201_1976_K, c1, 0);
|
|
3444
3629
|
continue;
|
|
3445
3630
|
}
|
|
3446
3631
|
fromhold_count = 1;
|
|
@@ -3448,60 +3633,60 @@ h_conv(FILE *f, nkf_char c1, nkf_char c2)
|
|
|
3448
3633
|
c2 = hold_buf[hold_index++];
|
|
3449
3634
|
fromhold_count++;
|
|
3450
3635
|
}else{
|
|
3451
|
-
c2 = (*i_getc)(f);
|
|
3636
|
+
c2 = (*i_getc)(nkf_state, f);
|
|
3452
3637
|
if (c2 == EOF){
|
|
3453
3638
|
c4 = EOF;
|
|
3454
3639
|
break;
|
|
3455
3640
|
}
|
|
3456
|
-
code_status(c2);
|
|
3641
|
+
code_status(nkf_state, c2);
|
|
3457
3642
|
}
|
|
3458
3643
|
c3 = 0;
|
|
3459
|
-
switch ((*iconv)(c1, c2, 0)) { /* can be EUC/SJIS/UTF-8 */
|
|
3644
|
+
switch ((*iconv)(nkf_state, c1, c2, 0)) { /* can be EUC/SJIS/UTF-8 */
|
|
3460
3645
|
case -2:
|
|
3461
3646
|
/* 4 bytes UTF-8 */
|
|
3462
3647
|
if (hold_index < hold_count){
|
|
3463
3648
|
c3 = hold_buf[hold_index++];
|
|
3464
|
-
} else if ((c3 = (*i_getc)(f)) == EOF) {
|
|
3649
|
+
} else if ((c3 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
3465
3650
|
ret = EOF;
|
|
3466
3651
|
break;
|
|
3467
3652
|
}
|
|
3468
|
-
code_status(c3);
|
|
3653
|
+
code_status(nkf_state, c3);
|
|
3469
3654
|
if (hold_index < hold_count){
|
|
3470
3655
|
c4 = hold_buf[hold_index++];
|
|
3471
|
-
} else if ((c4 = (*i_getc)(f)) == EOF) {
|
|
3656
|
+
} else if ((c4 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
3472
3657
|
c3 = ret = EOF;
|
|
3473
3658
|
break;
|
|
3474
3659
|
}
|
|
3475
|
-
code_status(c4);
|
|
3476
|
-
(*iconv)(c1, c2, (c3<<8)|c4);
|
|
3660
|
+
code_status(nkf_state, c4);
|
|
3661
|
+
(*iconv)(nkf_state, c1, c2, (c3<<8)|c4);
|
|
3477
3662
|
break;
|
|
3478
3663
|
case -3:
|
|
3479
3664
|
/* 4 bytes UTF-8 (check combining character) */
|
|
3480
3665
|
if (hold_index < hold_count){
|
|
3481
3666
|
c3 = hold_buf[hold_index++];
|
|
3482
3667
|
fromhold_count++;
|
|
3483
|
-
} else if ((c3 = (*i_getc)(f)) == EOF) {
|
|
3484
|
-
w_iconv_nocombine(c1, c2, 0);
|
|
3668
|
+
} else if ((c3 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
3669
|
+
w_iconv_nocombine(nkf_state, c1, c2, 0);
|
|
3485
3670
|
break;
|
|
3486
3671
|
}
|
|
3487
3672
|
if (hold_index < hold_count){
|
|
3488
3673
|
c4 = hold_buf[hold_index++];
|
|
3489
3674
|
fromhold_count++;
|
|
3490
|
-
} else if ((c4 = (*i_getc)(f)) == EOF) {
|
|
3491
|
-
w_iconv_nocombine(c1, c2, 0);
|
|
3675
|
+
} else if ((c4 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
3676
|
+
w_iconv_nocombine(nkf_state, c1, c2, 0);
|
|
3492
3677
|
if (fromhold_count <= 2)
|
|
3493
|
-
(*i_ungetc)(c3,f);
|
|
3678
|
+
(*i_ungetc)(nkf_state, c3,f);
|
|
3494
3679
|
else
|
|
3495
3680
|
hold_index--;
|
|
3496
3681
|
continue;
|
|
3497
3682
|
}
|
|
3498
|
-
if (w_iconv_combine(c1, c2, 0, c3, c4, 0)) {
|
|
3499
|
-
w_iconv_nocombine(c1, c2, 0);
|
|
3683
|
+
if (w_iconv_combine(nkf_state, c1, c2, 0, c3, c4, 0)) {
|
|
3684
|
+
w_iconv_nocombine(nkf_state, c1, c2, 0);
|
|
3500
3685
|
if (fromhold_count <= 2) {
|
|
3501
|
-
(*i_ungetc)(c4,f);
|
|
3502
|
-
(*i_ungetc)(c3,f);
|
|
3686
|
+
(*i_ungetc)(nkf_state, c4,f);
|
|
3687
|
+
(*i_ungetc)(nkf_state, c3,f);
|
|
3503
3688
|
} else if (fromhold_count == 3) {
|
|
3504
|
-
(*i_ungetc)(c4,f);
|
|
3689
|
+
(*i_ungetc)(nkf_state, c4,f);
|
|
3505
3690
|
hold_index--;
|
|
3506
3691
|
} else {
|
|
3507
3692
|
hold_index -= 2;
|
|
@@ -3513,64 +3698,64 @@ h_conv(FILE *f, nkf_char c1, nkf_char c2)
|
|
|
3513
3698
|
if (hold_index < hold_count){
|
|
3514
3699
|
c3 = hold_buf[hold_index++];
|
|
3515
3700
|
fromhold_count++;
|
|
3516
|
-
} else if ((c3 = (*i_getc)(f)) == EOF) {
|
|
3701
|
+
} else if ((c3 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
3517
3702
|
ret = EOF;
|
|
3518
3703
|
break;
|
|
3519
3704
|
} else {
|
|
3520
|
-
code_status(c3);
|
|
3705
|
+
code_status(nkf_state, c3);
|
|
3521
3706
|
}
|
|
3522
|
-
if ((*iconv)(c1, c2, c3) == -3) {
|
|
3707
|
+
if ((*iconv)(nkf_state, c1, c2, c3) == -3) {
|
|
3523
3708
|
/* 6 bytes UTF-8 (check combining character) */
|
|
3524
3709
|
nkf_char c5, c6;
|
|
3525
3710
|
if (hold_index < hold_count){
|
|
3526
3711
|
c4 = hold_buf[hold_index++];
|
|
3527
3712
|
fromhold_count++;
|
|
3528
|
-
} else if ((c4 = (*i_getc)(f)) == EOF) {
|
|
3529
|
-
w_iconv_nocombine(c1, c2, c3);
|
|
3713
|
+
} else if ((c4 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
3714
|
+
w_iconv_nocombine(nkf_state, c1, c2, c3);
|
|
3530
3715
|
continue;
|
|
3531
3716
|
}
|
|
3532
3717
|
if (hold_index < hold_count){
|
|
3533
3718
|
c5 = hold_buf[hold_index++];
|
|
3534
3719
|
fromhold_count++;
|
|
3535
|
-
} else if ((c5 = (*i_getc)(f)) == EOF) {
|
|
3536
|
-
w_iconv_nocombine(c1, c2, c3);
|
|
3720
|
+
} else if ((c5 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
3721
|
+
w_iconv_nocombine(nkf_state, c1, c2, c3);
|
|
3537
3722
|
if (fromhold_count == 4)
|
|
3538
3723
|
hold_index--;
|
|
3539
3724
|
else
|
|
3540
|
-
(*i_ungetc)(c4,f);
|
|
3725
|
+
(*i_ungetc)(nkf_state, c4,f);
|
|
3541
3726
|
continue;
|
|
3542
3727
|
}
|
|
3543
3728
|
if (hold_index < hold_count){
|
|
3544
3729
|
c6 = hold_buf[hold_index++];
|
|
3545
3730
|
fromhold_count++;
|
|
3546
|
-
} else if ((c6 = (*i_getc)(f)) == EOF) {
|
|
3547
|
-
w_iconv_nocombine(c1, c2, c3);
|
|
3731
|
+
} else if ((c6 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
3732
|
+
w_iconv_nocombine(nkf_state, c1, c2, c3);
|
|
3548
3733
|
if (fromhold_count == 5) {
|
|
3549
3734
|
hold_index -= 2;
|
|
3550
3735
|
} else if (fromhold_count == 4) {
|
|
3551
3736
|
hold_index--;
|
|
3552
|
-
(*i_ungetc)(c5,f);
|
|
3737
|
+
(*i_ungetc)(nkf_state, c5,f);
|
|
3553
3738
|
} else {
|
|
3554
|
-
(*i_ungetc)(c5,f);
|
|
3555
|
-
(*i_ungetc)(c4,f);
|
|
3739
|
+
(*i_ungetc)(nkf_state, c5,f);
|
|
3740
|
+
(*i_ungetc)(nkf_state, c4,f);
|
|
3556
3741
|
}
|
|
3557
3742
|
continue;
|
|
3558
3743
|
}
|
|
3559
|
-
if (w_iconv_combine(c1, c2, c3, c4, c5, c6)) {
|
|
3560
|
-
w_iconv_nocombine(c1, c2, c3);
|
|
3744
|
+
if (w_iconv_combine(nkf_state, c1, c2, c3, c4, c5, c6)) {
|
|
3745
|
+
w_iconv_nocombine(nkf_state, c1, c2, c3);
|
|
3561
3746
|
if (fromhold_count == 6) {
|
|
3562
3747
|
hold_index -= 3;
|
|
3563
3748
|
} else if (fromhold_count == 5) {
|
|
3564
3749
|
hold_index -= 2;
|
|
3565
|
-
(*i_ungetc)(c6,f);
|
|
3750
|
+
(*i_ungetc)(nkf_state, c6,f);
|
|
3566
3751
|
} else if (fromhold_count == 4) {
|
|
3567
3752
|
hold_index--;
|
|
3568
|
-
(*i_ungetc)(c6,f);
|
|
3569
|
-
(*i_ungetc)(c5,f);
|
|
3753
|
+
(*i_ungetc)(nkf_state, c6,f);
|
|
3754
|
+
(*i_ungetc)(nkf_state, c5,f);
|
|
3570
3755
|
} else {
|
|
3571
|
-
(*i_ungetc)(c6,f);
|
|
3572
|
-
(*i_ungetc)(c5,f);
|
|
3573
|
-
(*i_ungetc)(c4,f);
|
|
3756
|
+
(*i_ungetc)(nkf_state, c6,f);
|
|
3757
|
+
(*i_ungetc)(nkf_state, c5,f);
|
|
3758
|
+
(*i_ungetc)(nkf_state, c4,f);
|
|
3574
3759
|
}
|
|
3575
3760
|
}
|
|
3576
3761
|
}
|
|
@@ -3585,151 +3770,151 @@ h_conv(FILE *f, nkf_char c1, nkf_char c2)
|
|
|
3585
3770
|
* Check and Ignore BOM
|
|
3586
3771
|
*/
|
|
3587
3772
|
static void
|
|
3588
|
-
check_bom(FILE *f)
|
|
3773
|
+
check_bom(nkf_state_t *nkf_state, FILE *f)
|
|
3589
3774
|
{
|
|
3590
3775
|
int c2;
|
|
3591
3776
|
input_bom_f = FALSE;
|
|
3592
|
-
switch(c2 = (*i_getc)(f)){
|
|
3777
|
+
switch(c2 = (*i_getc)(nkf_state, f)){
|
|
3593
3778
|
case 0x00:
|
|
3594
|
-
if((c2 = (*i_getc)(f)) == 0x00){
|
|
3595
|
-
if((c2 = (*i_getc)(f)) == 0xFE){
|
|
3596
|
-
if((c2 = (*i_getc)(f)) == 0xFF){
|
|
3779
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0x00){
|
|
3780
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0xFE){
|
|
3781
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0xFF){
|
|
3597
3782
|
if(!input_encoding){
|
|
3598
|
-
set_iconv(TRUE, w_iconv32);
|
|
3783
|
+
set_iconv(nkf_state, TRUE, w_iconv32);
|
|
3599
3784
|
}
|
|
3600
3785
|
if (iconv == w_iconv32) {
|
|
3601
3786
|
input_bom_f = TRUE;
|
|
3602
3787
|
input_endian = ENDIAN_BIG;
|
|
3603
3788
|
return;
|
|
3604
3789
|
}
|
|
3605
|
-
(*i_ungetc)(0xFF,f);
|
|
3606
|
-
}else (*i_ungetc)(c2,f);
|
|
3607
|
-
(*i_ungetc)(0xFE,f);
|
|
3790
|
+
(*i_ungetc)(nkf_state, 0xFF,f);
|
|
3791
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3792
|
+
(*i_ungetc)(nkf_state, 0xFE,f);
|
|
3608
3793
|
}else if(c2 == 0xFF){
|
|
3609
|
-
if((c2 = (*i_getc)(f)) == 0xFE){
|
|
3794
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0xFE){
|
|
3610
3795
|
if(!input_encoding){
|
|
3611
|
-
set_iconv(TRUE, w_iconv32);
|
|
3796
|
+
set_iconv(nkf_state, TRUE, w_iconv32);
|
|
3612
3797
|
}
|
|
3613
3798
|
if (iconv == w_iconv32) {
|
|
3614
3799
|
input_endian = ENDIAN_2143;
|
|
3615
3800
|
return;
|
|
3616
3801
|
}
|
|
3617
|
-
(*i_ungetc)(0xFF,f);
|
|
3618
|
-
}else (*i_ungetc)(c2,f);
|
|
3619
|
-
(*i_ungetc)(0xFF,f);
|
|
3620
|
-
}else (*i_ungetc)(c2,f);
|
|
3621
|
-
(*i_ungetc)(0x00,f);
|
|
3622
|
-
}else (*i_ungetc)(c2,f);
|
|
3623
|
-
(*i_ungetc)(0x00,f);
|
|
3802
|
+
(*i_ungetc)(nkf_state, 0xFF,f);
|
|
3803
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3804
|
+
(*i_ungetc)(nkf_state, 0xFF,f);
|
|
3805
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3806
|
+
(*i_ungetc)(nkf_state, 0x00,f);
|
|
3807
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3808
|
+
(*i_ungetc)(nkf_state, 0x00,f);
|
|
3624
3809
|
break;
|
|
3625
3810
|
case 0xEF:
|
|
3626
|
-
if((c2 = (*i_getc)(f)) == 0xBB){
|
|
3627
|
-
if((c2 = (*i_getc)(f)) == 0xBF){
|
|
3811
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0xBB){
|
|
3812
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0xBF){
|
|
3628
3813
|
if(!input_encoding){
|
|
3629
|
-
set_iconv(TRUE, w_iconv);
|
|
3814
|
+
set_iconv(nkf_state, TRUE, w_iconv);
|
|
3630
3815
|
}
|
|
3631
3816
|
if (iconv == w_iconv) {
|
|
3632
3817
|
input_bom_f = TRUE;
|
|
3633
3818
|
return;
|
|
3634
3819
|
}
|
|
3635
|
-
(*i_ungetc)(0xBF,f);
|
|
3636
|
-
}else (*i_ungetc)(c2,f);
|
|
3637
|
-
(*i_ungetc)(0xBB,f);
|
|
3638
|
-
}else (*i_ungetc)(c2,f);
|
|
3639
|
-
(*i_ungetc)(0xEF,f);
|
|
3820
|
+
(*i_ungetc)(nkf_state, 0xBF,f);
|
|
3821
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3822
|
+
(*i_ungetc)(nkf_state, 0xBB,f);
|
|
3823
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3824
|
+
(*i_ungetc)(nkf_state, 0xEF,f);
|
|
3640
3825
|
break;
|
|
3641
3826
|
case 0xFE:
|
|
3642
|
-
if((c2 = (*i_getc)(f)) == 0xFF){
|
|
3643
|
-
if((c2 = (*i_getc)(f)) == 0x00){
|
|
3644
|
-
if((c2 = (*i_getc)(f)) == 0x00){
|
|
3827
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0xFF){
|
|
3828
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0x00){
|
|
3829
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0x00){
|
|
3645
3830
|
if(!input_encoding){
|
|
3646
|
-
set_iconv(TRUE, w_iconv32);
|
|
3831
|
+
set_iconv(nkf_state, TRUE, w_iconv32);
|
|
3647
3832
|
}
|
|
3648
3833
|
if (iconv == w_iconv32) {
|
|
3649
3834
|
input_endian = ENDIAN_3412;
|
|
3650
3835
|
return;
|
|
3651
3836
|
}
|
|
3652
|
-
(*i_ungetc)(0x00,f);
|
|
3653
|
-
}else (*i_ungetc)(c2,f);
|
|
3654
|
-
(*i_ungetc)(0x00,f);
|
|
3655
|
-
}else (*i_ungetc)(c2,f);
|
|
3837
|
+
(*i_ungetc)(nkf_state, 0x00,f);
|
|
3838
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3839
|
+
(*i_ungetc)(nkf_state, 0x00,f);
|
|
3840
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3656
3841
|
if(!input_encoding){
|
|
3657
|
-
set_iconv(TRUE, w_iconv16);
|
|
3842
|
+
set_iconv(nkf_state, TRUE, w_iconv16);
|
|
3658
3843
|
}
|
|
3659
3844
|
if (iconv == w_iconv16) {
|
|
3660
3845
|
input_endian = ENDIAN_BIG;
|
|
3661
3846
|
input_bom_f = TRUE;
|
|
3662
3847
|
return;
|
|
3663
3848
|
}
|
|
3664
|
-
(*i_ungetc)(0xFF,f);
|
|
3665
|
-
}else (*i_ungetc)(c2,f);
|
|
3666
|
-
(*i_ungetc)(0xFE,f);
|
|
3849
|
+
(*i_ungetc)(nkf_state, 0xFF,f);
|
|
3850
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3851
|
+
(*i_ungetc)(nkf_state, 0xFE,f);
|
|
3667
3852
|
break;
|
|
3668
3853
|
case 0xFF:
|
|
3669
|
-
if((c2 = (*i_getc)(f)) == 0xFE){
|
|
3670
|
-
if((c2 = (*i_getc)(f)) == 0x00){
|
|
3671
|
-
if((c2 = (*i_getc)(f)) == 0x00){
|
|
3854
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0xFE){
|
|
3855
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0x00){
|
|
3856
|
+
if((c2 = (*i_getc)(nkf_state, f)) == 0x00){
|
|
3672
3857
|
if(!input_encoding){
|
|
3673
|
-
set_iconv(TRUE, w_iconv32);
|
|
3858
|
+
set_iconv(nkf_state, TRUE, w_iconv32);
|
|
3674
3859
|
}
|
|
3675
3860
|
if (iconv == w_iconv32) {
|
|
3676
3861
|
input_endian = ENDIAN_LITTLE;
|
|
3677
3862
|
input_bom_f = TRUE;
|
|
3678
3863
|
return;
|
|
3679
3864
|
}
|
|
3680
|
-
(*i_ungetc)(0x00,f);
|
|
3681
|
-
}else (*i_ungetc)(c2,f);
|
|
3682
|
-
(*i_ungetc)(0x00,f);
|
|
3683
|
-
}else (*i_ungetc)(c2,f);
|
|
3865
|
+
(*i_ungetc)(nkf_state, 0x00,f);
|
|
3866
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3867
|
+
(*i_ungetc)(nkf_state, 0x00,f);
|
|
3868
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3684
3869
|
if(!input_encoding){
|
|
3685
|
-
set_iconv(TRUE, w_iconv16);
|
|
3870
|
+
set_iconv(nkf_state, TRUE, w_iconv16);
|
|
3686
3871
|
}
|
|
3687
3872
|
if (iconv == w_iconv16) {
|
|
3688
3873
|
input_endian = ENDIAN_LITTLE;
|
|
3689
3874
|
input_bom_f = TRUE;
|
|
3690
3875
|
return;
|
|
3691
3876
|
}
|
|
3692
|
-
(*i_ungetc)(0xFE,f);
|
|
3693
|
-
}else (*i_ungetc)(c2,f);
|
|
3694
|
-
(*i_ungetc)(0xFF,f);
|
|
3877
|
+
(*i_ungetc)(nkf_state, 0xFE,f);
|
|
3878
|
+
}else (*i_ungetc)(nkf_state, c2,f);
|
|
3879
|
+
(*i_ungetc)(nkf_state, 0xFF,f);
|
|
3695
3880
|
break;
|
|
3696
3881
|
default:
|
|
3697
|
-
(*i_ungetc)(c2,f);
|
|
3882
|
+
(*i_ungetc)(nkf_state, c2,f);
|
|
3698
3883
|
break;
|
|
3699
3884
|
}
|
|
3700
3885
|
}
|
|
3701
3886
|
|
|
3702
3887
|
static nkf_char
|
|
3703
|
-
broken_getc(FILE *f)
|
|
3888
|
+
broken_getc(nkf_state_t *nkf_state, FILE *f)
|
|
3704
3889
|
{
|
|
3705
3890
|
nkf_char c, c1;
|
|
3706
3891
|
|
|
3707
3892
|
if (!nkf_buf_empty_p(nkf_state->broken_buf)) {
|
|
3708
3893
|
return nkf_buf_pop(nkf_state->broken_buf);
|
|
3709
3894
|
}
|
|
3710
|
-
c = (*i_bgetc)(f);
|
|
3895
|
+
c = (*i_bgetc)(nkf_state, f);
|
|
3711
3896
|
if (c=='$' && nkf_state->broken_state != ESC
|
|
3712
3897
|
&& (input_mode == ASCII || input_mode == JIS_X_0201_1976_K)) {
|
|
3713
|
-
c1= (*i_bgetc)(f);
|
|
3898
|
+
c1= (*i_bgetc)(nkf_state, f);
|
|
3714
3899
|
nkf_state->broken_state = 0;
|
|
3715
3900
|
if (c1=='@'|| c1=='B') {
|
|
3716
3901
|
nkf_buf_push(nkf_state->broken_buf, c1);
|
|
3717
3902
|
nkf_buf_push(nkf_state->broken_buf, c);
|
|
3718
3903
|
return ESC;
|
|
3719
3904
|
} else {
|
|
3720
|
-
(*i_bungetc)(c1,f);
|
|
3905
|
+
(*i_bungetc)(nkf_state, c1,f);
|
|
3721
3906
|
return c;
|
|
3722
3907
|
}
|
|
3723
3908
|
} else if (c=='(' && nkf_state->broken_state != ESC
|
|
3724
3909
|
&& (input_mode == JIS_X_0208 || input_mode == JIS_X_0201_1976_K)) {
|
|
3725
|
-
c1= (*i_bgetc)(f);
|
|
3910
|
+
c1= (*i_bgetc)(nkf_state, f);
|
|
3726
3911
|
nkf_state->broken_state = 0;
|
|
3727
3912
|
if (c1=='J'|| c1=='B') {
|
|
3728
3913
|
nkf_buf_push(nkf_state->broken_buf, c1);
|
|
3729
3914
|
nkf_buf_push(nkf_state->broken_buf, c);
|
|
3730
3915
|
return ESC;
|
|
3731
3916
|
} else {
|
|
3732
|
-
(*i_bungetc)(c1,f);
|
|
3917
|
+
(*i_bungetc)(nkf_state, c1,f);
|
|
3733
3918
|
return c;
|
|
3734
3919
|
}
|
|
3735
3920
|
} else {
|
|
@@ -3739,7 +3924,7 @@ broken_getc(FILE *f)
|
|
|
3739
3924
|
}
|
|
3740
3925
|
|
|
3741
3926
|
static nkf_char
|
|
3742
|
-
broken_ungetc(nkf_char c, ARG_UNUSED FILE *f)
|
|
3927
|
+
broken_ungetc(nkf_state_t *nkf_state, nkf_char c, ARG_UNUSED FILE *f)
|
|
3743
3928
|
{
|
|
3744
3929
|
if (nkf_buf_length(nkf_state->broken_buf) < 2)
|
|
3745
3930
|
nkf_buf_push(nkf_state->broken_buf, c);
|
|
@@ -3747,7 +3932,7 @@ broken_ungetc(nkf_char c, ARG_UNUSED FILE *f)
|
|
|
3747
3932
|
}
|
|
3748
3933
|
|
|
3749
3934
|
static void
|
|
3750
|
-
eol_conv(nkf_char c2, nkf_char c1)
|
|
3935
|
+
eol_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
3751
3936
|
{
|
|
3752
3937
|
if (guess_f && input_eol != EOF) {
|
|
3753
3938
|
if (c2 == 0 && c1 == LF) {
|
|
@@ -3760,43 +3945,43 @@ eol_conv(nkf_char c2, nkf_char c1)
|
|
|
3760
3945
|
}
|
|
3761
3946
|
if (prev_cr || (c2 == 0 && c1 == LF)) {
|
|
3762
3947
|
prev_cr = 0;
|
|
3763
|
-
if (eolmode_f != LF) (*o_eol_conv)(0, CR);
|
|
3764
|
-
if (eolmode_f != CR) (*o_eol_conv)(0, LF);
|
|
3948
|
+
if (eolmode_f != LF) (*o_eol_conv)(nkf_state, 0, CR);
|
|
3949
|
+
if (eolmode_f != CR) (*o_eol_conv)(nkf_state, 0, LF);
|
|
3765
3950
|
}
|
|
3766
3951
|
if (c2 == 0 && c1 == CR) prev_cr = CR;
|
|
3767
|
-
else if (c2 != 0 || c1 != LF) (*o_eol_conv)(c2, c1);
|
|
3952
|
+
else if (c2 != 0 || c1 != LF) (*o_eol_conv)(nkf_state, c2, c1);
|
|
3768
3953
|
}
|
|
3769
3954
|
|
|
3770
3955
|
static void
|
|
3771
|
-
put_newline(void (*func)(nkf_char))
|
|
3956
|
+
put_newline(nkf_state_t *nkf_state, void (*func)(nkf_state_t *nkf_state, nkf_char))
|
|
3772
3957
|
{
|
|
3773
3958
|
switch (eolmode_f ? eolmode_f : DEFAULT_NEWLINE) {
|
|
3774
3959
|
case CRLF:
|
|
3775
|
-
(*func)(0x0D);
|
|
3776
|
-
(*func)(0x0A);
|
|
3960
|
+
(*func)(nkf_state, 0x0D);
|
|
3961
|
+
(*func)(nkf_state, 0x0A);
|
|
3777
3962
|
break;
|
|
3778
3963
|
case CR:
|
|
3779
|
-
(*func)(0x0D);
|
|
3964
|
+
(*func)(nkf_state, 0x0D);
|
|
3780
3965
|
break;
|
|
3781
3966
|
case LF:
|
|
3782
|
-
(*func)(0x0A);
|
|
3967
|
+
(*func)(nkf_state, 0x0A);
|
|
3783
3968
|
break;
|
|
3784
3969
|
}
|
|
3785
3970
|
}
|
|
3786
3971
|
|
|
3787
3972
|
static void
|
|
3788
|
-
oconv_newline(void (*func)(nkf_char, nkf_char))
|
|
3973
|
+
oconv_newline(nkf_state_t *nkf_state, void (*func)(nkf_state_t *nkf_state, nkf_char, nkf_char))
|
|
3789
3974
|
{
|
|
3790
3975
|
switch (eolmode_f ? eolmode_f : DEFAULT_NEWLINE) {
|
|
3791
3976
|
case CRLF:
|
|
3792
|
-
(*func)(0, 0x0D);
|
|
3793
|
-
(*func)(0, 0x0A);
|
|
3977
|
+
(*func)(nkf_state, 0, 0x0D);
|
|
3978
|
+
(*func)(nkf_state, 0, 0x0A);
|
|
3794
3979
|
break;
|
|
3795
3980
|
case CR:
|
|
3796
|
-
(*func)(0, 0x0D);
|
|
3981
|
+
(*func)(nkf_state, 0, 0x0D);
|
|
3797
3982
|
break;
|
|
3798
3983
|
case LF:
|
|
3799
|
-
(*func)(0, 0x0A);
|
|
3984
|
+
(*func)(nkf_state, 0, 0x0A);
|
|
3800
3985
|
break;
|
|
3801
3986
|
}
|
|
3802
3987
|
}
|
|
@@ -3824,7 +4009,7 @@ oconv_newline(void (*func)(nkf_char, nkf_char))
|
|
|
3824
4009
|
#define char_size(c2,c1) (c2?2:1)
|
|
3825
4010
|
|
|
3826
4011
|
static void
|
|
3827
|
-
fold_conv(nkf_char c2, nkf_char c1)
|
|
4012
|
+
fold_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
3828
4013
|
{
|
|
3829
4014
|
nkf_char prev0;
|
|
3830
4015
|
nkf_char fold_state;
|
|
@@ -3973,33 +4158,31 @@ fold_conv(nkf_char c2, nkf_char c1)
|
|
|
3973
4158
|
/* terminator process */
|
|
3974
4159
|
switch(fold_state) {
|
|
3975
4160
|
case LF:
|
|
3976
|
-
oconv_newline(o_fconv);
|
|
3977
|
-
(*o_fconv)(c2,c1);
|
|
4161
|
+
oconv_newline(nkf_state, o_fconv);
|
|
4162
|
+
(*o_fconv)(nkf_state, c2,c1);
|
|
3978
4163
|
break;
|
|
3979
4164
|
case 0:
|
|
3980
4165
|
return;
|
|
3981
4166
|
case CR:
|
|
3982
|
-
oconv_newline(o_fconv);
|
|
4167
|
+
oconv_newline(nkf_state, o_fconv);
|
|
3983
4168
|
break;
|
|
3984
4169
|
case TAB:
|
|
3985
4170
|
case SP:
|
|
3986
|
-
(*o_fconv)(0,SP);
|
|
4171
|
+
(*o_fconv)(nkf_state, 0,SP);
|
|
3987
4172
|
break;
|
|
3988
4173
|
default:
|
|
3989
|
-
(*o_fconv)(c2,c1);
|
|
4174
|
+
(*o_fconv)(nkf_state, c2,c1);
|
|
3990
4175
|
}
|
|
3991
4176
|
}
|
|
3992
4177
|
|
|
3993
|
-
static nkf_char z_prev2=0,z_prev1=0;
|
|
3994
|
-
|
|
3995
4178
|
static void
|
|
3996
|
-
z_conv(nkf_char c2, nkf_char c1)
|
|
4179
|
+
z_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
3997
4180
|
{
|
|
3998
4181
|
|
|
3999
4182
|
/* if (c2) c1 &= 0x7f; assertion */
|
|
4000
4183
|
|
|
4001
4184
|
if (c2 == JIS_X_0201_1976_K && (c1 == 0x20 || c1 == 0x7D || c1 == 0x7E)) {
|
|
4002
|
-
(*o_zconv)(c2,c1);
|
|
4185
|
+
(*o_zconv)(nkf_state, c2,c1);
|
|
4003
4186
|
return;
|
|
4004
4187
|
}
|
|
4005
4188
|
|
|
@@ -4008,20 +4191,20 @@ z_conv(nkf_char c2, nkf_char c1)
|
|
|
4008
4191
|
if (c2 == JIS_X_0201_1976_K) {
|
|
4009
4192
|
if (c1 == (0xde&0x7f)) { /* $BByE@(B */
|
|
4010
4193
|
z_prev2 = 0;
|
|
4011
|
-
(*o_zconv)(dv[(z_prev1-SP)*2], dv[(z_prev1-SP)*2+1]);
|
|
4194
|
+
(*o_zconv)(nkf_state, dv[(z_prev1-SP)*2], dv[(z_prev1-SP)*2+1]);
|
|
4012
4195
|
return;
|
|
4013
4196
|
} else if (c1 == (0xdf&0x7f) && ev[(z_prev1-SP)*2]) { /* $BH>ByE@(B */
|
|
4014
4197
|
z_prev2 = 0;
|
|
4015
|
-
(*o_zconv)(ev[(z_prev1-SP)*2], ev[(z_prev1-SP)*2+1]);
|
|
4198
|
+
(*o_zconv)(nkf_state, ev[(z_prev1-SP)*2], ev[(z_prev1-SP)*2+1]);
|
|
4016
4199
|
return;
|
|
4017
4200
|
} else if (x0213_f && c1 == (0xdf&0x7f) && ev_x0213[(z_prev1-SP)*2]) { /* $BH>ByE@(B */
|
|
4018
4201
|
z_prev2 = 0;
|
|
4019
|
-
(*o_zconv)(ev_x0213[(z_prev1-SP)*2], ev_x0213[(z_prev1-SP)*2+1]);
|
|
4202
|
+
(*o_zconv)(nkf_state, ev_x0213[(z_prev1-SP)*2], ev_x0213[(z_prev1-SP)*2+1]);
|
|
4020
4203
|
return;
|
|
4021
4204
|
}
|
|
4022
4205
|
}
|
|
4023
4206
|
z_prev2 = 0;
|
|
4024
|
-
(*o_zconv)(cv[(z_prev1-SP)*2], cv[(z_prev1-SP)*2+1]);
|
|
4207
|
+
(*o_zconv)(nkf_state, cv[(z_prev1-SP)*2], cv[(z_prev1-SP)*2+1]);
|
|
4025
4208
|
}
|
|
4026
4209
|
if (c2 == JIS_X_0201_1976_K) {
|
|
4027
4210
|
if (dv[(c1-SP)*2] || ev[(c1-SP)*2] || (x0213_f && ev_x0213[(c1-SP)*2])) {
|
|
@@ -4030,14 +4213,14 @@ z_conv(nkf_char c2, nkf_char c1)
|
|
|
4030
4213
|
z_prev2 = c2;
|
|
4031
4214
|
return;
|
|
4032
4215
|
} else {
|
|
4033
|
-
(*o_zconv)(cv[(c1-SP)*2], cv[(c1-SP)*2+1]);
|
|
4216
|
+
(*o_zconv)(nkf_state, cv[(c1-SP)*2], cv[(c1-SP)*2+1]);
|
|
4034
4217
|
return;
|
|
4035
4218
|
}
|
|
4036
4219
|
}
|
|
4037
4220
|
}
|
|
4038
4221
|
|
|
4039
4222
|
if (c2 == EOF) {
|
|
4040
|
-
(*o_zconv)(c2, c1);
|
|
4223
|
+
(*o_zconv)(nkf_state, c2, c1);
|
|
4041
4224
|
return;
|
|
4042
4225
|
}
|
|
4043
4226
|
|
|
@@ -4051,8 +4234,8 @@ z_conv(nkf_char c2, nkf_char c1)
|
|
|
4051
4234
|
c2 = 0;
|
|
4052
4235
|
c1 = SP;
|
|
4053
4236
|
} else if (alpha_f&4) {
|
|
4054
|
-
(*o_zconv)(0, SP);
|
|
4055
|
-
(*o_zconv)(0, SP);
|
|
4237
|
+
(*o_zconv)(nkf_state, 0, SP);
|
|
4238
|
+
(*o_zconv)(nkf_state, 0, SP);
|
|
4056
4239
|
return;
|
|
4057
4240
|
}
|
|
4058
4241
|
} else if (alpha_f&1 && 0x20<c1 && c1<0x7f && fv[c1-0x20]) {
|
|
@@ -4071,7 +4254,7 @@ z_conv(nkf_char c2, nkf_char c1)
|
|
|
4071
4254
|
case '&': entity = "&"; break;
|
|
4072
4255
|
}
|
|
4073
4256
|
if (entity){
|
|
4074
|
-
while (*entity) (*o_zconv)(0, *entity++);
|
|
4257
|
+
while (*entity) (*o_zconv)(nkf_state, 0, *entity++);
|
|
4075
4258
|
return;
|
|
4076
4259
|
}
|
|
4077
4260
|
}
|
|
@@ -4115,7 +4298,7 @@ z_conv(nkf_char c2, nkf_char c1)
|
|
|
4115
4298
|
break;
|
|
4116
4299
|
}
|
|
4117
4300
|
if (c) {
|
|
4118
|
-
(*o_zconv)(JIS_X_0201_1976_K, c);
|
|
4301
|
+
(*o_zconv)(nkf_state, JIS_X_0201_1976_K, c);
|
|
4119
4302
|
return;
|
|
4120
4303
|
}
|
|
4121
4304
|
} else if (c2 == 0x25) {
|
|
@@ -4137,19 +4320,19 @@ z_conv(nkf_char c2, nkf_char c1)
|
|
|
4137
4320
|
};
|
|
4138
4321
|
if (fullwidth_to_halfwidth[c1-0x20]){
|
|
4139
4322
|
c2 = fullwidth_to_halfwidth[c1-0x20];
|
|
4140
|
-
(*o_zconv)(JIS_X_0201_1976_K, c2>>8);
|
|
4323
|
+
(*o_zconv)(nkf_state, JIS_X_0201_1976_K, c2>>8);
|
|
4141
4324
|
if (c2 & 0xFF) {
|
|
4142
|
-
(*o_zconv)(JIS_X_0201_1976_K, c2&0xFF);
|
|
4325
|
+
(*o_zconv)(nkf_state, JIS_X_0201_1976_K, c2&0xFF);
|
|
4143
4326
|
}
|
|
4144
4327
|
return;
|
|
4145
4328
|
}
|
|
4146
4329
|
} else if (c2 == 0 && nkf_char_unicode_p(c1) &&
|
|
4147
4330
|
((c1&VALUE_MASK) == 0x3099 || (c1&VALUE_MASK) == 0x309A)) { /* $B9g@.MQByE@!&H>ByE@(B */
|
|
4148
|
-
(*o_zconv)(JIS_X_0201_1976_K, 0x5E + (c1&VALUE_MASK) - 0x3099);
|
|
4331
|
+
(*o_zconv)(nkf_state, JIS_X_0201_1976_K, 0x5E + (c1&VALUE_MASK) - 0x3099);
|
|
4149
4332
|
return;
|
|
4150
4333
|
}
|
|
4151
4334
|
}
|
|
4152
|
-
(*o_zconv)(c2,c1);
|
|
4335
|
+
(*o_zconv)(nkf_state, c2,c1);
|
|
4153
4336
|
}
|
|
4154
4337
|
|
|
4155
4338
|
|
|
@@ -4171,7 +4354,7 @@ z_conv(nkf_char c2, nkf_char c1)
|
|
|
4171
4354
|
)
|
|
4172
4355
|
|
|
4173
4356
|
static void
|
|
4174
|
-
rot_conv(nkf_char c2, nkf_char c1)
|
|
4357
|
+
rot_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
4175
4358
|
{
|
|
4176
4359
|
if (c2 == 0 || c2 == JIS_X_0201_1976_K || c2 == ISO_8859_1) {
|
|
4177
4360
|
c1 = rot13(c1);
|
|
@@ -4179,27 +4362,27 @@ rot_conv(nkf_char c2, nkf_char c1)
|
|
|
4179
4362
|
c1 = rot47(c1);
|
|
4180
4363
|
c2 = rot47(c2);
|
|
4181
4364
|
}
|
|
4182
|
-
(*o_rot_conv)(c2,c1);
|
|
4365
|
+
(*o_rot_conv)(nkf_state, c2,c1);
|
|
4183
4366
|
}
|
|
4184
4367
|
|
|
4185
4368
|
static void
|
|
4186
|
-
hira_conv(nkf_char c2, nkf_char c1)
|
|
4369
|
+
hira_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
4187
4370
|
{
|
|
4188
4371
|
if (hira_f & 1) {
|
|
4189
4372
|
if (c2 == 0x25) {
|
|
4190
4373
|
if (0x20 < c1 && c1 < 0x74) {
|
|
4191
4374
|
c2 = 0x24;
|
|
4192
|
-
(*o_hira_conv)(c2,c1);
|
|
4375
|
+
(*o_hira_conv)(nkf_state, c2,c1);
|
|
4193
4376
|
return;
|
|
4194
4377
|
} else if (c1 == 0x74 && nkf_enc_unicode_p(output_encoding)) {
|
|
4195
4378
|
c2 = 0;
|
|
4196
4379
|
c1 = nkf_char_unicode_new(0x3094);
|
|
4197
|
-
(*o_hira_conv)(c2,c1);
|
|
4380
|
+
(*o_hira_conv)(nkf_state, c2,c1);
|
|
4198
4381
|
return;
|
|
4199
4382
|
}
|
|
4200
4383
|
} else if (c2 == 0x21 && (c1 == 0x33 || c1 == 0x34)) {
|
|
4201
4384
|
c1 += 2;
|
|
4202
|
-
(*o_hira_conv)(c2,c1);
|
|
4385
|
+
(*o_hira_conv)(nkf_state, c2,c1);
|
|
4203
4386
|
return;
|
|
4204
4387
|
}
|
|
4205
4388
|
}
|
|
@@ -4213,12 +4396,12 @@ hira_conv(nkf_char c2, nkf_char c1)
|
|
|
4213
4396
|
c1 -= 2;
|
|
4214
4397
|
}
|
|
4215
4398
|
}
|
|
4216
|
-
(*o_hira_conv)(c2,c1);
|
|
4399
|
+
(*o_hira_conv)(nkf_state, c2,c1);
|
|
4217
4400
|
}
|
|
4218
4401
|
|
|
4219
4402
|
|
|
4220
4403
|
static void
|
|
4221
|
-
iso2022jp_check_conv(nkf_char c2, nkf_char c1)
|
|
4404
|
+
iso2022jp_check_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
4222
4405
|
{
|
|
4223
4406
|
#define RANGE_NUM_MAX 18
|
|
4224
4407
|
static const nkf_char range[RANGE_NUM_MAX][2] = {
|
|
@@ -4262,13 +4445,13 @@ iso2022jp_check_conv(nkf_char c2, nkf_char c1)
|
|
|
4262
4445
|
c1 = GETA2;
|
|
4263
4446
|
}
|
|
4264
4447
|
}
|
|
4265
|
-
(*o_iso2022jp_check_conv)(c2,c1);
|
|
4448
|
+
(*o_iso2022jp_check_conv)(nkf_state, c2,c1);
|
|
4266
4449
|
}
|
|
4267
4450
|
|
|
4268
4451
|
|
|
4269
4452
|
/* This converts =?ISO-2022-JP?B?HOGE HOGE?= */
|
|
4270
4453
|
|
|
4271
|
-
static const unsigned char *mime_pattern[] = {
|
|
4454
|
+
static const unsigned char *const mime_pattern[] = {
|
|
4272
4455
|
(const unsigned char *)"\075?EUC-JP?B?",
|
|
4273
4456
|
(const unsigned char *)"\075?SHIFT_JIS?B?",
|
|
4274
4457
|
(const unsigned char *)"\075?ISO-8859-1?Q?",
|
|
@@ -4286,7 +4469,7 @@ static const unsigned char *mime_pattern[] = {
|
|
|
4286
4469
|
|
|
4287
4470
|
|
|
4288
4471
|
/* $B3:Ev$9$k%3!<%I$NM%@hEY$r>e$2$k$?$a$NL\0u(B */
|
|
4289
|
-
static nkf_char (*const mime_priority_func[])(nkf_char c2, nkf_char c1, nkf_char c0) = {
|
|
4472
|
+
static nkf_char (*const mime_priority_func[])(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1, nkf_char c0) = {
|
|
4290
4473
|
e_iconv, s_iconv, 0, 0, 0, 0, 0,
|
|
4291
4474
|
#if defined(UTF8_INPUT_ENABLE)
|
|
4292
4475
|
w_iconv, w_iconv,
|
|
@@ -4315,53 +4498,44 @@ static const nkf_char mime_encode_method[] = {
|
|
|
4315
4498
|
|
|
4316
4499
|
/* MIME preprocessor fifo */
|
|
4317
4500
|
|
|
4318
|
-
#define MIME_BUF_SIZE (1024) /* 2^n ring buffer */
|
|
4319
|
-
#define MIME_BUF_MASK (MIME_BUF_SIZE-1)
|
|
4320
4501
|
#define mime_input_buf(n) mime_input_state.buf[(n)&MIME_BUF_MASK]
|
|
4321
|
-
static struct {
|
|
4322
|
-
unsigned char buf[MIME_BUF_SIZE];
|
|
4323
|
-
unsigned int top;
|
|
4324
|
-
unsigned int last; /* decoded */
|
|
4325
|
-
unsigned int input; /* undecoded */
|
|
4326
|
-
} mime_input_state;
|
|
4327
|
-
static nkf_char (*mime_iconv_back)(nkf_char c2,nkf_char c1,nkf_char c0) = NULL;
|
|
4328
4502
|
|
|
4329
4503
|
#define MAXRECOVER 20
|
|
4330
4504
|
|
|
4331
4505
|
static void
|
|
4332
|
-
mime_input_buf_unshift(nkf_char c)
|
|
4506
|
+
mime_input_buf_unshift(nkf_state_t *nkf_state, nkf_char c)
|
|
4333
4507
|
{
|
|
4334
4508
|
mime_input_buf(--mime_input_state.top) = (unsigned char)c;
|
|
4335
4509
|
}
|
|
4336
4510
|
|
|
4337
4511
|
static nkf_char
|
|
4338
|
-
mime_ungetc(nkf_char c, ARG_UNUSED FILE *f)
|
|
4512
|
+
mime_ungetc(nkf_state_t *nkf_state, nkf_char c, ARG_UNUSED FILE *f)
|
|
4339
4513
|
{
|
|
4340
|
-
mime_input_buf_unshift(c);
|
|
4514
|
+
mime_input_buf_unshift(nkf_state, c);
|
|
4341
4515
|
return c;
|
|
4342
4516
|
}
|
|
4343
4517
|
|
|
4344
4518
|
static nkf_char
|
|
4345
|
-
mime_ungetc_buf(nkf_char c, FILE *f)
|
|
4519
|
+
mime_ungetc_buf(nkf_state_t *nkf_state, nkf_char c, FILE *f)
|
|
4346
4520
|
{
|
|
4347
4521
|
if (mimebuf_f)
|
|
4348
|
-
(*i_mungetc_buf)(c,f);
|
|
4522
|
+
(*i_mungetc_buf)(nkf_state, c,f);
|
|
4349
4523
|
else
|
|
4350
4524
|
mime_input_buf(--mime_input_state.input) = (unsigned char)c;
|
|
4351
4525
|
return c;
|
|
4352
4526
|
}
|
|
4353
4527
|
|
|
4354
4528
|
static nkf_char
|
|
4355
|
-
mime_getc_buf(FILE *f)
|
|
4529
|
+
mime_getc_buf(nkf_state_t *nkf_state, FILE *f)
|
|
4356
4530
|
{
|
|
4357
4531
|
/* we don't keep eof of mime_input_buf, because it contains ?= as
|
|
4358
4532
|
a terminator. It was checked in mime_integrity. */
|
|
4359
4533
|
return ((mimebuf_f)?
|
|
4360
|
-
(*i_mgetc_buf)(f):mime_input_buf(mime_input_state.input++));
|
|
4534
|
+
(*i_mgetc_buf)(nkf_state, f):mime_input_buf(mime_input_state.input++));
|
|
4361
4535
|
}
|
|
4362
4536
|
|
|
4363
4537
|
static void
|
|
4364
|
-
switch_mime_getc(
|
|
4538
|
+
switch_mime_getc(nkf_state_t *nkf_state)
|
|
4365
4539
|
{
|
|
4366
4540
|
if (i_getc!=mime_getc) {
|
|
4367
4541
|
i_mgetc = i_getc; i_getc = mime_getc;
|
|
@@ -4374,7 +4548,7 @@ switch_mime_getc(void)
|
|
|
4374
4548
|
}
|
|
4375
4549
|
|
|
4376
4550
|
static void
|
|
4377
|
-
unswitch_mime_getc(
|
|
4551
|
+
unswitch_mime_getc(nkf_state_t *nkf_state)
|
|
4378
4552
|
{
|
|
4379
4553
|
if(mime_f==STRICT_MIME) {
|
|
4380
4554
|
i_mgetc = i_mgetc_buf;
|
|
@@ -4382,12 +4556,12 @@ unswitch_mime_getc(void)
|
|
|
4382
4556
|
}
|
|
4383
4557
|
i_getc = i_mgetc;
|
|
4384
4558
|
i_ungetc = i_mungetc;
|
|
4385
|
-
if(mime_iconv_back)set_iconv(FALSE, mime_iconv_back);
|
|
4559
|
+
if(mime_iconv_back)set_iconv(nkf_state, FALSE, mime_iconv_back);
|
|
4386
4560
|
mime_iconv_back = NULL;
|
|
4387
4561
|
}
|
|
4388
4562
|
|
|
4389
4563
|
static nkf_char
|
|
4390
|
-
mime_integrity(FILE *f, const unsigned char *p)
|
|
4564
|
+
mime_integrity(nkf_state_t *nkf_state, FILE *f, const unsigned char *p)
|
|
4391
4565
|
{
|
|
4392
4566
|
nkf_char c,d;
|
|
4393
4567
|
unsigned int q;
|
|
@@ -4399,7 +4573,7 @@ mime_integrity(FILE *f, const unsigned char *p)
|
|
|
4399
4573
|
while(*p) mime_input_buf(mime_input_state.input++) = *p++;
|
|
4400
4574
|
d = 0;
|
|
4401
4575
|
q = mime_input_state.input;
|
|
4402
|
-
while((c=(*i_getc)(f))!=EOF) {
|
|
4576
|
+
while((c=(*i_getc)(nkf_state, f))!=EOF) {
|
|
4403
4577
|
if (((mime_input_state.input-mime_input_state.top)&MIME_BUF_MASK)==0) {
|
|
4404
4578
|
break; /* buffer full */
|
|
4405
4579
|
}
|
|
@@ -4408,7 +4582,7 @@ mime_integrity(FILE *f, const unsigned char *p)
|
|
|
4408
4582
|
mime_input_buf(mime_input_state.input++) = (unsigned char)c;
|
|
4409
4583
|
/* mime_last_input = mime_input_state.input; */
|
|
4410
4584
|
mime_input_state.input = q;
|
|
4411
|
-
switch_mime_getc();
|
|
4585
|
+
switch_mime_getc(nkf_state);
|
|
4412
4586
|
return 1;
|
|
4413
4587
|
}
|
|
4414
4588
|
if (!( (c=='+'||c=='/'|| c=='=' || c=='?' || is_alnum(c))))
|
|
@@ -4421,12 +4595,12 @@ mime_integrity(FILE *f, const unsigned char *p)
|
|
|
4421
4595
|
mime_input_buf(mime_input_state.input++) = (unsigned char)c;
|
|
4422
4596
|
mime_input_state.last = mime_input_state.input; /* point undecoded buffer */
|
|
4423
4597
|
mime_decode_mode = 1; /* no decode on mime_input_buf last in mime_getc */
|
|
4424
|
-
switch_mime_getc(); /* anyway we need buffered getc */
|
|
4598
|
+
switch_mime_getc(nkf_state); /* anyway we need buffered getc */
|
|
4425
4599
|
return 1;
|
|
4426
4600
|
}
|
|
4427
4601
|
|
|
4428
4602
|
static nkf_char
|
|
4429
|
-
mime_begin_strict(FILE *f)
|
|
4603
|
+
mime_begin_strict(nkf_state_t *nkf_state, FILE *f)
|
|
4430
4604
|
{
|
|
4431
4605
|
nkf_char c1 = 0;
|
|
4432
4606
|
int i,j,k;
|
|
@@ -4440,7 +4614,7 @@ mime_begin_strict(FILE *f)
|
|
|
4440
4614
|
r[0]='='; r[1]='?';
|
|
4441
4615
|
|
|
4442
4616
|
for(i=2;p[i]>SP;i++) { /* start at =? */
|
|
4443
|
-
if (((r[i] = c1 = (*i_getc)(f))==EOF) || nkf_toupper(c1) != p[i]) {
|
|
4617
|
+
if (((r[i] = c1 = (*i_getc)(nkf_state, f))==EOF) || nkf_toupper(c1) != p[i]) {
|
|
4444
4618
|
/* pattern fails, try next one */
|
|
4445
4619
|
q = p;
|
|
4446
4620
|
while (mime_pattern[++j]) {
|
|
@@ -4452,9 +4626,9 @@ mime_begin_strict(FILE *f)
|
|
|
4452
4626
|
p = mime_pattern[j];
|
|
4453
4627
|
if (p) continue; /* found next one, continue */
|
|
4454
4628
|
/* all fails, output from recovery buffer */
|
|
4455
|
-
(*i_ungetc)(c1,f);
|
|
4629
|
+
(*i_ungetc)(nkf_state, c1,f);
|
|
4456
4630
|
for(j=0;j<i;j++) {
|
|
4457
|
-
(*oconv)(0,r[j]);
|
|
4631
|
+
(*oconv)(nkf_state, 0,r[j]);
|
|
4458
4632
|
}
|
|
4459
4633
|
return c1;
|
|
4460
4634
|
}
|
|
@@ -4462,23 +4636,23 @@ mime_begin_strict(FILE *f)
|
|
|
4462
4636
|
mime_decode_mode = p[i-2];
|
|
4463
4637
|
|
|
4464
4638
|
mime_iconv_back = iconv;
|
|
4465
|
-
set_iconv(FALSE, mime_priority_func[j]);
|
|
4466
|
-
clr_code_score(find_inputcode_byfunc(mime_priority_func[j]), SCORE_iMIME);
|
|
4639
|
+
set_iconv(nkf_state, FALSE, mime_priority_func[j]);
|
|
4640
|
+
clr_code_score(nkf_state, find_inputcode_byfunc(nkf_state, mime_priority_func[j]), SCORE_iMIME);
|
|
4467
4641
|
|
|
4468
4642
|
if (mime_decode_mode=='B') {
|
|
4469
4643
|
mimebuf_f = unbuf_f;
|
|
4470
4644
|
if (!unbuf_f) {
|
|
4471
4645
|
/* do MIME integrity check */
|
|
4472
|
-
return mime_integrity(f,mime_pattern[j]);
|
|
4646
|
+
return mime_integrity(nkf_state, f,mime_pattern[j]);
|
|
4473
4647
|
}
|
|
4474
4648
|
}
|
|
4475
|
-
switch_mime_getc();
|
|
4649
|
+
switch_mime_getc(nkf_state);
|
|
4476
4650
|
mimebuf_f = TRUE;
|
|
4477
4651
|
return c1;
|
|
4478
4652
|
}
|
|
4479
4653
|
|
|
4480
4654
|
static nkf_char
|
|
4481
|
-
mime_begin(FILE *f)
|
|
4655
|
+
mime_begin(nkf_state_t *nkf_state, FILE *f)
|
|
4482
4656
|
{
|
|
4483
4657
|
nkf_char c1 = 0;
|
|
4484
4658
|
int i,k;
|
|
@@ -4491,19 +4665,19 @@ mime_begin(FILE *f)
|
|
|
4491
4665
|
mime_input_buf(mime_input_state.last++)='='; mime_input_buf(mime_input_state.last++)='?';
|
|
4492
4666
|
for(i=2;i<MAXRECOVER;i++) { /* start at =? */
|
|
4493
4667
|
/* We accept any character type even if it is breaked by new lines */
|
|
4494
|
-
c1 = (*i_getc)(f); mime_input_buf(mime_input_state.last++) = (unsigned char)c1;
|
|
4668
|
+
c1 = (*i_getc)(nkf_state, f); mime_input_buf(mime_input_state.last++) = (unsigned char)c1;
|
|
4495
4669
|
if (c1==LF||c1==SP||c1==CR||
|
|
4496
4670
|
c1=='-'||c1=='_'||is_alnum(c1)) continue;
|
|
4497
4671
|
if (c1=='=') {
|
|
4498
4672
|
/* Failed. But this could be another MIME preemble */
|
|
4499
|
-
(*i_ungetc)(c1,f);
|
|
4673
|
+
(*i_ungetc)(nkf_state, c1,f);
|
|
4500
4674
|
mime_input_state.last--;
|
|
4501
4675
|
break;
|
|
4502
4676
|
}
|
|
4503
4677
|
if (c1!='?') break;
|
|
4504
4678
|
else {
|
|
4505
4679
|
/* c1=='?' */
|
|
4506
|
-
c1 = (*i_getc)(f); mime_input_buf(mime_input_state.last++) = (unsigned char)c1;
|
|
4680
|
+
c1 = (*i_getc)(nkf_state, f); mime_input_buf(mime_input_state.last++) = (unsigned char)c1;
|
|
4507
4681
|
if (!(++i<MAXRECOVER) || c1==EOF) break;
|
|
4508
4682
|
if (c1=='b'||c1=='B') {
|
|
4509
4683
|
mime_decode_mode = 'B';
|
|
@@ -4512,7 +4686,7 @@ mime_begin(FILE *f)
|
|
|
4512
4686
|
} else {
|
|
4513
4687
|
break;
|
|
4514
4688
|
}
|
|
4515
|
-
c1 = (*i_getc)(f); mime_input_buf(mime_input_state.last++) = (unsigned char)c1;
|
|
4689
|
+
c1 = (*i_getc)(nkf_state, f); mime_input_buf(mime_input_state.last++) = (unsigned char)c1;
|
|
4516
4690
|
if (!(++i<MAXRECOVER) || c1==EOF) break;
|
|
4517
4691
|
if (c1!='?') {
|
|
4518
4692
|
mime_decode_mode = FALSE;
|
|
@@ -4520,7 +4694,7 @@ mime_begin(FILE *f)
|
|
|
4520
4694
|
break;
|
|
4521
4695
|
}
|
|
4522
4696
|
}
|
|
4523
|
-
switch_mime_getc();
|
|
4697
|
+
switch_mime_getc(nkf_state);
|
|
4524
4698
|
if (!mime_decode_mode) {
|
|
4525
4699
|
/* false MIME premble, restart from mime_buffer */
|
|
4526
4700
|
mime_decode_mode = 1; /* no decode, but read from the mime_buffer */
|
|
@@ -4536,13 +4710,13 @@ mime_begin(FILE *f)
|
|
|
4536
4710
|
|
|
4537
4711
|
#ifdef CHECK_OPTION
|
|
4538
4712
|
static void
|
|
4539
|
-
no_putc(ARG_UNUSED nkf_char c)
|
|
4713
|
+
no_putc(ARG_UNUSED nkf_state_t *nkf_state, ARG_UNUSED nkf_char c)
|
|
4540
4714
|
{
|
|
4541
4715
|
;
|
|
4542
4716
|
}
|
|
4543
4717
|
|
|
4544
4718
|
static void
|
|
4545
|
-
debug(const char *str)
|
|
4719
|
+
debug(nkf_state_t *nkf_state, const char *str)
|
|
4546
4720
|
{
|
|
4547
4721
|
if (debug_f){
|
|
4548
4722
|
fprintf(stderr, "%s\n", str ? str : "NULL");
|
|
@@ -4551,7 +4725,7 @@ debug(const char *str)
|
|
|
4551
4725
|
#endif
|
|
4552
4726
|
|
|
4553
4727
|
static void
|
|
4554
|
-
set_input_codename(const char *codename)
|
|
4728
|
+
set_input_codename(nkf_state_t *nkf_state, const char *codename)
|
|
4555
4729
|
{
|
|
4556
4730
|
if (!input_codename) {
|
|
4557
4731
|
input_codename = codename;
|
|
@@ -4561,12 +4735,12 @@ set_input_codename(const char *codename)
|
|
|
4561
4735
|
}
|
|
4562
4736
|
|
|
4563
4737
|
static const char*
|
|
4564
|
-
get_guessed_code(
|
|
4738
|
+
get_guessed_code(nkf_state_t *nkf_state)
|
|
4565
4739
|
{
|
|
4566
4740
|
if (input_codename && !*input_codename) {
|
|
4567
4741
|
input_codename = "BINARY";
|
|
4568
4742
|
} else {
|
|
4569
|
-
struct input_code *p = find_inputcode_byfunc(iconv);
|
|
4743
|
+
struct input_code *p = find_inputcode_byfunc(nkf_state, iconv);
|
|
4570
4744
|
if (!input_codename) {
|
|
4571
4745
|
input_codename = "ASCII";
|
|
4572
4746
|
} else if (strcmp(input_codename, "Shift_JIS") == 0) {
|
|
@@ -4591,13 +4765,13 @@ get_guessed_code(void)
|
|
|
4591
4765
|
|
|
4592
4766
|
#if !defined(PERL_XS) && !defined(WIN32DLL)
|
|
4593
4767
|
static void
|
|
4594
|
-
print_guessed_code(char *filename)
|
|
4768
|
+
print_guessed_code(nkf_state_t *nkf_state, char *filename)
|
|
4595
4769
|
{
|
|
4596
4770
|
if (filename != NULL) printf("%s: ", filename);
|
|
4597
4771
|
if (input_codename && !*input_codename) {
|
|
4598
4772
|
printf("BINARY\n");
|
|
4599
4773
|
} else {
|
|
4600
|
-
input_codename = get_guessed_code();
|
|
4774
|
+
input_codename = get_guessed_code(nkf_state);
|
|
4601
4775
|
if (guess_f == 1) {
|
|
4602
4776
|
printf("%s\n", input_codename);
|
|
4603
4777
|
} else {
|
|
@@ -4621,71 +4795,71 @@ print_guessed_code(char *filename)
|
|
|
4621
4795
|
#ifdef INPUT_OPTION
|
|
4622
4796
|
|
|
4623
4797
|
static nkf_char
|
|
4624
|
-
hex_getc(nkf_char ch, FILE *f, nkf_char (*g)(FILE *f), nkf_char (*u)(nkf_char c, FILE *f))
|
|
4798
|
+
hex_getc(nkf_state_t *nkf_state, nkf_char ch, FILE *f, nkf_char (*g)(nkf_state_t *nkf_state, FILE *f), nkf_char (*u)(nkf_state_t *nkf_state, nkf_char c, FILE *f))
|
|
4625
4799
|
{
|
|
4626
4800
|
nkf_char c1, c2, c3;
|
|
4627
|
-
c1 = (*g)(f);
|
|
4801
|
+
c1 = (*g)(nkf_state, f);
|
|
4628
4802
|
if (c1 != ch){
|
|
4629
4803
|
return c1;
|
|
4630
4804
|
}
|
|
4631
|
-
c2 = (*g)(f);
|
|
4805
|
+
c2 = (*g)(nkf_state, f);
|
|
4632
4806
|
if (!nkf_isxdigit(c2)){
|
|
4633
|
-
(*u)(c2, f);
|
|
4807
|
+
(*u)(nkf_state, c2, f);
|
|
4634
4808
|
return c1;
|
|
4635
4809
|
}
|
|
4636
|
-
c3 = (*g)(f);
|
|
4810
|
+
c3 = (*g)(nkf_state, f);
|
|
4637
4811
|
if (!nkf_isxdigit(c3)){
|
|
4638
|
-
(*u)(c2, f);
|
|
4639
|
-
(*u)(c3, f);
|
|
4812
|
+
(*u)(nkf_state, c2, f);
|
|
4813
|
+
(*u)(nkf_state, c3, f);
|
|
4640
4814
|
return c1;
|
|
4641
4815
|
}
|
|
4642
4816
|
return (hex2bin(c2) << 4) | hex2bin(c3);
|
|
4643
4817
|
}
|
|
4644
4818
|
|
|
4645
4819
|
static nkf_char
|
|
4646
|
-
cap_getc(FILE *f)
|
|
4820
|
+
cap_getc(nkf_state_t *nkf_state, FILE *f)
|
|
4647
4821
|
{
|
|
4648
|
-
return hex_getc(':', f, i_cgetc, i_cungetc);
|
|
4822
|
+
return hex_getc(nkf_state, ':', f, i_cgetc, i_cungetc);
|
|
4649
4823
|
}
|
|
4650
4824
|
|
|
4651
4825
|
static nkf_char
|
|
4652
|
-
cap_ungetc(nkf_char c, FILE *f)
|
|
4826
|
+
cap_ungetc(nkf_state_t *nkf_state, nkf_char c, FILE *f)
|
|
4653
4827
|
{
|
|
4654
|
-
return (*i_cungetc)(c, f);
|
|
4828
|
+
return (*i_cungetc)(nkf_state, c, f);
|
|
4655
4829
|
}
|
|
4656
4830
|
|
|
4657
4831
|
static nkf_char
|
|
4658
|
-
url_getc(FILE *f)
|
|
4832
|
+
url_getc(nkf_state_t *nkf_state, FILE *f)
|
|
4659
4833
|
{
|
|
4660
|
-
return hex_getc('%', f, i_ugetc, i_uungetc);
|
|
4834
|
+
return hex_getc(nkf_state, '%', f, i_ugetc, i_uungetc);
|
|
4661
4835
|
}
|
|
4662
4836
|
|
|
4663
4837
|
static nkf_char
|
|
4664
|
-
url_ungetc(nkf_char c, FILE *f)
|
|
4838
|
+
url_ungetc(nkf_state_t *nkf_state, nkf_char c, FILE *f)
|
|
4665
4839
|
{
|
|
4666
|
-
return (*i_uungetc)(c, f);
|
|
4840
|
+
return (*i_uungetc)(nkf_state, c, f);
|
|
4667
4841
|
}
|
|
4668
4842
|
#endif
|
|
4669
4843
|
|
|
4670
4844
|
#ifdef NUMCHAR_OPTION
|
|
4671
4845
|
static nkf_char
|
|
4672
|
-
numchar_getc(FILE *f)
|
|
4846
|
+
numchar_getc(nkf_state_t *nkf_state, FILE *f)
|
|
4673
4847
|
{
|
|
4674
|
-
nkf_char (*g)(FILE *) = i_ngetc;
|
|
4675
|
-
nkf_char (*u)(nkf_char c ,FILE *f) = i_nungetc;
|
|
4848
|
+
nkf_char (*g)(nkf_state_t *nkf_state, FILE *) = i_ngetc;
|
|
4849
|
+
nkf_char (*u)(nkf_state_t *nkf_state, nkf_char c ,FILE *f) = i_nungetc;
|
|
4676
4850
|
int i = 0, j;
|
|
4677
4851
|
nkf_char buf[12];
|
|
4678
4852
|
nkf_char c = -1;
|
|
4679
4853
|
|
|
4680
|
-
buf[i] = (*g)(f);
|
|
4854
|
+
buf[i] = (*g)(nkf_state, f);
|
|
4681
4855
|
if (buf[i] == '&'){
|
|
4682
|
-
buf[++i] = (*g)(f);
|
|
4856
|
+
buf[++i] = (*g)(nkf_state, f);
|
|
4683
4857
|
if (buf[i] == '#'){
|
|
4684
4858
|
c = 0;
|
|
4685
|
-
buf[++i] = (*g)(f);
|
|
4859
|
+
buf[++i] = (*g)(nkf_state, f);
|
|
4686
4860
|
if (buf[i] == 'x' || buf[i] == 'X'){
|
|
4687
4861
|
for (j = 0; j < 7; j++){
|
|
4688
|
-
buf[++i] = (*g)(f);
|
|
4862
|
+
buf[++i] = (*g)(nkf_state, f);
|
|
4689
4863
|
if (!nkf_isxdigit(buf[i])){
|
|
4690
4864
|
if (buf[i] != ';'){
|
|
4691
4865
|
c = -1;
|
|
@@ -4698,7 +4872,7 @@ numchar_getc(FILE *f)
|
|
|
4698
4872
|
}else{
|
|
4699
4873
|
for (j = 0; j < 8; j++){
|
|
4700
4874
|
if (j){
|
|
4701
|
-
buf[++i] = (*g)(f);
|
|
4875
|
+
buf[++i] = (*g)(nkf_state, f);
|
|
4702
4876
|
}
|
|
4703
4877
|
if (!nkf_isdigit(buf[i])){
|
|
4704
4878
|
if (buf[i] != ';'){
|
|
@@ -4716,30 +4890,30 @@ numchar_getc(FILE *f)
|
|
|
4716
4890
|
return nkf_char_unicode_new(c);
|
|
4717
4891
|
}
|
|
4718
4892
|
while (i > 0){
|
|
4719
|
-
(*u)(buf[i], f);
|
|
4893
|
+
(*u)(nkf_state, buf[i], f);
|
|
4720
4894
|
--i;
|
|
4721
4895
|
}
|
|
4722
4896
|
return buf[0];
|
|
4723
4897
|
}
|
|
4724
4898
|
|
|
4725
4899
|
static nkf_char
|
|
4726
|
-
numchar_ungetc(nkf_char c, FILE *f)
|
|
4900
|
+
numchar_ungetc(nkf_state_t *nkf_state, nkf_char c, FILE *f)
|
|
4727
4901
|
{
|
|
4728
|
-
return (*i_nungetc)(c, f);
|
|
4902
|
+
return (*i_nungetc)(nkf_state, c, f);
|
|
4729
4903
|
}
|
|
4730
4904
|
#endif
|
|
4731
4905
|
|
|
4732
4906
|
#ifdef UNICODE_NORMALIZATION
|
|
4733
4907
|
|
|
4734
4908
|
static nkf_char
|
|
4735
|
-
nfc_getc(FILE *f)
|
|
4909
|
+
nfc_getc(nkf_state_t *nkf_state, FILE *f)
|
|
4736
4910
|
{
|
|
4737
|
-
nkf_char (*g)(FILE *f) = i_nfc_getc;
|
|
4738
|
-
nkf_char (*u)(nkf_char c ,FILE *f) = i_nfc_ungetc;
|
|
4911
|
+
nkf_char (*g)(nkf_state_t *nkf_state, FILE *f) = i_nfc_getc;
|
|
4912
|
+
nkf_char (*u)(nkf_state_t *nkf_state, nkf_char c ,FILE *f) = i_nfc_ungetc;
|
|
4739
4913
|
nkf_buf_t *buf = nkf_state->nfc_buf;
|
|
4740
4914
|
const unsigned char *array;
|
|
4741
4915
|
int lower=0, upper=NORMALIZATION_TABLE_LENGTH-1;
|
|
4742
|
-
nkf_char c = (*g)(f);
|
|
4916
|
+
nkf_char c = (*g)(nkf_state, f);
|
|
4743
4917
|
|
|
4744
4918
|
if (c == EOF || c > 0xFF || (c & 0xc0) == 0x80) return c;
|
|
4745
4919
|
|
|
@@ -4751,7 +4925,7 @@ nfc_getc(FILE *f)
|
|
|
4751
4925
|
array = normalization_table[mid].nfd;
|
|
4752
4926
|
for (len=0; len < NORMALIZATION_TABLE_NFD_LENGTH && array[len]; len++) {
|
|
4753
4927
|
if (len >= nkf_buf_length(buf)) {
|
|
4754
|
-
c = (*g)(f);
|
|
4928
|
+
c = (*g)(nkf_state, f);
|
|
4755
4929
|
if (c == EOF) {
|
|
4756
4930
|
len = 0;
|
|
4757
4931
|
lower = 1, upper = 0;
|
|
@@ -4777,16 +4951,16 @@ nfc_getc(FILE *f)
|
|
|
4777
4951
|
}
|
|
4778
4952
|
} while (lower <= upper);
|
|
4779
4953
|
|
|
4780
|
-
while (nkf_buf_length(buf) > 1) (*u)(nkf_buf_pop(buf), f);
|
|
4954
|
+
while (nkf_buf_length(buf) > 1) (*u)(nkf_state, nkf_buf_pop(buf), f);
|
|
4781
4955
|
c = nkf_buf_pop(buf);
|
|
4782
4956
|
|
|
4783
4957
|
return c;
|
|
4784
4958
|
}
|
|
4785
4959
|
|
|
4786
4960
|
static nkf_char
|
|
4787
|
-
nfc_ungetc(nkf_char c, FILE *f)
|
|
4961
|
+
nfc_ungetc(nkf_state_t *nkf_state, nkf_char c, FILE *f)
|
|
4788
4962
|
{
|
|
4789
|
-
return (*i_nfc_ungetc)(c, f);
|
|
4963
|
+
return (*i_nfc_ungetc)(nkf_state, c, f);
|
|
4790
4964
|
}
|
|
4791
4965
|
#endif /* UNICODE_NORMALIZATION */
|
|
4792
4966
|
|
|
@@ -4814,7 +4988,7 @@ base64decode(nkf_char c)
|
|
|
4814
4988
|
}
|
|
4815
4989
|
|
|
4816
4990
|
static nkf_char
|
|
4817
|
-
mime_getc(FILE *f)
|
|
4991
|
+
mime_getc(nkf_state_t *nkf_state, FILE *f)
|
|
4818
4992
|
{
|
|
4819
4993
|
nkf_char c1, c2, c3, c4, cc;
|
|
4820
4994
|
nkf_char t1, t2, t3, t4, mode, exit_mode;
|
|
@@ -4828,8 +5002,8 @@ mime_getc(FILE *f)
|
|
|
4828
5002
|
}
|
|
4829
5003
|
if (mime_decode_mode==1 ||mime_decode_mode==FALSE) {
|
|
4830
5004
|
mime_decode_mode=FALSE;
|
|
4831
|
-
unswitch_mime_getc();
|
|
4832
|
-
return (*i_getc)(f);
|
|
5005
|
+
unswitch_mime_getc(nkf_state);
|
|
5006
|
+
return (*i_getc)(nkf_state, f);
|
|
4833
5007
|
}
|
|
4834
5008
|
|
|
4835
5009
|
if (mimebuf_f == FIXED_MIME)
|
|
@@ -4837,7 +5011,7 @@ mime_getc(FILE *f)
|
|
|
4837
5011
|
else
|
|
4838
5012
|
exit_mode = FALSE;
|
|
4839
5013
|
if (mime_decode_mode == 'Q') {
|
|
4840
|
-
if ((c1 = (*i_mgetc)(f)) == EOF) return (EOF);
|
|
5014
|
+
if ((c1 = (*i_mgetc)(nkf_state, f)) == EOF) return (EOF);
|
|
4841
5015
|
restart_mime_q:
|
|
4842
5016
|
if (c1=='_' && mimebuf_f != FIXED_MIME) return SP;
|
|
4843
5017
|
if (c1<=SP || DEL<=c1) {
|
|
@@ -4849,35 +5023,35 @@ mime_getc(FILE *f)
|
|
|
4849
5023
|
}
|
|
4850
5024
|
|
|
4851
5025
|
mime_decode_mode = exit_mode; /* prepare for quit */
|
|
4852
|
-
if ((c2 = (*i_mgetc)(f)) == EOF) return (EOF);
|
|
5026
|
+
if ((c2 = (*i_mgetc)(nkf_state, f)) == EOF) return (EOF);
|
|
4853
5027
|
if (c1=='?'&&c2=='=' && mimebuf_f != FIXED_MIME) {
|
|
4854
5028
|
/* end Q encoding */
|
|
4855
5029
|
input_mode = exit_mode;
|
|
4856
5030
|
lwsp_count = 0;
|
|
4857
5031
|
lwsp_buf = nkf_xmalloc((lwsp_size+5)*sizeof(char));
|
|
4858
|
-
while ((c1=(*i_getc)(f))!=EOF) {
|
|
5032
|
+
while ((c1=(*i_getc)(nkf_state, f))!=EOF) {
|
|
4859
5033
|
switch (c1) {
|
|
4860
5034
|
case LF:
|
|
4861
5035
|
case CR:
|
|
4862
5036
|
if (c1==LF) {
|
|
4863
|
-
if ((c1=(*i_getc)(f))!=EOF && nkf_isblank(c1)) {
|
|
4864
|
-
i_ungetc(SP,f);
|
|
5037
|
+
if ((c1=(*i_getc)(nkf_state, f))!=EOF && nkf_isblank(c1)) {
|
|
5038
|
+
i_ungetc(nkf_state, SP,f);
|
|
4865
5039
|
continue;
|
|
4866
5040
|
} else {
|
|
4867
|
-
i_ungetc(c1,f);
|
|
5041
|
+
i_ungetc(nkf_state, c1,f);
|
|
4868
5042
|
}
|
|
4869
5043
|
c1 = LF;
|
|
4870
5044
|
} else {
|
|
4871
|
-
if ((c1=(*i_getc)(f))!=EOF && c1 == LF) {
|
|
4872
|
-
if ((c1=(*i_getc)(f))!=EOF && nkf_isblank(c1)) {
|
|
4873
|
-
i_ungetc(SP,f);
|
|
5045
|
+
if ((c1=(*i_getc)(nkf_state, f))!=EOF && c1 == LF) {
|
|
5046
|
+
if ((c1=(*i_getc)(nkf_state, f))!=EOF && nkf_isblank(c1)) {
|
|
5047
|
+
i_ungetc(nkf_state, SP,f);
|
|
4874
5048
|
continue;
|
|
4875
5049
|
} else {
|
|
4876
|
-
i_ungetc(c1,f);
|
|
5050
|
+
i_ungetc(nkf_state, c1,f);
|
|
4877
5051
|
}
|
|
4878
|
-
i_ungetc(LF,f);
|
|
5052
|
+
i_ungetc(nkf_state, LF,f);
|
|
4879
5053
|
} else {
|
|
4880
|
-
i_ungetc(c1,f);
|
|
5054
|
+
i_ungetc(nkf_state, c1,f);
|
|
4881
5055
|
}
|
|
4882
5056
|
c1 = CR;
|
|
4883
5057
|
}
|
|
@@ -4895,16 +5069,16 @@ mime_getc(FILE *f)
|
|
|
4895
5069
|
break;
|
|
4896
5070
|
}
|
|
4897
5071
|
if (lwsp_count > 0 && (c1 != '=' || (lwsp_buf[lwsp_count-1] != SP && lwsp_buf[lwsp_count-1] != TAB))) {
|
|
4898
|
-
i_ungetc(c1,f);
|
|
5072
|
+
i_ungetc(nkf_state, c1,f);
|
|
4899
5073
|
for(lwsp_count--;lwsp_count>0;lwsp_count--)
|
|
4900
|
-
i_ungetc(lwsp_buf[lwsp_count],f);
|
|
5074
|
+
i_ungetc(nkf_state, lwsp_buf[lwsp_count],f);
|
|
4901
5075
|
c1 = lwsp_buf[0];
|
|
4902
5076
|
}
|
|
4903
5077
|
nkf_xfree(lwsp_buf);
|
|
4904
5078
|
return c1;
|
|
4905
5079
|
}
|
|
4906
5080
|
if (c1=='='&&c2<SP) { /* this is soft wrap */
|
|
4907
|
-
while((c1 = (*i_mgetc)(f)) <=SP) {
|
|
5081
|
+
while((c1 = (*i_mgetc)(nkf_state, f)) <=SP) {
|
|
4908
5082
|
if (c1 == EOF) return (EOF);
|
|
4909
5083
|
}
|
|
4910
5084
|
mime_decode_mode = 'Q'; /* still in MIME */
|
|
@@ -4912,10 +5086,10 @@ mime_getc(FILE *f)
|
|
|
4912
5086
|
}
|
|
4913
5087
|
if (c1=='?') {
|
|
4914
5088
|
mime_decode_mode = 'Q'; /* still in MIME */
|
|
4915
|
-
(*i_mungetc)(c2,f);
|
|
5089
|
+
(*i_mungetc)(nkf_state, c2,f);
|
|
4916
5090
|
return c1;
|
|
4917
5091
|
}
|
|
4918
|
-
if ((c3 = (*i_mgetc)(f)) == EOF) return (EOF);
|
|
5092
|
+
if ((c3 = (*i_mgetc)(nkf_state, f)) == EOF) return (EOF);
|
|
4919
5093
|
if (c2<=SP) return c2;
|
|
4920
5094
|
mime_decode_mode = 'Q'; /* still in MIME */
|
|
4921
5095
|
return ((hex2bin(c2)<<4) + hex2bin(c3));
|
|
@@ -4923,7 +5097,7 @@ mime_getc(FILE *f)
|
|
|
4923
5097
|
|
|
4924
5098
|
if (mime_decode_mode != 'B') {
|
|
4925
5099
|
mime_decode_mode = FALSE;
|
|
4926
|
-
return (*i_mgetc)(f);
|
|
5100
|
+
return (*i_mgetc)(nkf_state, f);
|
|
4927
5101
|
}
|
|
4928
5102
|
|
|
4929
5103
|
|
|
@@ -4938,12 +5112,12 @@ mime_getc(FILE *f)
|
|
|
4938
5112
|
mode = mime_decode_mode;
|
|
4939
5113
|
mime_decode_mode = exit_mode; /* prepare for quit */
|
|
4940
5114
|
|
|
4941
|
-
while ((c1 = (*i_mgetc)(f))<=SP) {
|
|
5115
|
+
while ((c1 = (*i_mgetc)(nkf_state, f))<=SP) {
|
|
4942
5116
|
if (c1==EOF)
|
|
4943
5117
|
return (EOF);
|
|
4944
5118
|
}
|
|
4945
5119
|
mime_c2_retry:
|
|
4946
|
-
if ((c2 = (*i_mgetc)(f))<=SP) {
|
|
5120
|
+
if ((c2 = (*i_mgetc)(nkf_state, f))<=SP) {
|
|
4947
5121
|
if (c2==EOF)
|
|
4948
5122
|
return (EOF);
|
|
4949
5123
|
if (mime_f != STRICT_MIME) goto mime_c2_retry;
|
|
@@ -4954,32 +5128,32 @@ mime_getc(FILE *f)
|
|
|
4954
5128
|
input_mode = ASCII;
|
|
4955
5129
|
lwsp_count = 0;
|
|
4956
5130
|
lwsp_buf = nkf_xmalloc((lwsp_size+5)*sizeof(char));
|
|
4957
|
-
while ((c1=(*i_getc)(f))!=EOF) {
|
|
5131
|
+
while ((c1=(*i_getc)(nkf_state, f))!=EOF) {
|
|
4958
5132
|
switch (c1) {
|
|
4959
5133
|
case LF:
|
|
4960
5134
|
case CR:
|
|
4961
5135
|
if (c1==LF) {
|
|
4962
|
-
if ((c1=(*i_getc)(f))!=EOF && nkf_isblank(c1)) {
|
|
4963
|
-
i_ungetc(SP,f);
|
|
5136
|
+
if ((c1=(*i_getc)(nkf_state, f))!=EOF && nkf_isblank(c1)) {
|
|
5137
|
+
i_ungetc(nkf_state, SP,f);
|
|
4964
5138
|
continue;
|
|
4965
5139
|
} else {
|
|
4966
|
-
i_ungetc(c1,f);
|
|
5140
|
+
i_ungetc(nkf_state, c1,f);
|
|
4967
5141
|
}
|
|
4968
5142
|
c1 = LF;
|
|
4969
5143
|
} else {
|
|
4970
|
-
if ((c1=(*i_getc)(f))!=EOF) {
|
|
5144
|
+
if ((c1=(*i_getc)(nkf_state, f))!=EOF) {
|
|
4971
5145
|
if (c1==SP) {
|
|
4972
|
-
i_ungetc(SP,f);
|
|
5146
|
+
i_ungetc(nkf_state, SP,f);
|
|
4973
5147
|
continue;
|
|
4974
|
-
} else if ((c1=(*i_getc)(f))!=EOF && nkf_isblank(c1)) {
|
|
4975
|
-
i_ungetc(SP,f);
|
|
5148
|
+
} else if ((c1=(*i_getc)(nkf_state, f))!=EOF && nkf_isblank(c1)) {
|
|
5149
|
+
i_ungetc(nkf_state, SP,f);
|
|
4976
5150
|
continue;
|
|
4977
5151
|
} else {
|
|
4978
|
-
i_ungetc(c1,f);
|
|
5152
|
+
i_ungetc(nkf_state, c1,f);
|
|
4979
5153
|
}
|
|
4980
|
-
i_ungetc(LF,f);
|
|
5154
|
+
i_ungetc(nkf_state, LF,f);
|
|
4981
5155
|
} else {
|
|
4982
|
-
i_ungetc(c1,f);
|
|
5156
|
+
i_ungetc(nkf_state, c1,f);
|
|
4983
5157
|
}
|
|
4984
5158
|
c1 = CR;
|
|
4985
5159
|
}
|
|
@@ -4997,16 +5171,16 @@ mime_getc(FILE *f)
|
|
|
4997
5171
|
break;
|
|
4998
5172
|
}
|
|
4999
5173
|
if (lwsp_count > 0 && (c1 != '=' || (lwsp_buf[lwsp_count-1] != SP && lwsp_buf[lwsp_count-1] != TAB))) {
|
|
5000
|
-
i_ungetc(c1,f);
|
|
5174
|
+
i_ungetc(nkf_state, c1,f);
|
|
5001
5175
|
for(lwsp_count--;lwsp_count>0;lwsp_count--)
|
|
5002
|
-
i_ungetc(lwsp_buf[lwsp_count],f);
|
|
5176
|
+
i_ungetc(nkf_state, lwsp_buf[lwsp_count],f);
|
|
5003
5177
|
c1 = lwsp_buf[0];
|
|
5004
5178
|
}
|
|
5005
5179
|
nkf_xfree(lwsp_buf);
|
|
5006
5180
|
return c1;
|
|
5007
5181
|
}
|
|
5008
5182
|
mime_c3_retry:
|
|
5009
|
-
if ((c3 = (*i_mgetc)(f))<=SP) {
|
|
5183
|
+
if ((c3 = (*i_mgetc)(nkf_state, f))<=SP) {
|
|
5010
5184
|
if (c3==EOF)
|
|
5011
5185
|
return (EOF);
|
|
5012
5186
|
if (mime_f != STRICT_MIME) goto mime_c3_retry;
|
|
@@ -5014,7 +5188,7 @@ mime_getc(FILE *f)
|
|
|
5014
5188
|
return c3;
|
|
5015
5189
|
}
|
|
5016
5190
|
mime_c4_retry:
|
|
5017
|
-
if ((c4 = (*i_mgetc)(f))<=SP) {
|
|
5191
|
+
if ((c4 = (*i_mgetc)(nkf_state, f))<=SP) {
|
|
5018
5192
|
if (c4==EOF)
|
|
5019
5193
|
return (EOF);
|
|
5020
5194
|
if (mime_f != STRICT_MIME) goto mime_c4_retry;
|
|
@@ -5049,16 +5223,10 @@ mime_getc(FILE *f)
|
|
|
5049
5223
|
static const char basis_64[] =
|
|
5050
5224
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
5051
5225
|
|
|
5052
|
-
#define MIMEOUT_BUF_LENGTH 74
|
|
5053
|
-
static struct {
|
|
5054
|
-
unsigned char buf[MIMEOUT_BUF_LENGTH+1];
|
|
5055
|
-
int count;
|
|
5056
|
-
} mimeout_state;
|
|
5057
|
-
|
|
5058
5226
|
/*nkf_char mime_lastchar2, mime_lastchar1;*/
|
|
5059
5227
|
|
|
5060
5228
|
static void
|
|
5061
|
-
open_mime(nkf_char mode)
|
|
5229
|
+
open_mime(nkf_state_t *nkf_state, nkf_char mode)
|
|
5062
5230
|
{
|
|
5063
5231
|
const unsigned char *p;
|
|
5064
5232
|
int i;
|
|
@@ -5074,11 +5242,11 @@ open_mime(nkf_char mode)
|
|
|
5074
5242
|
i = 0;
|
|
5075
5243
|
if (base64_count>45) {
|
|
5076
5244
|
if (mimeout_state.count>0 && nkf_isblank(mimeout_state.buf[i])){
|
|
5077
|
-
(*o_mputc)(mimeout_state.buf[i]);
|
|
5245
|
+
(*o_mputc)(nkf_state, mimeout_state.buf[i]);
|
|
5078
5246
|
i++;
|
|
5079
5247
|
}
|
|
5080
|
-
put_newline(o_mputc);
|
|
5081
|
-
(*o_mputc)(SP);
|
|
5248
|
+
put_newline(nkf_state, o_mputc);
|
|
5249
|
+
(*o_mputc)(nkf_state, SP);
|
|
5082
5250
|
base64_count = 1;
|
|
5083
5251
|
if (mimeout_state.count>0 && nkf_isspace(mimeout_state.buf[i])) {
|
|
5084
5252
|
i++;
|
|
@@ -5086,39 +5254,39 @@ open_mime(nkf_char mode)
|
|
|
5086
5254
|
}
|
|
5087
5255
|
for (;i<mimeout_state.count;i++) {
|
|
5088
5256
|
if (nkf_isspace(mimeout_state.buf[i])) {
|
|
5089
|
-
(*o_mputc)(mimeout_state.buf[i]);
|
|
5257
|
+
(*o_mputc)(nkf_state, mimeout_state.buf[i]);
|
|
5090
5258
|
base64_count ++;
|
|
5091
5259
|
} else {
|
|
5092
5260
|
break;
|
|
5093
5261
|
}
|
|
5094
5262
|
}
|
|
5095
5263
|
while(*p) {
|
|
5096
|
-
(*o_mputc)(*p++);
|
|
5264
|
+
(*o_mputc)(nkf_state, *p++);
|
|
5097
5265
|
base64_count ++;
|
|
5098
5266
|
}
|
|
5099
5267
|
j = mimeout_state.count;
|
|
5100
5268
|
mimeout_state.count = 0;
|
|
5101
5269
|
for (;i<j;i++) {
|
|
5102
|
-
mime_putc(mimeout_state.buf[i]);
|
|
5270
|
+
mime_putc(nkf_state, mimeout_state.buf[i]);
|
|
5103
5271
|
}
|
|
5104
5272
|
}
|
|
5105
5273
|
|
|
5106
5274
|
static void
|
|
5107
|
-
mime_prechar(nkf_char c2, nkf_char c1)
|
|
5275
|
+
mime_prechar(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
5108
5276
|
{
|
|
5109
5277
|
if (mimeout_mode > 0){
|
|
5110
5278
|
if (c2 == EOF){
|
|
5111
5279
|
if (base64_count + mimeout_state.count/3*4> 73){
|
|
5112
|
-
(*o_base64conv)(EOF,0);
|
|
5113
|
-
oconv_newline(o_base64conv);
|
|
5114
|
-
(*o_base64conv)(0,SP);
|
|
5280
|
+
(*o_base64conv)(nkf_state, EOF,0);
|
|
5281
|
+
oconv_newline(nkf_state, o_base64conv);
|
|
5282
|
+
(*o_base64conv)(nkf_state, 0,SP);
|
|
5115
5283
|
base64_count = 1;
|
|
5116
5284
|
}
|
|
5117
5285
|
} else {
|
|
5118
5286
|
if ((c2 != 0 || c1 > DEL) && base64_count + mimeout_state.count/3*4> 66) {
|
|
5119
|
-
(*o_base64conv)(EOF,0);
|
|
5120
|
-
oconv_newline(o_base64conv);
|
|
5121
|
-
(*o_base64conv)(0,SP);
|
|
5287
|
+
(*o_base64conv)(nkf_state, EOF,0);
|
|
5288
|
+
oconv_newline(nkf_state, o_base64conv);
|
|
5289
|
+
(*o_base64conv)(nkf_state, 0,SP);
|
|
5122
5290
|
base64_count = 1;
|
|
5123
5291
|
mimeout_mode = -1;
|
|
5124
5292
|
}
|
|
@@ -5126,10 +5294,10 @@ mime_prechar(nkf_char c2, nkf_char c1)
|
|
|
5126
5294
|
} else if (c2) {
|
|
5127
5295
|
if (c2 != EOF && base64_count + mimeout_state.count/3*4> 60) {
|
|
5128
5296
|
mimeout_mode = (output_mode==ASCII ||output_mode == ISO_8859_1) ? 'Q' : 'B';
|
|
5129
|
-
open_mime(output_mode);
|
|
5130
|
-
(*o_base64conv)(EOF,0);
|
|
5131
|
-
oconv_newline(o_base64conv);
|
|
5132
|
-
(*o_base64conv)(0,SP);
|
|
5297
|
+
open_mime(nkf_state, output_mode);
|
|
5298
|
+
(*o_base64conv)(nkf_state, EOF,0);
|
|
5299
|
+
oconv_newline(nkf_state, o_base64conv);
|
|
5300
|
+
(*o_base64conv)(nkf_state, 0,SP);
|
|
5133
5301
|
base64_count = 1;
|
|
5134
5302
|
mimeout_mode = -1;
|
|
5135
5303
|
}
|
|
@@ -5137,86 +5305,86 @@ mime_prechar(nkf_char c2, nkf_char c1)
|
|
|
5137
5305
|
}
|
|
5138
5306
|
|
|
5139
5307
|
static void
|
|
5140
|
-
close_mime(
|
|
5308
|
+
close_mime(nkf_state_t *nkf_state)
|
|
5141
5309
|
{
|
|
5142
|
-
(*o_mputc)('?');
|
|
5143
|
-
(*o_mputc)('=');
|
|
5310
|
+
(*o_mputc)(nkf_state, '?');
|
|
5311
|
+
(*o_mputc)(nkf_state, '=');
|
|
5144
5312
|
base64_count += 2;
|
|
5145
5313
|
mimeout_mode = 0;
|
|
5146
5314
|
}
|
|
5147
5315
|
|
|
5148
5316
|
static void
|
|
5149
|
-
eof_mime(
|
|
5317
|
+
eof_mime(nkf_state_t *nkf_state)
|
|
5150
5318
|
{
|
|
5151
5319
|
switch(mimeout_mode) {
|
|
5152
5320
|
case 'Q':
|
|
5153
5321
|
case 'B':
|
|
5154
5322
|
break;
|
|
5155
5323
|
case 2:
|
|
5156
|
-
(*o_mputc)(basis_64[((
|
|
5157
|
-
(*o_mputc)('=');
|
|
5158
|
-
(*o_mputc)('=');
|
|
5324
|
+
(*o_mputc)(nkf_state, basis_64[((base64_state & 0x3)<< 4)]);
|
|
5325
|
+
(*o_mputc)(nkf_state, '=');
|
|
5326
|
+
(*o_mputc)(nkf_state, '=');
|
|
5159
5327
|
base64_count += 3;
|
|
5160
5328
|
break;
|
|
5161
5329
|
case 1:
|
|
5162
|
-
(*o_mputc)(basis_64[((
|
|
5163
|
-
(*o_mputc)('=');
|
|
5330
|
+
(*o_mputc)(nkf_state, basis_64[((base64_state & 0xF) << 2)]);
|
|
5331
|
+
(*o_mputc)(nkf_state, '=');
|
|
5164
5332
|
base64_count += 2;
|
|
5165
5333
|
break;
|
|
5166
5334
|
}
|
|
5167
5335
|
if (mimeout_mode > 0) {
|
|
5168
5336
|
if (mimeout_f!=FIXED_MIME) {
|
|
5169
|
-
close_mime();
|
|
5337
|
+
close_mime(nkf_state);
|
|
5170
5338
|
} else if (mimeout_mode != 'Q')
|
|
5171
5339
|
mimeout_mode = 'B';
|
|
5172
5340
|
}
|
|
5173
5341
|
}
|
|
5174
5342
|
|
|
5175
5343
|
static void
|
|
5176
|
-
mimeout_addchar(nkf_char c)
|
|
5344
|
+
mimeout_addchar(nkf_state_t *nkf_state, nkf_char c)
|
|
5177
5345
|
{
|
|
5178
5346
|
switch(mimeout_mode) {
|
|
5179
5347
|
case 'Q':
|
|
5180
5348
|
if (c==CR||c==LF) {
|
|
5181
|
-
(*o_mputc)(c);
|
|
5349
|
+
(*o_mputc)(nkf_state, c);
|
|
5182
5350
|
base64_count = 0;
|
|
5183
5351
|
} else if(!nkf_isalnum(c)) {
|
|
5184
|
-
(*o_mputc)('=');
|
|
5185
|
-
(*o_mputc)(bin2hex(((c>>4)&0xf)));
|
|
5186
|
-
(*o_mputc)(bin2hex((c&0xf)));
|
|
5352
|
+
(*o_mputc)(nkf_state, '=');
|
|
5353
|
+
(*o_mputc)(nkf_state, bin2hex(((c>>4)&0xf)));
|
|
5354
|
+
(*o_mputc)(nkf_state, bin2hex((c&0xf)));
|
|
5187
5355
|
base64_count += 3;
|
|
5188
5356
|
} else {
|
|
5189
|
-
(*o_mputc)(c);
|
|
5357
|
+
(*o_mputc)(nkf_state, c);
|
|
5190
5358
|
base64_count++;
|
|
5191
5359
|
}
|
|
5192
5360
|
break;
|
|
5193
5361
|
case 'B':
|
|
5194
|
-
|
|
5195
|
-
(*o_mputc)(basis_64[c>>2]);
|
|
5362
|
+
base64_state=c;
|
|
5363
|
+
(*o_mputc)(nkf_state, basis_64[c>>2]);
|
|
5196
5364
|
mimeout_mode=2;
|
|
5197
5365
|
base64_count ++;
|
|
5198
5366
|
break;
|
|
5199
5367
|
case 2:
|
|
5200
|
-
(*o_mputc)(basis_64[((
|
|
5201
|
-
|
|
5368
|
+
(*o_mputc)(nkf_state, basis_64[((base64_state & 0x3)<< 4) | ((c & 0xF0) >> 4)]);
|
|
5369
|
+
base64_state=c;
|
|
5202
5370
|
mimeout_mode=1;
|
|
5203
5371
|
base64_count ++;
|
|
5204
5372
|
break;
|
|
5205
5373
|
case 1:
|
|
5206
|
-
(*o_mputc)(basis_64[((
|
|
5207
|
-
(*o_mputc)(basis_64[c & 0x3F]);
|
|
5374
|
+
(*o_mputc)(nkf_state, basis_64[((base64_state & 0xF) << 2) | ((c & 0xC0) >>6)]);
|
|
5375
|
+
(*o_mputc)(nkf_state, basis_64[c & 0x3F]);
|
|
5208
5376
|
mimeout_mode='B';
|
|
5209
5377
|
base64_count += 2;
|
|
5210
5378
|
break;
|
|
5211
5379
|
default:
|
|
5212
|
-
(*o_mputc)(c);
|
|
5380
|
+
(*o_mputc)(nkf_state, c);
|
|
5213
5381
|
base64_count++;
|
|
5214
5382
|
break;
|
|
5215
5383
|
}
|
|
5216
5384
|
}
|
|
5217
5385
|
|
|
5218
5386
|
static void
|
|
5219
|
-
mime_putc(nkf_char c)
|
|
5387
|
+
mime_putc(nkf_state_t *nkf_state, nkf_char c)
|
|
5220
5388
|
{
|
|
5221
5389
|
int i, j;
|
|
5222
5390
|
nkf_char lastchar;
|
|
@@ -5225,23 +5393,23 @@ mime_putc(nkf_char c)
|
|
|
5225
5393
|
if (mimeout_mode == 'Q'){
|
|
5226
5394
|
if (base64_count > 71){
|
|
5227
5395
|
if (c!=CR && c!=LF) {
|
|
5228
|
-
(*o_mputc)('=');
|
|
5229
|
-
put_newline(o_mputc);
|
|
5396
|
+
(*o_mputc)(nkf_state, '=');
|
|
5397
|
+
put_newline(nkf_state, o_mputc);
|
|
5230
5398
|
}
|
|
5231
5399
|
base64_count = 0;
|
|
5232
5400
|
}
|
|
5233
5401
|
}else{
|
|
5234
5402
|
if (base64_count > 71){
|
|
5235
|
-
eof_mime();
|
|
5236
|
-
put_newline(o_mputc);
|
|
5403
|
+
eof_mime(nkf_state);
|
|
5404
|
+
put_newline(nkf_state, o_mputc);
|
|
5237
5405
|
base64_count = 0;
|
|
5238
5406
|
}
|
|
5239
5407
|
if (c == EOF) { /* c==EOF */
|
|
5240
|
-
eof_mime();
|
|
5408
|
+
eof_mime(nkf_state);
|
|
5241
5409
|
}
|
|
5242
5410
|
}
|
|
5243
5411
|
if (c != EOF) { /* c==EOF */
|
|
5244
|
-
mimeout_addchar(c);
|
|
5412
|
+
mimeout_addchar(nkf_state, c);
|
|
5245
5413
|
}
|
|
5246
5414
|
return;
|
|
5247
5415
|
}
|
|
@@ -5249,31 +5417,31 @@ mime_putc(nkf_char c)
|
|
|
5249
5417
|
/* mimeout_f != FIXED_MIME */
|
|
5250
5418
|
|
|
5251
5419
|
if (c == EOF) { /* c==EOF */
|
|
5252
|
-
if (mimeout_mode == -1 && mimeout_state.count > 1) open_mime(output_mode);
|
|
5420
|
+
if (mimeout_mode == -1 && mimeout_state.count > 1) open_mime(nkf_state, output_mode);
|
|
5253
5421
|
j = mimeout_state.count;
|
|
5254
5422
|
mimeout_state.count = 0;
|
|
5255
5423
|
i = 0;
|
|
5256
5424
|
if (mimeout_mode > 0) {
|
|
5257
|
-
if (!nkf_isblank(mimeout_state.buf[j-1])) {
|
|
5425
|
+
if (j > 0 && !nkf_isblank(mimeout_state.buf[j-1])) {
|
|
5258
5426
|
for (;i<j;i++) {
|
|
5259
5427
|
if (nkf_isspace(mimeout_state.buf[i]) && base64_count < 71){
|
|
5260
5428
|
break;
|
|
5261
5429
|
}
|
|
5262
|
-
mimeout_addchar(mimeout_state.buf[i]);
|
|
5430
|
+
mimeout_addchar(nkf_state, mimeout_state.buf[i]);
|
|
5263
5431
|
}
|
|
5264
|
-
eof_mime();
|
|
5432
|
+
eof_mime(nkf_state);
|
|
5265
5433
|
for (;i<j;i++) {
|
|
5266
|
-
mimeout_addchar(mimeout_state.buf[i]);
|
|
5434
|
+
mimeout_addchar(nkf_state, mimeout_state.buf[i]);
|
|
5267
5435
|
}
|
|
5268
5436
|
} else {
|
|
5269
5437
|
for (;i<j;i++) {
|
|
5270
|
-
mimeout_addchar(mimeout_state.buf[i]);
|
|
5438
|
+
mimeout_addchar(nkf_state, mimeout_state.buf[i]);
|
|
5271
5439
|
}
|
|
5272
|
-
eof_mime();
|
|
5440
|
+
eof_mime(nkf_state);
|
|
5273
5441
|
}
|
|
5274
5442
|
} else {
|
|
5275
5443
|
for (;i<j;i++) {
|
|
5276
|
-
mimeout_addchar(mimeout_state.buf[i]);
|
|
5444
|
+
mimeout_addchar(nkf_state, mimeout_state.buf[i]);
|
|
5277
5445
|
}
|
|
5278
5446
|
}
|
|
5279
5447
|
return;
|
|
@@ -5288,35 +5456,35 @@ mime_putc(nkf_char c)
|
|
|
5288
5456
|
if (mimeout_mode=='Q') {
|
|
5289
5457
|
if (c <= DEL && (output_mode==ASCII ||output_mode == ISO_8859_1)) {
|
|
5290
5458
|
if (c == CR || c == LF) {
|
|
5291
|
-
close_mime();
|
|
5292
|
-
(*o_mputc)(c);
|
|
5459
|
+
close_mime(nkf_state);
|
|
5460
|
+
(*o_mputc)(nkf_state, c);
|
|
5293
5461
|
base64_count = 0;
|
|
5294
5462
|
return;
|
|
5295
5463
|
} else if (c <= SP) {
|
|
5296
|
-
close_mime();
|
|
5464
|
+
close_mime(nkf_state);
|
|
5297
5465
|
if (base64_count > 70) {
|
|
5298
|
-
put_newline(o_mputc);
|
|
5466
|
+
put_newline(nkf_state, o_mputc);
|
|
5299
5467
|
base64_count = 0;
|
|
5300
5468
|
}
|
|
5301
5469
|
if (!nkf_isblank(c)) {
|
|
5302
|
-
(*o_mputc)(SP);
|
|
5470
|
+
(*o_mputc)(nkf_state, SP);
|
|
5303
5471
|
base64_count++;
|
|
5304
5472
|
}
|
|
5305
5473
|
} else {
|
|
5306
5474
|
if (base64_count > 70) {
|
|
5307
|
-
close_mime();
|
|
5308
|
-
put_newline(o_mputc);
|
|
5309
|
-
(*o_mputc)(SP);
|
|
5475
|
+
close_mime(nkf_state);
|
|
5476
|
+
put_newline(nkf_state, o_mputc);
|
|
5477
|
+
(*o_mputc)(nkf_state, SP);
|
|
5310
5478
|
base64_count = 1;
|
|
5311
|
-
open_mime(output_mode);
|
|
5479
|
+
open_mime(nkf_state, output_mode);
|
|
5312
5480
|
}
|
|
5313
5481
|
if (!nkf_noescape_mime(c)) {
|
|
5314
|
-
mimeout_addchar(c);
|
|
5482
|
+
mimeout_addchar(nkf_state, c);
|
|
5315
5483
|
return;
|
|
5316
5484
|
}
|
|
5317
5485
|
}
|
|
5318
5486
|
if (c != 0x1B) {
|
|
5319
|
-
(*o_mputc)(c);
|
|
5487
|
+
(*o_mputc)(nkf_state, c);
|
|
5320
5488
|
base64_count++;
|
|
5321
5489
|
return;
|
|
5322
5490
|
}
|
|
@@ -5333,14 +5501,14 @@ mime_putc(nkf_char c)
|
|
|
5333
5501
|
}
|
|
5334
5502
|
if (c==CR || c==LF) {
|
|
5335
5503
|
if (flag) {
|
|
5336
|
-
open_mime(output_mode);
|
|
5504
|
+
open_mime(nkf_state, output_mode);
|
|
5337
5505
|
output_mode = 0;
|
|
5338
5506
|
} else {
|
|
5339
5507
|
base64_count = 0;
|
|
5340
5508
|
}
|
|
5341
5509
|
}
|
|
5342
5510
|
for (i=0;i<mimeout_state.count;i++) {
|
|
5343
|
-
(*o_mputc)(mimeout_state.buf[i]);
|
|
5511
|
+
(*o_mputc)(nkf_state, mimeout_state.buf[i]);
|
|
5344
5512
|
if (mimeout_state.buf[i] == CR || mimeout_state.buf[i] == LF){
|
|
5345
5513
|
base64_count = 0;
|
|
5346
5514
|
}else{
|
|
@@ -5348,7 +5516,7 @@ mime_putc(nkf_char c)
|
|
|
5348
5516
|
}
|
|
5349
5517
|
}
|
|
5350
5518
|
if (flag) {
|
|
5351
|
-
eof_mime();
|
|
5519
|
+
eof_mime(nkf_state);
|
|
5352
5520
|
base64_count = 0;
|
|
5353
5521
|
mimeout_mode = 0;
|
|
5354
5522
|
}
|
|
@@ -5358,8 +5526,8 @@ mime_putc(nkf_char c)
|
|
|
5358
5526
|
if (base64_count > 1
|
|
5359
5527
|
&& base64_count + mimeout_state.count > 76
|
|
5360
5528
|
&& mimeout_state.buf[0] != CR && mimeout_state.buf[0] != LF){
|
|
5361
|
-
static const char
|
|
5362
|
-
|
|
5529
|
+
static const char str[] = "boundary=\"";
|
|
5530
|
+
enum {len = sizeof(str) - 1};
|
|
5363
5531
|
i = 0;
|
|
5364
5532
|
|
|
5365
5533
|
for (; i < mimeout_state.count - len; ++i) {
|
|
@@ -5370,19 +5538,19 @@ mime_putc(nkf_char c)
|
|
|
5370
5538
|
}
|
|
5371
5539
|
|
|
5372
5540
|
if (i == 0 || i == mimeout_state.count - len) {
|
|
5373
|
-
put_newline(o_mputc);
|
|
5541
|
+
put_newline(nkf_state, o_mputc);
|
|
5374
5542
|
base64_count = 0;
|
|
5375
5543
|
if (!nkf_isspace(mimeout_state.buf[0])){
|
|
5376
|
-
(*o_mputc)(SP);
|
|
5544
|
+
(*o_mputc)(nkf_state, SP);
|
|
5377
5545
|
base64_count++;
|
|
5378
5546
|
}
|
|
5379
5547
|
}
|
|
5380
5548
|
else {
|
|
5381
5549
|
int j;
|
|
5382
5550
|
for (j = 0; j <= i; ++j) {
|
|
5383
|
-
(*o_mputc)(mimeout_state.buf[j]);
|
|
5551
|
+
(*o_mputc)(nkf_state, mimeout_state.buf[j]);
|
|
5384
5552
|
}
|
|
5385
|
-
put_newline(o_mputc);
|
|
5553
|
+
put_newline(nkf_state, o_mputc);
|
|
5386
5554
|
base64_count = 1;
|
|
5387
5555
|
for (; j <= mimeout_state.count; ++j) {
|
|
5388
5556
|
mimeout_state.buf[j - i] = mimeout_state.buf[j];
|
|
@@ -5392,27 +5560,27 @@ mime_putc(nkf_char c)
|
|
|
5392
5560
|
}
|
|
5393
5561
|
mimeout_state.buf[mimeout_state.count++] = (char)c;
|
|
5394
5562
|
if (mimeout_state.count>MIMEOUT_BUF_LENGTH) {
|
|
5395
|
-
open_mime(output_mode);
|
|
5563
|
+
open_mime(nkf_state, output_mode);
|
|
5396
5564
|
}
|
|
5397
5565
|
}
|
|
5398
5566
|
return;
|
|
5399
5567
|
}else{
|
|
5400
5568
|
if (lastchar==CR || lastchar == LF){
|
|
5401
5569
|
for (i=0;i<mimeout_state.count;i++) {
|
|
5402
|
-
(*o_mputc)(mimeout_state.buf[i]);
|
|
5570
|
+
(*o_mputc)(nkf_state, mimeout_state.buf[i]);
|
|
5403
5571
|
}
|
|
5404
5572
|
base64_count = 0;
|
|
5405
5573
|
mimeout_state.count = 0;
|
|
5406
5574
|
}
|
|
5407
5575
|
if (lastchar==SP) {
|
|
5408
5576
|
for (i=0;i<mimeout_state.count-1;i++) {
|
|
5409
|
-
(*o_mputc)(mimeout_state.buf[i]);
|
|
5577
|
+
(*o_mputc)(nkf_state, mimeout_state.buf[i]);
|
|
5410
5578
|
base64_count++;
|
|
5411
5579
|
}
|
|
5412
5580
|
mimeout_state.buf[0] = SP;
|
|
5413
5581
|
mimeout_state.count = 1;
|
|
5414
5582
|
}
|
|
5415
|
-
open_mime(output_mode);
|
|
5583
|
+
open_mime(nkf_state, output_mode);
|
|
5416
5584
|
}
|
|
5417
5585
|
}else{
|
|
5418
5586
|
/* mimeout_mode == 'B', 1, 2 */
|
|
@@ -5421,13 +5589,13 @@ mime_putc(nkf_char c)
|
|
|
5421
5589
|
if (lastchar == CR || lastchar == LF){
|
|
5422
5590
|
if (nkf_isblank(c)) {
|
|
5423
5591
|
for (i=0;i<mimeout_state.count;i++) {
|
|
5424
|
-
mimeout_addchar(mimeout_state.buf[i]);
|
|
5592
|
+
mimeout_addchar(nkf_state, mimeout_state.buf[i]);
|
|
5425
5593
|
}
|
|
5426
5594
|
mimeout_state.count = 0;
|
|
5427
5595
|
} else {
|
|
5428
|
-
eof_mime();
|
|
5596
|
+
eof_mime(nkf_state);
|
|
5429
5597
|
for (i=0;i<mimeout_state.count;i++) {
|
|
5430
|
-
(*o_mputc)(mimeout_state.buf[i]);
|
|
5598
|
+
(*o_mputc)(nkf_state, mimeout_state.buf[i]);
|
|
5431
5599
|
}
|
|
5432
5600
|
base64_count = 0;
|
|
5433
5601
|
mimeout_state.count = 0;
|
|
@@ -5438,9 +5606,9 @@ mime_putc(nkf_char c)
|
|
|
5438
5606
|
if (nkf_isspace(c)) {
|
|
5439
5607
|
for (i=0;i<mimeout_state.count;i++) {
|
|
5440
5608
|
if (SP<mimeout_state.buf[i] && mimeout_state.buf[i]<DEL) {
|
|
5441
|
-
eof_mime();
|
|
5609
|
+
eof_mime(nkf_state);
|
|
5442
5610
|
for (i=0;i<mimeout_state.count;i++) {
|
|
5443
|
-
(*o_mputc)(mimeout_state.buf[i]);
|
|
5611
|
+
(*o_mputc)(nkf_state, mimeout_state.buf[i]);
|
|
5444
5612
|
base64_count++;
|
|
5445
5613
|
}
|
|
5446
5614
|
mimeout_state.count = 0;
|
|
@@ -5448,9 +5616,9 @@ mime_putc(nkf_char c)
|
|
|
5448
5616
|
}
|
|
5449
5617
|
mimeout_state.buf[mimeout_state.count++] = (char)c;
|
|
5450
5618
|
if (mimeout_state.count>MIMEOUT_BUF_LENGTH) {
|
|
5451
|
-
eof_mime();
|
|
5619
|
+
eof_mime(nkf_state);
|
|
5452
5620
|
for (j=0;j<mimeout_state.count;j++) {
|
|
5453
|
-
(*o_mputc)(mimeout_state.buf[j]);
|
|
5621
|
+
(*o_mputc)(nkf_state, mimeout_state.buf[j]);
|
|
5454
5622
|
base64_count++;
|
|
5455
5623
|
}
|
|
5456
5624
|
mimeout_state.count = 0;
|
|
@@ -5463,7 +5631,7 @@ mime_putc(nkf_char c)
|
|
|
5463
5631
|
j = mimeout_state.count;
|
|
5464
5632
|
mimeout_state.count = 0;
|
|
5465
5633
|
for (i=0;i<j;i++) {
|
|
5466
|
-
mimeout_addchar(mimeout_state.buf[i]);
|
|
5634
|
+
mimeout_addchar(nkf_state, mimeout_state.buf[i]);
|
|
5467
5635
|
}
|
|
5468
5636
|
}
|
|
5469
5637
|
return;
|
|
@@ -5476,25 +5644,25 @@ mime_putc(nkf_char c)
|
|
|
5476
5644
|
for (i=0;i<j;i++) {
|
|
5477
5645
|
if (mimeout_state.buf[i]==CR || mimeout_state.buf[i]==LF)
|
|
5478
5646
|
break;
|
|
5479
|
-
mimeout_addchar(mimeout_state.buf[i]);
|
|
5647
|
+
mimeout_addchar(nkf_state, mimeout_state.buf[i]);
|
|
5480
5648
|
}
|
|
5481
5649
|
if (i<j) {
|
|
5482
|
-
eof_mime();
|
|
5650
|
+
eof_mime(nkf_state);
|
|
5483
5651
|
base64_count=0;
|
|
5484
5652
|
for (;i<j;i++) {
|
|
5485
|
-
(*o_mputc)(mimeout_state.buf[i]);
|
|
5653
|
+
(*o_mputc)(nkf_state, mimeout_state.buf[i]);
|
|
5486
5654
|
}
|
|
5487
|
-
open_mime(output_mode);
|
|
5655
|
+
open_mime(nkf_state, output_mode);
|
|
5488
5656
|
}
|
|
5489
5657
|
}
|
|
5490
|
-
mimeout_addchar(c);
|
|
5658
|
+
mimeout_addchar(nkf_state, c);
|
|
5491
5659
|
}
|
|
5492
5660
|
|
|
5493
5661
|
static void
|
|
5494
|
-
base64_conv(nkf_char c2, nkf_char c1)
|
|
5662
|
+
base64_conv(nkf_state_t *nkf_state, nkf_char c2, nkf_char c1)
|
|
5495
5663
|
{
|
|
5496
|
-
mime_prechar(c2, c1);
|
|
5497
|
-
(*o_base64conv)(c2,c1);
|
|
5664
|
+
mime_prechar(nkf_state, c2, c1);
|
|
5665
|
+
(*o_base64conv)(nkf_state, c2,c1);
|
|
5498
5666
|
}
|
|
5499
5667
|
|
|
5500
5668
|
#ifdef HAVE_ICONV_H
|
|
@@ -5540,7 +5708,7 @@ nkf_iconv_convert(nkf_iconv_t *converter, FILE *input)
|
|
|
5540
5708
|
|
|
5541
5709
|
do {
|
|
5542
5710
|
if (c != EOF) {
|
|
5543
|
-
while ((c = (*i_getc)(f)) != EOF) {
|
|
5711
|
+
while ((c = (*i_getc)(nkf_state, f)) != EOF) {
|
|
5544
5712
|
input_buffer[input_length++] = c;
|
|
5545
5713
|
if (input_length < converter->input_buffer_size) break;
|
|
5546
5714
|
}
|
|
@@ -5548,7 +5716,7 @@ nkf_iconv_convert(nkf_iconv_t *converter, FILE *input)
|
|
|
5548
5716
|
|
|
5549
5717
|
size_t ret = iconv(converter->cd, &input_buffer, &input_length, &output_buffer, &output_length);
|
|
5550
5718
|
while (output_length-- > 0) {
|
|
5551
|
-
(*o_putc)(output_buffer[converter->output_buffer_size-output_length]);
|
|
5719
|
+
(*o_putc)(nkf_state, output_buffer[converter->output_buffer_size-output_length]);
|
|
5552
5720
|
}
|
|
5553
5721
|
if (ret == (size_t) - 1) {
|
|
5554
5722
|
switch (errno) {
|
|
@@ -5589,12 +5757,15 @@ nkf_iconv_close(nkf_iconv_t *convert)
|
|
|
5589
5757
|
|
|
5590
5758
|
|
|
5591
5759
|
static void
|
|
5592
|
-
reinit(
|
|
5760
|
+
reinit(nkf_state_t *nkf_state)
|
|
5593
5761
|
{
|
|
5762
|
+
nkf_buf_clear(nkf_state->std_gc_buf);
|
|
5763
|
+
nkf_buf_clear(nkf_state->broken_buf);
|
|
5764
|
+
nkf_buf_clear(nkf_state->nfc_buf);
|
|
5594
5765
|
{
|
|
5595
5766
|
struct input_code *p = input_code_list;
|
|
5596
5767
|
while (p->name){
|
|
5597
|
-
status_reinit(p++);
|
|
5768
|
+
status_reinit(nkf_state, p++);
|
|
5598
5769
|
}
|
|
5599
5770
|
}
|
|
5600
5771
|
unbuf_f = FALSE;
|
|
@@ -5700,16 +5871,17 @@ reinit(void)
|
|
|
5700
5871
|
input_codename = NULL;
|
|
5701
5872
|
input_encoding = NULL;
|
|
5702
5873
|
output_encoding = NULL;
|
|
5703
|
-
|
|
5874
|
+
nkf_state->broken_state = 0;
|
|
5875
|
+
base64_state = 0;
|
|
5704
5876
|
#ifdef WIN32DLL
|
|
5705
5877
|
reinitdll();
|
|
5706
5878
|
#endif /*WIN32DLL*/
|
|
5707
5879
|
}
|
|
5708
5880
|
|
|
5709
5881
|
static int
|
|
5710
|
-
module_connection(
|
|
5882
|
+
module_connection(nkf_state_t *nkf_state)
|
|
5711
5883
|
{
|
|
5712
|
-
if (input_encoding) set_input_encoding(input_encoding);
|
|
5884
|
+
if (input_encoding) set_input_encoding(nkf_state, input_encoding);
|
|
5713
5885
|
if (!output_encoding) {
|
|
5714
5886
|
output_encoding = nkf_default_encoding();
|
|
5715
5887
|
}
|
|
@@ -5717,7 +5889,7 @@ module_connection(void)
|
|
|
5717
5889
|
if (noout_f || guess_f) output_encoding = nkf_enc_from_index(ISO_2022_JP);
|
|
5718
5890
|
else return -1;
|
|
5719
5891
|
}
|
|
5720
|
-
set_output_encoding(output_encoding);
|
|
5892
|
+
set_output_encoding(nkf_state, output_encoding);
|
|
5721
5893
|
oconv = nkf_enc_to_oconv(output_encoding);
|
|
5722
5894
|
o_putc = std_putc;
|
|
5723
5895
|
if (nkf_enc_unicode_p(output_encoding))
|
|
@@ -5798,15 +5970,15 @@ module_connection(void)
|
|
|
5798
5970
|
i_bungetc = i_ungetc; i_ungetc = broken_ungetc;
|
|
5799
5971
|
}
|
|
5800
5972
|
if (input_encoding) {
|
|
5801
|
-
set_iconv(-TRUE, nkf_enc_to_iconv(input_encoding));
|
|
5973
|
+
set_iconv(nkf_state, -TRUE, nkf_enc_to_iconv(input_encoding));
|
|
5802
5974
|
} else {
|
|
5803
|
-
set_iconv(FALSE, e_iconv);
|
|
5975
|
+
set_iconv(nkf_state, FALSE, e_iconv);
|
|
5804
5976
|
}
|
|
5805
5977
|
|
|
5806
5978
|
{
|
|
5807
5979
|
struct input_code *p = input_code_list;
|
|
5808
5980
|
while (p->name){
|
|
5809
|
-
status_reinit(p++);
|
|
5981
|
+
status_reinit(nkf_state, p++);
|
|
5810
5982
|
}
|
|
5811
5983
|
}
|
|
5812
5984
|
return 0;
|
|
@@ -5818,15 +5990,15 @@ module_connection(void)
|
|
|
5818
5990
|
|
|
5819
5991
|
#if !defined(PERL_XS) && !defined(WIN32DLL)
|
|
5820
5992
|
static nkf_char
|
|
5821
|
-
noconvert(FILE *f)
|
|
5993
|
+
noconvert(nkf_state_t *nkf_state, FILE *f)
|
|
5822
5994
|
{
|
|
5823
5995
|
nkf_char c;
|
|
5824
5996
|
|
|
5825
5997
|
if (nop_f == 2)
|
|
5826
|
-
module_connection();
|
|
5827
|
-
while ((c = (*i_getc)(f)) != EOF)
|
|
5828
|
-
(*o_putc)(c);
|
|
5829
|
-
(*o_putc)(EOF);
|
|
5998
|
+
module_connection(nkf_state);
|
|
5999
|
+
while ((c = (*i_getc)(nkf_state, f)) != EOF)
|
|
6000
|
+
(*o_putc)(nkf_state, c);
|
|
6001
|
+
(*o_putc)(nkf_state, EOF);
|
|
5830
6002
|
return 1;
|
|
5831
6003
|
}
|
|
5832
6004
|
#endif
|
|
@@ -5839,12 +6011,12 @@ noconvert(FILE *f)
|
|
|
5839
6011
|
#define set_input_mode(mode) do { \
|
|
5840
6012
|
input_mode = mode; \
|
|
5841
6013
|
shift_mode = 0; \
|
|
5842
|
-
set_input_codename("ISO-2022-JP"); \
|
|
5843
|
-
debug("ISO-2022-JP"); \
|
|
6014
|
+
set_input_codename(nkf_state, "ISO-2022-JP"); \
|
|
6015
|
+
debug(nkf_state, "ISO-2022-JP"); \
|
|
5844
6016
|
} while (0)
|
|
5845
6017
|
|
|
5846
6018
|
static int
|
|
5847
|
-
kanji_convert(FILE *f)
|
|
6019
|
+
kanji_convert(nkf_state_t *nkf_state, FILE *f)
|
|
5848
6020
|
{
|
|
5849
6021
|
nkf_char c1=0, c2=0, c3=0, c4=0;
|
|
5850
6022
|
int shift_mode = 0; /* 0, 1, 2, 3 */
|
|
@@ -5858,58 +6030,58 @@ kanji_convert(FILE *f)
|
|
|
5858
6030
|
input_mode = ASCII;
|
|
5859
6031
|
output_mode = ASCII;
|
|
5860
6032
|
|
|
5861
|
-
if (module_connection() < 0) {
|
|
6033
|
+
if (module_connection(nkf_state) < 0) {
|
|
5862
6034
|
#if !defined(PERL_XS) && !defined(WIN32DLL)
|
|
5863
6035
|
fprintf(stderr, "no output encoding given\n");
|
|
5864
6036
|
#endif
|
|
5865
6037
|
return -1;
|
|
5866
6038
|
}
|
|
5867
|
-
check_bom(f);
|
|
6039
|
+
check_bom(nkf_state, f);
|
|
5868
6040
|
|
|
5869
6041
|
#ifdef UTF8_INPUT_ENABLE
|
|
5870
6042
|
if(iconv == w_iconv32){
|
|
5871
|
-
while ((c1 = (*i_getc)(f)) != EOF &&
|
|
5872
|
-
(c2 = (*i_getc)(f)) != EOF &&
|
|
5873
|
-
(c3 = (*i_getc)(f)) != EOF &&
|
|
5874
|
-
(c4 = (*i_getc)(f)) != EOF) {
|
|
6043
|
+
while ((c1 = (*i_getc)(nkf_state, f)) != EOF &&
|
|
6044
|
+
(c2 = (*i_getc)(nkf_state, f)) != EOF &&
|
|
6045
|
+
(c3 = (*i_getc)(nkf_state, f)) != EOF &&
|
|
6046
|
+
(c4 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
5875
6047
|
nkf_char c5, c6, c7, c8;
|
|
5876
|
-
if (nkf_iconv_utf_32(c1, c2, c3, c4) == (size_t)NKF_ICONV_WAIT_COMBINING_CHAR) {
|
|
5877
|
-
if ((c5 = (*i_getc)(f)) != EOF &&
|
|
5878
|
-
(c6 = (*i_getc)(f)) != EOF &&
|
|
5879
|
-
(c7 = (*i_getc)(f)) != EOF &&
|
|
5880
|
-
(c8 = (*i_getc)(f)) != EOF) {
|
|
5881
|
-
if (nkf_iconv_utf_32_combine(c1, c2, c3, c4, c5, c6, c7, c8)) {
|
|
5882
|
-
(*i_ungetc)(c8, f);
|
|
5883
|
-
(*i_ungetc)(c7, f);
|
|
5884
|
-
(*i_ungetc)(c6, f);
|
|
5885
|
-
(*i_ungetc)(c5, f);
|
|
5886
|
-
nkf_iconv_utf_32_nocombine(c1, c2, c3, c4);
|
|
6048
|
+
if (nkf_iconv_utf_32(nkf_state, c1, c2, c3, c4) == (size_t)NKF_ICONV_WAIT_COMBINING_CHAR) {
|
|
6049
|
+
if ((c5 = (*i_getc)(nkf_state, f)) != EOF &&
|
|
6050
|
+
(c6 = (*i_getc)(nkf_state, f)) != EOF &&
|
|
6051
|
+
(c7 = (*i_getc)(nkf_state, f)) != EOF &&
|
|
6052
|
+
(c8 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6053
|
+
if (nkf_iconv_utf_32_combine(nkf_state, c1, c2, c3, c4, c5, c6, c7, c8)) {
|
|
6054
|
+
(*i_ungetc)(nkf_state, c8, f);
|
|
6055
|
+
(*i_ungetc)(nkf_state, c7, f);
|
|
6056
|
+
(*i_ungetc)(nkf_state, c6, f);
|
|
6057
|
+
(*i_ungetc)(nkf_state, c5, f);
|
|
6058
|
+
nkf_iconv_utf_32_nocombine(nkf_state, c1, c2, c3, c4);
|
|
5887
6059
|
}
|
|
5888
6060
|
} else {
|
|
5889
|
-
nkf_iconv_utf_32_nocombine(c1, c2, c3, c4);
|
|
6061
|
+
nkf_iconv_utf_32_nocombine(nkf_state, c1, c2, c3, c4);
|
|
5890
6062
|
}
|
|
5891
6063
|
}
|
|
5892
6064
|
}
|
|
5893
6065
|
goto finished;
|
|
5894
6066
|
}
|
|
5895
6067
|
else if (iconv == w_iconv16) {
|
|
5896
|
-
while ((c1 = (*i_getc)(f)) != EOF &&
|
|
5897
|
-
(c2 = (*i_getc)(f)) != EOF) {
|
|
5898
|
-
size_t ret = nkf_iconv_utf_16(c1, c2, 0, 0);
|
|
6068
|
+
while ((c1 = (*i_getc)(nkf_state, f)) != EOF &&
|
|
6069
|
+
(c2 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6070
|
+
size_t ret = nkf_iconv_utf_16(nkf_state, c1, c2, 0, 0);
|
|
5899
6071
|
if (ret == NKF_ICONV_NEED_TWO_MORE_BYTES &&
|
|
5900
|
-
(c3 = (*i_getc)(f)) != EOF &&
|
|
5901
|
-
(c4 = (*i_getc)(f)) != EOF) {
|
|
5902
|
-
nkf_iconv_utf_16(c1, c2, c3, c4);
|
|
6072
|
+
(c3 = (*i_getc)(nkf_state, f)) != EOF &&
|
|
6073
|
+
(c4 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6074
|
+
nkf_iconv_utf_16(nkf_state, c1, c2, c3, c4);
|
|
5903
6075
|
} else if (ret == (size_t)NKF_ICONV_WAIT_COMBINING_CHAR) {
|
|
5904
|
-
if ((c3 = (*i_getc)(f)) != EOF &&
|
|
5905
|
-
(c4 = (*i_getc)(f)) != EOF) {
|
|
5906
|
-
if (nkf_iconv_utf_16_combine(c1, c2, c3, c4)) {
|
|
5907
|
-
(*i_ungetc)(c4, f);
|
|
5908
|
-
(*i_ungetc)(c3, f);
|
|
5909
|
-
nkf_iconv_utf_16_nocombine(c1, c2);
|
|
6076
|
+
if ((c3 = (*i_getc)(nkf_state, f)) != EOF &&
|
|
6077
|
+
(c4 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6078
|
+
if (nkf_iconv_utf_16_combine(nkf_state, c1, c2, c3, c4)) {
|
|
6079
|
+
(*i_ungetc)(nkf_state, c4, f);
|
|
6080
|
+
(*i_ungetc)(nkf_state, c3, f);
|
|
6081
|
+
nkf_iconv_utf_16_nocombine(nkf_state, c1, c2);
|
|
5910
6082
|
}
|
|
5911
6083
|
} else {
|
|
5912
|
-
nkf_iconv_utf_16_nocombine(c1, c2);
|
|
6084
|
+
nkf_iconv_utf_16_nocombine(nkf_state, c1, c2);
|
|
5913
6085
|
}
|
|
5914
6086
|
}
|
|
5915
6087
|
}
|
|
@@ -5917,11 +6089,11 @@ kanji_convert(FILE *f)
|
|
|
5917
6089
|
}
|
|
5918
6090
|
#endif
|
|
5919
6091
|
|
|
5920
|
-
while ((c1 = (*i_getc)(f)) != EOF) {
|
|
6092
|
+
while ((c1 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
5921
6093
|
#ifdef INPUT_CODE_FIX
|
|
5922
6094
|
if (!input_encoding)
|
|
5923
6095
|
#endif
|
|
5924
|
-
code_status(c1);
|
|
6096
|
+
code_status(nkf_state, c1);
|
|
5925
6097
|
if (c2) {
|
|
5926
6098
|
/* second byte */
|
|
5927
6099
|
if (c2 > ((input_encoding && nkf_enc_cp5022x_p(input_encoding)) ? 0x92 : DEL)) {
|
|
@@ -5929,7 +6101,7 @@ kanji_convert(FILE *f)
|
|
|
5929
6101
|
if (!estab_f&&!mime_decode_mode) {
|
|
5930
6102
|
/* in case of not established yet */
|
|
5931
6103
|
/* It is still ambiguous */
|
|
5932
|
-
if (h_conv(f, c2, c1)==EOF) {
|
|
6104
|
+
if (h_conv(nkf_state, f, c2, c1)==EOF) {
|
|
5933
6105
|
LAST;
|
|
5934
6106
|
}
|
|
5935
6107
|
else {
|
|
@@ -5952,7 +6124,7 @@ kanji_convert(FILE *f)
|
|
|
5952
6124
|
}
|
|
5953
6125
|
}
|
|
5954
6126
|
else if (nkf_char_unicode_p(c1)) {
|
|
5955
|
-
(*oconv)(0, c1);
|
|
6127
|
+
(*oconv)(nkf_state, 0, c1);
|
|
5956
6128
|
NEXT;
|
|
5957
6129
|
}
|
|
5958
6130
|
else {
|
|
@@ -6010,22 +6182,22 @@ kanji_convert(FILE *f)
|
|
|
6010
6182
|
MORE;
|
|
6011
6183
|
} else if (c1 == '=' && mime_f && !mime_decode_mode) {
|
|
6012
6184
|
/* Check MIME code */
|
|
6013
|
-
if ((c1 = (*i_getc)(f)) == EOF) {
|
|
6014
|
-
(*oconv)(0, '=');
|
|
6185
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
6186
|
+
(*oconv)(nkf_state, 0, '=');
|
|
6015
6187
|
LAST;
|
|
6016
6188
|
} else if (c1 == '?') {
|
|
6017
6189
|
/* =? is mime conversion start sequence */
|
|
6018
6190
|
if(mime_f == STRICT_MIME) {
|
|
6019
6191
|
/* check in real detail */
|
|
6020
|
-
if (mime_begin_strict(f) == EOF)
|
|
6192
|
+
if (mime_begin_strict(nkf_state, f) == EOF)
|
|
6021
6193
|
LAST;
|
|
6022
6194
|
SKIP;
|
|
6023
|
-
} else if (mime_begin(f) == EOF)
|
|
6195
|
+
} else if (mime_begin(nkf_state, f) == EOF)
|
|
6024
6196
|
LAST;
|
|
6025
6197
|
SKIP;
|
|
6026
6198
|
} else {
|
|
6027
|
-
(*oconv)(0, '=');
|
|
6028
|
-
(*i_ungetc)(c1,f);
|
|
6199
|
+
(*oconv)(nkf_state, 0, '=');
|
|
6200
|
+
(*i_ungetc)(nkf_state, c1,f);
|
|
6029
6201
|
SKIP;
|
|
6030
6202
|
}
|
|
6031
6203
|
} else {
|
|
@@ -6039,13 +6211,13 @@ kanji_convert(FILE *f)
|
|
|
6039
6211
|
shift_mode = 1;
|
|
6040
6212
|
SKIP;
|
|
6041
6213
|
} else if (c1 == ESC && (!is_8bit || mime_decode_mode)) {
|
|
6042
|
-
if ((c1 = (*i_getc)(f)) == EOF) {
|
|
6043
|
-
(*oconv)(0, ESC);
|
|
6214
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
6215
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6044
6216
|
LAST;
|
|
6045
6217
|
}
|
|
6046
6218
|
else if (c1 == '&') {
|
|
6047
6219
|
/* IRR */
|
|
6048
|
-
if ((c1 = (*i_getc)(f)) == EOF) {
|
|
6220
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
6049
6221
|
LAST;
|
|
6050
6222
|
} else {
|
|
6051
6223
|
SKIP;
|
|
@@ -6053,10 +6225,10 @@ kanji_convert(FILE *f)
|
|
|
6053
6225
|
}
|
|
6054
6226
|
else if (c1 == '$') {
|
|
6055
6227
|
/* GZDMx */
|
|
6056
|
-
if ((c1 = (*i_getc)(f)) == EOF) {
|
|
6228
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
6057
6229
|
/* don't send bogus code
|
|
6058
|
-
(*oconv)(0, ESC);
|
|
6059
|
-
(*oconv)(0, '$'); */
|
|
6230
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6231
|
+
(*oconv)(nkf_state, 0, '$'); */
|
|
6060
6232
|
LAST;
|
|
6061
6233
|
} else if (c1 == '@' || c1 == 'B') {
|
|
6062
6234
|
/* JIS X 0208 */
|
|
@@ -6064,11 +6236,11 @@ kanji_convert(FILE *f)
|
|
|
6064
6236
|
SKIP;
|
|
6065
6237
|
} else if (c1 == '(') {
|
|
6066
6238
|
/* GZDM4 */
|
|
6067
|
-
if ((c1 = (*i_getc)(f)) == EOF) {
|
|
6239
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
6068
6240
|
/* don't send bogus code
|
|
6069
|
-
(*oconv)(0, ESC);
|
|
6070
|
-
(*oconv)(0, '$');
|
|
6071
|
-
(*oconv)(0, '(');
|
|
6241
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6242
|
+
(*oconv)(nkf_state, 0, '$');
|
|
6243
|
+
(*oconv)(nkf_state, 0, '(');
|
|
6072
6244
|
*/
|
|
6073
6245
|
LAST;
|
|
6074
6246
|
} else if (c1 == '@'|| c1 == 'B') {
|
|
@@ -6088,10 +6260,10 @@ kanji_convert(FILE *f)
|
|
|
6088
6260
|
SKIP;
|
|
6089
6261
|
} else {
|
|
6090
6262
|
/* could be some special code */
|
|
6091
|
-
(*oconv)(0, ESC);
|
|
6092
|
-
(*oconv)(0, '$');
|
|
6093
|
-
(*oconv)(0, '(');
|
|
6094
|
-
(*oconv)(0, c1);
|
|
6263
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6264
|
+
(*oconv)(nkf_state, 0, '$');
|
|
6265
|
+
(*oconv)(nkf_state, 0, '(');
|
|
6266
|
+
(*oconv)(nkf_state, 0, c1);
|
|
6095
6267
|
SKIP;
|
|
6096
6268
|
}
|
|
6097
6269
|
} else if (broken_f&0x2) {
|
|
@@ -6100,17 +6272,17 @@ kanji_convert(FILE *f)
|
|
|
6100
6272
|
shift_mode = 0;
|
|
6101
6273
|
SKIP;
|
|
6102
6274
|
} else {
|
|
6103
|
-
(*oconv)(0, ESC);
|
|
6104
|
-
(*oconv)(0, '$');
|
|
6105
|
-
(*oconv)(0, c1);
|
|
6275
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6276
|
+
(*oconv)(nkf_state, 0, '$');
|
|
6277
|
+
(*oconv)(nkf_state, 0, c1);
|
|
6106
6278
|
SKIP;
|
|
6107
6279
|
}
|
|
6108
6280
|
} else if (c1 == '(') {
|
|
6109
6281
|
/* GZD4 */
|
|
6110
|
-
if ((c1 = (*i_getc)(f)) == EOF) {
|
|
6282
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
6111
6283
|
/* don't send bogus code
|
|
6112
|
-
(*oconv)(0, ESC);
|
|
6113
|
-
(*oconv)(0, '('); */
|
|
6284
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6285
|
+
(*oconv)(nkf_state, 0, '('); */
|
|
6114
6286
|
LAST;
|
|
6115
6287
|
}
|
|
6116
6288
|
else if (c1 == 'I') {
|
|
@@ -6129,14 +6301,14 @@ kanji_convert(FILE *f)
|
|
|
6129
6301
|
SKIP;
|
|
6130
6302
|
}
|
|
6131
6303
|
else {
|
|
6132
|
-
(*oconv)(0, ESC);
|
|
6133
|
-
(*oconv)(0, '(');
|
|
6304
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6305
|
+
(*oconv)(nkf_state, 0, '(');
|
|
6134
6306
|
SEND;
|
|
6135
6307
|
}
|
|
6136
6308
|
}
|
|
6137
6309
|
else if (c1 == '.') {
|
|
6138
6310
|
/* G2D6 */
|
|
6139
|
-
if ((c1 = (*i_getc)(f)) == EOF) {
|
|
6311
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
6140
6312
|
LAST;
|
|
6141
6313
|
}
|
|
6142
6314
|
else if (c1 == 'A') {
|
|
@@ -6145,38 +6317,38 @@ kanji_convert(FILE *f)
|
|
|
6145
6317
|
SKIP;
|
|
6146
6318
|
}
|
|
6147
6319
|
else {
|
|
6148
|
-
(*oconv)(0, ESC);
|
|
6149
|
-
(*oconv)(0, '.');
|
|
6320
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6321
|
+
(*oconv)(nkf_state, 0, '.');
|
|
6150
6322
|
SEND;
|
|
6151
6323
|
}
|
|
6152
6324
|
}
|
|
6153
6325
|
else if (c1 == 'N') {
|
|
6154
6326
|
/* SS2 */
|
|
6155
|
-
c1 = (*i_getc)(f);
|
|
6327
|
+
c1 = (*i_getc)(nkf_state, f);
|
|
6156
6328
|
if (g2 == ISO_8859_1) {
|
|
6157
6329
|
c2 = ISO_8859_1;
|
|
6158
6330
|
SEND;
|
|
6159
6331
|
}else{
|
|
6160
|
-
(*i_ungetc)(c1, f);
|
|
6332
|
+
(*i_ungetc)(nkf_state, c1, f);
|
|
6161
6333
|
/* lonely ESC */
|
|
6162
|
-
(*oconv)(0, ESC);
|
|
6334
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6163
6335
|
SEND;
|
|
6164
6336
|
}
|
|
6165
6337
|
}
|
|
6166
6338
|
else {
|
|
6167
|
-
i_ungetc(c1,f);
|
|
6339
|
+
i_ungetc(nkf_state, c1,f);
|
|
6168
6340
|
/* lonely ESC */
|
|
6169
|
-
(*oconv)(0, ESC);
|
|
6341
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6170
6342
|
SKIP;
|
|
6171
6343
|
}
|
|
6172
6344
|
} else if (c1 == ESC && iconv == s_iconv) {
|
|
6173
6345
|
/* ESC in Shift_JIS */
|
|
6174
|
-
if ((c1 = (*i_getc)(f)) == EOF) {
|
|
6175
|
-
(*oconv)(0, ESC);
|
|
6346
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
6347
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6176
6348
|
LAST;
|
|
6177
6349
|
} else if (c1 == '$') {
|
|
6178
6350
|
/* J-PHONE emoji */
|
|
6179
|
-
if ((c1 = (*i_getc)(f)) == EOF) {
|
|
6351
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) {
|
|
6180
6352
|
LAST;
|
|
6181
6353
|
} else if (('E' <= c1 && c1 <= 'G') ||
|
|
6182
6354
|
('O' <= c1 && c1 <= 'Q')) {
|
|
@@ -6190,53 +6362,53 @@ kanji_convert(FILE *f)
|
|
|
6190
6362
|
static const nkf_char jphone_emoji_first_table[7] =
|
|
6191
6363
|
{0xE1E0, 0xDFE0, 0xE2E0, 0xE3E0, 0xE4E0, 0xDFE0, 0xE0E0};
|
|
6192
6364
|
c3 = nkf_char_unicode_new(jphone_emoji_first_table[c1 % 7]);
|
|
6193
|
-
if ((c1 = (*i_getc)(f)) == EOF) LAST;
|
|
6365
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) LAST;
|
|
6194
6366
|
while (SP <= c1 && c1 <= 'z') {
|
|
6195
|
-
(*oconv)(0, c1 + c3);
|
|
6196
|
-
if ((c1 = (*i_getc)(f)) == EOF) LAST;
|
|
6367
|
+
(*oconv)(nkf_state, 0, c1 + c3);
|
|
6368
|
+
if ((c1 = (*i_getc)(nkf_state, f)) == EOF) LAST;
|
|
6197
6369
|
}
|
|
6198
6370
|
SKIP;
|
|
6199
6371
|
}
|
|
6200
6372
|
else {
|
|
6201
|
-
(*oconv)(0, ESC);
|
|
6202
|
-
(*oconv)(0, '$');
|
|
6373
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6374
|
+
(*oconv)(nkf_state, 0, '$');
|
|
6203
6375
|
SEND;
|
|
6204
6376
|
}
|
|
6205
6377
|
}
|
|
6206
6378
|
else {
|
|
6207
|
-
i_ungetc(c1,f);
|
|
6379
|
+
i_ungetc(nkf_state, c1,f);
|
|
6208
6380
|
/* lonely ESC */
|
|
6209
|
-
(*oconv)(0, ESC);
|
|
6381
|
+
(*oconv)(nkf_state, 0, ESC);
|
|
6210
6382
|
SKIP;
|
|
6211
6383
|
}
|
|
6212
6384
|
} else if (c1 == LF || c1 == CR) {
|
|
6213
6385
|
if (broken_f&4) {
|
|
6214
|
-
input_mode = ASCII; set_iconv(FALSE, 0);
|
|
6386
|
+
input_mode = ASCII; set_iconv(nkf_state, FALSE, 0);
|
|
6215
6387
|
SEND;
|
|
6216
6388
|
} else if (mime_decode_f && !mime_decode_mode){
|
|
6217
6389
|
if (c1 == LF) {
|
|
6218
|
-
if ((c1=(*i_getc)(f))!=EOF && c1 == SP) {
|
|
6219
|
-
i_ungetc(SP,f);
|
|
6390
|
+
if ((c1=(*i_getc)(nkf_state, f))!=EOF && c1 == SP) {
|
|
6391
|
+
i_ungetc(nkf_state, SP,f);
|
|
6220
6392
|
continue;
|
|
6221
6393
|
} else {
|
|
6222
|
-
i_ungetc(c1,f);
|
|
6394
|
+
i_ungetc(nkf_state, c1,f);
|
|
6223
6395
|
}
|
|
6224
6396
|
c1 = LF;
|
|
6225
6397
|
SEND;
|
|
6226
6398
|
} else { /* if (c1 == CR)*/
|
|
6227
|
-
if ((c1=(*i_getc)(f))!=EOF) {
|
|
6399
|
+
if ((c1=(*i_getc)(nkf_state, f))!=EOF) {
|
|
6228
6400
|
if (c1==SP) {
|
|
6229
|
-
i_ungetc(SP,f);
|
|
6401
|
+
i_ungetc(nkf_state, SP,f);
|
|
6230
6402
|
continue;
|
|
6231
|
-
} else if (c1 == LF && (c1=(*i_getc)(f))!=EOF && c1 == SP) {
|
|
6232
|
-
i_ungetc(SP,f);
|
|
6403
|
+
} else if (c1 == LF && (c1=(*i_getc)(nkf_state, f))!=EOF && c1 == SP) {
|
|
6404
|
+
i_ungetc(nkf_state, SP,f);
|
|
6233
6405
|
continue;
|
|
6234
6406
|
} else {
|
|
6235
|
-
i_ungetc(c1,f);
|
|
6407
|
+
i_ungetc(nkf_state, c1,f);
|
|
6236
6408
|
}
|
|
6237
|
-
i_ungetc(LF,f);
|
|
6409
|
+
i_ungetc(nkf_state, LF,f);
|
|
6238
6410
|
} else {
|
|
6239
|
-
i_ungetc(c1,f);
|
|
6411
|
+
i_ungetc(nkf_state, c1,f);
|
|
6240
6412
|
}
|
|
6241
6413
|
c1 = CR;
|
|
6242
6414
|
SEND;
|
|
@@ -6248,62 +6420,62 @@ kanji_convert(FILE *f)
|
|
|
6248
6420
|
/* send: */
|
|
6249
6421
|
switch(input_mode){
|
|
6250
6422
|
case ASCII:
|
|
6251
|
-
switch ((*iconv)(c2, c1, 0)) { /* can be EUC / SJIS / UTF-8 */
|
|
6423
|
+
switch ((*iconv)(nkf_state, c2, c1, 0)) { /* can be EUC / SJIS / UTF-8 */
|
|
6252
6424
|
case -2:
|
|
6253
6425
|
/* 4 bytes UTF-8 */
|
|
6254
|
-
if ((c3 = (*i_getc)(f)) != EOF) {
|
|
6255
|
-
code_status(c3);
|
|
6426
|
+
if ((c3 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6427
|
+
code_status(nkf_state, c3);
|
|
6256
6428
|
c3 <<= 8;
|
|
6257
|
-
if ((c4 = (*i_getc)(f)) != EOF) {
|
|
6258
|
-
code_status(c4);
|
|
6259
|
-
(*iconv)(c2, c1, c3|c4);
|
|
6429
|
+
if ((c4 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6430
|
+
code_status(nkf_state, c4);
|
|
6431
|
+
(*iconv)(nkf_state, c2, c1, c3|c4);
|
|
6260
6432
|
}
|
|
6261
6433
|
}
|
|
6262
6434
|
break;
|
|
6263
6435
|
case -3:
|
|
6264
6436
|
/* 4 bytes UTF-8 (check combining character) */
|
|
6265
|
-
if ((c3 = (*i_getc)(f)) != EOF) {
|
|
6266
|
-
if ((c4 = (*i_getc)(f)) != EOF) {
|
|
6267
|
-
if (w_iconv_combine(c2, c1, 0, c3, c4, 0)) {
|
|
6268
|
-
(*i_ungetc)(c4, f);
|
|
6269
|
-
(*i_ungetc)(c3, f);
|
|
6270
|
-
w_iconv_nocombine(c2, c1, 0);
|
|
6437
|
+
if ((c3 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6438
|
+
if ((c4 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6439
|
+
if (w_iconv_combine(nkf_state, c2, c1, 0, c3, c4, 0)) {
|
|
6440
|
+
(*i_ungetc)(nkf_state, c4, f);
|
|
6441
|
+
(*i_ungetc)(nkf_state, c3, f);
|
|
6442
|
+
w_iconv_nocombine(nkf_state, c2, c1, 0);
|
|
6271
6443
|
}
|
|
6272
6444
|
} else {
|
|
6273
|
-
(*i_ungetc)(c3, f);
|
|
6274
|
-
w_iconv_nocombine(c2, c1, 0);
|
|
6445
|
+
(*i_ungetc)(nkf_state, c3, f);
|
|
6446
|
+
w_iconv_nocombine(nkf_state, c2, c1, 0);
|
|
6275
6447
|
}
|
|
6276
6448
|
} else {
|
|
6277
|
-
w_iconv_nocombine(c2, c1, 0);
|
|
6449
|
+
w_iconv_nocombine(nkf_state, c2, c1, 0);
|
|
6278
6450
|
}
|
|
6279
6451
|
break;
|
|
6280
6452
|
case -1:
|
|
6281
6453
|
/* 3 bytes EUC or UTF-8 */
|
|
6282
|
-
if ((c3 = (*i_getc)(f)) != EOF) {
|
|
6283
|
-
code_status(c3);
|
|
6284
|
-
if ((*iconv)(c2, c1, c3) == -3) {
|
|
6454
|
+
if ((c3 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6455
|
+
code_status(nkf_state, c3);
|
|
6456
|
+
if ((*iconv)(nkf_state, c2, c1, c3) == -3) {
|
|
6285
6457
|
/* 6 bytes UTF-8 (check combining character) */
|
|
6286
6458
|
nkf_char c5, c6;
|
|
6287
|
-
if ((c4 = (*i_getc)(f)) != EOF) {
|
|
6288
|
-
if ((c5 = (*i_getc)(f)) != EOF) {
|
|
6289
|
-
if ((c6 = (*i_getc)(f)) != EOF) {
|
|
6290
|
-
if (w_iconv_combine(c2, c1, c3, c4, c5, c6)) {
|
|
6291
|
-
(*i_ungetc)(c6, f);
|
|
6292
|
-
(*i_ungetc)(c5, f);
|
|
6293
|
-
(*i_ungetc)(c4, f);
|
|
6294
|
-
w_iconv_nocombine(c2, c1, c3);
|
|
6459
|
+
if ((c4 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6460
|
+
if ((c5 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6461
|
+
if ((c6 = (*i_getc)(nkf_state, f)) != EOF) {
|
|
6462
|
+
if (w_iconv_combine(nkf_state, c2, c1, c3, c4, c5, c6)) {
|
|
6463
|
+
(*i_ungetc)(nkf_state, c6, f);
|
|
6464
|
+
(*i_ungetc)(nkf_state, c5, f);
|
|
6465
|
+
(*i_ungetc)(nkf_state, c4, f);
|
|
6466
|
+
w_iconv_nocombine(nkf_state, c2, c1, c3);
|
|
6295
6467
|
}
|
|
6296
6468
|
} else {
|
|
6297
|
-
(*i_ungetc)(c5, f);
|
|
6298
|
-
(*i_ungetc)(c4, f);
|
|
6299
|
-
w_iconv_nocombine(c2, c1, c3);
|
|
6469
|
+
(*i_ungetc)(nkf_state, c5, f);
|
|
6470
|
+
(*i_ungetc)(nkf_state, c4, f);
|
|
6471
|
+
w_iconv_nocombine(nkf_state, c2, c1, c3);
|
|
6300
6472
|
}
|
|
6301
6473
|
} else {
|
|
6302
|
-
(*i_ungetc)(c4, f);
|
|
6303
|
-
w_iconv_nocombine(c2, c1, c3);
|
|
6474
|
+
(*i_ungetc)(nkf_state, c4, f);
|
|
6475
|
+
w_iconv_nocombine(nkf_state, c2, c1, c3);
|
|
6304
6476
|
}
|
|
6305
6477
|
} else {
|
|
6306
|
-
w_iconv_nocombine(c2, c1, c3);
|
|
6478
|
+
w_iconv_nocombine(nkf_state, c2, c1, c3);
|
|
6307
6479
|
}
|
|
6308
6480
|
}
|
|
6309
6481
|
}
|
|
@@ -6319,18 +6491,18 @@ kanji_convert(FILE *f)
|
|
|
6319
6491
|
c1 = nkf_char_unicode_new((c2 - 0x7F) * 94 + c1 - 0x21 + 0xE000);
|
|
6320
6492
|
c2 = 0;
|
|
6321
6493
|
}
|
|
6322
|
-
(*oconv)(c2, c1); /* this is JIS, not SJIS/EUC case */
|
|
6494
|
+
(*oconv)(nkf_state, c2, c1); /* this is JIS, not SJIS/EUC case */
|
|
6323
6495
|
break;
|
|
6324
6496
|
#ifdef X0212_ENABLE
|
|
6325
6497
|
case JIS_X_0212:
|
|
6326
|
-
(*oconv)(PREFIX_EUCG3 | c2, c1);
|
|
6498
|
+
(*oconv)(nkf_state, PREFIX_EUCG3 | c2, c1);
|
|
6327
6499
|
break;
|
|
6328
6500
|
#endif /* X0212_ENABLE */
|
|
6329
6501
|
case JIS_X_0213_2:
|
|
6330
|
-
(*oconv)(PREFIX_EUCG3 | c2, c1);
|
|
6502
|
+
(*oconv)(nkf_state, PREFIX_EUCG3 | c2, c1);
|
|
6331
6503
|
break;
|
|
6332
6504
|
default:
|
|
6333
|
-
(*oconv)(input_mode, c1); /* other special case */
|
|
6505
|
+
(*oconv)(nkf_state, input_mode, c1); /* other special case */
|
|
6334
6506
|
}
|
|
6335
6507
|
|
|
6336
6508
|
c2 = 0;
|
|
@@ -6341,7 +6513,7 @@ kanji_convert(FILE *f)
|
|
|
6341
6513
|
|
|
6342
6514
|
finished:
|
|
6343
6515
|
/* epilogue */
|
|
6344
|
-
(*iconv)(EOF, 0, 0);
|
|
6516
|
+
(*iconv)(nkf_state, EOF, 0, 0);
|
|
6345
6517
|
if (!input_codename)
|
|
6346
6518
|
{
|
|
6347
6519
|
if (is_8bit) {
|
|
@@ -6351,9 +6523,9 @@ finished:
|
|
|
6351
6523
|
if (p->score < result->score) result = p;
|
|
6352
6524
|
++p;
|
|
6353
6525
|
}
|
|
6354
|
-
set_input_codename(result->name);
|
|
6526
|
+
set_input_codename(nkf_state, result->name);
|
|
6355
6527
|
#ifdef CHECK_OPTION
|
|
6356
|
-
debug(result->name);
|
|
6528
|
+
debug(nkf_state, result->name);
|
|
6357
6529
|
#endif
|
|
6358
6530
|
}
|
|
6359
6531
|
}
|
|
@@ -6368,7 +6540,7 @@ finished:
|
|
|
6368
6540
|
* -1: ArgumentError
|
|
6369
6541
|
*/
|
|
6370
6542
|
static int
|
|
6371
|
-
options(unsigned char *cp)
|
|
6543
|
+
options(nkf_state_t *nkf_state, unsigned char *cp)
|
|
6372
6544
|
{
|
|
6373
6545
|
nkf_char i, j;
|
|
6374
6546
|
unsigned char *p;
|
|
@@ -6593,7 +6765,7 @@ options(unsigned char *cp)
|
|
|
6593
6765
|
unicode_subchar += hex2bin(p[i]);
|
|
6594
6766
|
}
|
|
6595
6767
|
}
|
|
6596
|
-
w16e_conv(unicode_subchar, &i, &j);
|
|
6768
|
+
w16e_conv(nkf_state, unicode_subchar, &i, &j);
|
|
6597
6769
|
unicode_subchar = i<<8 | j;
|
|
6598
6770
|
continue;
|
|
6599
6771
|
}
|
|
@@ -6933,6 +7105,8 @@ options(unsigned char *cp)
|
|
|
6933
7105
|
int
|
|
6934
7106
|
main(int argc, char **argv)
|
|
6935
7107
|
{
|
|
7108
|
+
nkf_state_t nkf_state_object = {0};
|
|
7109
|
+
nkf_state_t *nkf_state = &nkf_state_object;
|
|
6936
7110
|
FILE *fin;
|
|
6937
7111
|
unsigned char *cp;
|
|
6938
7112
|
|
|
@@ -6945,11 +7119,11 @@ main(int argc, char **argv)
|
|
|
6945
7119
|
#ifdef DEFAULT_CODE_LOCALE
|
|
6946
7120
|
setlocale(LC_CTYPE, "");
|
|
6947
7121
|
#endif
|
|
6948
|
-
nkf_state_init();
|
|
7122
|
+
nkf_state_init(nkf_state);
|
|
6949
7123
|
|
|
6950
7124
|
for (argc--,argv++; (argc > 0) && **argv == '-'; argc--, argv++) {
|
|
6951
7125
|
cp = (unsigned char *)*argv;
|
|
6952
|
-
options(cp);
|
|
7126
|
+
options(nkf_state, cp);
|
|
6953
7127
|
#ifdef EXEC_IO
|
|
6954
7128
|
if (exec_f){
|
|
6955
7129
|
int fds[2], pid;
|
|
@@ -6991,7 +7165,7 @@ main(int argc, char **argv)
|
|
|
6991
7165
|
#endif
|
|
6992
7166
|
int x0213_f_back = x0213_f;
|
|
6993
7167
|
int guess_f_back = guess_f;
|
|
6994
|
-
reinit();
|
|
7168
|
+
reinit(nkf_state);
|
|
6995
7169
|
guess_f = guess_f_back;
|
|
6996
7170
|
mime_f = FALSE;
|
|
6997
7171
|
#ifdef CHECK_OPTION
|
|
@@ -7026,10 +7200,10 @@ main(int argc, char **argv)
|
|
|
7026
7200
|
#endif
|
|
7027
7201
|
setvbuffer(stdin, (char *) stdibuf, IOBUF_SIZE);
|
|
7028
7202
|
if (nop_f)
|
|
7029
|
-
noconvert(stdin);
|
|
7203
|
+
noconvert(nkf_state, stdin);
|
|
7030
7204
|
else {
|
|
7031
|
-
kanji_convert(stdin);
|
|
7032
|
-
if (guess_f) print_guessed_code(NULL);
|
|
7205
|
+
kanji_convert(nkf_state, stdin);
|
|
7206
|
+
if (guess_f) print_guessed_code(nkf_state, NULL);
|
|
7033
7207
|
}
|
|
7034
7208
|
} else {
|
|
7035
7209
|
int nfiles = argc;
|
|
@@ -7115,12 +7289,12 @@ main(int argc, char **argv)
|
|
|
7115
7289
|
#endif
|
|
7116
7290
|
setvbuffer(fin, (char *) stdibuf, IOBUF_SIZE);
|
|
7117
7291
|
if (nop_f)
|
|
7118
|
-
noconvert(fin);
|
|
7292
|
+
noconvert(nkf_state, fin);
|
|
7119
7293
|
else {
|
|
7120
7294
|
char *filename = NULL;
|
|
7121
|
-
kanji_convert(fin);
|
|
7295
|
+
kanji_convert(nkf_state, fin);
|
|
7122
7296
|
if (nfiles > 1) filename = origfname;
|
|
7123
|
-
if (guess_f) print_guessed_code(filename);
|
|
7297
|
+
if (guess_f) print_guessed_code(nkf_state, filename);
|
|
7124
7298
|
}
|
|
7125
7299
|
fclose(fin);
|
|
7126
7300
|
#ifdef OVERWRITE
|