some work in MainSpaceParser: added reading long (--longname) parameters

git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1025 e52654a7-88a9-db11-a3e9-0013d4bc506e
master
Tomasz Sowa 7 years ago
parent 7b4b576489
commit 9deb2ff2f2

@ -16,6 +16,9 @@ ifndef AR
AR = ar
endif
#CXX=g++48
#CXXFLAGS=-Wall -O0 -g3
export CXX
export CXXFLAGS
export LDFLAGS

@ -1,3 +1,4 @@
# DO NOT DELETE
mainspaceparser.o: mainspaceparser.h ../space/space.h ../textstream/types.h
mainspaceparser.o: ../utf8/utf8.h

@ -173,38 +173,93 @@ void MainSpaceParser::ParseSingleArgument(size_t argc, const char ** argv, size_
ConvertStr(argv[argv_index], temp_val);
temp_list_val.push_back(temp_val);
}
if( opt_size > 0 )
{
last_status = status_reading_eof;
last_error_token.clear();
}
}
temp_val.clear();
if( temp_list_val.empty() )
space->Add(temp_arg, temp_val);
else
if( temp_list_val.size() == 1 )
space->Add(temp_arg, temp_list_val[0] );
else
space->table[temp_arg] = temp_list_val; // !! IMPROVE ME
AddValueToItem(temp_arg, temp_val, temp_list_val);
}
}
void MainSpaceParser::ParseMultiArgument(size_t argc, const char ** argv, size_t & argv_index)
{
ConvertStr(argv[argv_index] + 2, wide_arg);
ConvertStr(argv[argv_index] + 2, temp_arg);
argv_index += 1;
size_t opt_size = RequireOption(temp_arg);
temp_list_val.clear();
if( opt_size > 0 )
{
for( ; opt_size > 0 && argv_index < argc ; --opt_size, ++argv_index)
{
ConvertStr(argv[argv_index], temp_val);
temp_list_val.push_back(temp_val);
}
if( opt_size > 0 )
{
last_status = status_reading_eof;
last_error_token.clear();
}
}
temp_val.clear();
AddValueToItem(temp_arg, temp_val, temp_list_val);
}
/*
* IMPLEMENT ME
* add checking for files here
*
*/
space->Add(wide_arg, temp_val);
argv_index += 1;
void MainSpaceParser::AddValueToItem(const std::wstring & name, const std::wstring & empty_value, const std::vector<std::wstring> & list)
{
std::wstring * val = space->GetValue(name);
if( !val )
{
if( list.empty() )
space->Add(name, empty_value);
else
if( list.size() == 1 )
space->Add(name, list[0]);
else
space->table[name] = list; // !! IMPROVE ME there'll be a new api in space
}
else
{
PT::Space::Table::iterator i = space->table.find(name);
PT::Space::Value * table_value;
if( i == space->table.end() )
{
table_value = &space->table[name];
table_value->push_back(*val);
space->table_single.erase(name);
}
else
{
table_value = &i->second;
}
if( list.empty() )
{
table_value->push_back(empty_value);
}
else
{
for(const auto & list_item : list)
table_value->push_back(list_item);
}
}
}
size_t MainSpaceParser::RequireOption(const std::wstring & arg)
{
size_t res = 0;

@ -63,6 +63,7 @@ public:
status_ok = 0,
status_space_not_assigned = 1,
status_syntax_error = 2,
status_reading_eof = 3 /* CHANGE ME give a better name */
};
void SetSpace(Space & space);
@ -88,7 +89,7 @@ private:
void ParseSingleArgument(size_t argc, const char ** argv, size_t & argv_index);
void ParseMultiArgument(size_t argc, const char ** argv, size_t & argv_index);
size_t RequireOption(const std::wstring & arg);
void AddValueToItem(const std::wstring & name, const std::wstring & empty_value, const std::vector<std::wstring> & list);
};

Loading…
Cancel
Save