Hi all,
Running Laz 1.8.2 on 64 bit windows 7.
I'm having a few problems with handling command line parameters, specifically the long options.
So my program can accept a whole bunch of parameters, which I have defined as constants for ease of configuration. I have also combined these into a string suitable for feeding into GetNonOptions.
{Short form options}
OptSFCount = 'c'; // Over-ride catalog filecount
OptSDFSName = 'd'; // Specify DFS filename to read / write
OptSExec = 'e'; // Specify Execution address when writing
OptSFile = 'f'; // Specify host file to read / write
OptSHelp = 'h'; // Get some help
OptSLoad = 'l'; // Specify load address when writing
OptSLabel = 'L'; // Set disk label when creating
OptSOpt = 'o'; // Set disk opt when creating
OptSQual = 'q'; // Specify qualifier, defaults to '$'
OptSTracks = 't'; // Specify max tracks when writing (40 or 80).
{Long form options}
OptLFCount = 'count';
OptLDFSName = 'dfs';
OptLExec = 'exec';
OptLFile = 'file';
OptLHelp = 'help';
OptLLoad = 'load';
OptLLabel = 'label';
OptLOpt = 'opt';
OptLQual = 'qual';
OptLTracks = 'tracks';
{Short and long opts as strings for use in CheckOpts}
ShortOpts : string = OptSFCount+ ':'+
OptSDFSName+ ':'+
OptSExec+ ':'+
OptSFile+ ':'+
OptSHelp+
OptSLoad+ ':'+
OptSLabel+ ':'+
OptSOpt+ ':'+
OptSQual+ ':'+
OptSTracks+ ':';
LongOpts : string = OptLFCount+ ' '+
OptLDFSName+ ' '+
OptLExec+ ' '+
OptLFile+ ' '+
OptLHelp+ ' '+
OptLLoad+ ' '+
OptLLabel+ ' '+
OptLOpt+ ' '+
OptLQual+ ' '+
OptLTracks+ ' ';
{Valid operations}
CmdCreate = 'create'; // Create a new disk image
CmdRead = 'read'; // Transfer DFS file to host
CmdWrite = 'write'; // Transfer host file to DFS
CmdCat = 'cat'; // Catalog the disk
CmdDump = 'dump'; // Dump the file in hex
NoCmds = 5;
My program is designed to be invoked with two manditory parameters, a command and a filename, however some of the commands can take optional parameters that I am specifying. So to get the list of *NON* options so that I can extract and validate the command and filename I use
// quick check parameters
ErrorMsg:=CheckOptions(ShortOpts, LongOpts);
// parse parameters
if HasOption(OptSHelp, OptLHelp) then
begin;
DoHelp;
// Terminate;
Exit;
end;
{ add your program here }
{ Get parameters that are not options}
GetNonOptions(ShortOpts, LongOpts, CmdParams);
{Get command and DFS disk name}
IF (CmdParams.Count > 1) THEN
BEGIN;
OpStr:=CmdParams.Strings[0];
DFSImageName:=CmdParams.Strings[1];
END
ELSE
ErrorMsg:=ErrorMsg+'Error must specify at least one operation and DFSImageFile';
In my DoRun procedure, however this exits with a parameter error when called :
F:\Phill\Dropbox\AtomDOS\DFSdisk>dfsdisk create test.ssd --tracks=80
Exception at 000000010002A4FA: EListError:
Invalid option at position 3: "tracks".
Anyone have any idea what is going on here?
Using the short option works without problems.
Cheers.
Phill.