1999-10-06 13:48:34 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: samples/console/console.cpp
|
2005-04-20 03:18:45 -04:00
|
|
|
// Purpose: A sample console (as opposed to GUI) program using wxWidgets
|
1999-10-06 13:48:34 -04:00
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04.10.99
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-10-22 05:24:15 -04:00
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
2010-06-21 17:03:47 -04:00
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
2000-03-04 21:23:53 -05:00
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
|
|
|
// need because it includes almost all "standard" wxWidgets headers)
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
2001-11-25 16:36:28 -05:00
|
|
|
#endif
|
2000-07-15 15:51:35 -04:00
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
#include <wx/app.h>
|
|
|
|
#include <wx/cmdline.h>
|
|
|
|
|
1999-10-22 05:24:15 -04:00
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
static const wxCmdLineEntryDesc cmdLineDesc[] =
|
2005-01-16 18:32:37 -05:00
|
|
|
{
|
2010-06-21 17:03:47 -04:00
|
|
|
{ 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" },
|
|
|
|
// ... your other command line options here...
|
2000-07-15 15:51:35 -04:00
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
{ wxCMD_LINE_NONE }
|
|
|
|
};
|
2000-03-17 18:02:38 -05:00
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
int main(int argc, char **argv)
|
2001-08-25 12:42:11 -04:00
|
|
|
{
|
2010-06-21 17:03:47 -04:00
|
|
|
wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
|
2001-08-25 12:42:11 -04:00
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
wxInitializer initializer;
|
|
|
|
if ( !initializer )
|
2001-08-25 12:42:11 -04:00
|
|
|
{
|
2010-06-21 17:03:47 -04:00
|
|
|
fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
|
|
|
|
return -1;
|
2001-08-25 12:42:11 -04:00
|
|
|
}
|
2010-06-19 08:48:46 -04:00
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
wxCmdLineParser parser(cmdLineDesc, argc, argv);
|
|
|
|
switch ( parser.Parse() )
|
2001-07-13 13:12:23 -04:00
|
|
|
{
|
2010-06-21 17:03:47 -04:00
|
|
|
case -1:
|
|
|
|
// help was given, terminating
|
2001-07-13 13:12:23 -04:00
|
|
|
break;
|
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
case 0:
|
|
|
|
// everything is ok; proceed
|
|
|
|
if (parser.Found("d"))
|
2001-07-13 13:12:23 -04:00
|
|
|
{
|
2010-06-21 17:03:47 -04:00
|
|
|
wxPrintf("Dummy switch was given...\n");
|
2001-07-13 13:12:23 -04:00
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
while (1)
|
2001-07-13 13:12:23 -04:00
|
|
|
{
|
2010-06-21 17:03:47 -04:00
|
|
|
wxChar input[128];
|
|
|
|
wxPrintf("Try to guess the magic number (type 'quit' to escape): ");
|
|
|
|
if ( !wxFgets(input, WXSIZEOF(input), stdin) )
|
2001-07-13 13:12:23 -04:00
|
|
|
break;
|
2001-01-24 11:37:04 -05:00
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
// kill the last '\n'
|
|
|
|
input[wxStrlen(input) - 1] = 0;
|
|
|
|
|
|
|
|
if (wxStrcmp(input, "quit") == 0)
|
|
|
|
break;
|
2001-01-24 11:37:04 -05:00
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
long val;
|
|
|
|
if (!wxString(input).ToLong(&val))
|
|
|
|
{
|
|
|
|
wxPrintf("Invalid number...\n");
|
|
|
|
continue;
|
|
|
|
}
|
2000-03-15 12:16:35 -05:00
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
if (val == 42)
|
|
|
|
wxPrintf("You guessed!\n");
|
|
|
|
else
|
|
|
|
wxPrintf("Bad luck!\n");
|
2001-01-24 11:37:04 -05:00
|
|
|
}
|
|
|
|
}
|
1999-12-29 14:18:01 -05:00
|
|
|
break;
|
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
default:
|
2010-05-29 03:56:08 -04:00
|
|
|
break;
|
2010-05-29 04:20:46 -04:00
|
|
|
}
|
2010-06-19 08:48:46 -04:00
|
|
|
|
2010-06-21 17:03:47 -04:00
|
|
|
// do something useful here
|
2005-03-30 10:44:52 -05:00
|
|
|
|
1999-10-06 13:48:34 -04:00
|
|
|
return 0;
|
|
|
|
}
|