Browsing this Thread:
1 Anonymous Users
Dynamic Lists, Hooks, Zune and Mr. X random's leisure gang |
||
---|---|---|
![]() Joined:
2009/5/15 13:18 From Naples, Italy
Group:
Member Posts:
423
![]() |
Hi!
I've written a function that takes a text file and breaks it in words. Every word is a struct, and every word-struct is part of a row dynamic list. Every row-list is part of another list that collects all rows. When i do this from console (without using zune) it all works like a charm. Now i've wrote a function (opendlg) that opens a file dialog and lets you choose what text file load. Then i process the text buffer to the list i told about. When i use the zune version, aros crashes: i wrote a view function that iterates through pointers and i notice they're wrong. The same function, used by console it's perfect. I report here a bit of what i've written so if anyone helps me, i would be really thankful to him! Yes! i use hooks to call opendlg! data structs: ////////////WORD LIST IN A ROW (LISTAPAROLE== WORDS LIST) typedef struct ListaParole{ char* testo; //text int tipoparola; ///kind of word: word, space, cr... struct ListaParole *ProssimaParola; //nextword struct ListaParole *ParolaPrecedente; //prevword } Parola; typedef Parola *ParolaPtr; //a pointer to /////////////WORD LIST typedef struct ListaRiga{ Parola* parola; //A POINTER TO WORD STRUCT struct ListaRiga *ProssimaRiga; //NEXTROW struct ListaRiga *RigaPrecedente; //PREVROW } Riga; typedef Riga *RigaPtr; //A POINTER TO First func int CaricaFileTesto(char* filename, char **TextArray); loads filename in txtarray. It uses c standard funcs. dismantlebomb() this closes and deallocates all. RigaPtr processaBuffer(char* inbuffer, RigaPtr *param_Testa); It transforms inbuffer in a list of lists. list of word for eevery row list Opendlg macro funct, mainly a wrapper funct It all works under shell (without zune, hooks) and with a text menu when i use the zune version it prints totally wrong nodes: it passes from 000000 address to ffffff and then, eventually, continues right... But usually aros resets itself or the app crashes... AROS_UFH13(ULONG, opendlg_function, AROS_UFHA(struct Hook*, hook, A0), AROS_UFHA(Object *, object,A1), AROS_UFHA(APTR, msg, A2), AROS_UFHA(struct FileRequester *, filereq, A3), AROS_UFHA(Object *, app, A4), AROS_UFHA(Object *, window, A5), AROS_UFHA(int *, textfilesize, A6), AROS_UFHA(char*, TextArray, A7), AROS_UFHA(RigaPtr *, PuntatorediTesta, A8), AROS_UFHA(int, risultato, A9), AROS_UFHA(struct_colonne *, ptrcolonne, A10), AROS_UFHA(int, itimeout, A11), AROS_UFHA(int, idefault, A12)) { AROS_USERFUNC_INIT //RigaPtr Testa; //Testa=PuntatorediTesta; // create and show FileRequester dialog box filereq = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest, ASLFR_TitleText, "Select a file", ASLFR_DoPatterns, TRUE, ASLFR_InitialDrawer, "SYS:", TAG_END); if (!filereq) { // display message box MUI_Request(app, window, 0, "Error", "OK", "Failed to create FileRequester dialog",TAG_END); return; } if (AslRequest(filereq, NULL)) // if we choosen OK { RigaPtr appoggioriga; char filename[255]; char dir[255]; strcpy(dir, filereq->rf_Dir); strcpy(filename, filereq->rf_File); *PuntatorediTesta=(RigaPtr)(malloc(sizeof(RigaPtr))); char full_filename[255]; strcpy(full_filename, dir); if ((dir[strlen(dir)]!='/')&&(dir[strlen(dir)]!=':')) strcat(full_filename,"/"); strcat(full_filename, filename); char msg[1000]; *textfilesize=LoadTextFile(full_filename, &TextArray); printf("\ntextfilesize %d", *textfilesize); if ((processaBuffer(TextArray, PuntatorediTesta))==NULL) { printf("\n nothing to do!!"); dismantlebomb(); } else { printf("\nhead pointer %p %p", PuntatorediTesta, *PuntatorediTesta); VisualizzaptrRiga(*PuntatorediTesta); printf("\nafter view"); ///HERE COMES THE ERROR. WHEN I USE VisualizzaptrRiga it's all wrong... risultato=AnalizzaRigadue(*PuntatorediTesta, ptrcolonne, &itimeout, &idefault, listobj); if (risultato<0) { printf("\nError"); } } MUI_Request(app, window, 0, "Notification", "OK", msg, TAG_END); } else { MUI_Request(app, window, 0, "Notification", "OK", "FileRequester dialog canceled",TAG_END); } return 11; AROS_USERFUNC_EXIT } Help....
Posted on: 2012/12/24 6:21
|
|
_________________
Somethin'nothin'o'u have: a working MPS1550 (Commodore Dot Matrix Color Printer) :p:p:p & 1 "amiga computer of the year 1986" sticker with an original 1987 coffee stain upon it!!! |
||
![]() |
Re: Dynamic Lists, Hooks, Zune and Mr. X random's leisure gang |
||
---|---|---|
![]() Joined:
2005/8/17 16:00 From Germany
Group:
Member Posts:
2220
![]() |
AROS_UFH13(ULONG, opendlg_function,
Callback functions usually have 3 arguments (hook, object, msg). Your example doesn't show how you use that function. I'm surprised that you can use registers up to A12. A 68k has only 8 address registers IIRC.
Posted on: 2012/12/25 4:47
|
|
_________________
AROS - Make code, not war ![]() |
||
![]() |
Re: Dynamic Lists, Hooks, Zune and Mr. X random's leisure gang |
||
---|---|---|
![]() Joined:
2009/5/15 13:18 From Naples, Italy
Group:
Member Posts:
423
![]() |
hi! and thank you!
i used this (as stated in asmcall.h) #define AROS_UFH13(t,n,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) \ __AROS_UFH_PREFIX t n (\ __AROS_UFHA(a1),\ __AROS_UFHA(a2),\ __AROS_UFHA(a3),\ __AROS_UFHA(a4),\ __AROS_UFHA(a5),\ __AROS_UFHA(a6),\ __AROS_UFHA(a7),\ __AROS_UFHA(a8),\ __AROS_UFHA(a9),\ __AROS_UFHA(a10),\ __AROS_UFHA(a11),\ __AROS_UFHA(a12),\ __AROS_UFHA(a13)\ ) { but i think (reading wiki) it could be better this: #define AROS_UFC13(t,n,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) \ (((__AROS_UFC_PREFIX t(*)(\ __AROS_UFPA(a1),\ __AROS_UFPA(a2),\ __AROS_UFPA(a3),\ __AROS_UFPA(a4),\ __AROS_UFPA(a5),\ __AROS_UFPA(a6),\ __AROS_UFPA(a7),\ __AROS_UFPA(a8),\ __AROS_UFPA(a9),\ __AROS_UFPA(a10),\ __AROS_UFPA(a11),\ __AROS_UFPA(a12),\ __AROS_UFPA(a13)\ ))n)(\ __AROS_UFCA(a1),\ __AROS_UFCA(a2),\ __AROS_UFCA(a3),\ __AROS_UFCA(a4),\ __AROS_UFCA(a5),\ __AROS_UFCA(a6),\ __AROS_UFCA(a7),\ __AROS_UFCA(a8),\ __AROS_UFCA(a9),\ __AROS_UFCA(a10),\ __AROS_UFCA(a11),\ __AROS_UFCA(a12),\ __AROS_UFCA(a13)\ )) later i'll try it! thank you!
Posted on: 2012/12/26 1:17
|
|
_________________
Somethin'nothin'o'u have: a working MPS1550 (Commodore Dot Matrix Color Printer) :p:p:p & 1 "amiga computer of the year 1986" sticker with an original 1987 coffee stain upon it!!! |
||
![]() |
Re: Dynamic Lists, Hooks, Zune and Mr. X random's leisure gang |
||
---|---|---|
![]() Joined:
2009/10/28 4:25 From Finland
Group:
Member Posts:
245
![]() |
@lellonapoli
Hook functions have only three parameters: hook, object and message. The hook parameter is a pointer to your filled out hook structure, and the object and message parameters depends on what the hook is used for. The parameters are passed in the registers A0 (hook), A2 (object) and A1 (message) and not A0 (hook), A1 (object) and A2 (message) as you have in your code. If you need to pass more data to your hook function you can make use of the h_UserData field of the hook structure. You can also avoid the AROS_UFH#? crap entirely by simply using the HookEntry function: ULONG YourHookFunction(struct Hook *hook, APTR object, APTR message); hook.h_Entry = HookEntry; hook.h_SubEntry = YourHookFunction;
Posted on: 2012/12/26 7:14
|
|
![]() |
Re: Dynamic Lists, Hooks, Zune and Mr. X random's leisure gang |
||
---|---|---|
![]() Joined:
2009/5/15 13:18 From Naples, Italy
Group:
Member Posts:
423
![]() |
@salass00:
thank you! i'm surely making confusion. This is the first time i use hooks. In my past mui studies i always used the megaswitch and, lesser, oop technique with dispatcher. Now, i don't want to call a system function, just "my" function and, studying zune, i decided to apply the hook technique. I don't wanna use globals so if i use what you wrote ULONG YourHookFunction(struct Hook *hook, APTR object, APTR message); hook.h_Entry = HookEntry; hook.h_SubEntry = YourHookFunction; should i put extra data in h_UserData?
Posted on: 2012/12/26 11:13
|
|
_________________
Somethin'nothin'o'u have: a working MPS1550 (Commodore Dot Matrix Color Printer) :p:p:p & 1 "amiga computer of the year 1986" sticker with an original 1987 coffee stain upon it!!! |
||
![]() |
Re: Dynamic Lists, Hooks, Zune and Mr. X random's leisure gang |
||
---|---|---|
![]() Joined:
2009/10/28 4:25 From Finland
Group:
Member Posts:
245
![]() |
Quote:
Yes, you can then access it through the hook pointer that gets passed to your hook function. Note that if you're doing a dispatcher for a MUI custom class you don't get to fill in the hook structure yourself so you can't use HookEntry in this specific case. In the Zune version of DiskImageGUI I use SDI includes which hides all the OS specific details when handling hooks. F.e. this is how I define the DriveList class dispatcher using SDI:
DISPATCHERPROTO(DriveList_Dispatch);
Edit: The hook user data field is called h_Data and not h_UserData, also you are not allowed to use it in MUI class dispatchers according to this page: http://tbs-software.com/guide/index.p ... oc%2FMUImaster.doc&node=4 Instead you may use cl_UserData and/or mcc_UserData fields for this purpose.
Posted on: 2012/12/26 11:43
|
|
![]() |
Re: Dynamic Lists, Hooks, Zune and Mr. X random's leisure gang |
||
---|---|---|
![]() Joined:
2009/5/15 13:18 From Naples, Italy
Group:
Member Posts:
423
![]() |
hi!
i downloaded sdi headers from the link you've kindly provided.:) I copied the headers (i use icaros) in development/include dir. I've tried to compile the examples, but none of them go. I compiled the hook example and gcc reports (amidevcpp too): expected '=', ',', ';', 'asm' or '__attribute__' before 'LONG' 'HelloFunc' undeclared here (not in a function) conflicting types for 'UtilityBase' ... this is the example: #include #include #include #include #include #include "SDI_hook.h" HOOKPROTONHNP(HelloFunc, LONG, char *txt) { printf("'%s' which returns ", txt); return -10; } MakeStaticHook(HelloHook, HelloFunc); struct Library *UtilityBase; #if defined(__amigaos4__) struct UtilityIFace *IUtility; #define GETINTERFACE(iface, base) (iface = (APTR)GetInterface((struct Library *)(base), "main", 1L, NULL)) #define DROPINTERFACE(iface) { DropInterface((APTR)(iface)); iface = NULL; } #else #define GETINTERFACE(iface, base) TRUE #define DROPINTERFACE(iface) #endif int main(void) { LONG ret = 0; if((UtilityBase = OpenLibrary("utility.library", 37))) { if(GETINTERFACE(IUtility, UtilityBase)) { printf("Hello! I am a "); ret = CallHook(&HelloHook, "portable Hook"); printf("%ld\n", ret); DROPINTERFACE(IUtility); } CloseLibrary(UtilityBase); } return 0; }
Posted on: 2012/12/28 2:39
|
|
_________________
Somethin'nothin'o'u have: a working MPS1550 (Commodore Dot Matrix Color Printer) :p:p:p & 1 "amiga computer of the year 1986" sticker with an original 1987 coffee stain upon it!!! |
||
![]() |
Re: Dynamic Lists, Hooks, Zune and Mr. X random's leisure gang |
||
---|---|---|
![]() Joined:
2005/8/17 16:00 From Germany
Group:
Member Posts:
2220
![]() |
This works for me:
#include <stdio.h>
The only significant modification is that I have changed the type of UtilityBase for AROS.
Posted on: 2012/12/28 4:08
|
|
_________________
AROS - Make code, not war ![]() |
||
![]() |
Re: Dynamic Lists, Hooks, Zune and Mr. X random's leisure gang |
||
---|---|---|
![]() Joined:
2009/5/15 13:18 From Naples, Italy
Group:
Member Posts:
423
![]() |
THX!!!
Solved it. Well, the sdi headers from sourceforge is a 2005 version not compatible with aros. Got the aros ones from an old icaros version and all went ok with examples. Solved even the crashes: I use HOOKPROTO.... and now it works. There's only a crash on exit but that's surely dyn memory not freed (or badly fred). Another question: what's the difference in running a program by wanderer (when i double click the program it works fine) or by shell (when i launch it from shell, it often crashes)?
Posted on: 2012/12/29 15:12
|
|
_________________
Somethin'nothin'o'u have: a working MPS1550 (Commodore Dot Matrix Color Printer) :p:p:p & 1 "amiga computer of the year 1986" sticker with an original 1987 coffee stain upon it!!! |
||
![]() |
Re: Dynamic Lists, Hooks, Zune and Mr. X random's leisure gang |
||
---|---|---|
![]() Joined:
2009/10/28 4:25 From Finland
Group:
Member Posts:
245
![]() |
@lellonapoli
Quote:
I meant that you should use the latest versions of the headers from the CVS: http://sditools.cvs.sourceforge.net/v ... ditools/sditools/headers/ Not some old ones from 2005.
Posted on: 2012/12/30 0:19
|
|
![]() |
You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.