English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 29 June 2021, 11:04   #81
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Aaaarrrgh!
Maybe this is a tiny detail which is worth documenting for potential plugin authors?

There is no way you would expect that
init()
is called with register arguments. Also the example code shows a standard
static void init(APTR userData)
. At least the plugin structure should have an entry like
void (*init)(register __a0 APTR userData)
to make that clear - or even better using the portable
__REG__
macro from
clib/compiler-specific.h
.

The best solution, in my opinion, would be to just use standard arguments on the stack and avoid any trouble with compiler-specific register arguments.
phx is offline  
Old 29 June 2021, 13:10   #82
boemann
Camilla, AmigaOS Dev.
 
Join Date: Mar 2020
Location: Frederiksberg
Posts: 327
But this is the definition of the function i call:


/* Now the real data comes */
void (*init)(APTR userData);

In my understanding this implies standard arguments, so I'm completely surprised it passes via a0 as that is not what i tried to do
boemann is offline  
Old 29 June 2021, 13:11   #83
boemann
Camilla, AmigaOS Dev.
 
Join Date: Mar 2020
Location: Frederiksberg
Posts: 327
ARghh from my makefile:

params=r
boemann is offline  
Old 29 June 2021, 14:45   #84
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Det var ikke så godt!

As TextEdit was already released with OS3.2, I guess the interface will not change again and has to be documented with register arguments?
phx is offline  
Old 29 June 2021, 14:50   #85
boemann
Camilla, AmigaOS Dev.
 
Join Date: Mar 2020
Location: Frederiksberg
Posts: 327
I have specifically not released api info officially. No one should publish plugins before there is an official api.

The whole purpose of doing it like this is so I can get feedback

So I have no problem with changing it for 3.2.1
boemann is offline  
Old 29 June 2021, 14:51   #86
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by boemann View Post
The whole purpose of doing it like this is so I can get feedback

So I have no problem with changing it for 3.2.1



Let's see if guy lateur can generate a working plugin now, with that knowledge.
phx is offline  
Old 29 June 2021, 14:53   #87
boemann
Camilla, AmigaOS Dev.
 
Join Date: Mar 2020
Location: Frederiksberg
Posts: 327
he should just be aware that he needs to do it for all the settings gui functions too

And obviously be prepared for a rebuild when 3.2.1 is out
boemann is offline  
Old 29 June 2021, 15:08   #88
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by phx View Post
Aaaarrrgh!
The best solution, in my opinion, would be to just use standard arguments on the stack and avoid any trouble with compiler-specific register arguments.

The Amiga loves register arguments and there is no argument against that^^
bebbo is offline  
Old 29 June 2021, 15:43   #89
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
It might be beneficial to keep the params=r in the makefile and declare the plugin functions prefixed with __stdargs ?
alkis is offline  
Old 29 June 2021, 17:31   #90
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by phx View Post
Let's see if guy lateur can generate a working plugin now, with that knowledge.
Yep, he sure can! Finally it's working! Thank you all for your time and energy you put into getting this to work, I greatly appreciate this! I can finally start concentrating on the highlighting itself.

Here's my
init()
function:
Code:
static void init(__reg("a0") APTR userData)
{
    struct Filetype *fType = (struct Filetype *)userData;
    struct Hook *hook      = NULL;
    
    if(!openLibs())
    {
        terminate(fType);
        return;
    }

    hook             = (struct Hook *)AllocVec(sizeof(struct Hook), MEMF_CLEAR);
    hook->h_Entry    = (ULONG (*)()) highlightBlock;
    hook->h_SubEntry = NULL;
    hook->h_Data     = 1234567;
    
    fType->highlighterHook    = hook;
    
    // any number or pointer of our choosing
    // does this have to be equal to hook->h_Data?
    fType->pluginData         = (ULONG)1234567;
    
    fType->name               = "ExampleName";
    fType->typeName           = "ExampleTypeName";
    fType->autoFileTypes      = "ExampleAFT"; // example? eg (*.s;*.i)?
    
    fType->terminate          = terminate;
    fType->settingsTitle      = settingsTitle;
    fType->settingsGadget     = settingsGadget;
    fType->processGadgetUp    = processGadgetUp;
    fType->setSettingsFromGUI = setSettingsFromGUI;
    fType->setGUIFromSettings = setGUIFromSettings;
    fType->applySettings      = applySettings;
    fType->saveSettings       = saveHighlightSettings;
    fType->loadSettings       = loadHighlightSettings;
    fType->disposeGadgets     = disposeGadgets;
}
For completeness, here's
highlightBlock()
:
Code:
ULONG __saveds highlightBlock(__reg("a0") struct Hook *h, __reg("a2") VOID *o, __reg("a1") VOID *msg)
{
    struct HighlightMessage *hm = (struct HighlightMessage *)msg;
    STRPTR text = hm->Text;
    UWORD state = hm->StatusOfPrevBlock;
    UWORD start = 0;
    UWORD end = strlen(text);

    // if line is longer than 10 chars we paint the entire line with color 3
    if (end > 10)
        HighlightSetFormat(o, start, end, (3<<8)|TBSTYLE_SETCOLOR);

    return (ULONG)state + 1L;
}
Here are my latest sources, including the binaries: master-20210629.zip

Quote:
Originally Posted by boemann View Post
he should just be aware that he needs to do it for all the settings gui functions too
Well to be brutally honest, I was kinda hoping you would release a more fleshed out example when 3.2.1 comes out and you release this officially. Eg, if you could release the code that handles the GUI for the highlighting as it is for the built-in types, I think that would be really beneficial for the community. If people can select the part type (eg label, instruction, literal, comment, ..) and set the color and the standard font properties (bold, italic, underline) for each one of those, that would already go a long way for most plugins, IMHO.

Also, a little more explanation would be welcome, but I'm sure you already knew that. Eg, does fType->pluginData need to be equal to hook->h_Data? How to specify the file types this highlighting automatically applies to (eg, .s and .i files)?

Quote:
Originally Posted by boemann View Post
And obviously be prepared for a rebuild when 3.2.1 is out
I'll be more than happy to do that when the time comes!
guy lateur is offline  
Old 29 June 2021, 17:36   #91
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Well done for the working plugin.

Just curious here, does it work if you remove __saveds from highlightBlock?
alkis is offline  
Old 29 June 2021, 17:40   #92
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by alkis View Post
Just curious here, does it work if you remove __saveds from highlightBlock?
Yep, apparently it does.
guy lateur is offline  
Old 29 June 2021, 17:41   #93
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
It should work. You are not referencing any plugin variables, just locals (or parameter's passed).
Anyways __saveds is there if you need to access any global plugin variable(s) I guess.
alkis is offline  
Old 29 June 2021, 17:45   #94
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by alkis View Post
It should work. You are not referencing any plugin variables, just locals (or parameter's passed).
Anyways __saveds is there if you need to access any global plugin variable(s) I guess.
Ok, thanks for elaborating on this. TBH, I only have a vague idea what these qualifiers really mean ATM..
guy lateur is offline  
Old 29 June 2021, 18:48   #95
boemann
Camilla, AmigaOS Dev.
 
Join Date: Mar 2020
Location: Frederiksberg
Posts: 327
Quote:
Originally Posted by alkis View Post
It might be beneficial to keep the params=r in the makefile and declare the plugin functions prefixed with __stdargs ?
yes
boemann is offline  
Old 29 June 2021, 19:36   #96
boemann
Camilla, AmigaOS Dev.
 
Join Date: Mar 2020
Location: Frederiksberg
Posts: 327
Quote:
Originally Posted by guy lateur View Post

Well to be brutally honest, I was kinda hoping you would release a more fleshed out example when 3.2.1 comes out and you release this officially. Eg, if you could release the code that handles the GUI for the highlighting as it is for the built-in types, I think that would be really beneficial for the community. If people can select the part type (eg label, instruction, literal, comment, ..) and set the color and the standard font properties (bold, italic, underline) for each one of those, that would already go a long way for most plugins, IMHO.

Also, a little more explanation would be welcome, but I'm sure you already knew that. Eg, does fType->pluginData need to be equal to hook->h_Data? How to specify the file types this highlighting automatically applies to (eg, .s and .i files)?
hook data and pluginData are both totally up to you to define, and does not have to be the same

the fType->autoFileTypes is the one that specieds the file to automatically apply to: for you that would be: "asm\ni"
This refers to asm and i defticons typenames

As for a more elaborate example, I'll have to see if it can be released, but apart from getting approval, I'm also not that proud of how the default plugins are coded. They do their job but were never intended to be top of the line - so using them as examples for others to learn from is maybe not so great. This means I should spend more time on making an example. Time I'd like to spend on other things too. We'll see
boemann is offline  
Old 29 June 2021, 20:17   #97
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by boemann View Post
hook data and pluginData are both totally up to you to define, and does not have to be the same

the fType->autoFileTypes is the one that specieds the file to automatically apply to: for you that would be: "asm\ni"
This refers to asm and i defticons typenames
Ok, thanks for the info.

Quote:
Originally Posted by boemann View Post
As for a more elaborate example, I'll have to see if it can be released, but apart from getting approval, I'm also not that proud of how the default plugins are coded. They do their job but were never intended to be top of the line - so using them as examples for others to learn from is maybe not so great. This means I should spend more time on making an example. Time I'd like to spend on other things too. We'll see
Sure, no worries, it's just an idea, something I would like to see.
guy lateur is offline  
Old 29 June 2021, 20:31   #98
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by alkis View Post
It should work. You are not referencing any plugin variables, just locals (or parameter's passed).
Anyways __saveds is there if you need to access any global plugin variable(s) I guess.

__saveds is not useful here - it's simply stupid.


And refering to the task's userdata pointer: How many plugins can store it's a4 register in the same location? And what happens if the main program uses that field too??


No baserel stuff in these plugins!

And if the same plugin is used by many instances: use only the allocated memory - pointer to stored in fType->pluginData - for everything. No global stuff. none at all.

Last edited by bebbo; 29 June 2021 at 20:39.
bebbo is offline  
Old 29 June 2021, 22:13   #99
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by bebbo View Post
__saveds is not useful here - it's simply stupid.
At least it is not necessary, as long as the plugin is not compiled with small data.

Quote:
And refering to the task's userdata pointer: How many plugins can store it's a4 register in the same location? And what happens if the main program uses that field too??

No baserel stuff in these plugins!
Sounds as if you are quite certain that a TextEdit plugin must be reentrant? Is that really the case? I didn't get this impression from existing example code. Maybe Camilla can make it clear.

Quote:
And if the same plugin is used by many instances:
This would be another open question. Does that happen? I could imagine that when you start TextEdit for a second time it will also load the plugins for a second time into memory. Camilla already confirmed that TextEdit is not reentrant (pure) itself.

Quote:
use only the allocated memory - pointer to stored in fType->pluginData - for everything. No global stuff. none at all.
I agree this is generally a good idea for reentrant programs. Maybe even for normal ones. But it usually forces you to write compiler-specific code when doing OS-calls, which depend on a static library base.
phx is offline  
Old 29 June 2021, 22:36   #100
boemann
Camilla, AmigaOS Dev.
 
Join Date: Mar 2020
Location: Frederiksberg
Posts: 327
Quote:
Originally Posted by phx View Post
Sounds as if you are quite certain that a TextEdit plugin must be reentrant? Is that really the case? I didn't get this impression from existing example code. Maybe Camilla can make it clear.

This would be another open question. Does that happen? I could imagine that when you start TextEdit for a second time it will also load the plugins for a second time into memory. Camilla already confirmed that TextEdit is not reentrant (pure) itself.

I agree this is generally a good idea for reentrant programs. Maybe even for normal ones. But it usually forces you to write compiler-specific code when doing OS-calls, which depend on a static library base.
TextEdit Plugins does not have to be reentrant/pure

A new instance of TextEdit will load the plugins again.

The default plugins use global vars for storing library bases as well as the settings for the plugin. (colors, softstyle for the various types)

The hook stores a pointer to the statemachine in it's data member, which is allocated and generated on init
boemann is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
AmigaOS 3.2 TextEdit - black text on black background? Warty support.Apps 7 08 June 2021 17:30
gedit asm syntax highlighting plugin? grond Coders. Asm / Hardware 0 19 May 2020 13:06
VBCC assembler linking syntax? NovaCoder Coders. General 2 20 May 2011 03:04
CLI Syntax Greaser New to Emulation or Amiga scene 1 08 October 2006 10:14
SynTax Disks (old) andreas request.Old Rare Games 1 19 July 2003 04:02

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:15.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.26700 seconds with 16 queries