The MASM Forum

Members Gallery => Showcase => Topic started by: hutch-- on December 25, 2022, 09:23:21 AM

Title: CodeEdit, the Christmas Edition
Post by: hutch-- on December 25, 2022, 09:23:21 AM
I have kept working on CodeEdit to try and get it up to a code editor standard. With this version which I hope is the final release, the auto-indent works, the tab replace which is compatible with the autoindent works fine. Double click word selection works correctly and F1 help uses that to call whatever help file you like. It is currently set with WIN32.HLP.

The DLL usage has been extended, the original "cplugin.dll" performs the same task that load on editor startup and a new capacity for transient load DLLs has been added. It uses the identical call format to simplify making the plugin DLLs, one for setting editor functionality like menus and so on, the other plugins are for transient or temporary loads on demand.

There is an additional script for making the barest plugin DLL (only has a MessageBox() to show it works) and the earlier one for more extensive work.

The one that load at startup (if you use it) must be named "cplugin.dll", any of the others that you may create must have a different name.

The complete package is an editor for programmers who can tweak it to suit their own programming style. In the development and testing, I have found it to be a pleasant enough editor to use, I hope it does the job for you.  :thumbsup:
Title: Re: CodeEdit, the Christmas Edition
Post by: HSE on December 27, 2022, 12:16:51 AM
Hi Hutch!

I don't understand so well cmd_tail, but look have some problem opening a file from explorer.

More easy, I adapted the reliable 32 bits GetCL:; #########################################################################

GetCL proc ArgNum:DWORD, ItemBuffer:QWORD

  ; -------------------------------------------------
  ; arguments returned in "ItemBuffer"
  ;
  ; arg 0 = program name
  ; arg 1 = 1st arg
  ; arg 2 = 2nd arg etc....
  ; -------------------------------------------------
  ; Return values in eax
  ;
  ; 1 = successful operation
  ; 2 = no argument exists at specified arg number
  ; 3 = non matching quotation marks
  ; 4 = empty quotation marks
  ; -------------------------------------------------

    LOCAL lpCmdLine      :QWORD
    LOCAL cmdBuffer[192] :BYTE
    LOCAL tmpBuffer[192] :BYTE

    USING rsi, rdi

    SaveRegs

    invoke GetCommandLine
    mov lpCmdLine, rax        ; address command line

  ; -------------------------------------------------
  ; count quotation marks to see if pairs are matched
  ; -------------------------------------------------
    xor ecx, ecx            ; zero ecx & use as counter
    mov rsi, lpCmdLine
   
    @@:
      lodsb
      cmp al, 0
      je @F
      cmp al, 34            ; [ " ] character
      jne @B
      inc ecx               ; increment counter
      jmp @B
    @@:

    push rcx                ; save count

    shr ecx, 1              ; integer divide ecx by 2
    shl ecx, 1              ; multiply ecx by 2 to get dividend

    pop rax                 ; put count in eax
    cmp eax, ecx            ; check if they are the same
    je @F
      RestoreRegs
      mov eax, 3            ; return 3 in eax = non matching quotation marks
      ret
    @@:

  ; ------------------------
  ; replace tabs with spaces
  ; ------------------------
    mov rsi, lpCmdLine
    lea rdi, cmdBuffer

    @@:
      lodsb
      cmp al, 0
      je rtOut
      cmp al, 9     ; tab
      jne rtIn
      mov al, 32
    rtIn:
      stosb
      jmp @B
    rtOut:
      stosb         ; write last byte

  ; -----------------------------------------------------------
  ; substitute spaces in quoted text with replacement character
  ; -----------------------------------------------------------
    lea rax, cmdBuffer
    mov rsi, rax
    mov rdi, rax

    subSt:
      lodsb
      cmp al, 0
      jne @F
      jmp subOut
    @@:
      cmp al, 34
      jne subNxt
      stosb
      jmp subSl     ; goto subloop
    subNxt:
      stosb
      jmp subSt

    subSl:
      lodsb
      cmp al, 32    ; space
      jne @F
        mov al, 254 ; substitute character
      @@:
      cmp al, 34
      jne @F
        stosb
        jmp subSt
      @@:
      stosb
      jmp subSl

    subOut:
      stosb         ; write last byte

  ; ----------------------------------------------------
  ; the following code determines the correct arg number
  ; and writes the arg into the destination buffer
  ; ----------------------------------------------------
    lea rax, cmdBuffer
    mov rsi, rax
    lea rdi, tmpBuffer

    mov ecx, 0          ; use ecx as counter

  ; ---------------------------
  ; strip leading spaces if any
  ; ---------------------------
    @@:
      lodsb
      cmp al, 32
      je @B

    l2St:
      cmp ecx, ArgNum     ; the number of the required cmdline arg
      je clSubLp2
      lodsb
      cmp al, 0
      je cl2Out
      cmp al, 32
      jne cl2Ovr           ; if not space

    @@:
      lodsb
      cmp al, 32          ; catch consecutive spaces
      je @B

      inc ecx             ; increment arg count
      cmp al, 0
      je cl2Out

    cl2Ovr:
      jmp l2St

    clSubLp2:
      stosb
    @@:
      lodsb
      cmp al, 32
      je cl2Out
      cmp al, 0
      je cl2Out
      stosb
      jmp @B

    cl2Out:
      mov al, 0
      stosb

  ; ------------------------------
  ; exit if arg number not reached
  ; ------------------------------
    .if ecx { ArgNum
      mov rdi, ItemBuffer
      mov al, 0
      stosb
      mov eax, 2  ; return value of 2 means arg did not exist
      RestoreRegs
      ret
    .endif

  ; -------------------------------------------------------------
  ; remove quotation marks and replace the substitution character
  ; -------------------------------------------------------------
    lea rax, tmpBuffer
    mov rsi, rax
    mov rdi, ItemBuffer

    rqStart:
      lodsb
      cmp al, 0
      je rqOut
      cmp al, 34    ; dont write [ " ] mark
      je rqStart
      cmp al, 254
      jne @F
      mov al, 32    ; substitute space
    @@:
      stosb
      jmp rqStart

  rqOut:
      stosb         ; write zero terminator

  ; ------------------
  ; handle empty quote
  ; ------------------
    mov rsi, ItemBuffer
    lodsb
    cmp al, 0
    jne @F
    RestoreRegs
    mov eax, 4  ; return value for empty quote
    ret
  @@:

    mov eax, 1  ; return value success

    RestoreRegs
   
    ret

GetCL endp

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


Then:
  ; --------------------------------------
  ; load file from command line if present
  ; --------------------------------------
    DBbegin
    DBclear

    invoke GetCommandLine
    invoke GetCL, 1, addr filebuffer
    DBreg rax
   
    .if rax == 1
   
        lea rax, filebuffer
        DBout rax
        cmp BYTE PTR [rax], 0           ; test if its empty
        je rfout                        ; bypass loading file if empty

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

        mov pbuf,ptr$(buffer)
        mcat pbuf,"Command line file '",pFile,"' cannot be found."
        invoke MsgboxI,hWnd,pbuf,"Whoops",MB_OK,10
        jmp rfout
    .endif
  @@:
    DBout pFile
    rcall file_read, hEdit, pFile

  rfout:
    DBend


But openning files from explorer I'm loosing CodeEditEx path  :biggrin: :biggrin: :biggrin:

That is for another day :thumbsup:
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 02:26:19 AM
Okay, dropping a file either onto the program icon or onto the editor window works; but was curious as to exactly what the issue is. So I tracked down what HSE is talking about.
Upon right clicking an .asm (probably other extensions as well) file in Explorer and clicking "Open With" then "Choose default program", when browsing to select CodeEditEx.exe as the program to open .asm files with, this is the result
Command line file
'"C:\Users\Administrator\downloads\CodeEditEx\findrepl.asm"' cannot be found.


Yikes. I should look at my own editors to see if this occurs there as well.
edited for clarity.
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 02:29:43 AM

Also tested on another file, not in the program directory...
Command line file
'"C:\Users\Administrator\Desktop\POE\poe.asm"' cannot be found.
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 04:01:08 AM
Given that the editor was written in Win10 64 bit and was designed for that OS or higher, it works perfectly here with both Explorer and Winfile. I know Z is using Win7 but I don't know what Hector is using.
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 04:23:46 AM
Whoops! Windows 10 64 bit...
Attemtping to open file via Explorer right click context menu "Open With"...
Same results as above...
I do have Windows 10, 64 bit capability when needed.   :tongue:


edit for typo.  :undecided:
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 04:28:05 AM
Give this test piece a blast. It works perfectly on Win10 64 Pro.

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

    include \masm64\include64\masm64rt.inc

    .code

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

entry_point proc

    LOCAL clp :QWORD                                ; command line pointer

    call GetCommandLine
    mov clp, rax

    rcall MessageBox,0,clp," GetCommandLine",MB_OK

    mov clp, rvcall(cmd_tail)

    rcall MessageBox,0,clp," cmd_tail",MB_OK

    .exit

entry_point endp

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

    end
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 04:31:56 AM
Quote from: hutch-- on December 27, 2022, 04:28:05 AM
Give this test piece a blast. It works perfectly on Win10 64 Pro.
It works... via Explorer  right click context menu, "Open With..."
lemme go back to Windows 10 and give it a whirl there...
Works with windows 10-64 as well
Title: Re: CodeEdit, the Christmas Edition
Post by: HSE on December 27, 2022, 04:41:40 AM
Hi Hutch!

Win 10 64 bits here, show exactly zedd's pictures. 

Apparently cmd_tail process first argument, but don't process second argument.
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 04:55:13 AM
Just try this, its a test of the "exist" algo.

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

    include \masm64\include64\masm64rt.inc

    .code

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

entry_point proc

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

    call GetCommandLine
    mov clp, rax

    rcall MessageBox,0,clp," GetCommandLine",MB_OK      ; show raw command line

    mov clp, rvcall(cmd_tail)

    rcall MessageBox,0,clp," cmd_tail",MB_OK            ; get the command tail

    rcall exist,clp                                     ; testing "exist" result
    mov rvl, rax
    rcall MessageBox,0,str$(rvl)," 1 = file exists",MB_OK

    .exit

entry_point endp

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

    end
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 05:01:18 AM
Quote from: hutch-- on December 27, 2022, 04:55:13 AM
Just try this, its a test of the "exist" algo.
assembled as console program
Used same method right click .asm file -> (Explorer -> Open With...) as with CodeEditEx.exe

No command tail, returns 0 in Windows 7 64 bit...


Now dropping a file onto the executable does work and returns 1
Title: Re: CodeEdit, the Christmas Edition
Post by: HSE on December 27, 2022, 05:03:28 AM
cmd_tail don't remove quotes in second argument.

You can see in my first post, I use exist without problem:
        mov pFile, rax
        rcall exist,pFile               ; check if file exists
        test rax, rax
        jnz @F
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 05:12:44 AM
Try this variant. What I am testing is if exist is being handled differently.

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

    include \masm64\include64\masm64rt.inc

    .code

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

entry_point proc

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

    call GetCommandLine
    mov clp, rax

    rcall MessageBox,0,clp," GetCommandLine",MB_OK      ; show raw command line

    mov clp, rvcall(cmd_tail)

    rcall MessageBox,0,clp," cmd_tail",MB_OK            ; get the command tail

    .if len(clp) == 0
      rcall MessageBox,0,"Nope"," cmd_tail",MB_OK
    .else
      rcall MessageBox,0,"Yurp"," cmd_tail",MB_OK
    .endif

    .exit

entry_point endp

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

    end
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 05:21:08 AM
Quote from: hutch-- on December 27, 2022, 05:12:44 AM
Try this variant. What I am testing is if exist is being handled differently.
Yurp! It wurked  :tongue:
Title: Re: CodeEdit, the Christmas Edition
Post by: HSE on December 27, 2022, 05:24:22 AM
 :biggrin: Yurp

Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 05:27:23 AM
Quote from: HSE on December 27, 2022, 05:24:22 AM
:biggrin: Yurp
Hey, I think hutch-- is onto something.  :biggrin:
Title: Re: CodeEdit, the Christmas Edition
Post by: jj2007 on December 27, 2022, 05:32:18 AM
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$() (https://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1011)))," 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:
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 05:36:30 AM
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...
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 05:46:00 AM
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...
Title: Re: CodeEdit, the Christmas Edition
Post by: HSE on December 27, 2022, 07:11:27 AM
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).
Title: Re: CodeEdit, the Christmas Edition
Post by: jj2007 on December 27, 2022, 08:08:15 AM
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:
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 08:35:07 AM
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.
Title: Re: CodeEdit, the Christmas Edition
Post by: 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
Title: Re: CodeEdit, the Christmas Edition
Post by: jj2007 on December 27, 2022, 08:48:41 AM
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.
Title: Re: CodeEdit, the Christmas Edition
Post by: HSE on December 27, 2022, 08:51:54 AM
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...
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 08:52:15 AM
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...
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 09:07:37 AM
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:
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 09:24:25 AM
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:
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 09:27:39 AM
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:
Title: Re: CodeEdit, the Christmas Edition
Post by: jj2007 on December 27, 2022, 09:47:14 AM
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?
Title: Re: CodeEdit, the Christmas Edition
Post by: HSE on December 27, 2022, 09:49:37 AM
Quote from: hutch-- on December 27, 2022, 09:24:25 AM
Seems like its OS difference with older OS versions.

:thumbsup: This OS is 2 years old, but perhaps could be related to OS language.

Later: Explorer have 2 years. Win say OS is from October 18, 2022  :biggrin:
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 09:53:01 AM
Now to test hutch's other 64 bit editors...  :badgrin:
If they used the same command line handling code, it is worth a look. I'll look into it later on sometime.
Title: Re: CodeEdit, the Christmas Edition
Post by: jj2007 on December 27, 2022, 10:35:48 AM
Quote from: hutch-- on December 27, 2022, 09:24:25 AM
Seems like its OS difference with older OS versions.

I couldn't see any differences between XP, 7 and 10, see reply #29. Tomorrow, if I find the time, I will test it on my Win98 machine.
Title: Re: CodeEdit, the Christmas Edition
Post by: zedd151 on December 27, 2022, 12:12:02 PM
Quote from: zedd151 on December 27, 2022, 09:53:01 AM
Now to test hutch's other 64 bit editors...  :badgrin:
If they used the same command line handling code, it is worth a look. I'll look into it later on sometime.

tEditor.exe from Masm64 SDK and tEdit.exe from Masm64/Examples/Advanced/tEdit also cannot be opened via Windows Explorer right click context menu "Open With...". I have not checked any further ... as I am 99% sure that they use the same command line handling.
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 02:11:43 PM
You are probably right Z, they all work perfectly on my US language version of Win10 64 Pro. What Hector has said also makes sense, different language versions of Windows sometimes do things differently and you only find out via experience as things like that are never documented by Microsoft.
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 05:03:42 PM
I thought this one was worth the effort, its an algo that only removes the leading and trailing double quote. You could probably get it a bit faster but I doubt its worth the effort.

; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»

    include \masm64\include64\masm64rt.inc

    .data
      cln db 34,"  How   D, I  am quoted   text.   ",34,0
      pcl dq cln

    .code

; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»

entry_point proc

    USING r12

    SaveRegs

    conout pcl,lf           ; before

    rcall unquote,pcl       ; strip the leading and trailing quotes
    rcall szMono,pcl        ; monospace the string

    conout pcl,lf           ; after

    waitkey
    RestoreRegs
    .exit

entry_point endp

; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»

NOSTACKFRAME

unquote proc
  ; -------------------------------------------------------
  ; remove single leading and single trailing double quotes
  ; -------------------------------------------------------
    mov r10, rcx                    ; source and dest are same address
    mov r11, rcx

    sub r10, 1
  @@:
    add r10, 1
    cmp BYTE PTR [r10], 34          ; strip the leading quote
    je @B

  @@:
    add r10, 1
    movzx rax, BYTE PTR [r10]       ; read byte from 1st address
    test rax, rax                   ; safety margin for text with no quotes
    jz @F                           ; exit on ASCII zero
    mov BYTE PTR [r11], al          ; copy byte to 2nd address
    add r11, 1
    cmp rax, 34                     ; test if its a quote
    jne @B
    mov BYTE PTR [r11-1], 0         ; terminate and overwrite trailing quote

  @@:

    ret

unquote endp

STACKFRAME

; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»

    end
Title: Re: CodeEdit, the Christmas Edition
Post by: jj2007 on December 27, 2022, 08:17:19 PM
Quote from: hutch-- on December 27, 2022, 02:11:43 PMdifferent language versions of Windows sometimes do things differently

I can confirm that in the Italian versions of Win XP, 7 and 10 Explorer has that habit of putting "quotes around paths with spaces". Now we still need to verify that behaviour for Win 11 and UK, US, Russian, Chinese etc versions.

For those who have one of the Windows versions with this behaviour, there is a really simple solution (http://masm32.com/board/index.php?topic=10560.msg116761#msg116761) taking advantage of a dedicated WinAPI function that gives you the un-quoted path for use with exist, ptr

See also https://learn.microsoft.com/en-us/troubleshoot/windows-server/deployment/filenames-with-spaces-require-quotation-mark (https://learn.microsoft.com/en-us/troubleshoot/windows-server/deployment/filenames-with-spaces-require-quotation-mark)
unfortunately, Micros*t doesn't give you a list of supported Windows versions :cool:
Title: Re: CodeEdit, the Christmas Edition
Post by: hutch-- on December 27, 2022, 09:44:13 PM
Interesting stuff but I would prefer one that was coded in assembler that I knew worked. One for ASCII, another for UNICODE. The one I posted above will accept any string and if it has quotes at either end, it will remove them.