Author Topic: Automated Plugin Builder plugin for qe  (Read 7381 times)

zedd151

  • Member
  • ****
  • Posts: 850
Automated Plugin Builder plugin for qe
« on: September 04, 2015, 02:54:22 PM »


Hi. I have created a plugin builder for qe that I have used for some time now. It greatly simplifies the creation of plugins for qeditor.
The stand alone version works so well, I decided to create it a plugin itself - to make plugin creation that much easier.


Yes qeditor comes with a good selection of plugins. Why would you want to create your own plugins? Formatting source files
is one of the reasons why I do.


July 21, 2018:


Version 5 Beta version is linked below - .dll only at this time.


Code: [Select]
-- Quick Instructions for the Plugin Builder --


1.  create a folder for your plugin project.


2.  create a file with your plugin procedure.
    just the procedure and any sub procedures that it uses.


3.  open the file in QEditor. Selection --> "Select All"


4.  Select Plugins --> Plugin Builder


5.  Enter the plugin main module name in the Dialog Box


6.  Enter the text that you want on QEditors menu in the Dialog Box


7.  Click "Process", and your project will automatically be built,
    the dll copied to masm32 plugins folder, and menu entry added for your plugin.
    If your orignal file was named "plugin proc name".asm, it will be overwritten.
    If you want to keep the original, I suggest using .txt or other extension.


8.  Files created automatically:
  a.  [Plugin Name].asm
  b.  [Plugin Name].bat
  c.  [Plugin Name].def
  d.  [Plugin Name].inc
  e.  [Plugin Name].dll


any .lib, .exp, .res, .obj files are deleted. You can reassemble using the .bat
file and removing the lines where those files are deleted if you need those files.




Back up your menus.ini file prior to using this product so if there are problems, you can reinstate the previous
menus.ini file. The Plugin Builder modifies your menus.ini file

Plugin Builder v5.0.1 DLL only; for testing -- Bug Reports welcome!  ** on hold til further notice **

** on hold til further notice **

Test plugin procedure for use with the Plugin Builder. It removes empty lines from a source file.
Now included in the Plugin Builder version 5 Beta DLL download.

Code: [Select]



; The procedure has two arguments, src buffer addr, and dst buffer addr.
; the buffers will be provided by the plugin builder.
; this small procedure removes empty lines
; the code should be written as if those buffers are already present.
; the plugin builder always uses the same format for the plugins it can process
; procname, src, dst


    uncrlfz proc src:dword, dst:dword
        mov esi, src
        mov edi, dst
    tiptop:
        mov al, byte ptr [esi]
        cmp al, 0
        jz done
        .if word ptr [esi] == 0D0Dh
        add esi, 1
        jmp tiptop
        .endif       
        mov [edi], al
        inc esi
        inc edi
        jmp tiptop
    done:
        mov byte ptr [edi], 0
        ret
    uncrlfz endp
« Last Edit: July 23, 2018, 05:54:54 AM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

dedndave

  • Member
  • *****
  • Posts: 8808
  • Still using Abacus 2.0
    • DednDave
Re: Automated Plugin Builder plugin for qe
« Reply #1 on: September 04, 2015, 04:33:45 PM »
 :t

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5851
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Automated Plugin Builder plugin for qe
« Reply #2 on: September 04, 2015, 06:04:23 PM »
Looks like it should work well Z. I wonder if anyone has noticed the plugin builder already installed in QE ? Its in the Code menu, "Create New QE Plugin". You can never make an editor that does what everyone wants and in part the design of QE with its various extension capacities is so folks who don't feel like writing their own editor from scratch can make custom capacities that suit their programming style or needs.

It will do simple templates that have no logic in them as plain text files, the later scripting engine can do far more complex things in terms of document and code output and the later plugin interface gives you specific control over inserting binary code.

I am pleased to see someone bothered to try the plugin interface as you can get it to do many useful things. You do need to have a reasonable "sniff" of how a Richedit2/3 DLL works but its no big deal to do most stuff.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

zedd151

  • Member
  • ****
  • Posts: 850
Re: Automated Plugin Builder plugin for qe
« Reply #3 on: September 04, 2015, 06:17:30 PM »
I wonder if anyone has noticed the plugin builder already installed in QE ? Its in the Code menu, "Create New QE Plugin".

Oh yes, I have used that. But there was a time I had a couple dozen small functions for formatting and it was kind of time consuming compiling each one. That is where the idea came to make the process more automatic.

zedd

I'm not always the sharpest knife in the drawer, but I have my moments.  :P

zedd151

  • Member
  • ****
  • Posts: 850
Re: Automated Plugin Builder plugin for qe
« Reply #4 on: September 06, 2015, 01:10:03 PM »
Here are a few example plugins for qe, built with the aid of the Plugin Builder if anyone is interested.

Mostly for formatting purposes.

There are 5 in this download:

1. First one aligns all the prototypes, and the .data, & .data? sections "DD", "DB", etc + "EQU"'s   -- for sloppy coders lol
2. second one places a space after each comma, if not already there.   --  looks better with the space, imo.
3. Third one removes both ";" and "comment * " style commenting.  --  I usually clean up the code from "examples" before I use it.
4. Fourth one removes double CrLfs.                                                 -- for those files with just too many empty lines
5. The last one replaces hard tabs with 4 spaces.                            -- for those pesky hard tabs

All of these were built with the PluginBuilder plugin.

enjoy.  :eusa_clap:

plugin set 1


« Last Edit: July 20, 2018, 04:46:09 AM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

zedd151

  • Member
  • ****
  • Posts: 850
Re: Automated Plugin Builder plugin for qe
« Reply #5 on: September 07, 2015, 05:58:24 AM »
A couple more (I think useful) plugins for qeditor:

1. ASM Snippet Creator. Will make a sequentilly numbered 'snippet' from he text selected in qeditor.
    The snippets will have the '.asm' extension.
    The snippet will be created in the folder where the original source resides.

2. Text Snippet Creator. Similarlly will make a Text 'snippet', but with the '.txt' extension, the extension
    required for use with the Plugin Builder stand-alone version.

« Last Edit: July 20, 2018, 02:28:15 PM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

zedd151

  • Member
  • ****
  • Posts: 850
Re: Automated Plugin Builder plugin for qe
« Reply #6 on: September 07, 2015, 11:35:36 PM »
A couple more plugins:

1. Masm reserved words to Lower Case. <--- the way I like it.

2. Masm reserved words to Upper Case. <--- some prefer it this way.

All masm reserved words plus cpu/fpu instructions, and registers are included in two

lists external from the plugins that may be modified.

All of the plugin sets that I have posted in this thread have ready-to-use plugins + source

Attachment removed as it is no longer needed. A link to the entire plugin collection is in my signature.
« Last Edit: July 20, 2018, 02:27:48 PM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

zedd151

  • Member
  • ****
  • Posts: 850
Re: Automated Plugin Builder plugin for qe
« Reply #7 on: September 08, 2015, 06:30:54 AM »
I won't be posting any more plugin sets on in this thread. However I have a link in my signature

with the latest Plugin Collection, that will include all plugin sets to date. Currently there are 3

Plugin sets as described in the above posts. If I come up with a very innovative plugin I will

post it to a new thread. Otherwise the more basic plugins will simply be added to the

Plugin Collection available at the link in my signature. So check it from time to time.  :t

edit ==

Note: I have had trouble downloading the files (ln my sig)  with InternetDownloadManager,

but the files download ok with it turned off. So if down load fails, don't use a download manager

firefox, IE, etc should download without any problems
« Last Edit: September 08, 2015, 09:26:48 AM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

zedd151

  • Member
  • ****
  • Posts: 850
Re: Automated Plugin Builder plugin for qe
« Reply #8 on: September 08, 2015, 02:00:33 PM »
    One of the original 'Testbeds' I created for testing my plugins. lol
It's an incomplete work, to be sure, and it has few features.

    What it does have is highlighting for the search and replace functions.
Search for a word, it gets highlighted when found. Replace a word,
you guessed it, it gets highlighted. The menus do not work, except
for "Build", but the toolbar buttons do, except for 'New File'.
I thought I had scrapped this little project (meant to) but I found it
today and thought I might post it as it has a couple of good examples
in it. It does lack commenting. Sorry about that, but you're a smart
bunch.

    I may have to look back into it, comment it properly, and rearrange
the procedures better. Right now they are a hodge-podge in at least one
file. The original sources were borrowed from the 'riched' example, and
one of iczelions tuts, I forget which one 33, 34 or 35. But some of the
procs were *slightly* modifed (I should have commented the changes)
and others are completely original work. I guess I will definitely have to
go back and comment everything.
 

From post below:

FWIW ...

Looks like you use notepad, or similar, and then copy-paste it here. If so, turn off wordwrap b4 u copy it to make a nice-looking paragraph


Zedds Editor
« Last Edit: July 20, 2018, 04:47:50 AM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

rrr314159

  • Member
  • *****
  • Posts: 1382
Re: Automated Plugin Builder plugin for qe
« Reply #9 on: September 09, 2015, 03:11:53 AM »
FWIW ...

Looks like you use notepad, or similar, and then copy-paste it here. If so, turn off wordwrap b4 u copy it to make a nice-looking paragraph
I am NaN ;)

zedd151

  • Member
  • ****
  • Posts: 850
Re: Automated Plugin Builder plugin for qe
« Reply #10 on: September 09, 2015, 04:31:11 AM »
To rrr314159:


See my post above yours.  :greenclp:

I have a bad habit of double spacing my lines, it's easier for me to read that way.
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

rrr314159

  • Member
  • *****
  • Posts: 1382
Re: Automated Plugin Builder plugin for qe
« Reply #11 on: September 09, 2015, 01:28:56 PM »
Hey, to each their own! I once had the problem I mentioned so thought maybe you did too, but as long as you're doing it on purpose ... who's going to argue with "The PlugIn King"?? :biggrin:
I am NaN ;)

zedd151

  • Member
  • ****
  • Posts: 850
Re: Automated Plugin Builder plugin for qe
« Reply #12 on: September 09, 2015, 01:42:45 PM »
Damn wrong button. - hit the notify instead of reply :shock:  :eusa_naughty:

Quote
who's going to argue with "The PlugIn King"?....


Now that was funny! The trouble with old farts like me is we get stuck in the same habiits.
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

zedd151

  • Member
  • ****
  • Posts: 850
Re: Automated Plugin Builder plugin for qe
« Reply #13 on: September 09, 2015, 05:35:58 PM »
    qeditor is very good at what it does, and it has many good features. There
are times however, that the need arises for customized features that are just not
present in qeditor, or its selection of built-in plugins. Scripting is like
learning a new language. It would indeed handle such needs, but for folks like
myself, it just isn't their cup of tea.

    Enter the qeditor plugin interface. It was I believe, designed to handle such
needs. However, to the newcomer, it's operation is not very straightforward. I
myself had a hard time creating my first few plugins. Of course, I thought that
they were brilliant, and unique. But one major flaw - they only worked part of the
time, and only with short texts. It took days to figure out why. I'm not big on
reading instructions - lol. But olly had helped me find the errors. That
is when I decided to embark on a mission to even further simplify the process.

    Most of you have already seen my 'Automated Plugin Builder', and the
subsequent plugin version (that was actually used to create itself). The following
are the templates that I had used before I started the "Automated" builders.

    Some of the old-timers may roll their eyes, but I present the templates that
served me well - for the newcomers that may wish to experiment creating their own
plugins without much hassle. They are an expansion by what is offered already in the
masm32 package.

(A version for the 'Legacy interface is attached as well) - I wanted to post both versions, but reached the character limit.

For the newer qeditor plugin interface:

Code: [Select]
        include \masm32\include\masm32rt.inc

        ; built-in plugin interface - *slightly* modified as we will deal
        ; mainly with the richedit control here
       
        PiEntryPoint    proto :dword

        ; my own interface to further simplify
        ; the creation of plugins for qe.
       
        CallPlugin      proto :dword ; ( arg = ptrPlugin:dword )
       
        ; The Plugin ; ( args = src:lpRichEdSelectedText, dst:lpModifiedText )
       
        plugin          proto :dword, :dword 
       
        ; some string handling functions, that
        ; preserve all registers except for eax
       
        zstcmpiz        proto :dword, :dword
        zstrcatz        proto :dword, :dword
        zstrclrz        proto :dword
        zstrcpyz        proto :dword, :dword
        zstrlenz        proto :dword
       
    .data?
   
        DLLinstance     dd ?    ; local DLL instance handle
        hRichEd         dd ?    ; handle to rich edit control in qeditor

    .code

    PiEntryPoint proc QEinterface:DWORD
    LOCAL Cr:CHARRANGE
   
        push 2                  ; The handle to the rich edit control
        call QEinterface        ; is the second (zero based) member
        mov hRichEd, eax        ; in the array 'QEinterface'
       
        ; =====================================================================
        ; The 'CallPlugin' procedure handles memory the allocation and releasing
        ; of memory, as well as getting the selected text prior to operation
        ; and replacing the selection with the text modified by the plugin
        ; =====================================================================

        invoke CallPlugin, addr plugin ; doing it in this fashion allows
                                       ; for running multiple plugins
                                       ; from one interface at the same time
                                       
      ; invoke CallPlugin, addr plugin2 ; not used, for illustrative purposes
      ; invoke CallPlugin, addr plugin3 ; not used, for illustrative purposes
      ; invoke CallPlugin, addr plugin4 ; not used, for illustrative purposes
     

        ; =====================================================================
        ; That is all there is to it! (Setting up the plugin, that is)
        ; The 'CallPlugin' procedure does most of the work.
        ; The plugin itself is up to you to design.
        ; =====================================================================
       

        ; =====================================================================
        ;                           IMPORTANT NOTE!
        ; =====================================================================
        ; When dealing with the text from qeditor each line is terminated only
        ; by  "0Dh"; expecting there to be an accompanying "0Ah" will lead to
        ; errors, and will eventually crash qeditor.
        ;=====================================================================

        @@:
        ret
    PiEntryPoint endp
   
    ;--- actual plugin handler ---------------------------------------------

    CallPlugin proc ptrPlugin:dword
    local tmpbuf:dword, Cr:CHARRANGE, tmpsize:dword, selsize:dword
    local tmpbuf2:dword, pluginx:dword

        ; put the address of the plugin into a variable
        mov eax, ptrPlugin
        mov pluginx, eax   

        ; get the start and end position of the selected text
        ; put those vales into a 'CHARRANGE' structure
        invoke SendMessage, hRichEd, EM_EXGETSEL, 0, ADDR Cr
        mov eax, Cr.cpMin
        mov edx, Cr.cpMax
       
        sub edx, eax        ; compare the end position to the start position
        jz nosel            ; which is checking if text is actually selected
        mov selsize, edx
        mov tmpsize, edx
       
        invoke GlobalAlloc, GPTR, tmpsize ; allocate input buffer
        mov tmpbuf, eax
       
        ; doubling the size of the output buffer, to ensure
        ; that there is ample memory.
        ; Often needed for plugins of this type, that manipulate
        ; the text in the editor.
       
        mov edx, tmpsize
        shl edx, 1   
                     
        invoke GlobalAlloc, GPTR, edx ; allocate output buffer
        mov tmpbuf2, eax
       
        ; put selection into input buffer
        invoke SendMessage, hRichEd, EM_GETSELTEXT, 0, tmpbuf
       
        push tmpbuf2        ; push offset to OUTPUT buffer
        push tmpbuf         ; push offset to INPUT buffer
        call pluginx        ; call the plugin

        ;---------------------------------------------------------
        ; replace the selected text in qeditor with the modified
        ; text from the output buffer
        ;---------------------------------------------------------
       
        invoke SendMessage, hRichEd, EM_REPLACESEL, 1, tmpbuf2
       
        invoke zstrlenz, tmpbuf2 ; obtain length of modified text
        mov tmpsize, eax
       
        mov eax, Cr.cpMin   ; add text length to the start
        add eax, tmpsize    ; position to obtain end position
                       
        mov Cr.cpMax, eax   ; adjust the end position of the selection
                            ; by resetting the cpMax value in the structure 'Cr'

        ;---------------------------------------------------------
        ; Update the selection in the rich edit control
        ;---------------------------------------------------------
                               
        invoke SendMessage, hRichEd, EM_EXSETSEL, 0, ADDR Cr

        ;---------------------------------------------------------
        ; Free the input and output memory blocks
        ;---------------------------------------------------------
       
        invoke GlobalFree, tmpbuf
        invoke GlobalFree, tmpbuf2
        jmp done
        nosel:
        fn MessageBoxA, 0, "Sorry, no text is selected", 0, 0
        done:
        ret
    CallPlugin endp


    ; ===================================================================
    ;
    ; example plugin - it removes duplicate spaces from the selected text
    ;
    ; ====================================================================


    plugin proc src:dword, dst:dword
        push esi
        push edi
        mov esi, src
        mov edi, dst
        top:
        @@:
        mov eax, [esi]
        cmp al, 0
        jz done
        cmp al, 20h
        jnz @f
        cmp ax, 2020h
        jnz @f
        inc esi
        jmp @b
        @@:
        mov [edi], al
        inc edi
        inc esi
        jmp top
        done:
        pop edi
        pop esi
        ret
    plugin endp


    zstrcatz proc dst:dword, subs:dword     ; works like lstrcat
        push esi
        push edi
        xor eax, eax
        invoke zstrlenz, dst
        mov edi, dst
        add edi, eax
        invoke zstrcpyz, edi, subs
        mov eax, dst
        pop edi
        pop esi
        ret
    zstrcatz endp

    zstrcpyz proc dst:dword, subs:dword     ; works like lstrcpy
        push esi
        push edi
        mov esi, subs
        mov edi, dst
        xor eax, eax
        @@:
        mov al, [esi]
        cmp al, 0
        jz @f
        mov [edi], al
        inc esi
        inc edi
        jmp @b
        @@:
        invoke zstrclrz, edi
        mov eax, dst
        pop edi
        pop esi
        ret
    zstrcpyz endp

    zstrclrz proc src:dword   ; zeros a buffer containing a zero term. string
        mov eax, src
        push eax
        @@:
        cmp byte ptr [eax], 0
        jz @f
        mov byte ptr [eax], 0
        inc eax
        jmp @b
        @@:
        pop eax
        ret
    zstrclrz endp

    zstrlenz proc src:dword                 ; works the same as lstrlen
        push esi
        push ecx
        mov esi, src
        xor eax, eax
        @@:
        mov cl, [esi]
        cmp cl, 0
        jz @f
        inc eax
        inc esi
        jmp @b
        @@:
        pop ecx
        pop esi
        ret
    zstrlenz endp

    .data
        ztbl \
        db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
        db 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
        db 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47
        db 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63
        db 64,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111
        db 112,113,114,115,116,117,118,119,120,121,122,91,92,93,94,95
        db 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111
        db 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127
        db 128 dup (0FFh)

    .code
   
    ;----------------- case insensitive string cmp routine -------------------

    zstcmpiz proc src:DWORD, dst:DWORD
        push esi
        push edi
        push ebx
        push edx
        push ecx
        mov esi, src
        mov edi, dst
        xor eax, eax
        @@:
        movzx edx, byte ptr [esi+eax]
        movzx ebx, byte ptr [edi+eax]
        movzx ecx, byte ptr [edx+ztbl]
        add eax, 1
        cmp cl, [ebx+ztbl]
        jne quit
        cmp edx, 0
        jz @f
        cmp ebx, 0
        jz @f
        jmp @b
        @@:
        sub eax, eax
        quit:
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    zstcmpiz endp

    LibMain proc instance:dword,reason:dword,unused:dword
        switch reason
        case DLL_PROCESS_ATTACH
        mrm DLLinstance,instance
        mov eax, TRUE
        endsw
        ret
    LibMain endp
   
    end LibMain

edit = found an error in the 'legacy' source - fixed



legacy plugin interface Download


new plugin interface Download

« Last Edit: July 20, 2018, 02:25:30 PM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

zedd151

  • Member
  • ****
  • Posts: 850
Re: Automated Plugin Builder plugin for qe
« Reply #14 on: September 14, 2015, 08:19:42 PM »
A quick little plugin

cmtBlock is a plugin for those that prefer
Code: [Select]
    comment * ##################################################################
        your comment here
        your comment here
        your comment here
        your comment here
        your comment here
    ########################################################################## *

style block commenting.

I have not added it to the 'Plugin Collection' as I am waiting to do a few more plugins before I do so.


CmtBlock Plugin Download
« Last Edit: July 20, 2018, 02:27:19 PM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P