--- nono/lib/config.cpp 2026/04/29 17:05:39 1.1.1.18 +++ nono/lib/config.cpp 2026/04/29 17:05:44 1.1.1.19 @@ -90,16 +90,30 @@ Config::Config() // Light スレッドをその反集合の CPU に割り付ける。 Add(".host-cpu-affinity", "auto"); - // シリアルポートのホスト側設定 - Add("hostcom-driver", "none"); - Add("hostcom-fallback", 0); - Add("hostcom-tcp-port", 9998); + // シリアルポートのホスト側設定。 + // fallback は少しの間残しておくがそのうち消す。 + Add("hostcom0-driver", "none"); + Add("hostcom0-fallback", 0); + Add("hostcom0-tcp-port", 9998); + + Add("hostcom1-driver", "none", VMCap::LUNA); + Add("hostcom1-fallback", 0, VMCap::LUNA); + Add("hostcom1-tcp-port", 9997, VMCap::LUNA); + + Add("hostcom2-driver", "none", VMCap::LUNA); + Add("hostcom2-fallback", 0, VMCap::LUNA); + Add("hostcom2-tcp-port", 9996, VMCap::LUNA); + + AddAlias("hostcom-driver", "hostcom0-driver"); + AddAlias("hostcom-fallback", "hostcom0-fallback"); + AddAlias("hostcom-tcp-port", "hostcom0-tcp-port"); // キーボードの入力モード Add("hostkbd-input", "char", VMCap::LUNA | VMCap::X68030); // ネットワークのホスト側設定。 // (0 と 1 で -driver の初期値が違う) + // fallback は少しの間残しておくがそのうち消す。 Add("hostnet0-driver", "auto"); Add("hostnet0-fallback", 0); Add("hostnet0-afpacket-ifname", "auto"); @@ -383,22 +397,35 @@ Config::Update(const std::string& line, } } +// 実行中に動的に変更する。 +bool +Config::UpdateRunning(const std::string& line) +{ + return UpdateLine(line, ConfigItem::FromRunning, ""); +} + // 更新1行分の共通処理。 // キーが見付からない場合は from によって動作が異なる。 // o 共通設定ファイルでなら、何もせず true を返す。 // o VM 設定ファイルでなら、エラーメッセージを表示するが true を返す。 // o コマンドラインでなら、エラーメッセージを表示して false を返す。 -// 戻り値 false は実行中止を示す。 +// 起動前のこれらでは、false は実行中止を示す。 +// また +// o 実行中の変更なら、何もせず false を返す。 +// この場合の false はキーが見付からなかったことを意味する。 +// (文法エラーの場合にも false が返るが、それはプログラムエラー) bool Config::UpdateLine(const std::string& line, ConfigItem::from_t from, const std::string& where) { std::string key; std::string val; + std::string head; // キーと値に分解 if (SplitKeyVal(&key, &val, line) == false) { - ConfigItem::PrintErr(from, where, "", line, "Syntax error"); + head = ConfigItem::ErrFrom(from, where, "", line); + warnx("%s: Syntax error", head.c_str()); return false; } @@ -408,6 +435,7 @@ Config::UpdateLine(const std::string& li // キーで検索 ConfigItem *itemptr = FindItem(key); if (itemptr == NULL) { + head = ConfigItem::ErrFrom(from, where, key, val); switch (from) { default: case ConfigItem::FromHome: @@ -421,13 +449,17 @@ Config::UpdateLine(const std::string& li // VM 設定ファイルなら警告のみで無視する。 // このファイルに他機種向けの設定があるのはおかしいが // 止めるほどではない。 - ConfigItem::PrintErr(from, where, key, val, "Unknown key, ignored"); + warnx("%s: Unknown key, ignored", head.c_str()); return true; case ConfigItem::FromOption: // コマンドラインからの場合はエラーにする。 - ConfigItem::PrintErr(from, where, key, val, "Unknown key"); + warnx("%s: Unknown key", head.c_str()); return false; + + case ConfigItem::FromRunning: + // 実行中なら、黙って無視する。 + return true; } } @@ -719,6 +751,33 @@ ConfigItem::SetDefault(const std::string } } +std::string +ConfigItem::ErrMsg() const +{ + // 定型文 + return ErrMsg("Invalid argument"); +} + +std::string +ConfigItem::ErrMsg(const char *fmt, ...) const +{ + char buf[1024]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + + std::string msg(buf); + return ErrMsg(msg); +} + +std::string +ConfigItem::ErrMsg(const std::string& msg) const +{ + return ErrFrom(from, where, key, value) + ": " + msg; +} + void ConfigItem::Err() const { @@ -743,14 +802,14 @@ ConfigItem::Err(const char *fmt, ...) co void ConfigItem::Err(const std::string& msg) const { - PrintErr(from, where, key, value, msg); + warnx("%s", ErrMsg(msg).c_str()); } -// この item についてエラーを表示する。 +// この item のエラーメッセージのヘッダ部分を返す。 // key=val の '=' がない場合のみ key を空、value を行全体として呼ぶ。 -/*static*/ void -ConfigItem::PrintErr(ConfigItem::from_t from, const std::string& where, - const std::string& key, const std::string& value, const std::string& msg) +/*static*/ std::string +ConfigItem::ErrFrom(ConfigItem::from_t from, const std::string& where, + const std::string& key, const std::string& value) { std::string fromstr; @@ -794,7 +853,7 @@ ConfigItem::PrintErr(ConfigItem::from_t break; } - warnx("%s: %s", fromstr.c_str(), msg.c_str()); + return fromstr; }