Menu

#108 Ability to read a command file

open
nobody
None
5
2012-12-07
2005-09-12
Anonymous
No

Current 7z command line version can't read a command
file ('@file' is able to read a list, not command, file) nor it
can use an environment variable to pass options.

In fact, enhancing is quite compact and easy.

In file Main.cpp (and, obviously, GUI.cpp), function
Main2, after "commandStrings.Delete(0)" instruction,
this simple code could process a SEVENZIP variable
and prepend the parsed string to the command line:

UStringVector commandStrings2;
wchar_t* envSevenZip = _wgetenv(L"SEVENZIP");
if (envSevenZip)
{
NCommandLineParser::SplitCommandLine
(envSevenZip, commandStrings2);
commandStrings = (commandStrings2 +=
commandStrings);
}

At this point, before parsing with parser.Parse1, a
new "parser.Parse0(commandStrings)" call could search
for '@commandfile' entries and update the
commandStrings accordingly.
It could sound like the following:

void CArchiveCommandLineParser::Parse0
(UStringVector& commandStrings)
{
for (int i=0; i < commandStrings.Size(); i++)
{
const UString &s = commandStrings[i];
if (s[0] == kFileListID)
{
if (s.Length() <= 1)
throw kUserErrorMessage;
UStringVector items;
if (!ReadNamesFromListFile(GetSystemString(s.Mid
(1), GetCurrentCodePage()), items))
throw "Incorrect command file";
commandStrings.Delete(i);
for (int j=items.Size()-1; j > -1; j--)
{
UStringVector items2;
NCommandLineParser::SplitCommandLine((const
wchar_t*)items[j], items2);
for (int k=items2.Size()-1; k > -1; k--)
commandStrings.Insert(i, items2[k]);
}
i--;
continue;
}
}
}

This routine would read one or more command files
(specified both on the "real" command line or in another
command file), inserting their contents in place of
the "@file" entry, recognizing commands, switches and
filenames even if more entries were specified on the
same line (like in Visual C++'s command files, in other
words).

So, having:

File ins1 contents:
a my.7z -ms=off
file1.txt file2.txt
dir1\dir2\*

File ins2 contents:
another.txt

C:\>set SEVENZIP=-mmf=bt2 -m0=lzma:d20
C:\>7z @ins1 co* ..\ui\*.cpp @ins2

would expand internally to:

7z -mmf=bt2 -m0=lzma:d20 a my.7z -ms=off file1.txt
file2.txt dir1\dir2\* co* ..\ui\*.cpp another.txt

as expected, giving more flexibility to the user.

It seems a *must* for DOS users (like Win 9x/ME
users), since the well known COMMAND.COM inability
of parsing long command lines.

And perhaps it could simplify arguments passing from
7zFM to 7zG, too.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB