Skip to content

Commit

Permalink
Added optionparser-1.7 files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary R. Van Sickle committed Aug 22, 2022
1 parent 4c9416b commit a159d7b
Show file tree
Hide file tree
Showing 12 changed files with 6,430 additions and 0 deletions.
2,427 changes: 2,427 additions & 0 deletions third_party/optionparser-1.7/Doxyfile

Large diffs are not rendered by default.

193 changes: 193 additions & 0 deletions third_party/optionparser-1.7/DoxygenLayout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<doxygenlayout version="1.0">
<!-- Navigation index tabs for HTML output -->
<navindex>
<tab type="mainpage" visible="yes" title="Overview"/>
<tab type="pages" visible="yes" title="" intro=""/>
<tab type="modules" visible="yes" title="" intro=""/>
<tab type="namespaces" visible="no" title="">
<tab type="namespacelist" visible="yes" title="" intro=""/>
<tab type="namespacemembers" visible="yes" title="" intro=""/>
</tab>
<tab type="classes" visible="yes" title="">
<tab type="classlist" visible="yes" title="" intro=""/>
<tab type="classindex" visible="$ALPHABETICAL_INDEX" title=""/>
<tab type="hierarchy" visible="yes" title="" intro=""/>
<tab type="classmembers" visible="no" title="" intro=""/>
</tab>
<tab type="files" visible="yes" title="">
<tab type="filelist" visible="yes" title="" intro=""/>
<tab type="globals" visible="yes" title="" intro=""/>
</tab>
<!--<tab type="dirs" visible="yes" title="" intro=""/>-->
<tab type="examples" visible="yes" title="" intro=""/>
</navindex>

<!-- Layout definition for a class page -->
<class>
<briefdescription visible="no"/>
<includes visible="$SHOW_INCLUDE_FILES"/>
<inheritancegraph visible="$CLASS_GRAPH"/>
<collaborationgraph visible="$COLLABORATION_GRAPH"/>
<allmemberslink visible="no"/>
<detaileddescription title=""/>
<memberdecl>
<nestedclasses visible="yes" title=""/>
<publictypes title=""/>
<publicslots title=""/>
<signals title=""/>
<publicmethods title=""/>
<publicstaticmethods title=""/>
<publicattributes title=""/>
<publicstaticattributes title=""/>
<protectedtypes title=""/>
<protectedslots title=""/>
<protectedmethods title=""/>
<protectedstaticmethods title=""/>
<protectedattributes title=""/>
<protectedstaticattributes title=""/>
<packagetypes title=""/>
<packagemethods title=""/>
<packagestaticmethods title=""/>
<packageattributes title=""/>
<packagestaticattributes title=""/>
<properties title=""/>
<events title=""/>
<privatetypes title=""/>
<privateslots title=""/>
<privatemethods title=""/>
<privatestaticmethods title=""/>
<privateattributes title=""/>
<privatestaticattributes title=""/>
<friends title=""/>
<related title="" subtitle=""/>
<membergroups visible="yes"/>
</memberdecl>

<memberdef>
<inlineclasses title=""/>
<typedefs title=""/>
<enums title=""/>
<constructors title=""/>
<functions title=""/>
<related title=""/>
<variables title=""/>
<properties title=""/>
<events title=""/>
</memberdef>
<usedfiles visible="$SHOW_USED_FILES"/>
<authorsection visible="yes"/>
</class>

<!-- Layout definition for a namespace page -->
<namespace>
<briefdescription visible="no"/>
<detaileddescription title=""/>
<memberdecl>
<nestednamespaces visible="yes" title=""/>
<classes visible="yes" title=""/>
<typedefs title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
<membergroups visible="yes"/>
</memberdecl>

<memberdef>
<inlineclasses title=""/>
<typedefs title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
</memberdef>
<authorsection visible="yes"/>
</namespace>

<!-- Layout definition for a file page -->
<file>
<briefdescription visible="no"/>
<detaileddescription title=""/>
<includes visible="$SHOW_INCLUDE_FILES"/>
<includegraph visible="$INCLUDE_GRAPH"/>
<includedbygraph visible="$INCLUDED_BY_GRAPH"/>
<sourcelink visible="yes"/>
<memberdecl>
<classes visible="yes" title=""/>
<namespaces visible="yes" title=""/>
<defines title=""/>
<typedefs title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
<membergroups visible="yes"/>
</memberdecl>

<memberdef>
<inlineclasses title=""/>
<defines title=""/>
<typedefs title=""/>
<enums title=""/>
<functions title=""/>
<variables title=""/>
</memberdef>
<authorsection/>
</file>

<!-- Layout definition for a group page -->
<group>
<briefdescription visible="no"/>
<detaileddescription title=""/>
<groupgraph visible="$GROUP_GRAPHS"/>
<memberdecl>
<classes visible="yes" title=""/>
<namespaces visible="yes" title=""/>
<dirs visible="yes" title=""/>
<nestedgroups visible="yes" title=""/>
<files visible="yes" title=""/>
<defines title=""/>
<typedefs title=""/>
<enums title=""/>
<enumvalues title=""/>
<functions title=""/>
<variables title=""/>
<signals title=""/>
<publicslots title=""/>
<protectedslots title=""/>
<privateslots title=""/>
<events title=""/>
<properties title=""/>
<friends title=""/>
<membergroups visible="yes"/>
</memberdecl>

<memberdef>
<pagedocs/>
<inlineclasses title=""/>
<defines title=""/>
<typedefs title=""/>
<enums title=""/>
<enumvalues title=""/>
<functions title=""/>
<variables title=""/>
<signals title=""/>
<publicslots title=""/>
<protectedslots title=""/>
<privateslots title=""/>
<events title=""/>
<properties title=""/>
<friends title=""/>
</memberdef>
<authorsection visible="yes"/>
</group>

<!-- Layout definition for a directory page -->
<directory>
<briefdescription visible="no"/>
<detaileddescription title=""/>
<directorygraph visible="yes"/>
<memberdecl>
<dirs visible="yes"/>
<files visible="yes"/>
</memberdecl>

</directory>
</doxygenlayout>
48 changes: 48 additions & 0 deletions third_party/optionparser-1.7/README_ARGC_ARGV
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
POSIX Guidelines for command line arguments

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

----------------------------------------------

From the C standard:

5.1.2.2.1 Program startup

The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent; or in some other implementation-defined manner.

If they are declared, the parameters to the main function shall obey the following
constraints:

— The value of argc shall be nonnegative.

— argv[argc] shall be a null pointer.

— If the value of argc is greater than zero, the array members argv[0] through
argv[argc-1] inclusive shall contain pointers to strings, which are given
implementation-defined values by the host environment prior to program startup.
The intent is to supply to the program information determined prior to program
startup from elsewhere in the hosted environment. If the host environment is
not capable of supplying strings with letters in both uppercase and lowercase,
the implementation shall ensure that the strings are received in lowercase.

— If the value of argc is greater than zero, the string pointed to by argv[0]
represents the program name; argv[0][0] shall be the null character if the
program name is not available from the host environment. If the value of argc is
greater than one, the strings pointed to by argv[1] through argv[argc-1]
represent the program parameters.

— The parameters argc and argv and the strings pointed to by the argv array shall
be modifiable by the program, and retain their last-stored values between program
startup and program termination.

53 changes: 53 additions & 0 deletions third_party/optionparser-1.7/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
CXX=g++
CXXFLAGS=-W -Wall -g -fmessage-length=0
CCFLAGS=$(CXXFLAGS) -fno-exceptions -fno-rtti -nodefaultlibs
OPTIMIZE=-Os -fomit-frame-pointer
#OPTIMIZE=-O0
LD=gcc # gcc automatically picks the correct crt*.o and helper libraries to link
VERSION=1.7
PACKAGEDIR=optionparser-$(VERSION)
TARBALL=../$(PACKAGEDIR).tar.gz

all: example_arg testparse testprintusage testodr example doc

# .cpp files depend on the C++ standard lib
%: %.cpp optionparser.h
$(CXX) $(CXXFLAGS) $(OPTIMIZE) -o $@ $<

# .cc files depend only on libc
%.o: %.cc optionparser.h
$(CXX) $(CCFLAGS) $(OPTIMIZE) -c $<

%: %.cc optionparser.h
$(CXX) $(CCFLAGS) $(OPTIMIZE) -lc -o $@ $<

testprintusage: testprintusage.cpp optionparser.h
$(CXX) $(CXXFLAGS) $(OPTIMIZE) -Wno-unused-result -o $@ $<

# testodr needs to be linked in a separate step rather than
# just passing both .cpp files to g++, because only this way
# can we be sure that duplicate definitions cause an error message.
testodr: testodr1.o testodr2.o
$(LD) -lc -o $@ $^

doc:
cd .. && doxygen
cd .. && cat Doxyfile | sed '/^INTERNAL_DOCS/s/YES/NO/;/^HTML_OUTPUT/s/-dev//' | doxygen -

clean:
rm -f testodr testodr1.o testodr2.o example.o example testprintusage testparse example_arg
rm -rf ../html ../html-dev $(PACKAGEDIR) $(TARBALL)
rm -f *~ ../*~

package:
rm -rf $(PACKAGEDIR)
mkdir -p $(PACKAGEDIR)/src
cp ../Doxyfile ../DoxygenLayout.xml ../README_ARGC_ARGV $(PACKAGEDIR)
cp Makefile example.cpp example_arg.cc optionparser.h \
testodr1.cc testodr2.cc testparse.cpp testprintusage.cpp \
printUsage.h $(PACKAGEDIR)/src
tar --owner=0 --group=0 -czf $(TARBALL) $(PACKAGEDIR)

upload: all package
cd .. && scp -r src/optionparser.h html/* optionparser-frs:/home/project-web/optionparser/htdocs
scp $(TARBALL) optionparser-frs:/home/frs/project/o/op/optionparser
56 changes: 56 additions & 0 deletions third_party/optionparser-1.7/src/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Written 2012 by Matthias S. Benkmann
*
* The author hereby waives all copyright and related rights to the contents
* of this example file (example.cpp) to the extent possible under the law.
*/

/**
* @file
* @brief Small demo of The Lean Mean C++ Option Parser.
*
* @include example.cpp
*/

#include <iostream>
#include <string>
#include <vector>
#include "optionparser.h"

enum optionIndex { UNKNOWN, HELP, PLUS };
const option::Descriptor usage[] =
{
{UNKNOWN, 0, "", "",option::Arg::None, "USAGE: example [options]\n\n"
"Options:" },
{HELP, 0,"", "help",option::Arg::None, " --help \tPrint usage and exit." },
{PLUS, 0,"p","plus",option::Arg::None, " --plus, -p \tIncrement count." },
{UNKNOWN, 0, "", "",option::Arg::None, "\nExamples:\n"
" example --unknown -- --this_is_no_option\n"
" example -unk --plus -ppp file1 file2\n" },
{0,0,0,0,0,0}
};

int main(int argc, char* argv[])
{
argc-=(argc>0); argv+=(argc>0); // skip program name argv[0] if present
option::Stats stats(usage, argc, argv);
std::vector<option::Option> options(stats.options_max);
std::vector<option::Option> buffer(stats.buffer_max);
option::Parser parse(usage, argc, argv, &options[0], &buffer[0]);

if (parse.error())
return 1;

if (options[HELP] || argc == 0) {
option::printUsage(std::cout, usage);
return 0;
}

std::cout << "--plus count: " <<
options[PLUS].count() << "\n";

for (option::Option* opt = options[UNKNOWN]; opt; opt = opt->next())
std::cout << "Unknown option: " << std::string(opt->name,opt->namelen) << "\n";

for (int i = 0; i < parse.nonOptionsCount(); ++i)
std::cout << "Non-option #" << i << ": " << parse.nonOption(i) << "\n";
}
Loading

0 comments on commit a159d7b

Please sign in to comment.