View Issue Details

IDProjectCategoryView StatusLast Update
0039005PatchesPackagespublic2021-06-16 22:45
ReporterCudaText man Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version2.1 (SVN) 
Summary0039005: Make params of UTF8Process.RunCmdFromPath - 'const'
DescriptionI fixed the comment above the func, and the func itself now has 'const' string parameters.
TagsNo tags attached.
Fixed in Revisionr65251
LazTarget-
Widgetset
Attached Files

Activities

CudaText man

2021-06-14 20:41

reporter  

run.diff (2,505 bytes)   
Index: components/lazutils/utf8process.pp
===================================================================
--- components/lazutils/utf8process.pp	(revision 65212)
+++ components/lazutils/utf8process.pp	(working copy)
@@ -51,7 +51,7 @@
   end;
 {$ENDIF}
 
-procedure RunCmdFromPath(ProgramFilename, CmdLineParameters: string);
+procedure RunCmdFromPath(const ProgramFilename, CmdLineParameters: string);
 function FindFilenameOfCmd(ProgramFilename: string): string;
 
 function GetSystemThreadCount: integer; // guess number of cores
@@ -155,21 +155,20 @@
 
 // Runs a short command which should point to an executable in
 // the environment PATH
-// For example: ProgramFilename=ls CmdLineParameters=-l /home
-// Will locate and execute the file /bin/ls
+// For example: ProgramFilename='ls' CmdLineParameters='-l /home'
+// Will locate and execute the file '/bin/ls'
 // If the command isn't found, an exception will be raised
-procedure RunCmdFromPath(ProgramFilename, CmdLineParameters: string);
+procedure RunCmdFromPath(const ProgramFilename, CmdLineParameters: string);
 var
-  OldProgramFilename: String;
+  NewProgramFilename: String;
   BrowserProcess: TProcessUTF8;
 begin
-  OldProgramFilename:=ProgramFilename;
-  ProgramFilename:=FindFilenameOfCmd(ProgramFilename);
+  NewProgramFilename:=FindFilenameOfCmd(ProgramFilename);
 
-  if ProgramFilename='' then
-    raise EFOpenError.Create(Format(lrsProgramFileNotFound, [OldProgramFilename]));
-  if not FileIsExecutable(ProgramFilename) then
-    raise EFOpenError.Create(Format(lrsCanNotExecute, [ProgramFilename]));
+  if NewProgramFilename='' then
+    raise EFOpenError.Create(Format(lrsProgramFileNotFound, [ProgramFilename]));
+  if not FileIsExecutable(NewProgramFilename) then
+    raise EFOpenError.Create(Format(lrsCanNotExecute, [NewProgramFilename]));
 
   // run
   BrowserProcess := TProcessUTF8.Create(nil);
@@ -176,12 +175,12 @@
   try
     BrowserProcess.InheritHandles:=false;
     // Encloses the executable with "" if its name has spaces
-    if Pos(' ',ProgramFilename)>0 then
-      ProgramFilename:='"'+ProgramFilename+'"';
+    if Pos(' ',NewProgramFilename)>0 then
+      NewProgramFilename:='"'+NewProgramFilename+'"';
 
     {$Push}
     {$WARN SYMBOL_DEPRECATED OFF}
-    BrowserProcess.CommandLine := ProgramFilename;
+    BrowserProcess.CommandLine := NewProgramFilename;
     if CmdLineParameters<>'' then
       BrowserProcess.CommandLine := BrowserProcess.CommandLine + ' ' + CmdLineParameters;
     {$Pop}
run.diff (2,505 bytes)   

CudaText man

2021-06-14 20:46

reporter   ~0131311

And additional change (not in the .diff file): this param can be 'const' too!
function FindFilenameOfCmd(ProgramFilename: string): string;
begin
  Result:=TrimFilename(ProgramFilename);
  if not FilenameIsAbsolute(Result) then begin
    if Pos(PathDelim,Result)>0 then begin
      // with sub directory => relative to current directory
      Result:=CleanAndExpandFilename(Result);
    end else begin
      // search in PATH
      Result:=FindDefaultExecutablePath(Result);
    end;
  end;
  if (Result<>'') and not FileExistsUTF8(Result) then
    Result:='';
end;

Juha Manninen

2021-06-16 21:40

developer   ~0131346

Applied, thanks.

Issue History

Date Modified Username Field Change
2021-06-14 20:41 CudaText man New Issue
2021-06-14 20:41 CudaText man File Added: run.diff
2021-06-14 20:46 CudaText man Note Added: 0131311
2021-06-16 21:24 Juha Manninen Assigned To => Juha Manninen
2021-06-16 21:24 Juha Manninen Status new => assigned
2021-06-16 21:40 Juha Manninen Status assigned => resolved
2021-06-16 21:40 Juha Manninen Resolution open => fixed
2021-06-16 21:40 Juha Manninen Fixed in Revision => r65251
2021-06-16 21:40 Juha Manninen LazTarget => -
2021-06-16 21:40 Juha Manninen Note Added: 0131346
2021-06-16 22:45 CudaText man Status resolved => closed