|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2018 [email protected]
4: //
5:
6: #include "vm.h"
7: #include "wxheader.h"
8: #include "wxmainframe.h"
9: #include "wxmainview.h"
10: #include "wxtextpanel.h"
11: #include "mainapp.h"
12: #include <wx/cmdline.h>
13:
14: // イベントタイプの定義
15: DEFINE_EVENT_TYPE(WXW_EVT_CREATE);
16: DEFINE_EVENT_TYPE(WXW_EVT_MONITOR_UPDATE);
17:
18: // コマンドラインオプションとか
19: bool console_log;
20:
21: // コマンドラインオプション
22: static const wxCmdLineEntryDesc cmddesc[] =
23: {
24: { wxCMD_LINE_OPTION, "b", "b", "breakpoint", wxCMD_LINE_VAL_STRING },
25: { wxCMD_LINE_OPTION, "c", "c", "vm directory", wxCMD_LINE_VAL_STRING },
26: { wxCMD_LINE_SWITCH, "d", "d", "debugger prompt on startup", },
27: { wxCMD_LINE_SWITCH, "C", "C", "console log" },
28: { wxCMD_LINE_SWITCH, "f", "f", "fast mode" },
29: { wxCMD_LINE_OPTION, "L", "L", "loglevel (-L help displays names)",
30: wxCMD_LINE_VAL_STRING },
31: { wxCMD_LINE_OPTION, "M", "M", "monitors to display at startup",
32: wxCMD_LINE_VAL_STRING },
33: { wxCMD_LINE_OPTION, "s", "s", "screen scale", wxCMD_LINE_VAL_STRING },
34: { wxCMD_LINE_OPTION, "", "fontsize", "font size {12, 16, 24} (default:12)",
35: wxCMD_LINE_VAL_STRING },
36: { wxCMD_LINE_SWITCH, "v", "v", "version" },
37:
38: { wxCMD_LINE_NONE },
39: };
40:
41: class WXApp
42: : public wxApp
43: {
44: public:
45: bool OnInit();
46: private:
47: bool Parse();
48: bool ParseMonitors(const wxString& str);
49: int SearchMonitorName(const char *name);
50: };
51:
52: IMPLEMENT_APP(WXApp)
53:
54: bool
55: WXApp::OnInit()
56: {
57: debug_breakaddr = 0xffffffff;
58: WXMainView::screen_scale = 1.0;
59: WXTextPanel::global_fontsize = FONT_6x12;
60: vmdir = ".";
61:
62: if (!Parse()) {
63: return false;
64: }
65:
66: // -C オプションならコンソールにもログを出力
67: if (!main_init<false>(console_log)) {
68: return false;
69: }
70:
71: // メインウィンドウ
72: gMainFrame = new WXMainFrame(NULL);
73: gMainFrame->Show(true);
74: SetTopWindow(gMainFrame);
75: return true;
76: }
77:
78: bool
79: WXApp::Parse()
80: {
81: u_long ulval;
82:
83: wxCmdLineParser cmd(argc, argv);
84: cmd.SetDesc(cmddesc);
85: if (cmd.Parse() != 0) {
86: return false;
87: }
88:
89: wxString arg;
90:
91: // -v
92: if (cmd.Found("v")) {
93: fprintf(stderr, "nono version %d.%d.%d\n",
94: NONO_MAJOR_VER, NONO_MINOR_VER, NONO_PATCH_VER);
95: return false;
96: }
97:
98: // -b ブレイクポイント
99: if (cmd.Found("b", &arg)) {
100: arg.ToULong(&ulval, 16);
101: debug_breakaddr = ulval;
102: }
103:
104: // -c 設定ファイル
105: if (cmd.Found("c", &arg)) {
106: vmdir = std::string((const char *)arg.mb_str());
107: }
108:
109: // -L ログレベル
110: if (cmd.Found("L", &arg)) {
111: strlcpy(logopt, (const char *)arg.mb_str(), sizeof(logopt));
112: }
113:
114: // -M 起動時に表示するモニタ
115: if (cmd.Found("M", &arg)) {
116: if (!ParseMonitors(arg)) {
117: return false;
118: }
119: }
120:
121: // screen scale
122: if (cmd.Found("s", &arg)) {
123: if (!arg.ToDouble(&WXMainView::screen_scale)) {
124: return false;
125: }
126: }
127:
128: // テキスト系コントロールのフォントサイズ
129: if (cmd.Found("fontsize", &arg)) {
130: fontsize_t fontsize;
131: arg.ToULong(&ulval, 10);
132: switch (ulval) {
133: case 12:
134: fontsize = FONT_6x12;
135: break;
136: case 16:
137: fontsize = FONT_8x16;
138: break;
139: case 24:
140: fontsize = FONT_12x24;
141: break;
142: default:
143: return false;
144: }
145: WXTextPanel::global_fontsize = fontsize;
146: }
147:
148: console_log = cmd.Found("C");
149: debug_on_start = cmd.Found("d");
150: fast_mode = cmd.Found("f");
151:
152: return true;
153: }
154:
155: // -M オプションの解析。書式は
156: // -M <name>[,<name>[,...]]
157: // -M help
158: // 継続不能なエラーなら false を返す。
159: bool
160: WXApp::ParseMonitors(const wxString& str)
161: {
162: const char *sep = ",";
163: char *word;
164: char *last;
165: char buf[str.Length() + 1];
166:
167: if (str == wxT("help")) {
168: for (int i = 0; i < WinID_MAX; i++) {
169: fprintf(stderr, " %s\n", WXMainFrame::monitor_names[i]);
170: }
171: return false;
172: }
173:
174: // 由緒正しい C でパースしてしまう
175: strcpy(buf, (const char *)str.mb_str());
176: for (word = strtok_r(buf, sep, &last);
177: word;
178: word = strtok_r(NULL, sep, &last))
179: {
180: int i = SearchMonitorName(word);
181: if (i < 0) {
182: warnx("Unknown window name \"%s\"", word);
183: return false;
184: }
185: WXMainFrame::monitor_start[i] = true;
186: }
187: return true;
188: }
189:
190: int
191: WXApp::SearchMonitorName(const char *name)
192: {
193: for (int i = 0; i < WinID_MAX; i++) {
194: if (strcmp(name, WXMainFrame::monitor_names[i]) == 0) {
195: return i;
196: }
197: }
198: return -1;
199: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.