Hi, just updated hooktest.c to use OS4 hooks "mode". It works fine. IS this the right way if updating/coding? Or must I for every AllocSys.. add FreeSys..?
TIA
;/* gcc hooktest2.c -o HookTest2 -Wall -lauto -gstabs quit */ #include <proto/dos.h> #include <proto/locale.h> #include <proto/exec.h> void fmtfunct(struct Hook *hook, struct Locale *locale, ULONG ch) { char *buffer = (char *)hook->h_Data; *buffer++ = ch; hook->h_Data = (APTR)buffer; } int main(void) { struct DateStamp ds; char buffer[30]; struct Hook *prhook; IDOS->DateStamp(&ds); // fmthook.h_Entry = (HOOKFUNC)fmtfunct; // fmthook.h_Data = (APTR)buffer; prhook = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK, ASOHOOK_Entry, fmtfunct, ASOHOOK_Data, buffer, TAG_DONE); ILocale->FormatDate(NULL,"%d-%m-%Y", &ds, prhook); IDOS->Printf("Fecha: %s\n",buffer); // fmthook.h_Entry = (HOOKFUNC)fmtfunct; // fmthook.h_Data = (APTR)buffer; prhook = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK, ASOHOOK_Entry, fmtfunct, ASOHOOK_Data, buffer, TAG_DONE); ILocale->FormatDate(NULL,"%d", &ds, prhook); IDOS->Printf("Day: %s\n",buffer); // fmthook.h_Entry = (HOOKFUNC)fmtfunct; // fmthook.h_Data = (APTR)buffer; prhook = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK, ASOHOOK_Entry, fmtfunct, ASOHOOK_Data, buffer, TAG_DONE); ILocale->FormatDate(NULL,"%m", &ds, prhook); IDOS->Printf("Month: %s ",buffer); // fmthook.h_Entry = (HOOKFUNC)fmtfunct; // fmthook.h_Data = (APTR)buffer; prhook = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK, ASOHOOK_Entry, fmtfunct, ASOHOOK_Data, buffer, TAG_DONE); ILocale->FormatDate(NULL,"%B", &ds, prhook); IDOS->Printf("(%s)\n",buffer); // fmthook.h_Entry = (HOOKFUNC)fmtfunct; // fmthook.h_Data = (APTR)buffer; prhook = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK, ASOHOOK_Entry, fmtfunct, ASOHOOK_Data, buffer, TAG_DONE); ILocale->FormatDate(NULL,"%Y", &ds, prhook); IDOS->Printf("Year: %s\n",buffer); IExec->FreeSysObject(ASOT_HOOK, prhook); return(RETURN_OK); }
Of course! Each AllocSysObject() is an allocation so it must be deallocated, regardless of your using a single variable for the hook pointer.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
OK, THX.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
I would call AllocSysObject only once in the beginning and then only poke the new buffer pointer into hook->h_Data. You do this in your fmtfunct routine anyway, so it should be legal for the main routine, too.
Hi, as I'm not very good coder.
How do I "poke the new buffer pointer into hook->h_Data"?
BTW I found another way to get Year/Month/Day values:
Is there a better/proper way to do what I'm trying to achieve (get Date and split YYYY MM DD into integer variables)?
TIA
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
From utility/date.h:
hook->h_Data = (APTR)buffer;
@gazelle & @thomas THX both modes working fine.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P