-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkanji.c
executable file
·2073 lines (1960 loc) · 45.6 KB
/
kanji.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $Id: kanji.c,v 1.12 2001/04/15 16:35:44 amura Exp $ */
/*
* Kanji handling routines.
* These are only used when KANJI is #defined.
*
* Coded by Shigeki Yoshida ([email protected])
*/
/*
* $Log: kanji.c,v $
* Revision 1.12 2001/04/15 16:35:44 amura
* patch for VC 6.0 from Katsuyoshi Ohara
*
* Revision 1.11 2001/02/18 17:07:25 amura
* append AUTOSAVE feature (but NOW not work)
*
* Revision 1.10 2001/02/11 15:40:25 amura
* some function are changed to static for speed/size
*
* Revision 1.9 2001/01/20 15:49:36 amura
* move TOUFU charactor to kinit.h
*
* Revision 1.8 2001/01/11 13:15:17 amura
* add Shift-JIS toufu charactor
*
* Revision 1.7 2001/01/05 14:07:03 amura
* first implementation of Hojo Kanji support
*
* Revision 1.6 2000/12/18 17:17:41 amura
* fix dropped NINPUT
*
* Revision 1.5 2000/12/14 18:12:14 amura
* use alloca() and more memory secure
*
* Revision 1.4 2000/11/16 14:31:12 amura
* fix some typos which cause compile error when using
* strict ANSI-C compiler (ex ACK, gcc-1.x)
*
* Revision 1.3 2000/09/21 17:28:30 amura
* replace macro _WIN32 to WIN32 for Cygwin
*
* Revision 1.2 2000/06/29 17:52:56 amura
* enable VTCURSOR all input kanji code
*
* Revision 1.1.1.1 2000/06/27 01:47:55 amura
* import to CVS
*
*/
/* 90.01.29 Created by S.Yoshida */
#include "config.h" /* 90.12.20 by S.Yoshida */
#ifdef KANJI /* 90.01.29 by S.Yoshida */
#include "def.h"
#include "kinit.h"
int global_kfio = KFIO; /* default-kanji-fileio-code */
int global_kexpect = KEXPECT; /* kanji-expected-code */
int global_kinput = KINPUT; /* kanji-input-code */
int global_kdisplay = KDISPLAY; /* kanji-display-code */
static int to_k_fio = TO_KFIO; /* to-kanji-fileio */
static int to_a_fio = TO_AFIO; /* to-ascii-fileio */
static int to_k_display = TO_KDISPLAY; /* to-kanji-display */
static int to_a_display = TO_ADISPLAY; /* to-ascii-display */
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
static int to_kana_fio = TO_KANAFIO; /* to-kana-fileio */
static int to_kana_display = TO_KANADISPLAY; /* to-kana-display */
#endif /* HANKANA */
static int local_kfin; /* Buffer local file input code. */
static char symbol_c[] = {'N', 'S', 'J', 'E', 'W', '-', 'T'};
static char *symbol_s[] = {"No-conversion", "Shift-JIS", "JIS", "EUC", "UTF-8", "NIL", "T"};
/* Symbol chars & strings to */
/* display a KANJI code info to */
/* the user. This order depend */
/* on the values of KANJI code */
/* macro defined at def.h. */
static char *kcodename_u[] = {"NOCONV", "SHIFT-JIS", "JIS", "EUC", "UTF-8", "NIL", "T"};
static char *kcodename_l[] = {"noconv", "shift-jis", "jis", "euc", "utf-8", "nil", "t"};
#define NKCODENAME 6
/* The strings of KANJI code */
/* name and the numner of KANJI */
/* code to determine what KANJI */
/* code the user want to use. */
/* This order depend on the */
/* values of KANJI code macro */
/* defined at def.h. */
#define ESC CCHR('[') /* Escape char. */
#define issjis1st(c) (((c) >= 0x81 && (c) <= 0x9f) || \
((c) >= 0xe0 && (c) <= 0xfc))
#define iseuc1st(c) ((c) >= 0xa1 && (c) <= 0xfe)
#define isutf81st(c) ((c) >= 0xc0)
#ifdef HANKANA
#define iskana(c) ((c) >= 0xa0 && (c) < 0xe0)
#endif
#define UCS_NULL 0xfeff
#include "UCS2JIS.i"
#include "JIS2UCS.i"
static inline unsigned short _UTF8toUCS(const char utf8[])
{
unsigned short c = 255 & utf8[0];
if (c < 128)
return c;
if (!(c & 64)) /* [1] or [2] */
return UCS_NULL;
if (!(c & 32)) /* [0][1] */
return ((31 & c) << 6) | (63 & utf8[1]);
if (!(c & 16)) /* [0][1][2] */
return ((15 & c) << 12) | ((63 & utf8[1]) << 6) | (63 & utf8[2]);
return UCS_NULL;
}
static inline int _UCStoUTF8(unsigned short ucs, char utf8[])
{
if (ucs == UCS_NULL)
return 0;
if (ucs < 128) {
utf8[0] = (char)ucs;
return 1;
}
if (ucs < 2048) {
utf8[0] = (char)(0xc0 | (ucs >> 6));
utf8[1] = (char)(0x80 | (63 & ucs));
return 2;
}
utf8[0] = (char)(0xe0 | (ucs >> 12));
utf8[1] = (char)(0x80 | (63 & (ucs >> 6)));
utf8[2] = (char)(0x80 | (63 & ucs));
return 3;
}
static inline unsigned short _EUCtoUCS(const char euc[])
{
int c = 255 & euc[0];
switch (c) {
case 0x8e:
return JIS2UCS[255 & euc[1]];
case 0x8f:
return JIS2UCS[0x8000 | (((127 & euc[1]) << 8) | (127 & euc[2]))];
default:
if (c >= 128)
c = ((127 & c) << 8) | (127 & euc[1]);
return JIS2UCS[c];
}
}
static inline int _UCStoEUC(unsigned short ucs, char euc[])
{
int e = UCS2JIS[ucs];
if (e == UCS_NULL)
return 0;
if (e < 128) {
euc[0] = (char)e;
return 1;
}
if (e < 256) {
euc[0] = (char)0x8e;
euc[1] = (char)e;
return 2;
}
if (e < 0x8000) {
euc[0] = (char)(0x80 | (e >> 8));
euc[1] = (char)(0x80 | e);
return 2;
}
euc[0] = (char)0x8f;
euc[1] = (char)(e >> 8);
euc[2] = (char)(0x80 | e);
return 3;
}
/* 90.07.25 Change to inline routine by S.Yoshida (from) */
#define jtoe(c1, c2) {c1 |= 0x80; c2 |= 0x80;}
#define etoj(c1, c2) {c1 &= 0x7f; c2 &= 0x7f;}
#define stoe(c1, c2) \
{\
if (c1 >=0xe0)\
c1 -= 0x40;\
if (c2 >= 0x9f) {\
c1 = (c1 - 0x88) * 2 + 0xb0;\
c2 += 0x02;\
} else {\
if (c2 >= 0x7f)\
c2 -= 0x01;\
c1 = (c1 - 0x89) * 2 + 0xb1;\
c2 = c2 + 0x61;\
}\
}
#define etos(c1, c2) \
{\
c1 &= 0x7f;\
c2 &= 0x7f;\
if(c1 >= 0x5f)\
c1 += 0x80;\
if((c1 % 2) == 0) {\
c1 = (c1 - 0x30) / 2 + 0x88;\
c2 += 0x7e;\
} else {\
if(c2 >= 0x60)\
c2 += 0x01;\
c1 = (c1 - 0x31) / 2 + 0x89;\
c2 += 0x1f;\
}\
c1 &= 0xff;\
c2 &= 0xff;\
}
/* 90.07.25 Change to inline routine by S.Yoshida (to) */
#define CAT_NONE 0 /* Category: No category. */
#define CAT_ASCII 1 /* Category: ASCII code char. */
#define CAT_KIGOU 2 /* Category: JIS KIGOU char. */
#define CAT_EISUUJI 3 /* Category: JIS EI-SUUJI char. */
#define CAT_HIRAGANA 4 /* Category: HIRAGANA char. */
#define CAT_KATAKANA 5 /* Category: KATAKANA char. */
#define CAT_GREEK 6 /* Category: JIS GREEK char. */
#define CAT_RUSSIAN 7 /* Category: JIS RUSSIAN char. */
#define CAT_KANJI 8 /* Category: KANJI char. */
/* prototype for static routines */
static int kcodenumber pro((int *code, int num));
static int kanalastchar pro((int *lastch));
static int klastchar pro((int *lastch, int kselect));
static int kcodecheck pro((char *p, int len));
static int bufjtoe_c pro((char *j, int len));
int bufstoe_c pro((char *p, int len));
/*
* COMMAND: change-default-fileio-code
* This is a command processor for changing the value of the global
* file I/O KANJI code. When this function is called, the value is
* changed rotaly. (NIL -> NOCONV -> SJIS -> JIS -> EUC -> UTF-8)
*/
/*ARGSUSED*/
k_rot_fio(f, n)
{
if (global_kfio == NIL) {
global_kfio = NOCONV;
} else if (global_kfio == NOCONV) {
global_kfio = SJIS;
} else if (global_kfio == SJIS) {
global_kfio = JIS;
} else if (global_kfio == JIS) {
global_kfio = EUC;
} else if (global_kfio == EUC) {
global_kfio = UTF8;
} else if (global_kfio == UTF8) {
global_kfio = NIL;
}
return TRUE;
}
/*
* COMMAND: set-default-fileio-code
* This is a command processor for setting the value of the global
* file I/O KANJI code.
*/
/*ARGSUSED*/
k_set_fio(f, n)
{
register int s;
if (f & FFARG) {
if (n >= 0 && n < NKCODENAME - 1) {
global_kfio = n;
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = kcodenumber(&n, NKCODENAME - 1)) == TRUE) {
global_kfio = n;
}
return (s);
}
/*
* COMMAND: change-fileio-code
* This is a command processor for changing the value of the buffer
* local file I/O KANJI code. When this function is called, the value
* is changed rotaly. (NIL -> NOCONV -> SJIS -> JIS -> EUC -> UTF-8)
*/
/*ARGSUSED*/
k_rot_buffio(f, n)
{
if (curbp->b_kfio == NIL) {
curbp->b_kfio = NOCONV;
} else if (curbp->b_kfio == NOCONV) {
curbp->b_kfio = SJIS;
} else if (curbp->b_kfio == SJIS) {
curbp->b_kfio = JIS;
} else if (curbp->b_kfio == JIS) {
curbp->b_kfio = EUC;
} else if (curbp->b_kfio == EUC) {
curbp->b_kfio = UTF8;
} else if (curbp->b_kfio == UTF8) {
curbp->b_kfio = NIL;
}
upmodes(curbp); /* Only update cur-buf's modeline. */
return TRUE;
}
/*
* COMMAND: set-kanji-fileio-code
* This is a command processor for setting the value of the buffer
* local file I/O KANJI code.
*/
/*ARGSUSED*/
k_set_buffio(f, n)
{
register int s;
if (f & FFARG) {
if (n > 0 && n < NKCODENAME - 1) {
curbp->b_kfio = n;
upmodes(curbp); /* Only update cur-buf's modeline. */
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = kcodenumber(&n, NKCODENAME - 1)) == TRUE) {
curbp->b_kfio = n;
upmodes(curbp); /* Only update cur-buf's modeline. */
}
return (s);
}
/*
* COMMAND: set-kanji-expected-code
* This is a command processor for setting the value of the global
* expected file input KANJI code.
*/
/*ARGSUSED*/
k_set_expect(f, n)
{
register int s;
if (f & FFARG) {
if (n > 0 && n < NKCODENAME) {
global_kexpect = n;
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = kcodenumber(&n, NKCODENAME)) == TRUE) {
global_kexpect = n;
}
return (s);
}
/*
* COMMAND: change-input-code
* This is a command processor for changing the value of the global
* keyboard input KANJI code. When this function is called, the value
* is changed rotaly. (NOCONV -> SJIS -> JIS -> EUC -> UTF8)
*/
/*ARGSUSED*/
k_rot_input(f, n)
{
if (global_kinput == NOCONV) {
global_kinput = SJIS;
} else if (global_kinput == SJIS) {
global_kinput = JIS;
} else if (global_kinput == JIS) {
global_kinput = EUC;
} else if (global_kinput == EUC) {
global_kinput = UTF8;
} else if (global_kinput == UTF8) {
global_kinput = NOCONV;
}
upmodes(NULL); /* Update each win's modeline. */
return TRUE;
}
/*
* COMMAND: set-kanji-input-code
* This is a command processor for setting the value of the global
* keyboard input KANJI code.
*/
/*ARGSUSED*/
k_set_input(f, n)
{
register int s;
if (f & FFARG) {
if (n > 0 && n < NKCODENAME - 1) {
global_kinput = n;
upmodes(NULL); /* Update each win's modeline. */
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = kcodenumber(&n, NKCODENAME - 1)) == TRUE) {
global_kinput = n;
upmodes(NULL); /* Update each win's modeline. */
}
return (s);
}
/*
* COMMAND: change-display-code
* This is a command processor for changing the value of the global
* display KANJI code. When this function is called, the value is
* changed rotaly. (NOCONV -> SJIS -> JIS -> EUC -> UTF8)
*/
/*ARGSUSED*/
k_rot_display(f, n)
{
if (global_kdisplay == NOCONV) {
global_kdisplay = SJIS;
} else if (global_kdisplay == SJIS) {
global_kdisplay = JIS;
} else if (global_kdisplay == JIS) {
global_kdisplay = EUC;
} else if (global_kdisplay == EUC) {
global_kdisplay = UTF8;
} else if (global_kdisplay == UTF8) {
global_kdisplay = NOCONV;
}
sgarbf = TRUE; /* Must update full screen. */
return TRUE;
}
/*
* COMMAND: set-kanji-display-code
* This is a command processor for setting the value of the global
* display KANJI code.
*/
/*ARGSUSED*/
k_set_display(f, n)
{
register int s;
if (f & FFARG) {
if (n > 0 && n < NKCODENAME - 1) {
global_kdisplay = n;
sgarbf = TRUE; /* Must update full screen. */
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = kcodenumber(&n, NKCODENAME - 1)) == TRUE) {
global_kdisplay = n;
sgarbf = TRUE; /* Must update full screen. */
}
return (s);
}
/*
* COMMAND: list-kanji-code
* Display a list of kanji-code related valiables in the *Kanji Codes*
* buffer.
*/
/*ARGSUSED*/
k_list_code(f, n)
{
register BUFFER *bp;
register WINDOW *wp;
char line[80];
if ((bp = bfind("*Kanji Codes*", TRUE)) == NULL) return FALSE;
#ifdef AUTOSAVE /* 96.12.24 by M.Suzuki */
bp->b_flag &= ~(BFCHG | BFACHG); /* Blow away old. */
#else
bp->b_flag &= ~BFCHG; /* Blow away old. */
#endif /* AUTOSAVE */
if (bclear(bp) != TRUE) return FALSE;
strcpy(line, "* List of kanji-code related variables *");
if (addline(bp, line) == FALSE) return FALSE;
strcpy(line, "Global variables:");
if (addline(bp, line) == FALSE) return FALSE;
sprintf(line, "\tdefault-kanji-fileio-code : %s",
symbol_s[global_kfio]);
if (addline(bp, line) == FALSE) return FALSE;
sprintf(line, "\tkanji-expected-code : %s",
symbol_s[global_kexpect]);
if (addline(bp, line) == FALSE) return FALSE;
sprintf(line, "\tkanji-display-code : %s",
symbol_s[global_kdisplay]);
if (addline(bp, line) == FALSE) return FALSE;
sprintf(line, "\tkanji-input-code : %s",
symbol_s[global_kinput]);
if (addline(bp, line) == FALSE) return FALSE;
if (curbp->b_kfio == JIS ||
global_kfio == JIS || global_kdisplay == JIS) {
sprintf(line, "\tto-kanji-fileio : %d (%c)",
to_k_fio, to_k_fio);
if (addline(bp, line) == FALSE) return FALSE;
sprintf(line, "\tto-ascii-fileio : %d (%c)",
to_a_fio, to_a_fio);
if (addline(bp, line) == FALSE) return FALSE;
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
sprintf(line, "\tto-kana-fileio : %d (%c)",
to_kana_fio, to_kana_fio);
if (addline(bp, line) == FALSE) return FALSE;
#endif /* HANKANA */
sprintf(line, "\tto-kanji-display : %d (%c)",
to_k_display, to_k_display);
if (addline(bp, line) == FALSE) return FALSE;
sprintf(line, "\tto-ascii-display : %d (%c)",
to_a_display, to_a_display);
if (addline(bp, line) == FALSE) return FALSE;
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
sprintf(line, "\tto-kana-display : %d (%c)",
to_kana_display, to_kana_display);
if (addline(bp, line) == FALSE) return FALSE;
#endif /* HANKANA */
}
strcpy(line, "Buffer local variable:");
if (addline(bp, line) == FALSE) return FALSE;
sprintf(line, "\tkanji-fileio-code : %s",
symbol_s[curbp->b_kfio]);
if (addline(bp, line) == FALSE) return FALSE;
if ((wp = popbuf(bp)) == NULL) return FALSE;
bp->b_dotp = lforw(bp->b_linep); /* put dot at beginning of buffer */
bp->b_doto = 0;
wp->w_dotp = bp->b_dotp; /* fix up if window already on screen */
wp->w_doto = bp->b_doto;
return TRUE;
}
/*
* COMMAND: list-kanji-code-briefly
* Display a list of values of kanji-code related valiables in the
* mini buffer.
*/
/*ARGSUSED*/
k_show_code(f, n)
{
char buf[80];
char *bp;
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
sprintf(buf, "global:[FID=%c%c%c] local:[F=%c] expected:[E=%c]",
#else /* not HANKANA */
sprintf(buf, "global: [FID=%c%c%c] local: [F=%c] expected: [E=%c]",
#endif /* HANKANA */
symbol_c[global_kfio],
symbol_c[global_kinput],
symbol_c[global_kdisplay],
symbol_c[curbp->b_kfio],
symbol_c[global_kexpect]);
if (curbp->b_kfio == JIS ||
global_kfio == JIS || global_kdisplay == JIS) {
bp = buf + strlen(buf);
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
sprintf(bp,
" K:[FD=%c%c] A:[FD=%c%c] KANA:[FD=%c%c]",
to_k_fio, to_k_display, to_a_fio, to_a_display,
to_kana_fio, to_kana_display);
#else /* not HANKANA */
sprintf(bp, " Ksel: [FD=%c%c] Asel: [FD=%c%c]",
to_k_fio, to_k_display, to_a_fio, to_a_display);
#endif /* HANKANA */
}
ewprintf(buf);
return TRUE;
}
/*
* COMMAND: set-to-kanji-fileio
* This is a command processor for setting the value of the global
* KANJI select char for a file.
*/
/*ARGSUSED*/
k_set_tokfio(f, n)
{
int s;
if (f & FFARG) {
if (n == '@' || n == 'B') {
to_k_fio = n;
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = klastchar(&n, TRUE)) == TRUE) {
to_k_fio = n;
}
return (s);
}
/*
* COMMAND: set-to-ascii-fileio
* This is a command processor for setting the value of the global
* ASCII select char for a file.
*/
/*ARGSUSED*/
k_set_toafio(f, n)
{
register int s;
if (f & FFARG) {
if (n == 'B' || n == 'J' || n == 'H') {
to_a_fio = n;
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = klastchar(&n, FALSE)) == TRUE) {
to_a_fio = n;
}
return (s);
}
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
/*
* COMMAND: set-to-kana-fileio
* This is a command processor for setting the value of the global
* KANA select char for a file.
*/
/*ARGSUSED*/
k_set_tokanafio(f, n)
{
register int s;
if (f & FFARG) {
if (n == '7' || n == '8' || n == 'I') {
to_kana_fio = n;
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = kanalastchar(&n)) == TRUE) {
to_kana_fio = n;
}
return (s);
}
/*
* COMMAND: set-to-kana-display
* This is a command processor for setting the value of the global
* KANA select char for a display.
*/
/*ARGSUSED*/
k_set_tokanadisplay(f, n)
{
int s;
if (f & FFARG) {
if (n == '7' || n == '8' || n == 'I') {
to_kana_fio = n;
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = kanalastchar(&n)) == TRUE) {
to_kana_display = n;
}
return (s);
}
#endif /* HANKANA */
/*
* COMMAND: set-to-kanji-display
* This is a command processor for setting the value of the global
* KANJI select char for a display.
*/
/*ARGSUSED*/
k_set_tokdisplay(f, n)
{
int s;
if (f & FFARG) {
if (n == '@' || n == 'B') {
to_k_fio = n;
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = klastchar(&n, TRUE)) == TRUE) {
to_k_display = n;
}
return (s);
}
/*
* COMMAND: set-to-ascii-display
* This is a command processor for setting the value of the global
* ASCII select char for a display.
*/
/*ARGSUSED*/
k_set_toadisplay(f, n)
{
int s;
if (f & FFARG) {
if (n == 'B' || n == 'J' || n == 'H') {
to_a_fio = n;
s = TRUE;
} else {
s = FALSE;
}
} else if ((s = klastchar(&n, FALSE)) == TRUE) {
to_a_display = n;
}
return (s);
}
/*
* Select target KANJI code and return its inner number.
*/
static int
kcodenumber(code, num)
int *code;
int num;
{
register int s;
register int i;
register int n;
char kcode[NINPUT];
for (n = 0; n < 2; n++) {
if ((s = ereply("Kanji Code System : ", kcode, sizeof(kcode))) != TRUE) {
return (s);
}
if (ISDIGIT(kcode[0])) {
if ((i = atoi(kcode)) >= 0 && i < num) {
*code = i;
return TRUE;
}
} else {
for (i = 0; i < num; i++) {
if (strcmp(kcodename_u[i], kcode) == 0 ||
strcmp(kcodename_l[i], kcode) == 0) {
*code = i;
return TRUE;
}
}
}
}
return FALSE;
}
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
/*
* Input last char of the KANA code select escape sequence,
* and return its value.
*/
static int
kanalastchar(lastch)
int *lastch;
{
register int s;
register int i;
register char *p = "KANA Select Char [78I] : ";
register int n;
char lchar[NINPUT];
for (n = 0; n < 2; n++) {
if ((s = ereply(p, lchar, sizeof(lchar))) != TRUE) {
return (s);
}
if (ISDIGIT(lchar[0])) {
i = atoi(lchar);
if (i==7) i='7';
if (i==8) i='8';
} else {
i = lchar[0];
}
if (i == '7' || i == '8' || i == 'I') {
*lastch = i;
return TRUE;
}
}
return FALSE;
}
#endif /* HANKANA */
/*
* Input last char of the KANJI/ASCII code select escape sequence,
* and return its value. KANJI select char is input when kselect
* is TRUE, othewise ASCII select char is input.
*/
static int
klastchar(lastch, kselect)
int *lastch;
int kselect;
{
register int s;
register int i;
register char *p = kselect ? "KANJI Select Char [@B] : " :
"ASCII Select Char [BHJ] : ";
register int n;
char lchar[NINPUT];
for (n = 0; n < 2; n++) {
if ((s = ereply(p, lchar, sizeof(lchar))) != TRUE) {
return (s);
}
if (ISDIGIT(lchar[0])) {
i = atoi(lchar);
} else {
i = lchar[0];
}
if ((kselect && (i == '@' || i == 'B')) ||
(!kselect && (i == 'B' || i == 'J' || i == 'H'))) {
*lastch = i;
return TRUE;
}
}
return FALSE;
}
/*
* Set the buffer local file I/O code when buffer is created.
*/
VOID
ksetbufcode(bp)
BUFFER *bp;
{
bp->b_kfio = global_kfio;
}
/*
* Show file I/O, input, display KANJI code into mode line.
*/
kdispbufcode(bp)
register BUFFER *bp;
{
register int n = 0;
/* 90.12.28 Change display style like as Nemacs 3.3. by S.Yoshida */
vtputc(symbol_c[bp->b_kfio]); n++;
vtputc(symbol_c[global_kinput]); n++;
vtputc(symbol_c[global_kdisplay]); n++;
vtputc(':'); n++;
return (n);
}
/*
* Input one byte from the keyboard with KANJI code conversion.
*/
#define SELROMA 0
#define SELKANJI 1
#define SELKANA 2
#define SELHOJO 3
static int kgetkey_more = FALSE;
#ifdef HOJO_KANJI
static int hojo1st = '\0';
#endif
VOID
kgetkeyflush()
{
kgetkey_more = FALSE;
#ifdef HOJO_KANJI
hojo1st = '\0';
#endif
}
kgetkey()
{
static int kselected = SELROMA;
static int savedchar = '\0'; /* 91.01.15 NULL -> '\0' */
register int c1, c2; /* 90.07.25 Add "register". */
/* by S.Yoshida */
#ifdef HOJO_KANJI
if (hojo1st != '\0') {
c1 = hojo1st;
hojo1st = '\0';
return c1;
}
#endif
if (kgetkey_more) {
kgetkey_more = FALSE;
return (savedchar);
}
reinput:
c1 = getkbd();
/*
* If you enable next codes, you cannot input C-n,C-o in JIS input mode.
* I think this state you don't want to, I disable these.
* 27 mar 2000, amura
*/
#ifdef notdef /* HANKANA /* 92.11.21 by S.Sasaki */
if (global_kinput == JIS && c1 == 0x0e) {
kselected = SELKANA;
goto reinput;
}
if (global_kinput == JIS && c1 == 0x0f) {
kselected = SELROMA;
goto reinput;
}
#endif /* HANKANA */
if (global_kinput == JIS && c1 == ESC) {
if ((c1 = getkbd()) == '$') {
if ((c2 = getkbd()) == '@' || c2 == 'B') {
kselected = SELKANJI;
goto reinput;
#ifdef HOJO_KANJI
} else if (c2 == '(') {
if ((c1 = getkbd()) == 'D') {
kselected = SELHOJO;
goto reinput;
}
else {
ungetkbd(c1);
ungetkbd(c2);
ungetkbd('$');
c1 = ESC;
}
#endif
} else {
ungetkbd(c2);
ungetkbd(c1);
c1 = ESC;
}
} else if (c1 == '(') {
if ((c2 = getkbd()) == 'B' || c2 == 'J' || c2 == 'H') {
kselected = SELROMA;
/* When typeahead() is TRUE, update() */
/* isn't done. So, sometimes a input */
/* strings isn't displayed with JIS */
/* code input. To display the input */
/* strings certainly, do update() when */
/* ASCII select sequence has come. */
update();
goto reinput;
} else {
ungetkbd(c2);
ungetkbd(c1);
c1 = ESC;
}
#ifdef VTCURSOR /* 92.03.16 by Gen KUROKI, renamed by amura */
} else if (c1 == 'O' || c1 == '[') {
c2 = getkbd();
switch (c2) {
case 'A': c1 = CCHR('P'); break;
case 'B': c1 = CCHR('N'); break;
case 'C': c1 = CCHR('F'); break;
case 'D': c1 = CCHR('B'); break;
default:
ungetkbd(c2);
ungetkbd(c1);
c1 = ESC;
break;
}
#endif /* VTCURSOR */
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
} else if (c1 == '(') {
if ((c2 = getkbd()) == 'I' ) {
kselected = SELKANA;
goto reinput;
} else {
ungetkbd(c2);
ungetkbd(c1);
c1 = ESC;
}
#endif /* HANKANA */
} else {
#ifdef JISFIX /* 92.03.16 by Gen KUROKI */
savedchar = c1;
kgetkey_more = TRUE;
#else /* not JISFIX */
ungetkbd(c1);
#endif /* JISFIX */
c1 = ESC;
}
#ifdef JISFIX /* 92.03.16 by Gen KUROKI */
} else if (global_kinput == JIS && c1 == 0xff ) {
c1 = 0x7f;
#endif /* JISFIX */
} else if (global_kinput == JIS && kselected == SELKANJI) {
#ifdef JISFIX /* 92.03.16 by Gen KUROKI */
c1 &= 0x7f;
if (!ISCTRL(c1)) {
#endif /* JISFIX */
c2 = getkbd();
jtoe(c1, c2);
savedchar = c2;
kgetkey_more = TRUE;
#ifdef JISFIX /* 92.03.16 by Gen KUROKI */
}
#endif /* JISFIX */
#ifdef HOJO_KANJI
} else if (global_kinput == JIS && kselected == SELHOJO) {
c1 &= 0x7f;
c2 = getkbd();
jtoe(c1, c2);
hojo1st = c1;
savedchar = c2;
kgetkey_more = TRUE;
c1 = SS3;
#endif /* HOJO_KANJI */
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
} else if (global_kinput == JIS && kselected == SELKANA) {
savedchar = c1 | 0x80;
kgetkey_more = TRUE;
c1 = SS2;