Pārlūkot izejas kodu

* Some small improvements, added some clarification to readme

Michaël Van Canneyt 1 gadu atpakaļ
vecāks
revīzija
37e4fed3d4

+ 10 - 4
utils/dotutils/README.txt

@@ -35,7 +35,7 @@ This file is used to construct dotted unit files from undotted files.
 
 The file must be contain all files in a give directory grouped:
 
-Ff a line contains no rule or compile options, the last used rule/compile options for a file in the same directory is reused.
+If a line contains no rule or compile options, the last used rule/compile options for a file in the same directory is reused.
 
 ```
 src/sysutils.pp=System;-S2
@@ -47,16 +47,18 @@ will result in classes being parsed with -S2 and the resulting name will be Syst
 the name of the math unit will not be changed.
 
 
-### Known units rules
+## Known units rules
 
 A file with OldName=Rule pairs to apply to unit names in a uses clause. a Rule may never specify a path
 or an extension. The same extension as the original is used. 
 
-## Conversion Rules
+This file is used by the prefixunits tool.
+
+# Conversion Rules
 
 A rule can take the following forms:
   
-"*DottedUnitName" : Use the dotted name as ypes.
+"*DottedUnitName" : Use the dotted name as typed.
    
 Example:
 
@@ -210,6 +212,10 @@ a rule file of units to treat and the 'known mappings' rule file.
 ## prefixunits.pp
 
 Prefix units in a uses clause of a single program or unit.
+This is the main tool: it allows you to change the uses clause of your
+program or unit so it uses dotted names, based on a list of known aliases.
+
+
 
 ## proxyunit.pp
 

+ 6 - 3
utils/dotutils/namespacetool.pas

@@ -396,9 +396,12 @@ begin
       P:=Pos(' ',Opt);
       if P=0 then
         P:=Length(Opt)+1;
-      aOpts[I]:=Copy(Opt,1,P-1);
-      Opt:=Trim(Copy(Opt,P+1));
-      inc(I);
+      if p>1 then
+        begin
+        aOpts[I]:=Copy(Opt,1,P-1);
+        Opt:=Trim(Copy(Opt,P+1));
+        inc(I);
+        end;
     until (Opt='');
     SetLength(aOpts,I);
     end;

+ 6 - 3
utils/dotutils/prefixer.pas

@@ -377,7 +377,7 @@ end;
 function TPrefixer.GetDestFileName: String;
 
 Var
-  DN, FN : String;
+  DN, FN, NS : String;
 
 begin
   Result:=FDestFileName;
@@ -385,10 +385,13 @@ begin
     begin
     DN:=ExtractFilePath(FileName);
     FN:=ExtractFileName(FileName);
+    NS:=NameSpace;
+    if NS<>'' then
+      NS:=NS+'.';
     if CasedFileNames then
-      Result:=DN+NameSpace+'.'+FN
+      Result:=DN+NS+FN
     else
-      Result:=DN+LowerCase(NameSpace+'.'+FN);
+      Result:=DN+LowerCase(NS+FN);
     end;
 end;
 

+ 11 - 3
utils/dotutils/prefixunits.pp

@@ -59,6 +59,9 @@ begin
   Writeln('-n or --namespace=NS              Namespace to apply to file.');
   Writeln('-o or --option=option             Option to pass to compiler.');
   Writeln('-b or --backup                    Create backups of existing files when overwriting.');
+  writeln('-p --program                      Assume the sources are a program. This will not write a dotted file. Namespace is not needed');
+  Writeln('-r or --replace                   Default is to create an include and use a define to separate dotted from non-dotted');
+  Writeln('                                  Use this to replace the units clause as-is.');
   Writeln('All other options are passed as-is to the parser');
   Halt(Ord(Err<>''));
 end;
@@ -66,12 +69,13 @@ end;
 procedure TApplication.DoRun;
 
 Const
-  ShortOpts = 'bhf:k:n:o:d:';
-  LongOpts : Array of string = ('backup','filename:','known-namespaces:','namespace:','option:','dest-filename:');
+  ShortOpts = 'bhf:k:n:o:d:rp';
+  LongOpts : Array of string = ('backup','filename:','known-namespaces:','namespace:','option:','dest-filename:','replace','program');
 
 Var
   S : String;
   Opts : Array of string;
+  Prog : Boolean;
 
 begin
   Terminate;
@@ -79,6 +83,8 @@ begin
   if (S<>'') or HasOption('h','help') then
     Usage(S);
   FPrefixer.NameSpace:=GetOptionValue('n','namespace');
+  if HasOption('r','replace') then
+    FPrefixer.UnitFileMode :=fmReplace;
   FPrefixer.FileName:=GetOptionValue('f','filename');
   FPrefixer.DestFileName:=GetOptionValue('d','dest-filename');
   FPrefixer.CreateBackups:=HasOption('b','backup');
@@ -89,10 +95,12 @@ begin
       FPrefixer.FileName:=Opts[0];
     end;
   Opts:=GetOptionValues('o','option');
+  Prog:=HasOption('p','program');
   For S in Opts do
     FPrefixer.Params.Add(S);
-  if (FPrefixer.NameSpace='') then
+  if Not Prog and (FPrefixer.NameSpace='') then
     Usage('Namespace is required');
+  FPrefixer.SkipDestFileName:=Prog;
   if (FPrefixer.FileName='') then
     Usage('Filename is required');
   S:=GetOptionValue('k','known-namespaces');