@@ -76,6 +76,7 @@ CBasis::CBasis(CAyaVM &vmr) : vm(vmr)
76
76
msglang_for_compat = MSGLANG_JAPANESE;
77
77
78
78
dic_charset = CHARSET_SJIS;
79
+ setting_charset = CHARSET_SJIS;
79
80
output_charset = CHARSET_UTF8;
80
81
file_charset = CHARSET_SJIS;
81
82
save_charset = CHARSET_UTF8;
@@ -375,7 +376,9 @@ void CBasis::LoadBaseConfigureFile(std::vector<CDic1> &dics)
375
376
376
377
// ファイルを開く
377
378
yaya::string_t filename = load_path + modulename + config_file_name_trailer + L" .txt" ;
378
- LoadBaseConfigureFile_Base (filename,dics,dic_charset);
379
+
380
+ // 読み込み当初は文字コードが定義されていないので、CHARSET_UNDEFにする
381
+ LoadBaseConfigureFile_Base (filename,dics,CHARSET_UNDEF);
379
382
380
383
if ( yayamsg::IsEmpty () ) { // エラーメッセージテーブルが読めていない
381
384
SetParameter (L" messagetxt" ,msglang_for_compat == MSGLANG_JAPANESE ? L" messagetxt/japanese.txt" : L" messagetxt/english.txt" );
@@ -398,11 +401,21 @@ void CBasis::LoadBaseConfigureFile_Base(yaya::string_t filename,std::vector<CDic
398
401
yaya::string_t cmd, param;
399
402
size_t line=0 ;
400
403
404
+ char cset_real;
405
+
401
406
while ( true ) {
402
407
line += 1 ;
403
408
404
409
// 1行読み込み
405
- if (yaya::ws_fgets (readline, fp, cset, 0 , line) == yaya::WS_EOF) {
410
+ cset_real = cset;
411
+
412
+ if ( cset == CHARSET_UNDEF ) {
413
+ // 後の設定で変更されている可能性があるので、毎回上書きすること
414
+ // always overwrite cset_real because setting_charset may be modified in SetParameter function
415
+ cset_real = setting_charset;
416
+ }
417
+
418
+ if (yaya::ws_fgets (readline, fp, cset_real, 0 , line) == yaya::WS_EOF) {
406
419
// ファイルを閉じる
407
420
fclose (fp);
408
421
@@ -446,7 +459,7 @@ bool CBasis::SetParameter(const yaya::string_t &cmd, const yaya::string_t ¶m
446
459
447
460
yaya::string_t filename = load_path + param1;
448
461
449
- char cset = dic_charset ;
462
+ char cset = setting_charset ;
450
463
if ( param2.size () ) {
451
464
char cx = Ccct::CharsetTextToID (param2.c_str ());
452
465
if ( cx != CHARSET_DEFAULT ) {
@@ -463,7 +476,7 @@ bool CBasis::SetParameter(const yaya::string_t &cmd, const yaya::string_t ¶m
463
476
464
477
yaya::string_t filename = load_path + param1;
465
478
466
- char cset = dic_charset ;
479
+ char cset = setting_charset ;
467
480
if ( param2.size () ) {
468
481
char cx = Ccct::CharsetTextToID (param2.c_str ());
469
482
if ( cx != CHARSET_DEFAULT ) {
@@ -609,6 +622,7 @@ bool CBasis::SetParameter(const yaya::string_t &cmd, const yaya::string_t ¶m
609
622
// charset
610
623
else if ( cmd == L" charset" ) {
611
624
dic_charset = Ccct::CharsetTextToID (param.c_str ());
625
+ setting_charset = dic_charset;
612
626
output_charset = dic_charset;
613
627
file_charset = dic_charset;
614
628
save_charset = dic_charset;
@@ -621,6 +635,10 @@ bool CBasis::SetParameter(const yaya::string_t &cmd, const yaya::string_t ¶m
621
635
dic_charset = Ccct::CharsetTextToID (param.c_str ());
622
636
return true ;
623
637
}
638
+ else if ( cmd == L" charset.setting" ) {
639
+ setting_charset = Ccct::CharsetTextToID (param.c_str ());
640
+ return true ;
641
+ }
624
642
else if ( cmd == L" charset.output" ) {
625
643
output_charset = Ccct::CharsetTextToID (param.c_str ());
626
644
return true ;
@@ -744,6 +762,9 @@ CValue CBasis::GetParameter(const yaya::string_t &cmd)
744
762
else if ( cmd == L" charset.dic" ) {
745
763
return Ccct::CharsetIDToTextW (dic_charset);
746
764
}
765
+ else if ( cmd == L" charset.setting" ) {
766
+ return Ccct::CharsetIDToTextW (setting_charset);
767
+ }
747
768
else if ( cmd == L" charset.output" ) {
748
769
return Ccct::CharsetIDToTextW (output_charset);
749
770
}
0 commit comments