Browse Source

* Emit help text if options not correct

git-svn-id: trunk@11370 -
michael 17 years ago
parent
commit
32d0e652ff
2 changed files with 36 additions and 8 deletions
  1. 16 2
      packages/chm/src/chmcmd.lpr
  2. 20 6
      packages/chm/src/chmls.lpr

+ 16 - 2
packages/chm/src/chmcmd.lpr

@@ -25,17 +25,31 @@ program chmcmd;
 uses
   Classes, chmfilewriter;
 
+Procedure Usage;
+
+begin
+  Writeln(StdErr,'Usage: chmcmd  <filename>');
+  Halt(1);
+end;
+
+
 var
   OutStream: TFileStream;
   Project: TChmProject;
+
 begin
-  if Paramcount = 1 then begin
+  if (Paramcount=1) and (ParamStr(1)<>'-h') and (ParamStr(1)<>'-?') then 
+    begin
     Project := TChmProject.Create;
     Project.LoadFromFile(ParamStr(1));
     OutStream := TFileStream.Create(Project.OutputFileName, fmCreate, fmOpenWrite);
     Project.WriteChm(OutStream);
     OutStream.Free;
     Project.Free;
-  end;
+    end
+  else
+    begin
+    Usage;
+    end; 
 end.
 

+ 20 - 6
packages/chm/src/chmls.lpr

@@ -76,14 +76,28 @@ begin
   WriteLn(Name);
 end;
 
+Procedure Usage;
+
+begin
+  WriteLn('   Usage:  chmls filename.chm [section number]');
+  Halt(1);
+end;
+
 // Start of program
 begin
-  if Paramcount < 1 then begin
-    WriteLn('   Usage:  chmls filename.chm [section number]');
-    exit;
-  end;
-  if ParamCount > 1 then Section := StrToInt(ParamStr(2));
-  
+  if (Paramcount < 1) or (Paramstr(1)='-h') or (Paramstr(1)='-?') then 
+    begin
+    usage;
+    end;
+  if ParamCount > 1 then 
+    begin
+    Section := StrToIntDef(ParamStr(2),-1);
+    If (Section=-1) then
+      begin
+      Usage;
+      Halt(1);
+      end;
+    end; 
   Stream := TFileStream.Create(ParamStr(1), fmOpenRead);
   JunkObject := TJunkObject.Create;
   ITS:= TITSFReader.Create(Stream, True);