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

add fwgo.
author pyon@macmini
date Wed, 15 Jul 2020 18:18:24 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/kaigo/horori/console/console.cpp	Wed Jul 15 18:18:24 2020 +0900
@@ -0,0 +1,101 @@
+/* console.cpp
+ *  Last Change: 2020-04-24 金 13:58:59.
+ *                            by T.Mutoh
+ */
+#include "wx/wxprec.h"
+
+#include <wx/wx.h>
+#include <wx/app.h>
+#include <wx/cmdline.h>
+
+static const wxCmdLineEntryDesc cmdLineDesc[] =
+{
+	{wxCMD_LINE_SWITCH, "h", "help", "show this help message",
+		wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP},
+	{wxCMD_LINE_SWITCH, "d", "dummy", "a dummy switch",
+		wxCMD_LINE_VAL_NONE, 0},
+	{wxCMD_LINE_SWITCH, "s", "secret", "a secret switch",
+		wxCMD_LINE_VAL_NONE, wxCMD_LINE_HIDDEN},
+	// ... your other command line options here...
+
+	wxCMD_LINE_DESC_END
+};
+
+int main(int argc, char **argv)
+{
+	wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
+
+	wxInitializer initializer;
+	if (!initializer) {
+		fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
+		return -1;
+	}
+
+	wxCmdLineParser parser(cmdLineDesc, argc, argv);
+	switch (parser.Parse()) {
+		case -1:
+			// help was given, terminating
+			break;
+
+		case 0:
+			// everything is ok; proceed
+			if (parser.Found("d")) {
+				wxPrintf("Dummy switch was given...\n");
+
+				while (1) {
+					wxChar input[128];
+					wxPrintf("Try to guess the magic number (type 'quit' to escape): ");
+					if ( !wxFgets(input, WXSIZEOF(input), stdin) )
+						break;
+
+					// kill the last '\n'
+					input[wxStrlen(input) - 1] = 0;
+
+					if (wxStrcmp(input, "quit") == 0)
+						break;
+
+					long val;
+					if (!wxString(input).ToLong(&val)) {
+						wxPrintf("Invalid number...\n");
+						continue;
+					}
+
+					if (val == 42)
+						wxPrintf("You guessed!\n");
+					else
+						wxPrintf("Bad luck!\n");
+				}
+			}
+			if (parser.Found("s")) {
+				wxPrintf("Secret switch was given...\n");
+			}
+
+			break;
+
+		default:
+			break;
+	}
+
+	if (argc == 1) {
+		wxPrintf("Welcome to the wxWidgets 'console' sample!\n");
+		wxPrintf("For more information, run it again with the --help option\n");
+	}
+
+	// do something useful here
+	wxString s = wxT("443201");
+	wxString t, u;
+	int x = 23;
+	for (int i = 0; i < s.Len(); i++) {
+		t += wxString::Format(wxT("%c"), s[i].GetValue() ^ x); 
+	}
+	wxPrintf(t);
+	wxPrintf("\n");
+
+	for (int i = 0; i < t.Len(); i++) {
+		u += wxString::Format(wxT("%c"), t[i].GetValue() ^ x); 
+	}
+	wxPrintf(u);
+
+	return 0;
+}
+