]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/console/console.cpp
Tamil translations update from Dinakar T.D.
[wxWidgets.git] / samples / console / console.cpp
... / ...
CommitLineData
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// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// For compilers that support precompilation, includes "wx/wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
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"
30#endif
31
32#include <wx/app.h>
33#include <wx/cmdline.h>
34
35// ============================================================================
36// implementation
37// ============================================================================
38
39static const wxCmdLineEntryDesc cmdLineDesc[] =
40{
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...
45
46 { wxCMD_LINE_NONE }
47};
48
49int main(int argc, char **argv)
50{
51 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
52
53 wxInitializer initializer;
54 if ( !initializer )
55 {
56 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
57 return -1;
58 }
59
60 wxCmdLineParser parser(cmdLineDesc, argc, argv);
61 switch ( parser.Parse() )
62 {
63 case -1:
64 // help was given, terminating
65 break;
66
67 case 0:
68 // everything is ok; proceed
69 if (parser.Found("d"))
70 {
71 wxPrintf("Dummy switch was given...\n");
72
73 while (1)
74 {
75 wxChar input[128];
76 wxPrintf("Try to guess the magic number (type 'quit' to escape): ");
77 if ( !wxFgets(input, WXSIZEOF(input), stdin) )
78 break;
79
80 // kill the last '\n'
81 input[wxStrlen(input) - 1] = 0;
82
83 if (wxStrcmp(input, "quit") == 0)
84 break;
85
86 long val;
87 if (!wxString(input).ToLong(&val))
88 {
89 wxPrintf("Invalid number...\n");
90 continue;
91 }
92
93 if (val == 42)
94 wxPrintf("You guessed!\n");
95 else
96 wxPrintf("Bad luck!\n");
97 }
98 }
99 break;
100
101 default:
102 break;
103 }
104
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
113 // do something useful here
114
115 return 0;
116}