Skip to content

Commit

Permalink
Merge pull request #304 from g-maxime/append
Browse files Browse the repository at this point in the history
CLI: Add ability to append values to text fields with +=
  • Loading branch information
g-maxime authored Oct 29, 2024
2 parents af8c837 + cf5ffa4 commit 69256b8
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Source/CLI/CLI_Help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ std::string Help()
ToDisplay<<"--MaxMomentaryLoudness= specified bext max mnomentary loudness"<<std::endl;
ToDisplay<<"--MaxShortTermLoudness= specified bext maw short term loudness"<<std::endl;
ToDisplay<<"--History= specified bext history"<<std::endl;
ToDisplay<<"--IARL= specified INFO IARL"<<std::endl;
ToDisplay<<"--ISFT= specified INFO ISFT"<<std::endl;
ToDisplay<<"--xxxx= specified INFO xxxx..."<<std::endl;
ToDisplay<<"--IARL[+]= Insert or append specified INFO IARL"<<std::endl;
ToDisplay<<"--ISFT[+]= Insert or append specified INFO ISFT"<<std::endl;
ToDisplay<<"--xxxx[+]= Insert or append specified INFO xxxx..."<<std::endl;
ToDisplay<<""<<std::endl;
ToDisplay<<" Extract Core Document to:"<<std::endl;
ToDisplay<<"--out-core current display in CSV format (disable others displays)"<<std::endl;
Expand Down
13 changes: 10 additions & 3 deletions Source/CLI/CommandLine_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ CL_OPTION(Chunks_Remove)
CL_OPTION(Default)
{
//Form : --(Field)=(Value)
bool Append=false;
size_t Egal_Pos;
if (Argument.size()==2)
Egal_Pos=string::npos;
Expand All @@ -864,10 +865,13 @@ CL_OPTION(Default)
return 1;
}

if (Egal_Pos && Argument[Egal_Pos-1]=='+')
Append=true;

#ifdef _WIN32
Ztring Field(Ztring().From_UTF8(Argument), 2, Egal_Pos-2); Field.MakeLowerCase();
Ztring Field(Ztring().From_UTF8(Argument), 2, Egal_Pos-(Append?3:2)); Field.MakeLowerCase();
#else
Ztring Field(Ztring().From_Local(Argument), 2, Egal_Pos-2); Field.MakeLowerCase();
Ztring Field(Ztring().From_Local(Argument), 2, Egal_Pos-(Append?3:2)); Field.MakeLowerCase();
#endif
if (Field!=__T("description")
&& Field!=__T("originator")
Expand All @@ -893,7 +897,10 @@ CL_OPTION(Default)
}

string Value=string(Argument, Egal_Pos+1, std::string::npos);
C.In_Core_Add(Field.To_UTF8(), Value);
if (Append)
C.In_Core_Append(Field.To_UTF8(), Value);
else
C.In_Core_Add(Field.To_UTF8(), Value);

return -2; //Continue
}
Expand Down
91 changes: 88 additions & 3 deletions Source/Common/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,14 @@ float Core::Menu_File_Open_Files_Finish_Middle ()
if (Handler_in_Core_Item==Handler->second.In_Core.end())
Handler->second.In_Core[Ztring().From_UTF8(In_Core_Item->first).MakeLowerCase().To_UTF8()]=In_Core_Item->second;
}


for (map<string, Ztring>::iterator In_Core_Item=Handler_Default.In_Core_Append.begin(); In_Core_Item!=Handler_Default.In_Core_Append.end(); In_Core_Item++)
{
map<string, Ztring>::iterator Handler_in_Core_Item=Handler->second.In_Core_Append.find(Ztring().From_UTF8(In_Core_Item->first).MakeLowerCase().To_UTF8());
if (Handler_in_Core_Item==Handler->second.In_Core_Append.end())
Handler->second.In_Core_Append[Ztring().From_UTF8(In_Core_Item->first).MakeLowerCase().To_UTF8()]=In_Core_Item->second;
}

//Special Characters
if (SpecialChars_Enabled)
{
Expand All @@ -359,6 +366,16 @@ float Core::Menu_File_Open_Files_Finish_Middle ()
Field->second.FindAndReplace(__T("\\0"), __T("\0"), 0, Ztring_Recursive);
Field->second.FindAndReplace(__T("|SC1|"), __T("\\"), 0, Ztring_Recursive);
}

for (map<string, Ztring>::iterator Field=Handler->second.In_Core_Append.begin(); Field!=Handler->second.In_Core_Append.end(); Field++)
{
Field->second.FindAndReplace(__T("\\\\"), __T("|SC1|"), 0, Ztring_Recursive);
Field->second.FindAndReplace(__T("\\r"), __T("\r"), 0, Ztring_Recursive);
Field->second.FindAndReplace(__T("\\n"), __T("\n"), 0, Ztring_Recursive);
Field->second.FindAndReplace(__T("\\t"), __T("\t"), 0, Ztring_Recursive);
Field->second.FindAndReplace(__T("\\0"), __T("\0"), 0, Ztring_Recursive);
Field->second.FindAndReplace(__T("|SC1|"), __T("\\"), 0, Ztring_Recursive);
}
}

//Reading
Expand Down Expand Up @@ -392,13 +409,20 @@ float Core::Menu_File_Open_Files_Finish_Middle ()
}

//Modifying file with --xxx values
if (!Handler->second.In_Core.empty())
if (!Handler->second.In_Core.empty() || !Handler->second.In_Core_Append.empty())
{
for (map<string, Ztring>::iterator In_Core_Item=Handler->second.In_Core.begin(); In_Core_Item!=Handler->second.In_Core.end(); In_Core_Item++)
{
Handler->second.Riff->Set(In_Core_Item->first, In_Core_Item->second.To_UTF8(), Rules);
StdAll(Handler);
}

for (map<string, Ztring>::iterator In_Core_Item=Handler->second.In_Core_Append.begin(); In_Core_Item!=Handler->second.In_Core_Append.end(); In_Core_Item++)
{
string Value=Handler->second.Riff->Get(In_Core_Item->first);
Handler->second.Riff->Set(In_Core_Item->first, Value + In_Core_Item->second.To_UTF8(), Rules);
StdAll(Handler);
}
}
else if (Handler->second.In_Core_Remove)
{
Expand Down Expand Up @@ -1262,7 +1286,13 @@ bool Core::In_Core_Add (const string &FileName, const string &Field, const strin
return true;

if (File::Exists(Ztring().From_UTF8(FileName)))
{
map<string, Ztring>::iterator ToErase=Handlers[FileName].In_Core_Append.find(Field);
if (ToErase!=Handlers[FileName].In_Core_Append.end())
Handlers[FileName].In_Core_Append.erase(ToErase);

Handlers[FileName].In_Core[Field]=Ztring().From_UTF8(Value);
}
else
{
//Handling wildcards
Expand All @@ -1271,7 +1301,13 @@ bool Core::In_Core_Add (const string &FileName, const string &Field, const strin
List.push_back(Ztring().From_UTF8(FileName));

for (size_t Pos=0; Pos<List.size(); Pos++)
{
map<string, Ztring>::iterator ToErase=Handlers[List[Pos].To_UTF8()].In_Core_Append.find(Field);
if (ToErase!=Handlers[List[Pos].To_UTF8()].In_Core_Append.end())
Handlers[FileName].In_Core_Append.erase(ToErase);

Handlers[List[Pos].To_UTF8()].In_Core[Field]=Ztring().From_UTF8(Value);
}
}

return true;
Expand All @@ -1282,7 +1318,11 @@ bool Core::In_Core_Add (const string &Field, const string &Value)
{
if (Value=="NOCHANGE")
return true;


map<string, Ztring>::iterator ToErase=Handler_Default.In_Core_Append.find(Field);
if (ToErase!=Handler_Default.In_Core_Append.end())
Handler_Default.In_Core_Append.erase(ToErase);

Handler_Default.In_Core[Field]=Ztring().From_UTF8(Value);

return true;
Expand All @@ -1294,6 +1334,51 @@ bool Core::In_Chunk_Remove(const string &Field)
Handler_Default.In_Chunks_Remove.push_back(Ztring().From_UTF8(Field));
return true;
}

//---------------------------------------------------------------------------
bool Core::In_Core_Append(const string &FileName, const string &Field, const string &Value)
{
if (Value=="NOCHANGE")
return true;

if (File::Exists(Ztring().From_UTF8(FileName)))
{
map<string, Ztring>::iterator ToErase=Handlers[FileName].In_Core.find(Field);
if (ToErase!=Handlers[FileName].In_Core.end())
Handlers[FileName].In_Core.erase(ToErase);

Handlers[FileName].In_Core_Append[Field]=Ztring().From_UTF8(Value);
}
else
{
//Handling wildcards
ZtringList List=Dir::GetAllFileNames(Ztring().From_UTF8(FileName));
if (List.empty())
List.push_back(Ztring().From_UTF8(FileName));

for (size_t Pos=0; Pos<List.size(); Pos++)
{
map<string, Ztring>::iterator ToErase=Handlers[List[Pos].To_UTF8()].In_Core.find(Field);
if (ToErase!=Handlers[List[Pos].To_UTF8()].In_Core.end())
Handlers[FileName].In_Core.erase(ToErase);
Handlers[List[Pos].To_UTF8()].In_Core_Append[Field]=Ztring().From_UTF8(Value);
}
}

return true;
}

//---------------------------------------------------------------------------
bool Core::In_Core_Append(const string &Field, const string &Value)
{
map<string, Ztring>::iterator ToErase=Handler_Default.In_Core.find(Field);
if (ToErase!=Handler_Default.In_Core.end())
Handler_Default.In_Core.erase(ToErase);

Handler_Default.In_Core_Append[Field]=Ztring().From_UTF8(Value);

return true;
}
//---------------------------------------------------------------------------
string Core::Out_Core_Read (const string &FileName, const string &Field)
{
Expand Down
3 changes: 3 additions & 0 deletions Source/Common/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class Core : public Thread
bool In_Core_Add (const string &FileName, const string &Field, const string &Value);
bool In_Core_Add (const string &Field, const string &Value);
bool In_Chunk_Remove (const string &Field);
bool In_Core_Append (const string &FileName, const string &Field, const string &Value);
bool In_Core_Append (const string &Field, const string &Value);
string Out_Core_Read (const string &FileName, const string &Field);

//Configuration
Expand Down Expand Up @@ -186,6 +188,7 @@ class Core : public Thread
{
Riff_Handler *Riff;
map<string, Ztring> In_Core;
map<string, Ztring> In_Core_Append;
bool In_Core_Remove;
bool In__PMX_Remove;
bool In__PMX_XML;
Expand Down

0 comments on commit 69256b8

Please sign in to comment.