Recent

Author Topic: Expected behaviour of StrToCmdLineParam in LazFileUtils?  (Read 11085 times)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Expected behaviour of StrToCmdLineParam in LazFileUtils?
« on: June 13, 2014, 06:49:48 pm »
Laz 1.2.2/FPC 2.6.4 - Windows 8.  Also confirmed under Laz Trunk/FPC Trunk.

Where would I be expected to use StrToCmdLineParam? 

I *think* I've found a bug, but I'm doubtful as this seems like a common function, so maybe it's being used incorrectly.

When I run the following
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
Var
  s: String;
begin
  s := 'C:\Program Files';
  ShowMessage(StrToCmdLineParam(s));
end; 

I expect to see "C:\Program Files" as the result (" or double quotes are expected on the command line for file/folder names with spaces on them).
Instead I see 'C:\Program Files'

This is causing an issue in the Lazarus-CCR package mplayer.  Any filenames with spaces passed to Filename don't get played.  I've changed the relevant line in MPLayerCtrl.pas, confirming it's definitely StrToCmdLineParam at fault.  I do know spaces in filenames causes problem for the mplayer package under Linux as well, but am not in a position to confirm if it's the single quotes at fault there, or some other issue.

So, either mplayer is incorrectly using StrToCmdLineParam (on at least Windows), or StrToCmdLineParam is returning incorrect values.   I can't find any useful documentation on StrToCmdLineParam, so I'm really not sure which issue to report/try to fix, so am looking for advice from you guys :-)

More Information:  StrToCmdLineParam is behaving as it's designed to behave (see comments in code below, this is directly from LazFileUtils.pas), so I'm kind of leaning towards it's use in mplayer is incorrect, on the other hand - I can't imagine when StrToCmdLineParam as is would be useful...
Code: [Select]
function StrToCmdLineParam(const Param: string): string;
{ <empty> -> ''
  word -> word
  word1 word2 -> 'word1 word2'
  word's -> "word's"
  a" -> 'a"'
  "a" -> '"a"'
  'a' -> "'a'"
  #0 character -> cut the rest
}
const
  NoQuot = ' ';
  AnyQuot = '*';
var
  Quot: Char;
  p: PChar;
  i: Integer;
begin
...
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Expected behaviour of StrToCmdLineParam in LazFileUtils?
« Reply #1 on: June 28, 2014, 08:54:05 pm »
I moved away from using StrToCmdLineParam in mplayer (in fact completely redesigned away from using .commandline), and that resolved the issue of filenames with spaces in them...

Still no idea where that function would be useful, but definitely not in Command Line Parameters for most programs under Windows...
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Expected behaviour of StrToCmdLineParam in LazFileUtils?
« Reply #2 on: June 29, 2014, 01:19:05 am »
The constant issues found with quoting etc and little platform differences in quoting (e.g. -Ofilename.ext with a spaced filename will be encoded "-Ofile name.ext" on *nix and -O"File name.ext" on Windows), were the reason to steer away from a cmdline as principle for TProcess. It was simply to fragile.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Expected behaviour of StrToCmdLineParam in LazFileUtils?
« Reply #3 on: June 29, 2014, 10:13:44 am »
Thanks for that Marco, but I wasn't chasing an explanation of why .Commandline is deprecated in some places.

This topic is about StrToCmdLineParam.

Quote
Where would I be expected to use StrToCmdLineParam? 

In both the scenarios you've described StrToCmdLineParam fails.   My question is:

 Is this a bug an issue?
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Expected behaviour of StrToCmdLineParam in LazFileUtils?
« Reply #4 on: June 29, 2014, 12:37:08 pm »
I can't answer that, since I only work on TProcess, not the Lazarus side of it. IMHO anything -UTF8 is only a stopgap till real unicode support arrives (in trunk)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Expected behaviour of StrToCmdLineParam in LazFileUtils?
« Reply #5 on: June 29, 2014, 01:05:37 pm »
IMHO anything -UTF8 is only a stopgap till real unicode support arrives (in trunk)

Many thanks.  This supports my thinking as well :-)
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

 

TinyPortal © 2005-2018