changed the way how the library is built
- now there is only one Makefile in the root directory and we have only one pikotools.a lib file - removed: mainparser
This commit is contained in:
parent
61291cf7ad
commit
5b5a1dfbb6
74
Makefile
74
Makefile
|
@ -1,4 +1,14 @@
|
|||
# Makefile for GNU make
|
||||
sourcefiles:=$(shell find . -name "*.cpp")
|
||||
objfiles:=$(patsubst %.cpp,%.o,$(sourcefiles))
|
||||
|
||||
|
||||
|
||||
CXX = g++10
|
||||
#CXX = clang++
|
||||
#CXXFLAGS = -fsanitize=address -O0 -g3 -gdwarf-2 -O0 -std=c++14 -I../ttmath -I../pikotools -Wl,-rpath=/usr/local/lib/gcc5/ -Wall -pedantic -Wextra
|
||||
#CXXFLAGS = -O0 -g3 -gdwarf-2 -O0 -std=c++17 -I../ttmath -I../pikotools -Wl,-rpath=/usr/local/lib/gcc7/ -Wall -pedantic -Wextra
|
||||
CXXFLAGS = -Wl,-rpath=/usr/local/lib/gcc10/ -O0 -g3 -std=c++20 -I../pikotools -Wall -pedantic
|
||||
|
||||
|
||||
ifndef CXX
|
||||
CXX = clang++
|
||||
|
@ -16,61 +26,35 @@ ifndef AR
|
|||
AR = ar
|
||||
endif
|
||||
|
||||
#CXX=g++5
|
||||
#CXXFLAGS=-Wall -O0 -g3 -gdwarf-2 -std=c++14
|
||||
|
||||
export CXX
|
||||
export CXXFLAGS
|
||||
export LDFLAGS
|
||||
export AR
|
||||
#export CXX
|
||||
#export CXXFLAGS
|
||||
#export LDFLAGS
|
||||
#export AR
|
||||
|
||||
|
||||
all: space mainparser mainspaceparser utf8 date convert log
|
||||
libname = pikotools.a
|
||||
|
||||
|
||||
all: $(libname)
|
||||
|
||||
|
||||
space: FORCE
|
||||
@cd space ; $(MAKE) -e
|
||||
|
||||
mainparser: FORCE
|
||||
@cd mainparser ; $(MAKE) -e
|
||||
|
||||
mainspaceparser: FORCE
|
||||
@cd mainspaceparser ; $(MAKE) -e
|
||||
|
||||
utf8: FORCE
|
||||
@cd utf8 ; $(MAKE) -e
|
||||
|
||||
date: FORCE
|
||||
@cd date ; $(MAKE) -e
|
||||
|
||||
convert: FORCE
|
||||
@cd convert ; $(MAKE) -e
|
||||
|
||||
log: FORCE
|
||||
@cd log ; $(MAKE) -e
|
||||
$(libname): $(objfiles)
|
||||
$(AR) rcs $(libname) $(objfiles)
|
||||
|
||||
|
||||
|
||||
|
||||
FORCE:
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) -o $@ $<
|
||||
|
||||
|
||||
clean:
|
||||
@cd space ; $(MAKE) -e clean
|
||||
@cd mainparser ; $(MAKE) -e clean
|
||||
@cd mainspaceparser ; $(MAKE) -e clean
|
||||
@cd utf8 ; $(MAKE) -e clean
|
||||
@cd date ; $(MAKE) -e clean
|
||||
@cd convert ; $(MAKE) -e clean
|
||||
@cd log ; $(MAKE) -e clean
|
||||
rm -f $(objfiles)
|
||||
rm -f $(libname)
|
||||
|
||||
|
||||
depend:
|
||||
@cd space ; $(MAKE) -e depend
|
||||
@cd mainparser ; $(MAKE) -e depend
|
||||
@cd mainspaceparser ; $(MAKE) -e depend
|
||||
@cd utf8 ; $(MAKE) -e depend
|
||||
@cd date ; $(MAKE) -e depend
|
||||
@cd convert ; $(MAKE) -e depend
|
||||
@cd log ; $(MAKE) -e depend
|
||||
makedepend -Y. -f- $(sourcefiles) > Makefile.dep
|
||||
|
||||
|
||||
-include Makefile.dep
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
# DO NOT DELETE
|
||||
|
||||
./convert/misc.o: ./convert/misc.h ./convert/text.h
|
||||
./convert/text.o: ./convert/text.h
|
||||
./convert/inttostr.o: ./convert/inttostr.h
|
||||
./date/date.o: ./date/date.h convert/inttostr.h
|
||||
./log/filelog.o: ./log/filelog.h textstream/textstream.h space/space.h
|
||||
./log/filelog.o: textstream/types.h convert/inttostr.h date/date.h
|
||||
./log/filelog.o: membuffer/membuffer.h textstream/types.h utf8/utf8.h
|
||||
./log/filelog.o: utf8/utf8_templates.h utf8/utf8_private.h
|
||||
./log/log.o: ./log/log.h textstream/textstream.h space/space.h
|
||||
./log/log.o: textstream/types.h convert/inttostr.h date/date.h
|
||||
./log/log.o: membuffer/membuffer.h textstream/types.h ./log/filelog.h
|
||||
./log/log.o: utf8/utf8.h utf8/utf8_templates.h utf8/utf8_private.h
|
||||
./mainspaceparser/mainspaceparser.o: ./mainspaceparser/mainspaceparser.h
|
||||
./mainspaceparser/mainspaceparser.o: space/space.h textstream/types.h
|
||||
./mainspaceparser/mainspaceparser.o: convert/inttostr.h utf8/utf8.h
|
||||
./mainspaceparser/mainspaceparser.o: textstream/textstream.h date/date.h
|
||||
./mainspaceparser/mainspaceparser.o: membuffer/membuffer.h textstream/types.h
|
||||
./mainspaceparser/mainspaceparser.o: utf8/utf8_templates.h
|
||||
./mainspaceparser/mainspaceparser.o: utf8/utf8_private.h
|
||||
./space/jsontospaceparser.o: ./space/jsontospaceparser.h ./space/space.h
|
||||
./space/jsontospaceparser.o: textstream/types.h convert/inttostr.h
|
||||
./space/jsontospaceparser.o: utf8/utf8.h textstream/textstream.h
|
||||
./space/jsontospaceparser.o: space/space.h date/date.h membuffer/membuffer.h
|
||||
./space/jsontospaceparser.o: textstream/types.h utf8/utf8_templates.h
|
||||
./space/jsontospaceparser.o: utf8/utf8_private.h convert/strtoint.h
|
||||
./space/jsontospaceparser.o: ./convert/text.h ./convert/misc.h
|
||||
./space/space.o: ./space/space.h textstream/types.h convert/inttostr.h
|
||||
./space/space.o: utf8/utf8.h textstream/textstream.h space/space.h
|
||||
./space/space.o: date/date.h membuffer/membuffer.h textstream/types.h
|
||||
./space/space.o: utf8/utf8_templates.h utf8/utf8_private.h convert/convert.h
|
||||
./space/space.o: ./convert/inttostr.h convert/patternreplacer.h
|
||||
./space/space.o: convert/strtoint.h ./convert/text.h ./convert/misc.h
|
||||
./space/spaceparser.o: ./space/spaceparser.h ./space/space.h
|
||||
./space/spaceparser.o: textstream/types.h convert/inttostr.h utf8/utf8.h
|
||||
./space/spaceparser.o: textstream/textstream.h space/space.h date/date.h
|
||||
./space/spaceparser.o: membuffer/membuffer.h textstream/types.h
|
||||
./space/spaceparser.o: utf8/utf8_templates.h utf8/utf8_private.h
|
||||
./space/spacetojson.o: ./space/spacetojson.h ./space/space.h
|
||||
./space/spacetojson.o: textstream/types.h convert/inttostr.h
|
||||
./utf8/utf8.o: ./utf8/utf8.h textstream/textstream.h space/space.h
|
||||
./utf8/utf8.o: textstream/types.h convert/inttostr.h date/date.h
|
||||
./utf8/utf8.o: membuffer/membuffer.h textstream/types.h utf8/utf8_templates.h
|
||||
./utf8/utf8.o: utf8/utf8_private.h
|
||||
./utf8/utf8_private.o: utf8/utf8_private.h textstream/textstream.h
|
||||
./utf8/utf8_private.o: space/space.h textstream/types.h convert/inttostr.h
|
||||
./utf8/utf8_private.o: date/date.h membuffer/membuffer.h textstream/types.h
|
|
@ -1,27 +0,0 @@
|
|||
include Makefile.o.dep
|
||||
|
||||
libname=convert.a
|
||||
|
||||
all: $(libname)
|
||||
|
||||
$(libname): $(o)
|
||||
$(AR) rcs $(libname) $(o)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) -I.. $<
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -I.. -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f $(libname)
|
||||
|
||||
|
||||
include Makefile.dep
|
|
@ -1,5 +0,0 @@
|
|||
# DO NOT DELETE
|
||||
|
||||
inttostr.o: inttostr.h
|
||||
misc.o: misc.h text.h
|
||||
text.o: text.h
|
|
@ -1 +0,0 @@
|
|||
o = inttostr.o misc.o text.o
|
|
@ -1,27 +0,0 @@
|
|||
include Makefile.o.dep
|
||||
|
||||
libname=date.a
|
||||
|
||||
all: $(libname)
|
||||
|
||||
$(libname): $(o)
|
||||
$(AR) rcs $(libname) $(o)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) -I.. $<
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -I.. -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f $(libname)
|
||||
|
||||
|
||||
include Makefile.dep
|
|
@ -1,3 +0,0 @@
|
|||
# DO NOT DELETE
|
||||
|
||||
date.o: date.h ../convert/inttostr.h
|
|
@ -1 +0,0 @@
|
|||
o = date.o
|
27
log/Makefile
27
log/Makefile
|
@ -1,27 +0,0 @@
|
|||
include Makefile.o.dep
|
||||
|
||||
libname=log.a
|
||||
|
||||
all: $(libname)
|
||||
|
||||
$(libname): $(o)
|
||||
$(AR) rcs $(libname) $(o)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) -I.. $<
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -I.. -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f $(libname)
|
||||
|
||||
|
||||
include Makefile.dep
|
|
@ -1,10 +0,0 @@
|
|||
# DO NOT DELETE
|
||||
|
||||
filelog.o: filelog.h ../textstream/textstream.h ../space/space.h
|
||||
filelog.o: ../textstream/types.h ../convert/inttostr.h ../date/date.h
|
||||
filelog.o: ../membuffer/membuffer.h ../textstream/types.h ../utf8/utf8.h
|
||||
filelog.o: ../utf8/utf8_templates.h ../utf8/utf8_private.h
|
||||
log.o: log.h ../textstream/textstream.h ../space/space.h
|
||||
log.o: ../textstream/types.h ../convert/inttostr.h ../date/date.h
|
||||
log.o: ../membuffer/membuffer.h ../textstream/types.h filelog.h
|
||||
log.o: ../utf8/utf8.h ../utf8/utf8_templates.h ../utf8/utf8_private.h
|
|
@ -1 +0,0 @@
|
|||
o = filelog.o log.o
|
|
@ -1,27 +0,0 @@
|
|||
include Makefile.o.dep
|
||||
|
||||
libname=mainparser.a
|
||||
|
||||
all: $(libname)
|
||||
|
||||
$(libname): $(o)
|
||||
$(AR) rcs $(libname) $(o)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) -I.. $<
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -I.. -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f $(libname)
|
||||
|
||||
|
||||
include Makefile.dep
|
|
@ -1,3 +0,0 @@
|
|||
# DO NOT DELETE
|
||||
|
||||
mainparser.o: mainparser.h
|
|
@ -1 +0,0 @@
|
|||
o = mainparser.o
|
|
@ -1,237 +0,0 @@
|
|||
/*
|
||||
* This file is a part of PikoTools
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include "mainparser.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
namespace PT
|
||||
{
|
||||
|
||||
|
||||
MainParser::MainParser()
|
||||
{
|
||||
argsize = 0;
|
||||
arg = 0;
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
MainParser::MainParser(int argc, const char ** argv)
|
||||
{
|
||||
Set(argc, argv);
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainParser::Set(int argc, const char ** argv)
|
||||
{
|
||||
argsize = argc;
|
||||
arg = argv;
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainParser::Reset()
|
||||
{
|
||||
argindex = 1;
|
||||
offset = 0;
|
||||
has_single_param = false;
|
||||
has_double_param = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char MainParser::GetSingleParam()
|
||||
{
|
||||
if( !has_single_param )
|
||||
return 0;
|
||||
|
||||
if( last_single_param != 0 )
|
||||
return last_single_param;
|
||||
|
||||
Advance();
|
||||
|
||||
if( argindex >= argsize )
|
||||
return 0;
|
||||
|
||||
last_single_param = arg[argindex][offset];
|
||||
offset += 1;
|
||||
|
||||
return last_single_param;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MainParser::IsSingleParam(char c)
|
||||
{
|
||||
return GetSingleParam() == c;
|
||||
}
|
||||
|
||||
|
||||
const char * MainParser::GetDoubleParam()
|
||||
{
|
||||
empty = 0;
|
||||
|
||||
if( !has_double_param )
|
||||
return ∅
|
||||
|
||||
if( last_double_param != &empty )
|
||||
return last_double_param;
|
||||
|
||||
Advance();
|
||||
|
||||
if( argindex >= argsize )
|
||||
return ∅
|
||||
|
||||
last_double_param = &arg[argindex][offset];
|
||||
offset = 0;
|
||||
argindex += 1;
|
||||
|
||||
return last_double_param;
|
||||
}
|
||||
|
||||
|
||||
bool MainParser::IsDoubleParam(const char * param)
|
||||
{
|
||||
return strcmp(GetDoubleParam(), param) == 0;
|
||||
}
|
||||
|
||||
|
||||
const char * MainParser::GetValue()
|
||||
{
|
||||
empty = 0;
|
||||
Advance();
|
||||
|
||||
if( argindex >= argsize )
|
||||
return ∅
|
||||
|
||||
const char * value = &arg[argindex][offset];
|
||||
offset = 0;
|
||||
argindex += 1;
|
||||
has_single_param = false;
|
||||
has_double_param = false;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MainParser::NextParam()
|
||||
{
|
||||
bool was_single_param = has_single_param;
|
||||
has_single_param = false;
|
||||
has_double_param = false;
|
||||
last_single_param = 0;
|
||||
last_double_param = ∅
|
||||
empty = 0;
|
||||
|
||||
if( Advance() )
|
||||
was_single_param = false;
|
||||
|
||||
if( argindex >= argsize )
|
||||
return false;
|
||||
|
||||
if( arg[argindex][offset]=='-' )
|
||||
{
|
||||
if( arg[argindex][offset+1]=='-' )
|
||||
{
|
||||
has_double_param = true;
|
||||
offset += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
has_single_param = true;
|
||||
offset += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( was_single_param )
|
||||
has_single_param = true;
|
||||
}
|
||||
|
||||
return has_single_param || has_double_param;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MainParser::IsEnd()
|
||||
{
|
||||
Advance();
|
||||
|
||||
return argindex >= argsize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MainParser::HasSingleParam()
|
||||
{
|
||||
return has_single_param;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MainParser::HasDoubleParam()
|
||||
{
|
||||
return has_double_param;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MainParser::Advance()
|
||||
{
|
||||
bool was_incremented = false;
|
||||
|
||||
while( argindex < argsize && arg[argindex][offset] == 0 )
|
||||
{
|
||||
offset = 0;
|
||||
argindex += 1;
|
||||
was_incremented = true;
|
||||
}
|
||||
|
||||
return was_incremented;
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
/*
|
||||
* This file is a part of PikoTools
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef headerfile_picotools_mainparser_mainparser
|
||||
#define headerfile_picotools_mainparser_mainparser
|
||||
|
||||
|
||||
namespace PT
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
a very little parser for main(int argc, char ** argv) parameters
|
||||
look in sample/sample.cpp how to use the parser
|
||||
*/
|
||||
class MainParser
|
||||
{
|
||||
public:
|
||||
|
||||
MainParser();
|
||||
MainParser(int argc, const char ** argv);
|
||||
|
||||
// setting arguments passed to main(int argc, char ** argv) function
|
||||
void Set(int argc, const char ** argv);
|
||||
|
||||
// reseting the current state of parsing
|
||||
// now you can start parsing from the beginning
|
||||
// you don't have to call it for the first time
|
||||
// (is automatically called by the Set method)
|
||||
void Reset();
|
||||
|
||||
// checking if there is a next single or double parameter
|
||||
// this method represents the main loop of checking parameters
|
||||
bool NextParam();
|
||||
|
||||
// returning a single parameter (if exists) or '\0' otherwise
|
||||
// single parameter means a parameter with '-' at the beginning e.g. "-a"
|
||||
// next call to this method (without calling NextParam) returns the same value
|
||||
// this method should be called after NextParam()
|
||||
char GetSingleParam();
|
||||
|
||||
// calling GetSingleParam() and comparign with 'c'
|
||||
bool IsSingleParam(char c);
|
||||
|
||||
// returning a string for a double parameter or an empty string if there is no such a parameter
|
||||
// double parameter means a parameter with '--' at the beginning e.g. "--output"
|
||||
// next call to this method (without calling NextParam) returns the same value
|
||||
// GetDoubleParam() should be called after NextParam()
|
||||
// this method never returns a null pointer -- if there is no a param name (end of the string)
|
||||
// a pointer to en empty string will be returned
|
||||
const char * GetDoubleParam();
|
||||
|
||||
// calling GetDoubleParam() and comparing with 'param'
|
||||
// so you don't have to call strcmp directly
|
||||
bool IsDoubleParam(const char * param);
|
||||
|
||||
// returning a string representing a value
|
||||
// you have to know which parameter requires a value
|
||||
// and if such a parameter is found then use this method to obtain the value
|
||||
// the method advances the current pointer so next call to this method return a next value
|
||||
// you can call GetValue() even when NextParam() has returned false
|
||||
// in such a case this gets you the last values (those at the end of the parameter list)
|
||||
// this method never returns a null pointer -- if there is no a value (end of the string)
|
||||
// a pointer to en empty string will be returned
|
||||
const char * GetValue();
|
||||
|
||||
// returning true if the input string is finished
|
||||
// there are no more parameters or values
|
||||
bool IsEnd();
|
||||
|
||||
// returning true if there is a single parameter
|
||||
// should be called after NextParam()
|
||||
bool HasSingleParam();
|
||||
|
||||
// returning true if there is a double parameter
|
||||
// should be called after NextParam()
|
||||
bool HasDoubleParam();
|
||||
|
||||
private:
|
||||
|
||||
bool Advance();
|
||||
|
||||
int argindex;
|
||||
int offset;
|
||||
int argsize;
|
||||
const char ** arg;
|
||||
char empty;
|
||||
bool has_single_param;
|
||||
bool has_double_param;
|
||||
char last_single_param;
|
||||
const char * last_double_param;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif
|
|
@ -1,10 +0,0 @@
|
|||
output=sample
|
||||
|
||||
all: $(output)
|
||||
|
||||
$(output): sample.cpp ../mainparser.h ../mainparser.cpp
|
||||
g++ -o $(output) sample.cpp ../mainparser.cpp
|
||||
|
||||
clean:
|
||||
rm -f $(output)
|
||||
rm -f $(output).exe
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* This file is a part of MainParser -- simple parser for main() parameters
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include "../mainparser.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
MainParser mp;
|
||||
|
||||
// suppose you call a 'programname' in such a way:
|
||||
// $ programname -a -b - c --longparam -- otherlongparam -xyz paramwithvalue -x --longparam2 longwithvalue lastvalue1 lastvalue2 lastvalue3
|
||||
// so the main() function get this table as input:
|
||||
|
||||
const char * tab[] = {
|
||||
"programname",
|
||||
"-a",
|
||||
"-b",
|
||||
"-",
|
||||
"c",
|
||||
"--longparam",
|
||||
"--",
|
||||
"otherlongparam",
|
||||
"-xyz",
|
||||
"paramwithvalue",
|
||||
"-x",
|
||||
"--longparam2",
|
||||
"longwithvalue",
|
||||
"lastvalue1", // some values left at the end
|
||||
"lastvalue2", // you can get them by using GetValue() method
|
||||
"lastvalue3",
|
||||
};
|
||||
|
||||
mp.Set(sizeof(tab)/sizeof(const char*), tab);
|
||||
|
||||
while( mp.NextParam() )
|
||||
{
|
||||
if( mp.GetSingleParam() != 0 )
|
||||
{
|
||||
std::cout << "-" << mp.GetSingleParam() << std::endl;
|
||||
|
||||
// we know that 'z' requires a value
|
||||
if( mp.GetSingleParam() == 'z' )
|
||||
std::cout << "value for z: " << mp.GetValue() << std::endl;
|
||||
}
|
||||
|
||||
if( *mp.GetDoubleParam() )
|
||||
{
|
||||
std::cout << "--" << mp.GetDoubleParam() << std::endl;
|
||||
|
||||
// we know that "longparam2" requires a value
|
||||
if( strcmp(mp.GetDoubleParam(), "longparam2") == 0 )
|
||||
std::cout << "value for longparam2: " << mp.GetValue() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
while( !mp.IsEnd() )
|
||||
std::cout << mp.GetValue() << std::endl;
|
||||
}
|
||||
|
||||
/*
|
||||
program output:
|
||||
|
||||
-a
|
||||
-b
|
||||
-c
|
||||
--longparam
|
||||
--otherlongparam
|
||||
-x
|
||||
-y
|
||||
-z
|
||||
value for z: paramwithvalue
|
||||
-x
|
||||
--longparam2
|
||||
value for longparam2: longwithvalue
|
||||
lastvalue1
|
||||
lastvalue2
|
||||
lastvalue3
|
||||
*/
|
|
@ -1,27 +0,0 @@
|
|||
include Makefile.o.dep
|
||||
|
||||
libname=mainspaceparser.a
|
||||
|
||||
all: $(libname)
|
||||
|
||||
$(libname): $(o)
|
||||
$(AR) rcs $(libname) $(o)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) -I.. $<
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -I.. -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f $(libname)
|
||||
|
||||
|
||||
include Makefile.dep
|
|
@ -1,7 +0,0 @@
|
|||
# DO NOT DELETE
|
||||
|
||||
mainspaceparser.o: mainspaceparser.h ../space/space.h ../textstream/types.h
|
||||
mainspaceparser.o: ../convert/inttostr.h ../utf8/utf8.h
|
||||
mainspaceparser.o: ../textstream/textstream.h ../date/date.h
|
||||
mainspaceparser.o: ../membuffer/membuffer.h ../textstream/types.h
|
||||
mainspaceparser.o: ../utf8/utf8_templates.h ../utf8/utf8_private.h
|
|
@ -1 +0,0 @@
|
|||
o = mainspaceparser.o
|
|
@ -1,27 +0,0 @@
|
|||
include Makefile.o.dep
|
||||
|
||||
libname=space.a
|
||||
|
||||
all: $(libname)
|
||||
|
||||
$(libname): $(o)
|
||||
$(AR) rcs $(libname) $(o)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) -I.. $<
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -I.. -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f $(libname)
|
||||
|
||||
|
||||
include Makefile.dep
|
|
@ -1,27 +0,0 @@
|
|||
# DO NOT DELETE
|
||||
|
||||
jsontospaceparser.o: jsontospaceparser.h space.h ../textstream/types.h
|
||||
jsontospaceparser.o: ../convert/inttostr.h ../utf8/utf8.h
|
||||
jsontospaceparser.o: ../textstream/textstream.h ../space/space.h
|
||||
jsontospaceparser.o: ../date/date.h ../membuffer/membuffer.h
|
||||
jsontospaceparser.o: ../textstream/types.h ../utf8/utf8_templates.h
|
||||
jsontospaceparser.o: ../utf8/utf8_private.h ../convert/strtoint.h
|
||||
jsontospaceparser.o: ../convert/text.h ../convert/misc.h
|
||||
main.o: space.h ../textstream/types.h ../convert/inttostr.h ../utf8/utf8.h
|
||||
main.o: ../textstream/textstream.h ../space/space.h ../date/date.h
|
||||
main.o: ../membuffer/membuffer.h ../textstream/types.h
|
||||
main.o: ../utf8/utf8_templates.h ../utf8/utf8_private.h
|
||||
main.o: ../space/jsontospaceparser.h
|
||||
space.o: space.h ../textstream/types.h ../convert/inttostr.h ../utf8/utf8.h
|
||||
space.o: ../textstream/textstream.h ../space/space.h ../date/date.h
|
||||
space.o: ../membuffer/membuffer.h ../textstream/types.h
|
||||
space.o: ../utf8/utf8_templates.h ../utf8/utf8_private.h ../convert/convert.h
|
||||
space.o: ../convert/inttostr.h ../convert/patternreplacer.h
|
||||
space.o: ../convert/strtoint.h ../convert/text.h ../convert/misc.h
|
||||
spaceparser.o: spaceparser.h space.h ../textstream/types.h
|
||||
spaceparser.o: ../convert/inttostr.h ../utf8/utf8.h
|
||||
spaceparser.o: ../textstream/textstream.h ../space/space.h ../date/date.h
|
||||
spaceparser.o: ../membuffer/membuffer.h ../textstream/types.h
|
||||
spaceparser.o: ../utf8/utf8_templates.h ../utf8/utf8_private.h
|
||||
spacetojson.o: spacetojson.h space.h ../textstream/types.h
|
||||
spacetojson.o: ../convert/inttostr.h
|
|
@ -1 +0,0 @@
|
|||
o = jsontospaceparser.o main.o space.o spaceparser.o spacetojson.o
|
|
@ -1,27 +0,0 @@
|
|||
include Makefile.o.dep
|
||||
|
||||
libname=utf8.a
|
||||
|
||||
all: $(libname)
|
||||
|
||||
$(libname): $(o)
|
||||
$(AR) rcs $(libname) $(o)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) -I.. $<
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -I.. -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f $(libname)
|
||||
|
||||
|
||||
include Makefile.dep
|
|
@ -1,9 +0,0 @@
|
|||
# DO NOT DELETE
|
||||
|
||||
utf8_private.o: utf8_private.h ../textstream/textstream.h ../space/space.h
|
||||
utf8_private.o: ../textstream/types.h ../convert/inttostr.h ../date/date.h
|
||||
utf8_private.o: ../membuffer/membuffer.h ../textstream/types.h
|
||||
utf8.o: utf8.h ../textstream/textstream.h ../space/space.h
|
||||
utf8.o: ../textstream/types.h ../convert/inttostr.h ../date/date.h
|
||||
utf8.o: ../membuffer/membuffer.h ../textstream/types.h
|
||||
utf8.o: ../utf8/utf8_templates.h utf8_private.h
|
|
@ -1 +0,0 @@
|
|||
o = utf8_private.o utf8.o
|
Loading…
Reference in New Issue