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