Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / stacks / AROSTCP / syslog / hooks.c
blobeff489c2139f481c17bd231da3735a91450447e8
1 /* SysLog Listview hooks */
3 #if !defined(__AROS__)
4 #define __NOLIBBASE__
5 #endif
7 #include <proto/exec.h>
8 #include <proto/muimaster.h>
9 #include <proto/dos.h>
10 #include <proto/locale.h>
11 #include <clib/alib_protos.h>
12 #include <libraries/asl.h>
13 #include <mui/NList_mcc.h>
14 //#include <exec/rawfmt.h>
15 #include <string.h>
16 #include "main.h"
17 #include "colorlist.h"
19 extern STRPTR levels[];
21 /* PutCharFunc hook for FormatDate */
23 #if !defined(__AROS__)
24 void PutCharFunc(void)
26 struct Hook *h = (struct Hook*)REG_A0;
27 BYTE ch = (BYTE)REG_A1;
28 #else
29 AROS_UFH3(
30 void, PutCharFunc,
31 AROS_UFHA(struct Hook *, h, A0),
32 AROS_UFHA(APTR *, obj, A2),
33 AROS_UFHA(BYTE, ch, A1)
36 AROS_USERFUNC_INIT
37 #endif
39 #if !defined(__AROS__)
40 *((STRPTR)h->h_Data)++ = ch;
41 #else
42 AROS_USERFUNC_EXIT
43 #endif
46 #if !defined(__AROS__)
47 struct EmulLibEntry g_PutCharFunc = {TRAP_LIB, 0, (void (*)(void))PutCharFunc};
48 struct Hook h_PutCharFunc = {{NULL, NULL}, (HOOKFUNC)&g_PutCharFunc, NULL, NULL};
49 #else
50 struct Hook h_PutCharFunc;
51 #endif
53 /* SaveAs hook called on menu notification, saves all log to a text file. */
55 LONG SaveAsHook(void)
57 Object *list = (Object*)REG_A2;
58 struct FileRequester *freq;
60 if (freq = MUI_AllocAslRequest(ASL_FileRequest, NULL))
62 if (MUI_AslRequestTags(freq,
63 ASLFR_Window, (ULONG)_window(list),
64 ASLFR_TitleText, "Save media log file",
65 ASLFR_DoSaveMode, TRUE,
66 TAG_END))
68 BPTR lock;
70 if (lock = Lock(freq->fr_Drawer, SHARED_LOCK))
72 BPTR olddir, logfile;
74 olddir = CurrentDir(lock);
75 if (logfile = Open(freq->fr_File, MODE_NEWFILE))
77 LONG entry;
78 struct SysLogEntry *sle;
80 for (entry = 0; ; entry++)
82 DoMethod(list, MUIM_List_GetEntry, entry, (ULONG)&sle);
83 if (!sle) break;
84 FPrintf(logfile, "\"%s\", \"%s\", \"%s\", \"%s\"\n", sle->Time, levels[LOG_PRI(sle->Level)],
85 sle->ProcessName, sle->EventDescription);
87 Close(logfile);
89 CurrentDir(olddir);
90 UnLock(lock);
93 MUI_FreeAslRequest(freq);
95 return 0;
98 struct EmulLibEntry g_SaveAsHook = {TRAP_LIB, 0, (void (*)(void))SaveAsHook};
99 struct Hook h_SaveAsHook = {{NULL, NULL}, (HOOKFUNC)&g_SaveAsHook, NULL, NULL};