News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Commandline syntax

Started by jj2007, August 30, 2010, 08:40:30 AM

Previous topic - Next topic

jj2007

Question to the experts: What do you think about allowing apostrophes as delimiters in commandline arguments? I could not find any hints at MSDN how to treat this, but my intuition says it should be possible...

get cl.exe arg1 "second arg"   'third arg' fourth_arg

Grateful if somebody tried to throw unusual commandlines at get cl.exe in attachment, and see if it's crashable.

Results for MasmBasic CL$(n):
arg #0 = [get cl.exe]
arg #1 = [arg1]
arg #2 = [second arg]
arg #3 = [third arg]
arg #4 = [fourth_arg]
arg #5 = [no such arg]
94 bytes proc size

Results for Masm32 GetCL:
arg #0 = [get cl.exe]
arg #1 = [arg1]
arg #2 = [second arg]
arg #3 = ['third]
arg #4 = [arg']
arg #5 = [fourth_arg]
274 bytes


And no, I not gonna count their cycles :bg

P.S.:
include \masm32\include\masm32rt.inc

.data?
buffer db 1024 dup(?)

.code
start:
print "Testing the GetCL function:", 13, 10
xor ebx, ebx
.Repeat
invoke GetCL, ebx, offset buffer
.Break .if eax!=1
print str$(ebx), "=", 9
print offset buffer, 13, 10
inc ebx
.Until ebx>99
inkey "All done"
exit

end start


Looks pretty straightforward, but try in Explorer to select more than 5 files, and drag them over the executable...
The culprit sits in \masm32\m32lib\getcl.asm, line 190, stosb.

FORTRANS

Hi,

   The problem is that an apostrophe is a legal character
in a path or file name.

Regards,

Steve N.


D:\msdownld.tmp>copy con file's
asdfsdf
^Z
        1 file(s) copied.

D:\msdownld.tmp>dir
Volume in drive D is DATA
Volume Serial Number is 5825-EC14

Directory of D:\msdownld.tmp

12/21/2004  10:22a      <DIR>          .
12/21/2004  10:22a      <DIR>          ..
08/30/2010  06:51a              95,927 EAOE~1.ZIP
08/30/2010  07:06a                   9 file's
               2 File(s)         95,936 bytes
               2 Dir(s)       4,882,432 bytes free

jj2007

Quote from: FORTRANS on August 30, 2010, 12:09:48 PM
The problem is that an apostrophe is a legal character in a path or file name.

Steve,

So are spaces - in both cases you should/must use "That is my mum's birthday.jpg"
This works with the attached routing, but in addition you can also pass an argument like 'these are "quotes"'

Jochen

FORTRANS

Hi,

   But if you are following the "normal" file name rules you
cannot put a quote into the name.  And what do you want
to do with something like 'Lead Tail'.  Is it two legal file
names or one file with a space?

Regards,

Steve


D:\msdownld.tmp>copy con 'file"2'
asdqwe
^Z
        1 file(s) copied.

D:\msdownld.tmp>dir
Volume in drive D is DATA
Volume Serial Number is 5825-EC14

Directory of D:\msdownld.tmp

12/21/2004  10:22a      <DIR>          .
12/21/2004  10:22a      <DIR>          ..
08/30/2010  07:06a                   9 file's
08/30/2010  01:23p                   8 'file2'
08/30/2010  01:27p                   8 'Lead
08/30/2010  01:28p                   8 Tail'



jj2007

Quote from: FORTRANS on August 30, 2010, 06:30:54 PM
   But if you are following the "normal" file name rules you
cannot put a quote into the name.  And what do you want
to do with something like 'Lead Tail'.  Is it two legal file
names or one file with a space?

Steve,
Valid points. And you put my nose onto a bug - the Lead Tail did not behave properly.
Now it does, with MasmBasic version 3008b.

["get cl.exe" "'Lead" "Tail'" 'third arg' "fourth arg"]

Results for MasmBasic CL$(n):
arg #0 = [get cl.exe]
arg #1 = ['Lead]
arg #2 = [Tail']
arg #3 = [third arg]
arg #4 = [fourth arg]
arg #5 = [no such arg]
104 bytes proc size

Results for Masm32 GetCL:
arg #0 = [get cl.exe]
arg #1 = ['Lead]
arg #2 = [Tail']
arg #3 = ['third]
arg #4 = [arg']
arg #5 = [fourth arg]
274 bytes


Re "normal" file names, I guess for anything more exotic than DOS 8.3 one would put "quotes" anyway; and don't forget that we may want to pass not only file names.

Regards,
Jochen

FORTRANS

Hi,

QuoteRe "normal" file names, I guess for anything more exotic than DOS 8.3 one would put "quotes" anyway; and don't forget that we may want to pass not only file names.

   Quite right.  The thing is you want consistant behavior.
Anyway they are your rules for your program.  Many
programs only allow one quoting character to keep things
simple.

Cheers,

Steve N.

Rockoon

I think his point is that the user may not be making the decision about how the parameters are passed, but instead another launching application may be making it (such as with Explorer's drag'n'drop files onto program icon feature)

...the standard is to wrap quotes around filenames with spaces in them, but there is no standard for wrapping quotes around filenames with apostrophes in them. The space character is the standard primary parameter delimiter and I don't see why you would want to go messing with that.
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.

hutch--

Either spaces or tabs are conventional as delimiters in a command line but of course long file names with spaces complicated this a lot. It is always problematic to get everything to work as there are many ways to start an application and many of them are inconsistent in how they format the command line arguments. If you want to use non-standard command lines I would be inclined to fully enclose them in double quotes, isolate the contents wthin the double quotes then parse them as you like.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: Rockoon on August 30, 2010, 10:02:25 PM
I think his point is that the user may not be making the decision about how the parameters are passed, but instead another launching application may be making it (such as with Explorer's drag'n'drop files onto program icon feature)

...the standard is to wrap quotes around filenames with spaces in them, but there is no standard for wrapping quotes around filenames with apostrophes in them. The space character is the standard primary parameter delimiter and I don't see why you would want to go messing with that.

> there is no standard for wrapping quotes around filenames with apostrophes in them
Just test that: drag'n'drop with Explorer gives this:
Results for MasmBasic CL$(n):
arg #0 = [D:\masm32\RichMasm\Get CL.exe]
arg #1 = [D:\masm32\RichMasm\Apo'Strophe.txt]
arg #2 = [D:\masm32\RichMasm\Copia di Apo'Strophe.txt]
104 bytes proc size

Results for Masm32 GetCL:
arg #0 = [D:\masm32\RichMasm\Get CL.exe]
arg #1 = [D:\masm32\RichMasm\Apo'Strophe.txt]
arg #2 = [D:\masm32\RichMasm\Copia di Apo'Strophe.txt]
274 bytes

So that's perfect :bg

Rockoon

OK, now test it with every other application launcher.. that will only take you about 5 years.

oh, and use a file with an apostrophe that is 8.3 compatible or else you are introducing another variable
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.

mineiro

"get cl.exe" mkdir '\2'\1
'get cl.exe' mkdir '\2'\1
regards

sinsi

The single quote has always been a legal character, the double quote hasn't. All up to you how you want to do it, but convention says no.
A bit like the switch char - *nix (apparently?) use a minus whereas DOS prefers the slash but the program decides (and the slash is not allowed in a filename
whereas a minus is).

Naming Files, Paths, and Namespaces
Light travels faster than sound, that's why some people seem bright until you hear them.

jj2007

Quote from: mineiro on August 31, 2010, 07:17:04 AM
"get cl.exe" mkdir '\2'\1
'get cl.exe' mkdir '\2'\1
regards
Thanks. First one will work if enclosed in quotes and produce three folders:
'
2'
1

Windows will refuse to launch the second one.

jj2007

Quote from: Rockoon on August 31, 2010, 06:53:03 AM
OK, now test it with every other application launcher.. that will only take you about 5 years.

oh, and use a file with an apostrophe that is 8.3 compatible or else you are introducing another variable

Create a file Apo'po'.txt and drag it over Get cl.exe, it will work just fine. Whether the name Apo'po'.txt is DOS compliant, is another question ;-)

Anyway, it seems that by using "quotes" (which Explorer does when dragging), the special cases 'Lead and Tail' and Apo'po'.txt can be handled just fine:
Results for MasmBasic CL$(n):
arg #0 = [D:\masm32\RichMasm\Get CL.exe]
arg #1 = [D:\masm32\RichMasm\Tail']
arg #2 = [D:\masm32\RichMasm\'Lead]
arg #3 = [D:\masm32\RichMasm\Apo'po'.txt]
arg #4 = [D:\masm32\RichMasm\Copy of Apo'po'.txt]
104 bytes proc size

Results for Masm32 GetCL:
arg #0 = [D:\masm32\RichMasm\Get CL.exe]
arg #1 = [D:\masm32\RichMasm\Tail']
arg #2 = [D:\masm32\RichMasm\'Lead]
arg #3 = [D:\masm32\RichMasm\Apo'po'.txt]
arg #4 = [D:\masm32\RichMasm\Copy of Apo'po'.txt]


This line behaves marginally different:
"get cl.exe" arg1 "'Lead2" "Tail3'" 'these "quotes" are cute' "isn't it fun?" "'apo quotes'"

Results for MasmBasic CL$(n):
arg #0 = [get cl.exe]
arg #1 = [arg1]
arg #2 = ['Lead2]
arg #3 = [Tail3']
arg #4 = [these "quotes" are cute]
arg #5 = [isn't it fun?]
arg #6 = ['apo quotes']

Results for Masm32 GetCL:
arg #0 = [get cl.exe]
arg #1 = [arg1]
arg #2 = ['Lead2]
arg #3 = [Tail3']
arg #4 = ['these]
arg #5 = [quotes]
arg #6 = [are]
arg #7 = [cute']
arg #8 = [isn't it fun?]
arg #9 = ['apo quotes']


I herewith declare it a feature :green2

sinsi

Well I think it's a bad idea jj. A single quote is a legitimate filename character. Look how much chaos a space can cause, now you want to add to that?

Curious, how does CommandLineToArgvW go with that? Same as the masm32 version I guess.
Light travels faster than sound, that's why some people seem bright until you hear them.