]> git.saurik.com Git - wxWidgets.git/blob - samples/console/console.cpp
supporting alignment in single line controls, see #14452
[wxWidgets.git] / samples / console / console.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: A sample console (as opposed to GUI) program using wxWidgets
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 04.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers)
29 #ifndef WX_PRECOMP
30 #include "wx/wx.h"
31 #endif
32
33 #include <wx/app.h>
34 #include <wx/cmdline.h>
35
36 // ============================================================================
37 // implementation
38 // ============================================================================
39
40 static const wxCmdLineEntryDesc cmdLineDesc[] =
41 {
42 { wxCMD_LINE_SWITCH, "h", "help", "show this help message",
43 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
44 { wxCMD_LINE_SWITCH, "d", "dummy", "a dummy switch" },
45 // ... your other command line options here...
46
47 { wxCMD_LINE_NONE }
48 };
49
50 int main(int argc, char **argv)
51 {
52 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
53
54 wxInitializer initializer;
55 if ( !initializer )
56 {
57 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
58 return -1;
59 }
60
61 wxCmdLineParser parser(cmdLineDesc, argc, argv);
62 switch ( parser.Parse() )
63 {
64 case -1:
65 // help was given, terminating
66 break;
67
68 case 0:
69 // everything is ok; proceed
70 if (parser.Found("d"))
71 {
72 wxPrintf("Dummy switch was given...\n");
73
74 while (1)
75 {
76 wxChar input[128];
77 wxPrintf("Try to guess the magic number (type 'quit' to escape): ");
78 if ( !wxFgets(input, WXSIZEOF(input), stdin) )
79 break;
80
81 // kill the last '\n'
82 input[wxStrlen(input) - 1] = 0;
83
84 if (wxStrcmp(input, "quit") == 0)
85 break;
86
87 long val;
88 if (!wxString(input).ToLong(&val))
89 {
90 wxPrintf("Invalid number...\n");
91 continue;
92 }
93
94 if (val == 42)
95 wxPrintf("You guessed!\n");
96 else
97 wxPrintf("Bad luck!\n");
98 }
99 }
100 break;
101
102 default:
103 break;
104 }
105
106 if ( argc == 1 )
107 {
108 // If there were no command-line options supplied, emit a message
109 // otherwise it's not obvious that the sample ran successfully
110 wxPrintf("Welcome to the wxWidgets 'console' sample!\n");
111 wxPrintf("For more information, run it again with the --help option\n");
112 }
113
114 // do something useful here
115
116 return 0;
117 }