Minor fixes to comments.
[AROS.git] / rom / usb / poseidon / PsdErrorlog.c
blobbb82b2df87eb32ac14cee6d32b2099714fcb6db0
1 /*
2 ** PsdErrorlog by Chris Hodges <chrisly@platon42.de>
3 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <exec/exec.h>
9 #include <dos/datetime.h>
10 #include <libraries/poseidon.h>
11 #include <proto/poseidon.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
15 #define ARGS_NOFLUSH 0
16 #define ARGS_DEBUG 1
17 #define ARGS_NOTS 2
18 #define ARGS_SIZEOF 3
20 static const char *template = "NOFLUSH/S,DEBUG/S,NOTIMESTAMPS=NOTS/S";
21 const char *version = "$VER: PsdErrorlog 4.0 (28.06.09) by Chris Hodges <chrisly@platon42.de>";
22 static IPTR ArgsArray[ARGS_SIZEOF];
23 static struct RDArgs *ArgsHook = NULL;
25 void fail(char *str)
27 if(ArgsHook)
29 FreeArgs(ArgsHook);
30 ArgsHook = NULL;
32 if(str)
34 PutStr(str);
35 exit(20);
37 exit(0);
40 int main(int argc, char *argv[])
42 struct Library *ps;
43 struct List *errmsgs;
44 struct Node *pem;
45 ULONG level;
46 IPTR origin;
47 IPTR errstr;
48 STRPTR errmsg = NULL;
49 struct DateStamp *ds;
50 struct DateTime dt;
51 struct DateStamp currdate;
52 UBYTE strdate[LEN_DATSTRING];
53 UBYTE strtime[LEN_DATSTRING];
55 if(!(ArgsHook = ReadArgs(template, ArgsArray, NULL)))
56 fail("Wrong arguments!\n");
58 if((ps = OpenLibrary("poseidon.library", 4)))
60 DateStamp(&currdate);
61 if(ArgsArray[ARGS_DEBUG])
63 psdDebugSemaphores();
64 } else {
65 if(ArgsArray[ARGS_NOFLUSH])
67 psdLockReadPBase();
68 } else {
69 psdLockWritePBase();
72 psdGetAttrs(PGA_STACK, NULL, PA_ErrorMsgList, &errmsgs, TAG_END);
73 pem = errmsgs->lh_Head;
74 while(pem->ln_Succ)
76 ds = NULL;
77 psdGetAttrs(PGA_ERRORMSG, pem,
78 EMA_Level, &level,
79 EMA_Origin, &origin,
80 EMA_Msg, &errstr,
81 EMA_DateStamp, &ds,
82 TAG_END);
83 if(ds && (!ArgsArray[ARGS_NOTS]))
85 dt.dat_Stamp.ds_Days = ds->ds_Days;
86 dt.dat_Stamp.ds_Minute = ds->ds_Minute;
87 dt.dat_Stamp.ds_Tick = ds->ds_Tick;
88 dt.dat_Format = FORMAT_DEF;
89 dt.dat_Flags = 0;
90 dt.dat_StrDay = NULL;
91 dt.dat_StrDate = strdate;
92 dt.dat_StrTime = strtime;
93 DateToStr(&dt);
94 if(currdate.ds_Days == ds->ds_Days)
96 Printf("%s| %2ld-%s: %s\n", strtime, level, origin, errstr);
97 } else {
98 Printf("%s %s| %2ld-%s: %s\n", strdate, strtime, level, origin, errstr);
100 } else {
101 Printf("%2ld-%s: %s\n", level, origin, errstr);
103 pem = pem->ln_Succ;
105 if(!ArgsArray[ARGS_NOFLUSH])
107 Forbid();
108 while(errmsgs->lh_Head->ln_Succ)
110 psdRemErrorMsg(errmsgs->lh_Head);
112 Permit();
114 if(!ArgsArray[ARGS_DEBUG])
116 psdUnlockPBase();
118 CloseLibrary(ps);
119 } else {
120 errmsg = "Unable to open poseidon.library\n";
122 fail(errmsg);
123 return(0); // never gets here, just to shut the compiler up