News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

CodeEdit, the Christmas Edition

Started by hutch--, December 25, 2022, 09:23:21 AM

Previous topic - Next topic

jj2007

Quote from: hutch-- on December 27, 2022, 04:55:13 AM
Just try this, its a test of the "exist" algo.

entry_point proc
  rcall MessageBox,0,str$(rv(exist, CL$()))," 1 = file exists",MB_OK
  invoke MessageBox, 0, CL$(), chr$("The command line:"), MB_OK


Works like a charm, even with extra long command lines with spaces and apostrophes etc.

Source of CL$() attached, ruthless stolen from MasmBasic and minimally modified for use with the Masm64 SDK :cool:

hutch--

Converted the test piece to console so the results can be directly posted.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm64\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL clp :QWORD                                    ; command line pointer
    LOCAL rvl :QWORD

    call GetCommandLine
    mov clp, rax

    conout "----------------",lf
    conout "Raw command line",lf
    conout "----------------",lf
    conout clp,lf,lf

    mov clp, rvcall(cmd_tail)

    conout "----------------",lf
    conout "Command tail",lf
    conout "----------------",lf
    conout clp,lf,lf

    conout "----------------",lf
    conout "Testing 'exist'",lf
    conout "----------------",lf

    rcall exist,clp,lf
    conout str$(rax),lf

    waitkey

    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end


This is the result on my Win10 64 Pro.

----------------
Raw command line
----------------
"K:\masm64_00\TestCL\TestCL.exe" K:\masm64_00\TestCL\TestCL.obj

----------------
Command tail
----------------
K:\masm64_00\TestCL\TestCL.obj

----------------
Testing 'exist'
----------------
1
Press any key to continue...

hutch--

Run directly from the console.

K:\masm64_00\TestCL>testcl makeit.bat
----------------
Raw command line
----------------
testcl  makeit.bat

----------------
Command tail
----------------
makeit.bat

----------------
Testing 'exist'
----------------
1
Press any key to continue...

HSE

Quote from: hutch-- on December 27, 2022, 05:46:00 AM
Run directly from the console.

Never was a problem to run program from command line  :biggrin:.

Problem is to run program from explorer (like how is usual with qEditor).
Equations in Assembly: SmplMath

jj2007

Quote from: hutch-- on December 27, 2022, 05:36:30 AM
Converted the test piece to console so the results can be directly posted.

Doesn't work. Try my (very simple) code above to see the difference.

Hint: It works fine, of course, with e.g. C:\Masm32\QEditor.exe; but it fails with any path that has a space, because Windows has the bad habit of adding "quotes" :cool:

hutch--

Could you run the last example, I don't have anything as old as Win7 running but I need to see if the full command line returned by GetCommandLine() still has the second half quoted. On my Win10 64 Pro, it is returned without quotes.

jj,

I am trying to track down a variation between Win10-11 and old OS versions, not looking for someone elses code.

hutch--

As I still don't know what is happening win win7, try this.

    call cmd_tail                   ; get command tail
    mov pFile, rax                  ; store rax in variable
    cmp BYTE PTR [rax], 0           ; test if its empty
    je rfout                        ; bypass loading file if empty

    rcall szRemove,pFile,pFile,chr$(34)        ; < add this line

    rcall exist,pFile               ; check if file exists
    test rax, rax
    jnz @F

jj2007

Quote from: hutch-- on December 27, 2022, 08:35:07 AMjj,

I am trying to track down a variation between Win10-11 and old OS versions, not looking for someone elses code.

There is no difference between Win7 and Win10 for Explorer's habit to add quotes, but I can't speak for Win11.

HSE

It's not an OS problem, just explorer sorround strings with quotes.

From explorer:
----------------
Raw command line
----------------
"D:\masm32\projects\CodeEditEx\test\test.exe" "D:\masm32\projects\CodeEditEx\test\test.asm"

----------------
Command tail
----------------
"D:\masm32\projects\CodeEditEx\test\test.asm"

----------------
Testing 'exist'
----------------
0
Press any key to continue...


From command prompt:
----------------
Raw command line
----------------
test  test.asm

----------------
Command tail
----------------
test.asm

----------------
Testing 'exist'
----------------
1
Press any key to continue...


From explorer, removing quotes:
    mov clp, rvcall(cmd_tail)
    rcall szRemove,clp,clp,chr$(34)        ; < add this line

----------------
Raw command line
----------------
"D:\masm32\projects\CodeEditEx\test\test.exe" "D:\masm32\projects\CodeEditEx\test\test.asm"

----------------
Command tail
----------------
D:\masm32\projects\CodeEditEx\test\test.asm

----------------
Testing 'exist'
----------------
1
Press any key to continue...
Equations in Assembly: SmplMath

zedd151

Quote from: hutch-- on December 27, 2022, 08:42:43 AM
As I still don't know what is happening win win7, try this.

    call cmd_tail                   ; get command tail
    mov pFile, rax                  ; store rax in variable
    cmp BYTE PTR [rax], 0           ; test if its empty
    je rfout                        ; bypass loading file if empty

    rcall szRemove,pFile,pFile,chr$(34)        ; < add this line

    rcall exist,pFile               ; check if file exists
    test rax, rax
    jnz @F



  where's the rest of the code, or where to insert this?

Continued below...

zedd151

Okay, I inserted that code into CodeEditEx (Duh! I totally spaced out there, looking in the test code for where to insert)


Yurp! it works ok Windows 7 64 bit.  :thumbsup:


excerpt from the modified CodeEditEx.asm
---------------------------------------------------------------
  ; --------------------------------------
  ; load file from command line if present
  ; --------------------------------------


    call cmd_tail                   ; get command tail
    mov pFile, rax                  ; store rax in variable
    cmp BYTE PTR [rax], 0           ; test if its empty
    je rfout                        ; bypass loading file if empty


    rcall szRemove,pFile,pFile,chr$(34)        ; < add this line


    rcall exist,pFile               ; check if file exists
    test rax, rax
    jnz @F
;  ...  code continues ...


-------------------------------------------------------------------------------------
Now will it work with spaces in the path?  :tongue:


edited for paste error... whoops  :rolleyes:

hutch--

Seems like its OS difference with older OS versions. If stripping quotes works, the problem is solved for old OS versions. One of the joys you get used to is function variation from one OS version to the next.  :tongue:

zedd151

Quote from: hutch-- on December 27, 2022, 09:24:25 AM
Seems like its OS difference with older OS versions.
All's well that ends well.  :biggrin:  At least it didn't have to wait until next Christmas to be ready.  :tongue:

jj2007

I made some tests with this code (attached, with test files):

include \masm64\include64\masm64rt.inc
.code
entry_point proc
  invoke GetCommandLine
  conout rax
  invoke MessageBox, 0, rv(GetCommandLine), chr$("GetCommandLine:"), MB_OK
  .exit
entry_point endp
end


Results:

a) Windows XP:
"C:\Masm64\Examples\ShowTheRawCommandLine.exe" "C:\Masm64\Examples\test with space.txt"
"C:\Masm64\Examples\ShowTheRawCommandLine.exe" C:\Masm64\Examples\test.txt


b) Windows 7-64:
"C:\Masm64\Examples\ShowTheRawCommandLine.exe" "C:\Masm64\Examples\test with space.txt"
"C:\Masm64\Examples\ShowTheRawCommandLine.exe" C:\Masm64\Examples\test.txt


c) Windows 10:
"C:\Masm64\Examples\ShowTheRawCommandLine.exe" "C:\Masm64\Examples\test with space.txt"
"C:\Masm64\Examples\ShowTheRawCommandLine.exe" C:\Masm64\Examples\test.txt


Unfortunately, I don't have a Win-11 machine at hand - can somebody test it, please?