Skip to content

Commit cdc03de

Browse files
committed
Add help and improved handling parameters
1 parent f60642a commit cdc03de

1 file changed

Lines changed: 47 additions & 22 deletions

File tree

entries/ocoddo/src/Project1.lpr

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -364,30 +364,55 @@ TStationSummary = record
364364
WriteLn(ToStr(RST));
365365
end;
366366

367-
var
368-
I: Ind;
369-
N: Str;
370-
V: I64;
371-
begin
372-
if Length(Parameters) = 0 then
373-
Exit;
367+
function HandleParameters(out AFilePath: TFilePath): Bool;
368+
var
369+
I: Ind;
370+
N: Str;
371+
V: I64;
372+
begin
373+
Result := False;
374+
if Length(Parameters) = 0 then
375+
begin
376+
WriteLn;
377+
WriteLn('1BRC');
378+
WriteLn('----');
379+
WriteLn('Made by O');
380+
WriteLn;
381+
WriteLn('Usage:');
382+
WriteLn('./ocoddo ./input.txt [Options]');
383+
WriteLn;
384+
WriteLn('Options:');
385+
WriteLn('--jumper-count=[Value]. Use 128, 192, 256, etc');
386+
WriteLn('--part-size=[Value]. Use 128, 192, 256, etc');
387+
WriteLn('--processor-count=[Value]. Use 1 or more');
388+
WriteLn;
389+
Exit;
390+
end;
374391

375-
ProcessorCount := LogicalProcessorCount;
376-
JumperCount := 256 * 1024;
377-
PartSize := 192 * 1024 - ReadMargin;
392+
ProcessorCount := LogicalProcessorCount;
393+
JumperCount := 256 * 1024;
394+
PartSize := 192 * 1024 - ReadMargin;
378395

379-
for I := 1 to High(Parameters) do
380-
begin
381-
N := Name(Parameters[I]);
382-
ToI64(Value(Parameters[I]), V);
383-
384-
if N = 'jumper-count' then
385-
JumperCount := V * 1024
386-
else if N = 'part-size' then
387-
PartSize := (V * 1024) - ReadMargin
388-
else if N = 'processor-count' then
389-
ProcessorCount := V;
396+
for I := 1 to High(Parameters) do
397+
begin
398+
N := Name(Parameters[I]);
399+
ToI64(Value(Parameters[I]), V);
400+
401+
if N = 'jumper-count' then
402+
JumperCount := V * 1024
403+
else if N = 'part-size' then
404+
PartSize := (V * 1024) - ReadMargin
405+
else if N = 'processor-count' then
406+
ProcessorCount := V;
407+
end;
408+
409+
AFilePath := Fix(Value(Parameters[0]));
410+
Result := True;
390411
end;
391412

392-
Run(&File(Fix(Value(Parameters[0]))));
413+
var
414+
FN: TFilePath;
415+
begin
416+
if HandleParameters(FN) then
417+
Run(&File(FN));
393418
end.

0 commit comments

Comments
 (0)