comparison src/kaigo/horori/console/console.cpp @ 57:05f3d51ad966

add fwgo.
author pyon@macmini
date Wed, 15 Jul 2020 18:18:24 +0900
parents
children
comparison
equal deleted inserted replaced
56:7396e7407abd 57:05f3d51ad966
1 /* console.cpp
2 * Last Change: 2020-04-24 金 13:58:59.
3 * by T.Mutoh
4 */
5 #include "wx/wxprec.h"
6
7 #include <wx/wx.h>
8 #include <wx/app.h>
9 #include <wx/cmdline.h>
10
11 static const wxCmdLineEntryDesc cmdLineDesc[] =
12 {
13 {wxCMD_LINE_SWITCH, "h", "help", "show this help message",
14 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP},
15 {wxCMD_LINE_SWITCH, "d", "dummy", "a dummy switch",
16 wxCMD_LINE_VAL_NONE, 0},
17 {wxCMD_LINE_SWITCH, "s", "secret", "a secret switch",
18 wxCMD_LINE_VAL_NONE, wxCMD_LINE_HIDDEN},
19 // ... your other command line options here...
20
21 wxCMD_LINE_DESC_END
22 };
23
24 int main(int argc, char **argv)
25 {
26 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
27
28 wxInitializer initializer;
29 if (!initializer) {
30 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
31 return -1;
32 }
33
34 wxCmdLineParser parser(cmdLineDesc, argc, argv);
35 switch (parser.Parse()) {
36 case -1:
37 // help was given, terminating
38 break;
39
40 case 0:
41 // everything is ok; proceed
42 if (parser.Found("d")) {
43 wxPrintf("Dummy switch was given...\n");
44
45 while (1) {
46 wxChar input[128];
47 wxPrintf("Try to guess the magic number (type 'quit' to escape): ");
48 if ( !wxFgets(input, WXSIZEOF(input), stdin) )
49 break;
50
51 // kill the last '\n'
52 input[wxStrlen(input) - 1] = 0;
53
54 if (wxStrcmp(input, "quit") == 0)
55 break;
56
57 long val;
58 if (!wxString(input).ToLong(&val)) {
59 wxPrintf("Invalid number...\n");
60 continue;
61 }
62
63 if (val == 42)
64 wxPrintf("You guessed!\n");
65 else
66 wxPrintf("Bad luck!\n");
67 }
68 }
69 if (parser.Found("s")) {
70 wxPrintf("Secret switch was given...\n");
71 }
72
73 break;
74
75 default:
76 break;
77 }
78
79 if (argc == 1) {
80 wxPrintf("Welcome to the wxWidgets 'console' sample!\n");
81 wxPrintf("For more information, run it again with the --help option\n");
82 }
83
84 // do something useful here
85 wxString s = wxT("443201");
86 wxString t, u;
87 int x = 23;
88 for (int i = 0; i < s.Len(); i++) {
89 t += wxString::Format(wxT("%c"), s[i].GetValue() ^ x);
90 }
91 wxPrintf(t);
92 wxPrintf("\n");
93
94 for (int i = 0; i < t.Len(); i++) {
95 u += wxString::Format(wxT("%c"), t[i].GetValue() ^ x);
96 }
97 wxPrintf(u);
98
99 return 0;
100 }
101