diff options
-rw-r--r-- | examples/README | 11 | ||||
-rw-r--r-- | examples/examples-8.0.sln | 26 | ||||
-rw-r--r-- | examples/examples-9.0.sln | 26 | ||||
-rw-r--r-- | examples/features/README | 21 | ||||
-rw-r--r-- | examples/features/driver.cxx | 62 | ||||
-rw-r--r-- | examples/features/features-8.0.vcproj | 237 | ||||
-rw-r--r-- | examples/features/features-9.0.vcproj | 233 | ||||
-rw-r--r-- | examples/features/makefile | 63 | ||||
-rw-r--r-- | examples/features/options.cli | 39 | ||||
-rw-r--r-- | examples/hello/README | 26 | ||||
-rw-r--r-- | examples/hello/driver.cxx | 6 | ||||
-rw-r--r-- | examples/hello/hello-8.0.vcproj | 237 | ||||
-rw-r--r-- | examples/hello/hello-9.0.vcproj | 233 | ||||
-rw-r--r-- | examples/makefile | 2 |
14 files changed, 1219 insertions, 3 deletions
diff --git a/examples/README b/examples/README new file mode 100644 index 0000000..d333f11 --- /dev/null +++ b/examples/README @@ -0,0 +1,11 @@ +This directory contains a number of examples that show how to use the CLI +language and compiler to implement command line interface parsing in C++. +The following list gives an overview of each example. See the README files +in example directories for more information on each example. + +hello + A simple "Hello, world!" example that shows how to implement a very basic + command line interface using CLI. + +features + Shows how to use various features of the CLI language. diff --git a/examples/examples-8.0.sln b/examples/examples-8.0.sln new file mode 100644 index 0000000..8b7e077 --- /dev/null +++ b/examples/examples-8.0.sln @@ -0,0 +1,26 @@ +
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hello", "hello\hello-8.0.vcproj", "{4813826B-CC80-4D8F-8E4C-D89DB83B6479}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "features", "features\features-8.0.vcproj", "{FA7FD071-4FF6-4EB3-96E0-95366AB2CA6F}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {4813826B-CC80-4D8F-8E4C-D89DB83B6479}.Debug|Win32.ActiveCfg = Debug|Win32
+ {4813826B-CC80-4D8F-8E4C-D89DB83B6479}.Debug|Win32.Build.0 = Debug|Win32
+ {4813826B-CC80-4D8F-8E4C-D89DB83B6479}.Release|Win32.ActiveCfg = Release|Win32
+ {4813826B-CC80-4D8F-8E4C-D89DB83B6479}.Release|Win32.Build.0 = Release|Win32
+ {FA7FD071-4FF6-4EB3-96E0-95366AB2CA6F}.Debug|Win32.ActiveCfg = Debug|Win32
+ {FA7FD071-4FF6-4EB3-96E0-95366AB2CA6F}.Debug|Win32.Build.0 = Debug|Win32
+ {FA7FD071-4FF6-4EB3-96E0-95366AB2CA6F}.Release|Win32.ActiveCfg = Release|Win32
+ {FA7FD071-4FF6-4EB3-96E0-95366AB2CA6F}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/examples/examples-9.0.sln b/examples/examples-9.0.sln new file mode 100644 index 0000000..8a2d2b5 --- /dev/null +++ b/examples/examples-9.0.sln @@ -0,0 +1,26 @@ +
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hello", "hello\hello-9.0.vcproj", "{C955CE91-C424-44A8-AAC5-64D50CDADABA}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "features", "features\features-9.0.vcproj", "{A2A8DB0D-FA16-4F85-9775-8ADBDD06AE90}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {C955CE91-C424-44A8-AAC5-64D50CDADABA}.Debug|Win32.ActiveCfg = Debug|Win32
+ {C955CE91-C424-44A8-AAC5-64D50CDADABA}.Debug|Win32.Build.0 = Debug|Win32
+ {C955CE91-C424-44A8-AAC5-64D50CDADABA}.Release|Win32.ActiveCfg = Release|Win32
+ {C955CE91-C424-44A8-AAC5-64D50CDADABA}.Release|Win32.Build.0 = Release|Win32
+ {A2A8DB0D-FA16-4F85-9775-8ADBDD06AE90}.Debug|Win32.ActiveCfg = Debug|Win32
+ {A2A8DB0D-FA16-4F85-9775-8ADBDD06AE90}.Debug|Win32.Build.0 = Debug|Win32
+ {A2A8DB0D-FA16-4F85-9775-8ADBDD06AE90}.Release|Win32.ActiveCfg = Release|Win32
+ {A2A8DB0D-FA16-4F85-9775-8ADBDD06AE90}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/examples/features/README b/examples/features/README new file mode 100644 index 0000000..fc30a53 --- /dev/null +++ b/examples/features/README @@ -0,0 +1,21 @@ +This example shows how to use various features of the CLI language. + +The example consists of the following files: + +options.cli + Options class definition in the CLI language. + +options.hxx +options.ixx +options.cxx + Options class implementation in C++. These files are generated by the CLI + compiler from hello.cli using the following command line: + + cli options.cli + +driver.cxx + Driver for the example. It first instantiates the option class which parses + the command line. The driver then examines and prints the options values. + +To run the example you can try various command lines suggested in the +options.cli file. diff --git a/examples/features/driver.cxx b/examples/features/driver.cxx new file mode 100644 index 0000000..339f4c1 --- /dev/null +++ b/examples/features/driver.cxx @@ -0,0 +1,62 @@ +// file : examples/features/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include <iostream> +#include <iterator> +#include <algorithm> + +#include "options.hxx" + +using namespace std; + +int +main (int argc, char* argv[]) +{ + try + { + features::options o (argc, argv); + + // --out-dir | -o + // + if (!o.out_dir ().empty ()) + cerr << "output dir: " << o.out_dir () << endl; + + // --first-name & --last-name + // + cerr << "first name: " << o.first_name () << endl + << "last name : " << o.last_name () << endl; + + // --vector | -v & --set | -s + // + if (!o.vector ().empty ()) + { + copy (o.vector ().begin (), o.vector ().end (), + ostream_iterator<int> (cerr, " ")); + cerr << endl; + } + + if (!o.set ().empty ()) + { + copy (o.set ().begin (), o.set ().end (), + ostream_iterator<int> (cerr, " ")); + cerr << endl; + } + + // --map | -m + // + typedef map<std::string, std::string> str_map; + const str_map& m (o.map ()); + str_map::const_iterator i (m.find ("a")); + + if (i != m.end ()) + cerr << "value for the 'a' key: " << i->second << endl; + + } + catch (const cli::exception& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/examples/features/features-8.0.vcproj b/examples/features/features-8.0.vcproj new file mode 100644 index 0000000..e7d27b8 --- /dev/null +++ b/examples/features/features-8.0.vcproj @@ -0,0 +1,237 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="features"
+ ProjectGUID="{FA7FD071-4FF6-4EB3-96E0-95366AB2CA6F}"
+ RootNamespace="features"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{6A1107DB-7C6A-4A11-9CFE-459920046C0F}"
+ >
+ <File
+ RelativePath=".\driver.cxx"
+ >
+ </File>
+ <File
+ RelativePath=".\options.cxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{D90959E6-C0B2-4EFA-90D2-B89A6CB5705B}"
+ >
+ <File
+ RelativePath=".\options.hxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="CLI Files"
+ Filter="*.cli"
+ >
+ <File
+ RelativePath=".\options.cli"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli options.cli"
+ CommandLine="..\..\cli\cli.exe options.cli"
+ Outputs="options.hxx;options.ixx;options.cxx"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli options.cli"
+ CommandLine="..\..\cli\cli.exe options.cli"
+ Outputs="options.hxx;options.ixx;options.cxx"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Inline Files"
+ Filter="*.ixx"
+ >
+ <File
+ RelativePath=".\options.ixx"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/examples/features/features-9.0.vcproj b/examples/features/features-9.0.vcproj new file mode 100644 index 0000000..bf18ffc --- /dev/null +++ b/examples/features/features-9.0.vcproj @@ -0,0 +1,233 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="features"
+ ProjectGUID="{A2A8DB0D-FA16-4F85-9775-8ADBDD06AE90}"
+ RootNamespace="features"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{BFE61235-527C-4E63-BD47-3FE0704D9142}"
+ >
+ <File
+ RelativePath=".\driver.cxx"
+ >
+ </File>
+ <File
+ RelativePath=".\options.cxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{FD0912F2-D273-4BA9-B66D-81BA1C037991}"
+ >
+ <File
+ RelativePath=".\options.hxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Inline Files"
+ Filter="*.ixx"
+ >
+ <File
+ RelativePath=".\options.ixx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="CLI Files"
+ Filter="*.cli"
+ >
+ <File
+ RelativePath=".\options.cli"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli options.cli"
+ CommandLine="..\..\cli\cli.exe options.cli"
+ Outputs="options.hxx;options.ixx;options.cxx"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli options.cli"
+ CommandLine="..\..\cli\cli.exe options.cli"
+ Outputs="options.hxx;options.ixx;options.cxx"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/examples/features/makefile b/examples/features/makefile new file mode 100644 index 0000000..c599afe --- /dev/null +++ b/examples/features/makefile @@ -0,0 +1,63 @@ +# file : examples/features/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2009 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +cli := options.cli +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(cli:.cli=.o)) +dep := $(obj:.o=.o.d) + +driver := $(out_base)/driver +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(obj) + +$(obj) $(dep): cpp_options := -I$(out_base) + +genf := $(cli:.cli=.hxx) $(cli:.cli=.ixx) $(cli:.cli=.cxx) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): cli := $(out_root)/cli/cli +$(gen): $(out_root)/cli/cli + +$(call include-dep,$(dep),$(obj),$(gen)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + +# Clean. +# +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(cli:.cli=.cxx.cli.clean)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(gen): | $(out_base)/.gitignore +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/cli/cli-cxx.make) + +# Dependencies. +# +$(call import,$(src_root)/cli/makefile) diff --git a/examples/features/options.cli b/examples/features/options.cli new file mode 100644 index 0000000..e6a8738 --- /dev/null +++ b/examples/features/options.cli @@ -0,0 +1,39 @@ +include <set>; +include <map>; +include <vector>; +include <string>; + +// We can place the options classes into namespaces which mapped to C++ +// namespaces. +// +namespace features +{ + class options + { + // We can have several aliases for the same option. The first one is used + // to derive the accessor name. + // + std::string --out-dir | -o; + + // We can use both assignment and constructor notations to provide the + // default option value. + // + std::string --first-name = "John"; + std::string --last-name ("Mr John Doe", 8, 3); + + // We can use containers to to collect option value. If we have a command + // line like this: -v 1 -v 2 -v 1 -s 1 -s 2 -s 1 then the vector returned + // by the vector() accessor will contain three elements: 1, 2, and 1 while + // the set returned by the set() accessor will contain two elements: 1 and + // 2. + // + std::vector<int> --vector | -v; + std::set<int> --set | -s; + + // We can also use maps. In this case the option value is expected to have + // two part, the key and the value, separated by '='. For example: -m a=A + // -m =B -m c= -m d (same as -m d=). + // + std::map<std::string, std::string> --map | -m; + }; +} diff --git a/examples/hello/README b/examples/hello/README new file mode 100644 index 0000000..a1fe976 --- /dev/null +++ b/examples/hello/README @@ -0,0 +1,26 @@ +This is a "Hello, world!" example that shows how to implement a very basic +command line interface using CLI. + +The example consists of the following files: + +hello.cli + Options class definition in the CLI language. + +hello.hxx +hello.ixx +hello.cxx + Options class implementation in C++. These files are generated by the CLI + compiler from hello.cli using the following command line: + + cli hello.cli + +driver.cxx + Driver for the example. It first instantiates the option class which parses + the command line. The driver then examines the options and prints the + greeting string for each name passed as argument. + +To run the example you can try the following command lines: + +$ ./driver --help +$ ./driver John Jane +$ ./driver --greeting Hi --exclamations 3 John Jane diff --git a/examples/hello/driver.cxx b/examples/hello/driver.cxx index 6641d4b..b08e6be 100644 --- a/examples/hello/driver.cxx +++ b/examples/hello/driver.cxx @@ -14,8 +14,8 @@ usage () { cerr << "usage: driver <options> <names>" << endl << " [--help]" << endl - << " [--greeting|-g <string>]" << endl - << " [--exclamations|-e <integer>]" << endl; + << " [--greeting <string>]" << endl + << " [--exclamations <integer>]" << endl; } int @@ -39,6 +39,8 @@ main (int argc, char* argv[]) return 1; } + // Print the greetings. + // for (int i = end; i < argc; i++) { cout << o.greeting () << ", " << argv[i]; diff --git a/examples/hello/hello-8.0.vcproj b/examples/hello/hello-8.0.vcproj new file mode 100644 index 0000000..6415d8c --- /dev/null +++ b/examples/hello/hello-8.0.vcproj @@ -0,0 +1,237 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="hello"
+ ProjectGUID="{4813826B-CC80-4D8F-8E4C-D89DB83B6479}"
+ RootNamespace="hello"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\driver.cxx"
+ >
+ </File>
+ <File
+ RelativePath=".\hello.cxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\hello.hxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="CLI Files"
+ Filter="*.cli"
+ >
+ <File
+ RelativePath=".\hello.cli"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli hello.cli"
+ CommandLine="..\..\cli\cli.exe hello.cli"
+ Outputs="hello.hxx;hello.ixx;hello.cxx"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli hello.cli"
+ CommandLine="..\..\cli\cli.exe hello.cli"
+ Outputs="hello.hxx;hello.ixx;hello.cxx"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Inline Files"
+ Filter="*.ixx"
+ >
+ <File
+ RelativePath=".\hello.ixx"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/examples/hello/hello-9.0.vcproj b/examples/hello/hello-9.0.vcproj new file mode 100644 index 0000000..3ca9838 --- /dev/null +++ b/examples/hello/hello-9.0.vcproj @@ -0,0 +1,233 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="hello"
+ ProjectGUID="{C955CE91-C424-44A8-AAC5-64D50CDADABA}"
+ RootNamespace="hello"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\driver.cxx"
+ >
+ </File>
+ <File
+ RelativePath=".\hello.cxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\hello.hxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Inline Files"
+ Filter="*.ixx"
+ >
+ <File
+ RelativePath=".\hello.ixx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="CLI Files"
+ Filter="*.cli"
+ >
+ <File
+ RelativePath=".\hello.cli"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli hello.cli"
+ CommandLine="..\..\cli\cli.exe hello.cli"
+ Outputs="hello.hxx;hello.ixx;hello.cxx"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli hello.cli"
+ CommandLine="..\..\cli\cli.exe hello.cli"
+ Outputs="hello.hxx;hello.ixx;hello.cxx"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/examples/makefile b/examples/makefile index 31a72b7..0180e9a 100644 --- a/examples/makefile +++ b/examples/makefile @@ -5,7 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make -examples := hello +examples := hello features default := $(out_base)/ clean := $(out_base)/.clean |